Example #1
0
def toList(s, listid, dialname=None, listname=None):
    elem = JsonParser().parse(s)
    object = elem.getAsJsonObject()
    array = object.getAsJsonArray(listid)
    list = []
    lform = None
    if dialname != None: lform = miscutil.toListMap(dialname, listname)
    for i in range(array.size()):
        ma = {}
        o = array.get(i)
        #        print i,o
        s = o.entrySet()
        for e in s:
            #            print e,e.getKey(),e.getValue()
            if e.getValue().isJsonNull(): val = None
            else:
                if lform != None:
                    (ttype, after) = miscutil.getColumnDescr(lform, e.getKey())
                p = o.getAsJsonPrimitive(e.getKey())
                if p.isBoolean(): val = p.getAsBoolean()
                elif p.isNumber():
                    val = p.getAsDouble()
                    if lform != None:
                        if ttype == cutil.LONG: val = int(val)
                else:
                    val = p.getAsString()
                    if lform != None:
                        if ttype == cutil.DATE: val = con.StoDate(val)
                        if ttype == cutil.DATETIME:
                            val = con.StoDate(val, True)
            ma[e.getKey()] = val
        list.append(ma)

    return list
Example #2
0
def toList(s,listid,dialname=None,listname=None) :
    elem = JsonParser().parse(s)
    object = elem.getAsJsonObject()
    array = object.getAsJsonArray(listid)
    list=[]
    lform = None
    if dialname != None : lform = miscutil.toListMap(dialname,listname) 
    for i in range (array.size()) :
        ma = {}
        o = array.get(i)
#        print i,o
        s = o.entrySet()
        for e in s :
#            print e,e.getKey(),e.getValue()
            if e.getValue().isJsonNull() : val = None
            else :
                if lform != None : (ttype,after) = miscutil.getColumnDescr(lform,e.getKey())
                p = o.getAsJsonPrimitive(e.getKey())           
                if p.isBoolean() : val = p.getAsBoolean()
                elif  p.isNumber() :
                    val = p.getAsDouble()
                    if lform != None :
                        if ttype == cutil.LONG : val = int(val)
                else : 
                    val = p.getAsString()
                    if lform != None : 
                        if ttype == cutil.DATE : val = con.StoDate(val)
                        if ttype == cutil.DATETIME : val = con.StoDate(val,True)                                        
            ma[e.getKey()] = val
        list.append(ma)
           
    return list
def lookup_workspace_id_by_workspace_name(rest_api, workspace_name):
    request = QueryRequest("Workspace")
    request.setQueryFilter(QueryFilter("Name", "=", workspace_name))
    request.setFetch(Fetch(["ObjectId"]))

    workspace_query_response = rest_api.query(request)
    if workspace_query_response.wasSuccessful():
        result = workspace_query_response.getResults()
        parser = JsonParser()
        object = (parser.parse(result.toString())).get(0).getAsJsonObject()
        return object.get("ObjectID").getAsString()
Example #4
0
from com.google.gson import JsonObject
from com.google.gson import JsonParser
from com.google.gson import JsonPrimitive
from java.io import FileReader

separator = java.lang.System.getProperty("line.separator")

parser = JsonParser()
infile = (len(sys.argv) == 1) and sys.argv[0] or "config.json"
print "Processing ** '%s' **" % infile

reader = FileReader(infile)
json = parser.parse(reader)
nodeName = json.get('node').get('name')
node = AdminConfig.getid('/Node:%s/' % nodeName)
if not node:
  raise Exception("WebSphere node '%s' not found" % nodeName)


def hasAppName(appName):
  return len(AdminConfig.getid("/Deployment:" + appName + "/")) > 0


def printDeleteName(type, param):
  print "Deleting %s: %s" % (type, param.get('name'))


def printCreateName(type, param):
  print "Creating %s: %s" % (type, param.get('name'))

     */
    public void translateAString (String text) throws Exception {
        URL url = new URL (HOST + PATH + params);

        List<RequestBody> objList = new ArrayList<>();
        objList.add(new RequestBody(text));
        String content = new Gson().toJson(objList);
        translatedText = Post(url, content);
    }

    /*
     *  This function was not written by the team.
     *  Source: https://docs.microsoft.com/en-us/azure/cognitive-services/translator/quickstart-java-translate
     */
    public String prettify(String json_text) {
        JsonParser parser = new JsonParser();
        JsonElement json = parser.parse(json_text);
        Gson gson = new GsonBuilder().setPrettyPrinting().create();
        return gson.toJson(json);
    }

    /*
     *  Returns this part of json_text:
     *      "text":"[EVERYTHING IN HERE]","to":
     */
    public String getTextFromJson (String json_text) {
        return json_text.substring(json_text.indexOf("\"text\":") + 8, json_text.indexOf("\",\"to\":"));
    }

    /*
     *  Set the params global variable to be used in the next text translation.
Example #6
0
# for jython 2.1

from java.lang import System
print System.getProperty("java.version")

# JsonParser
from com.google.gson import JsonPrimitive
from com.google.gson import JsonParser
parser = JsonParser()

# read from file
from java.io import FileReader
reader = FileReader("/wasbear/server2.json")
json = parser.parse(reader)
json.get('node').isJsonArray()

json = parser.parse("{'node':{'name':'node01'}}")
node = json.get('node')