Example usage for com.google.gson JsonObject getAsJsonArray

List of usage examples for com.google.gson JsonObject getAsJsonArray

Introduction

In this page you can find the example usage for com.google.gson JsonObject getAsJsonArray.

Prototype

public JsonArray getAsJsonArray(String memberName) 

Source Link

Document

Convenience method to get the specified member as a JsonArray.

Usage

From source file:edu.isi.wings.portal.classes.JsonHandler.java

License:Apache License

public SetExpression deserialize(JsonElement el, Type typeOfSrc, JsonDeserializationContext context) {
    if (el.isJsonObject()) {
        JsonObject obj = el.getAsJsonObject();
        SetOperator op = context.deserialize(obj.get("op"), SetOperator.class);
        SetExpression expr = new SetExpression(op);
        for (JsonElement arg : obj.getAsJsonArray("args")) {
            expr.add((SetExpression) context.deserialize(arg, SetExpression.class));
        }// ww w .  j av  a  2 s  .c  om
        return expr;
    } else {
        String portid = el.getAsString();
        Port port = new Port(portid);
        return new SetExpression(SetOperator.XPRODUCT, port);
    }
}

From source file:edu.jhuapl.dorset.agents.FlickrAgent.java

License:Open Source License

protected String getImageUrl(String json) {
    Gson gson = new Gson();
    JsonObject jsonObj = gson.fromJson(json, JsonObject.class);
    JsonObject photos = jsonObj.getAsJsonObject("photos");
    JsonArray photoArray = photos.getAsJsonArray("photo");
    JsonObject photo = photoArray.get(0).getAsJsonObject();
    String id = photo.get("id").getAsString();
    String secret = photo.get("secret").getAsString();
    String server = photo.get("server").getAsString();
    String farm = photo.get("farm").getAsString();

    return "https://farm" + farm + ".staticflickr.com/" + server + "/" + id + "_" + secret + "_z.jpg";
}

From source file:edu.washington.iam.tools.netact.NetactDNSVerifier.java

License:Apache License

/**
 * Test if a user has ownership of a domain
 *
 * @param id user's uwnetid/*from   w w  w  . ja  v a2s .  c om*/
 * @param domain to test
 * @param return list of owners (can be null)
 */

public boolean isOwner(String dns, String id, List<String> owners) throws DNSVerifyException {

    boolean isOwner = false;
    if (id == null)
        id = "";
    log.debug("looking for owner (" + id + ") in " + dns);

    try {
        String[] urls = { hostUrl, domainUrl };
        for (String url : urls) {
            String respString = webClient.simpleRestGet(url + dns);
            // log.debug("got: " + respString);

            JsonParser parser = new JsonParser();
            JsonElement ele = parser.parse(respString);
            if (ele.isJsonObject()) {
                JsonObject resp = ele.getAsJsonObject();
                if (resp.get("table").isJsonObject()) {
                    JsonObject tbl = resp.getAsJsonObject("table");
                    if (tbl.get("row").isJsonArray()) {
                        JsonArray ids = tbl.getAsJsonArray("row");
                        for (int i = 0; i < ids.size(); i++) {
                            JsonObject idi = ids.get(i).getAsJsonObject();
                            JsonPrimitive oidu = idi.getAsJsonPrimitive("uwnetid");
                            if (oidu == null)
                                continue;
                            String oid = oidu.getAsString();
                            if (oid.equals(id)) {
                                if (owners == null)
                                    return true; // done
                                isOwner = true;
                            }
                            if (owners != null && !owners.contains(oid))
                                owners.add(oid);
                        }
                    } else {
                        String oid = tbl.getAsJsonObject("row").getAsJsonPrimitive("uwnetid").getAsString();
                        if (oid.equals(id)) {
                            if (owners == null)
                                return true; // done
                            isOwner = true;
                        }
                        if (owners != null && !owners.contains(oid))
                            owners.add(oid);
                    }
                }
            }
        }

    } catch (Exception e) {
        log.debug("netact dns lookup error: " + e);
        throw new DNSVerifyException(e.getMessage() + " : " + e.getCause());
    }

    // do substrings too
    dns = dns.replaceFirst("[^\\.]+\\.", "");
    // log.debug("do substrings: " + dns);
    int p = dns.indexOf(".");
    if (p > 0) {
        if (isOwner(dns, id, owners)) {
            if (owners == null)
                return true; // done
            isOwner = true;
        }
    }
    return isOwner;
}

From source file:es.bsc.demiurge.ws.rest.RestInputValidator.java

License:Open Source License

public void checkVmDescriptions(JsonObject vmsJson) {
    if (vmsJson.get("vms") == null) {
        throw new WebApplicationException(400);
    }/*from   ww w.j  a  va2  s . c  o  m*/

    String[] requiredParams = { "name", "image", "cpus", "ramMb", "diskGb" };
    JsonArray vmsJsonArray = vmsJson.getAsJsonArray("vms");
    for (JsonElement vmJsonElement : vmsJsonArray) {
        JsonObject vmJson = vmJsonElement.getAsJsonObject();
        for (String requiredParam : requiredParams) {

            // Check that the required parameters have been included
            if (vmJson.get(requiredParam) == null) {
                throw new WebApplicationException(400);
            }

            // Check that CPUs, ramMb, and diskGb have non-negative values
            if (requiredParam.equals("cpus") || requiredParam.equals("ramMb")
                    || requiredParam.equals("diskGb")) {
                if (vmJson.get(requiredParam).getAsInt() < 0) {
                    throw new WebApplicationException(400);
                }
            }

            // Check that the name is not empty
            if (requiredParam.equals("name")) {
                if (vmJson.get(requiredParam).getAsString().equals("")) {
                    throw new WebApplicationException(400);
                }
            }

        }
    }
}

From source file:eu.betaas.service.extendedservice.api.impl.LEZProcessor.java

License:Apache License

public synchronized void managePositionData(JsonObject data) {
    JsonObject jsonObj;/*from w  w  w . j ava  2  s  . co m*/
    JsonElement jsonElement;
    String lat, lon, userId;
    double latVal, lonVal;

    mLogger.info("Received position data");

    try {
        JsonObject serviceResult = data.getAsJsonObject(JSON_FIELD_SERVICE_RESULT);
        if (serviceResult == null) {
            mLogger.error("Cannot get ServiceResult");
            return;
        }

        JsonArray dataList = serviceResult.getAsJsonArray(JSON_FIELD_DATALIST);
        if (dataList == null) {
            mLogger.error("Cannot get dataList");
            return;
        }

        // scan all received points
        for (int i = 0; i < dataList.size(); i++) {
            jsonObj = dataList.get(i).getAsJsonObject();
            if (jsonObj == null) {
                mLogger.error("Cannot get data element n. " + i);
                return;
            }
            jsonElement = jsonObj.get(JSON_FIELD_USER_ID);
            if (jsonElement == null) {
                mLogger.error("Cannot get user ID from element n. " + i);
                return;
            }
            userId = jsonElement.toString();
            if (userId == null) {
                mLogger.error("Got null user ID from element n. " + i);
                return;
            }
            if (userId.startsWith("\""))
                userId = userId.substring(1);
            if (userId.endsWith("\""))
                userId = userId.substring(0, userId.length() - 1);
            if (userId.isEmpty()) {
                mLogger.error("Got empty user ID from element n. " + i);
                return;
            }

            try {
                jsonElement = jsonObj.get(JSON_FIELD_LAT);
                if (jsonElement == null) {
                    mLogger.error("Cannot get lat from element n. " + i);
                    return;
                }
                lat = jsonElement.toString();
                latVal = Double.parseDouble(lat);

                jsonElement = jsonObj.get(JSON_FIELD_LON);
                if (jsonElement == null) {
                    mLogger.error("Cannot get lon from element n. " + i);
                    return;
                }
                lon = jsonElement.toString();
                lonVal = Double.parseDouble(lon);

            } catch (Exception efe) {
                throw new Exception("Invalid numberic conversion on element n." + i + ": " + efe.getMessage());
            }

            processUserPosition(userId, latVal, lonVal);
        }

    } catch (Exception e) {
        mLogger.error("Cannot manage received position data: " + e.getMessage());
        e.printStackTrace();
    }

}

From source file:eu.betaas.service.extendedservice.api.impl.LEZProcessor.java

License:Apache License

public synchronized void manageTrafficData(JsonObject data) {
    JsonObject jsonObj;/*from w  ww.  java  2  s  .  com*/
    JsonElement jsonElement;
    String carsMinute, lat, lon;
    double latVal, lonVal;
    float carsMinuteVal;

    mLogger.info("Received traffic data");

    try {
        JsonObject serviceResult = data.getAsJsonObject(JSON_FIELD_SERVICE_RESULT);
        if (serviceResult == null) {
            mLogger.error("Cannot get ServiceResult");
            return;
        }

        JsonArray dataList = serviceResult.getAsJsonArray(JSON_FIELD_DATALIST);
        if (dataList == null) {
            mLogger.error("Cannot get dataList");
            return;
        }

        // scan all received elements
        for (int i = 0; i < dataList.size(); i++) {
            jsonObj = dataList.get(i).getAsJsonObject();
            if (jsonObj == null) {
                mLogger.error("Cannot get data element n. " + i);
                return;
            }

            try {
                jsonElement = jsonObj.get(JSON_FIELD_MEASUREMENT);
                if (jsonElement == null) {
                    mLogger.error("Cannot get measurement from element n. " + i);
                    return;
                }
                carsMinute = jsonElement.toString();
                if (carsMinute.startsWith("\""))
                    carsMinute = carsMinute.substring(1);
                if (carsMinute.endsWith("\""))
                    carsMinute = carsMinute.substring(0, carsMinute.length() - 1);
                carsMinuteVal = Float.parseFloat(carsMinute);

                jsonElement = jsonObj.get(JSON_FIELD_LAT);
                if (jsonElement == null) {
                    mLogger.error("Cannot get lat from element n. " + i);
                    return;
                }
                lat = jsonElement.toString();
                latVal = Double.parseDouble(lat);

                jsonElement = jsonObj.get(JSON_FIELD_LON);
                if (jsonElement == null) {
                    mLogger.error("Cannot get lon from element n. " + i);
                    return;
                }
                lon = jsonElement.toString();
                lonVal = Double.parseDouble(lon);

            } catch (Exception efe) {
                throw new Exception("Invalid numeric conversion on element n." + i + ": " + efe.getMessage());
            }

            processTrafficIntensity(latVal, lonVal, carsMinuteVal);
        }

    } catch (Exception e) {
        mLogger.error("Cannot manage received traffic data: " + e.getMessage());
    }
}

From source file:eu.betaas.service.servicemanager.application.RequestManager.java

License:Apache License

/**
 * @param serviceID/* ww  w .  j av a  2s.  c o  m*/
 * @param combineValues if true SM tries to combine (if possible) the values with the operator
 * @param token the Base64 encoded token to access the service 
 * @return the data provided by the thing service having the specified ID
 */
public String getThingServiceData(String serviceID, boolean combineValues, String token) {

    TaaSResourceManager taasRM = ServiceManager.getInstance().getResourceManagerIF();
    if (taasRM == null) {
        mLogger.error("TaaSRM not available to get data");
        return "";
    }

    byte[] decodedToken = null;
    try {
        if (token != null)
            decodedToken = Base64Utility.decode(token);
    } catch (Exception e) {
        mLogger.error("Cannot decode token: " + e.getMessage());
    }

    JsonObject data = taasRM.getData(serviceID, decodedToken);

    if (data == null) {
        mLogger.error("TaaSRM returned a null data");
        return "";
    }
    JsonObject serviceResult = data.getAsJsonObject("ServiceResult");
    if (serviceResult == null) {
        mLogger.error("ServiceResult not found in TaaSRM result");
        return "";
    }

    if (!combineValues) {
        return data.toString();
    }

    JsonElement operator = serviceResult.get("operator");
    JsonArray dataList = serviceResult.getAsJsonArray("dataList");
    try {
        String combinedResult = combine(dataList, operator);
        return combinedResult;
    } catch (Exception e) {
        mLogger.warn("Cannot combine received values: " + e.getMessage());
        mLogger.warn("Returning uncombined data");
        return data.toString();
    }
}

From source file:eu.betaas.taas.contextmanager.api.impl.ThingsServiceManagerImpl.java

License:Apache License

private JsonObject setContextThingServices(String sjoThingServiceNameList_new,
        JsonObject joThingServiceNameList) {
    JsonParser jp = new JsonParser();
    JsonObject joThingServiceNameList_new = (JsonObject) jp.parse(sjoThingServiceNameList_new);

    JsonArray jaThingServiceNameList_old = new JsonArray();

    JsonArray jaThingServiceNameList_new_list = (JsonArray) joThingServiceNameList_new.get(LIST);
    jaThingServiceNameList_old = joThingServiceNameList.getAsJsonArray(LIST);
    jaThingServiceNameList_old.addAll(jaThingServiceNameList_new_list);

    joThingServiceNameList.add(LIST, jaThingServiceNameList_old);

    JsonArray jaThingServiceNameList_new_listEq = (JsonArray) joThingServiceNameList_new.get(LIST_EQ);
    joThingServiceNameList.getAsJsonArray(LIST_EQ).addAll(jaThingServiceNameList_new_listEq);

    return joThingServiceNameList;
}

From source file:eu.betaas.taas.contextmanager.api.impl.ThingsServiceManagerImpl.java

License:Apache License

public JsonObject checkThingLocation(String term) {
    // true:sensor
    // false:actuator
    boolean bCorrect = true;
    boolean firstSenseOnly = false;

    JsonObject oTerm = null;//w w  w  . jav  a 2s  .c o  m
    JsonObject joTempResultValue = null;
    JsonObject joSynonymO = null;
    JsonObject joSynonymW = null;
    JsonArray jaSynonymsO = new JsonArray();
    JsonArray jaSynonymsW = new JsonArray();

    term = term.toLowerCase();
    mLogger.debug("Term: " + term.toUpperCase() + ".");

    try {
        // 1.- Verify if the term already exists on the ontology
        joTempResultValue = verifyTermOnOntology(term);
        if (!(joTempResultValue == null))
            mLogger.debug("- The term " + term.toUpperCase() + " is on the ontology. ");
        else {
            // The term is not in the ontology
            mLogger.debug("- The term " + term.toUpperCase() + " is NOT on the ontology. ");

            // 2.- Get all the synsets related with that term
            JsonArray aSynset = oWordNetUtils.getSynsets(term, true);

            mLogger.debug("- Different senses for the term " + term.toUpperCase() + ": ");
            if (aSynset.size() < 1)
                mLogger.debug("  No Synsets on Wordnet.");

            jaSynonymsO = new JsonArray();
            jaSynonymsW = new JsonArray();
            for (JsonElement sSynset : aSynset) {
                JsonObject joLemma = sSynset.getAsJsonObject();

                // SYNSETID
                String sTotalSynset = joLemma.get(SYNSETID).toString();
                String search4DigitSynset = sTotalSynset.substring(5, 9);
                String search8DigitSynset = sTotalSynset.substring(5, 13);
                // 3.- Check synonyms on the ontology
                bCorrect = verifySynset(search4DigitSynset);
                mLogger.debug("  Synset: " + sTotalSynset);

                // SYNONYMS
                String sSynonyms = joLemma.get(SYNONYM).toString().replace("\\\"", "");
                mLogger.debug("  Synonyms: " + sSynonyms);

                // DEFINITION
                String sDefinition = joLemma.get(DEFINITION).toString().replace("\\\"", "");
                mLogger.debug("  Definition: " + sDefinition);

                // Already exists some synonyms on the ontology
                if (bCorrect) {
                    joSynonymO = new JsonObject();
                    joSynonymO.addProperty(SYNSETID, search8DigitSynset);
                    joSynonymO.addProperty(SYNONYM, sSynonyms);
                    joSynonymO.addProperty(DEFINITION, sDefinition);
                    mLogger.debug("    YES, on the ontology you can find synomyns to the term "
                            + term.toUpperCase() + " with synset " + sTotalSynset + ".");
                    mLogger.debug("    The synonym common pattern is: " + search4DigitSynset);
                    mLogger.debug("    Synonyms on the ontology: " + lSynonyms.toUpperCase());
                    jaSynonymsO.add(joSynonymO);
                } else {
                    joSynonymW = new JsonObject();
                    joSynonymW.addProperty(SYNSETID, search8DigitSynset);
                    joSynonymW.addProperty(SYNONYM, sSynonyms);
                    joSynonymW.addProperty(DEFINITION, sDefinition);
                    mLogger.debug("    NO, on the ontology you can't find synomyns to the term "
                            + term.toUpperCase() + " with synset " + sTotalSynset
                            + ". The synonym common pattern is: " + search4DigitSynset);
                    jaSynonymsW.add(joSynonymW);

                    // HOLONYMS
                    JsonArray aHolonym = joLemma.getAsJsonArray(HOLONYM);
                    if (aHolonym == null) {//
                        mLogger.debug("    NO, there is not holonyms for the term " + term.toUpperCase()
                                + " on WORDNET.");

                        // HYPERNYMS
                        JsonArray aHypernym = joLemma.getAsJsonArray(HYPERNYM);
                        if (aHypernym == null)
                            mLogger.debug("    NO, there is not hypernyms for the term " + term.toUpperCase()
                                    + " on WORDNET.");
                        else {
                            mLogger.debug("    YES, there are hypernyms for the term " + term.toUpperCase()
                                    + " on WORDNET. Hypernyms: " + aHypernym.toString().toUpperCase());
                            for (JsonElement eHypernym : aHypernym) {
                                JsonObject jobject = eHypernym.getAsJsonObject();
                                String sHypernym = jobject.get(TERM).toString().replace("\"", "");

                                oTerm = verifyTermOnOntology(sHypernym);
                                if (!(oTerm == null)) {
                                    mLogger.debug("      YES, the term " + sHypernym.toString()
                                            + " is on the ONTOLOGY. Hypernyms: "
                                            + aHypernym.toString().toUpperCase());
                                    mLogger.debug("      Add term " + term.toUpperCase()
                                            + " on the ONTOLOGY. Term related with the hypernym "
                                            + sHypernym.toUpperCase());
                                    this.addThingType(sHypernym, term, search8DigitSynset, sDefinition);
                                    firstSenseOnly = true;
                                    joTempResultValue = oTerm;
                                    break;
                                } else {
                                    mLogger.debug("      NO, the term " + sHypernym.toUpperCase()
                                            + " is not on the ONTOLOGY.");

                                    // HYPERHYPERNYMS
                                    JsonArray aHyperHypernym = joLemma.getAsJsonArray(HYPERHYPERNYM);
                                    if (aHyperHypernym == null)
                                        mLogger.debug("      NO, there is not hyperhypernyms for the term "
                                                + sHypernym.toUpperCase() + " on WORDNET.");
                                    else {
                                        mLogger.debug("      YES, there are hyperhypernyms for the term "
                                                + sHypernym.toUpperCase() + " on WORDNET. Hyperhypernyms: "
                                                + aHyperHypernym.toString().toUpperCase());
                                        for (JsonElement eHyperHypernym : aHyperHypernym) {
                                            JsonObject jobject2 = eHyperHypernym.getAsJsonObject();
                                            String sHyperHypernym = jobject2.get(TERM).toString().replace("\"",
                                                    "");

                                            oTerm = verifyTermOnOntology(sHyperHypernym);
                                            if (!(oTerm == null)) {
                                                mLogger.debug(
                                                        "          YES, the term " + sHyperHypernym.toString()
                                                                + " is on the ONTOLOGY. HyperHypernyms: "
                                                                + aHyperHypernym.toString().toUpperCase());
                                                mLogger.debug("          Add term " + term.toUpperCase()
                                                        + " on the ONTOLOGY. Term related with the hyperhypernym "
                                                        + sHyperHypernym.toUpperCase());
                                                this.addThingType(sHyperHypernym, term, search8DigitSynset,
                                                        sDefinition);
                                                firstSenseOnly = true;
                                                joTempResultValue = oTerm;
                                                break;
                                            } else
                                                mLogger.debug(
                                                        "          NO, the term " + sHyperHypernym.toUpperCase()
                                                                + " is not on the ONTOLOGY.");
                                        }
                                    }

                                }
                            }
                        }

                    } else {
                        mLogger.debug("    YES, there are holonyms for the term " + term.toUpperCase()
                                + " on WORDNET. Holonyms: " + aHolonym.toString().toUpperCase());
                        for (JsonElement eHolonym : aHolonym) {
                            JsonObject jobject = eHolonym.getAsJsonObject();
                            String sHolonym = jobject.get(TERM).toString().replace("\"", "");

                            oTerm = verifyTermOnOntology(sHolonym);
                            if (!(oTerm == null)) {
                                mLogger.debug("      YES, the term " + sHolonym.toUpperCase()
                                        + " is on the ONTOLOGY. Holonyms: "
                                        + aHolonym.toString().toUpperCase());
                                mLogger.debug("      Add term " + term.toUpperCase()
                                        + " on the ONTOLOGY. Term related with the holonym "
                                        + sHolonym.toUpperCase());
                                this.addThingType(sHolonym, term, search8DigitSynset, sDefinition);
                                firstSenseOnly = true;
                                joTempResultValue = oTerm;
                                break;
                            } else {
                                mLogger.debug("      NO, the term " + sHolonym.toUpperCase()
                                        + " is not on the ONTOLOGY.");

                                // HYPERHOLONYMS
                                JsonArray aHyperHolonym = joLemma.getAsJsonArray(HYPERHOLONYM);
                                if (aHyperHolonym == null) {//
                                    mLogger.debug("    NO, there is not hyperholonyms for the term "
                                            + term.toUpperCase() + " on WORDNET.");
                                } else {
                                    mLogger.debug("    YES, there are hyperholonyms for the term "
                                            + term.toUpperCase() + " on WORDNET. Hyperholonyms: "
                                            + aHyperHolonym.toString().toUpperCase());
                                    for (JsonElement eHyperHolonym : aHyperHolonym) {
                                        JsonObject jobject1 = eHyperHolonym.getAsJsonObject();
                                        String sHyperHolonym = jobject1.get(TERM).toString().replace("\"", "");

                                        oTerm = verifyTermOnOntology(sHyperHolonym);
                                        if (!(oTerm == null)) {
                                            mLogger.debug("      YES, the term " + sHyperHolonym.toUpperCase()
                                                    + " is on the ONTOLOGY. HyperHolonyms: "
                                                    + aHyperHolonym.toString().toUpperCase());
                                            mLogger.debug("      Add term " + term.toUpperCase()
                                                    + " on the ONTOLOGY. Term related with the hyperholonym "
                                                    + sHyperHolonym.toUpperCase());
                                            this.addThingType(sHyperHolonym, term, search8DigitSynset,
                                                    sDefinition);
                                            firstSenseOnly = true;
                                            joTempResultValue = oTerm;
                                            break;
                                        } else
                                            mLogger.debug("      NO, the term " + sHyperHolonym.toUpperCase()
                                                    + " is not on the ONTOLOGY.");
                                    }
                                }

                            }
                        }
                    }

                    //
                    //            // HOLOHOLONYMS
                    //            JsonArray aHoloHolonym = joLemma.getAsJsonArray(HOLOHOLONYM);
                    //            if (aHoloHolonym == null) {//
                    //              mLogger.info("    NO, there is not holoholonyms for the term "+ term.toUpperCase()+ " on WORDNET.");
                    //              // //// HYPERNYMS 
                    //
                    //            } else {
                    //              mLogger.info("    YES, there are holoholonyms for the term "+ term.toUpperCase()+ " on WORDNET. Holonyms: "+ aHoloHolonym.toString().toUpperCase());
                    //              for (JsonElement eHoloHolonym : aHoloHolonym) {
                    //                JsonObject jobject = eHoloHolonym.getAsJsonObject();
                    //                String sHoloHolonym = jobject.get(TERM).toString().replace("\"", "");
                    //
                    //                JsonObject oTerm = verifyTermOnOntology(sHoloHolonym);
                    //                if (!(oTerm == null)) {
                    //                  mLogger.info("    YES, the term "+ sHoloHolonym.toUpperCase()+ " is on the ONTOLOGY. Holonyms: "+ aHoloHolonym.toString().toUpperCase());
                    //                  mLogger.info("    Add term "+ term.toUpperCase()+ " on the ONTOLOGY. Term related with the holonym "+ sHoloHolonym.toUpperCase());
                    //                } else
                    //                  mLogger.info("      NO, the term "+ sHoloHolonym.toUpperCase()+ " is not on the ONTOLOGY.");
                    //              }
                    //            }

                }
                mLogger.debug("");
            }

            if (!firstSenseOnly) {
                joTempResultValue = new JsonObject();
                joTempResultValue.add(TERM, new JsonPrimitive(term));

                // NO, on the ontology you can't find synomyns to the term
                if (jaSynonymsO.size() < 1) {
                    if (jaSynonymsW.size() == 1) {
                        joTempResultValue.add(DISAMBIGUATION, new JsonPrimitive(false));
                        mLogger.debug("      Add term " + term.toUpperCase() + " on the ONTOLOGY. ");
                        //              this.addThingType(null, term, search8DigitSynset, sDefinition);
                    } else
                        joTempResultValue.add(DISAMBIGUATION, new JsonPrimitive(true));
                    joTempResultValue.add(SYNONYMS, jaSynonymsW);
                } else {
                    // YES, on the ontology you can find synomyns to the term
                    if (jaSynonymsO.size() > 1) {
                        joTempResultValue.add(DISAMBIGUATION, new JsonPrimitive(true));
                        joTempResultValue.add(SYNONYMS, jaSynonymsO);
                    } else if (jaSynonymsO.size() == 1) {
                        joTempResultValue.add(DISAMBIGUATION, new JsonPrimitive(false));
                        joTempResultValue.add(SYNONYMS, jaSynonymsO);

                        JsonObject joTempResult = jaSynonymsO.get(0).getAsJsonObject();
                        addThingType(sBroaderTerm, term, joTempResult.get(SYNSETID).toString(),
                                joTempResult.get(DEFINITION).toString());
                    }
                }
            }
        }

        mLogger.info("- Sending JSON to disambiguate to the TA.");
        mLogger.info("  JSON: " + joTempResultValue.toString());
    } catch (Exception e) {
        mLogger.error(
                "CheckThingLocation " + e.getMessage() + " " + e.getLocalizedMessage() + " " + e.getCause());
    }
    return joTempResultValue;
}

From source file:eu.betaas.taas.securitymanager.taastrustmanager.taasproxy.TaaSCMClient.java

License:Apache License

public ArrayList<String> getThingServices() {
    logger.debug("Calling Get Thing Services to the CM for getting the full list");
    ArrayList<String> myList = null;
    try {/*  w w  w  .j  a  v a  2s. co  m*/
        // Retrieve the JasonArray object with the list
        String resList = myClient.getContextThingServices();
        JsonElement jelement = new JsonParser().parse(resList);
        JsonObject parsedRes = jelement.getAsJsonObject();
        JsonArray listArray = parsedRes.getAsJsonArray("list");

        // Transform the JasonArray in an ArrayList
        myList = new ArrayList<String>();
        for (int i = 0; i < listArray.size(); i++) {
            myList.add(listArray.get(i).getAsString());
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        return new ArrayList<String>();
    }

    logger.debug("Invocation done! Retrieved: " + myList.size());
    return myList;
}