Example usage for javax.json JsonObject entrySet

List of usage examples for javax.json JsonObject entrySet

Introduction

In this page you can find the example usage for javax.json JsonObject entrySet.

Prototype

Set<Map.Entry<K, V>> entrySet();

Source Link

Document

Returns a Set view of the mappings contained in this map.

Usage

From source file:at.porscheinformatik.sonarqube.licensecheck.license.License.java

@Deprecated
private static void readLegacyJson(String serializedLicensesString, List<License> licenses) {
    // deprecated - remove with later release
    try (JsonReader jsonReader = Json.createReader(new StringReader(serializedLicensesString))) {
        JsonObject licensesJson = jsonReader.readObject();
        for (Map.Entry<String, JsonValue> licenseJson : licensesJson.entrySet()) {
            JsonObject value = (JsonObject) licenseJson.getValue();
            licenses.add(new License(value.getString("name"), licenseJson.getKey(), value.getString("status")));
        }//from  ww  w.  j av a  2s .  c o m
    }
}

From source file:uk.ac.ebi.ep.data.service.BioPortalService.java

@Transactional
public String getDiseaseDescription(String term) {
    String definition = "";

    // Reader reader = new StringReader(get(REST_URL + "/search?q=" + term+"&ontology={EFO,MeSH,OMIM}&exact_match=true"));
    Reader reader = new StringReader(get(REST_URL + "/search?q=" + term));

    JsonReader jsonReader = Json.createReader(reader);

    JsonObject jo = jsonReader.readObject();

    JsonArray jsonArray = jo.getJsonArray("collection");
    for (JsonObject obj : jsonArray.getValuesAs(JsonObject.class)) {

        for (Map.Entry<String, JsonValue> entry : obj.entrySet()) {

            if (entry.getKey().equalsIgnoreCase(DEFINITION)) {

                definition = entry.getValue().toString().replace("\"", "").replaceAll("\\[", "")
                        .replaceAll("\\]", "");
            }/*from   w  w  w .j a  va 2  s  . c  o  m*/

        }
    }

    return definition;
}

From source file:org.ocelotds.marshalling.ArgumentServices.java

public Map getJavaResultFromSpecificUnmarshallerMap(String json, IJsonMarshaller marshaller)
        throws JsonUnmarshallingException {
    try {/*ww w  .  j av  a  2s .  c o m*/
        Map<String, Object> result = new HashMap();
        JsonReader createReader = Json.createReader(new StringReader(json));
        JsonObject readObject = createReader.readObject();
        for (Map.Entry<String, JsonValue> entry : readObject.entrySet()) {
            String key = entry.getKey();
            JsonValue jsonValue = entry.getValue();
            result.put(key, marshaller.toJava(jsonValue.toString()));
        }
        return result;
    } catch (Throwable t) {
        throw new JsonUnmarshallingException(t.getMessage());
    }
}

From source file:uk.ac.ebi.ep.adapter.bioportal.BioPortalService.java

@Override
public Disease getDisease(String term) throws BioportalAdapterException {
    String definition = "";

    // Reader reader = new StringReader(get(REST_URL + "/search?q=" + term+"&ontology={EFO,MeSH,OMIM}&exact_match=true"));
    Reader reader = new StringReader(get(REST_URL + "/search?q=" + term));

    JsonReader jsonReader = Json.createReader(reader);

    JsonObject jo = jsonReader.readObject();

    JsonArray jsonArray = jo.getJsonArray("collection");
    Disease disease = null;/* w w w.  ja va 2s .c o m*/
    for (JsonObject obj : jsonArray.getValuesAs(JsonObject.class)) {
        disease = new Disease();
        disease.setId(term);
        for (Map.Entry<String, JsonValue> entry : obj.entrySet()) {

            if (entry.getKey().equalsIgnoreCase(LABEL)) {
                String name = entry.getValue().toString();
                disease.setName(name);

            }
            if (entry.getKey().equalsIgnoreCase(DEFINITION)) {

                definition = entry.getValue().toString().replace("\"", "").replaceAll("\\[", "")
                        .replaceAll("\\]", "");
                disease.setDescription(definition);
            }

        }
    }

    return disease;
}

From source file:uk.ac.ebi.ep.adapter.bioportal.BioPortalService.java

@Override
public Disease getDiseaseByName(String term, String diseaseId) throws BioportalAdapterException {
    String definition = "";

    // Reader reader = new StringReader(get(REST_URL + "/search?q=" + term+"&ontology={EFO,MeSH,OMIM}&exact_match=true"));
    Reader reader = new StringReader(get(REST_URL + "/search?q=" + term));

    JsonReader jsonReader = Json.createReader(reader);

    JsonObject jo = jsonReader.readObject();

    JsonArray jsonArray = jo.getJsonArray("collection");
    Disease disease = null;/*from ww w.j a v a 2 s.  c  o  m*/
    for (JsonObject obj : jsonArray.getValuesAs(JsonObject.class)) {
        disease = new Disease();
        disease.setId(diseaseId);
        for (Map.Entry<String, JsonValue> entry : obj.entrySet()) {

            switch (entry.getKey()) {
            case LABEL:
                if (entry.getKey().equalsIgnoreCase(LABEL)) {
                    String name = entry.getValue().toString();
                    name = name.replaceAll("^\"|\"$", "");
                    if (name.equalsIgnoreCase(term)) {
                        disease.setName(name);

                    }

                }
                break;
            case DEFINITION:
                if (entry.getKey().equalsIgnoreCase(DEFINITION)) {
                    definition = entry.getValue().toString().replace("\"", "").replaceAll("\\[", "")
                            .replaceAll("\\]", "");

                    disease.setDescription(definition);
                    return disease;
                }
                break;

            }

        }
    }

    return disease;
}

From source file:eu.forgetit.middleware.component.Condensator.java

public void imageClustering(Exchange exchange) {

    logger.debug("New message retrieved");

    JsonObject jsonBody = MessageTools.getBody(exchange);

    JsonObjectBuilder job = Json.createObjectBuilder();

    for (Entry<String, JsonValue> entry : jsonBody.entrySet()) {
        job.add(entry.getKey(), entry.getValue());
    }/*from  ww  w.ja va  2s  .c om*/

    if (jsonBody != null) {

        String xmlPath = jsonBody.getString("extractorOutput");
        logger.debug("Retrieved XML of image collection Path: " + xmlPath);
        job.add("extractorOutput", xmlPath);

        if (xmlPath != null && !xmlPath.isEmpty()) {

            String response = service.request(xmlPath);
            logger.debug("Image clustering result:\n" + response);
            job.add("result", response);

        } else {
            logger.debug("Unable to process XML results, wrong request");
            job.add("result", "Unable to process XML results, wrong request");
        }

        exchange.getOut().setBody(job.build().toString());
        exchange.getOut().setHeaders(exchange.getIn().getHeaders());

    }
}

From source file:eu.forgetit.middleware.component.Condensator.java

public void videoClustering(Exchange exchange) {

    System.out.println("New message retrieved");

    logger.debug("New message retrieved");

    JsonObject jsonBody = MessageTools.getBody(exchange);

    JsonObjectBuilder job = Json.createObjectBuilder();

    for (Entry<String, JsonValue> entry : jsonBody.entrySet()) {
        job.add(entry.getKey(), entry.getValue());
    }//from  w w w .  j  av a  2  s .  co  m

    if (jsonBody != null) {

        String videoXMLPath = jsonBody.getString("video_xmls");
        System.out.println("Retrieved Video XMLs Path: " + videoXMLPath);

        //String method = jsonBody.getString("method");
        //System.out.println("Retrieved VAM: "+method);

        // ONE video per call

        if (videoXMLPath != null && !videoXMLPath.isEmpty()) {

            System.out.println("Executing Video Clustering Method: ");

            String response_temp = service.video_clustering_request(videoXMLPath);

            System.out.println("Clustering method result:\n" + response_temp);
            // callid is returned at the response 
            String callid;
            String[] callid_tmp = response_temp.split("::");
            callid = callid_tmp[1].trim();
            String response = service.video_clustering_result(callid);

            logger.debug("Video Clustering result:\n" + response);

            job.add("result", response);

        } else {

            System.out.println("Unable to process video xmls, wrong request");
            job.add("result", "Unable to process video, wrong request");

        }

        exchange.getOut().setBody(job.build().toString());
        exchange.getOut().setHeaders(exchange.getIn().getHeaders());

    }

}

From source file:httputils.RavelloHttpClient.java

public JsonObject publishBlueprint(String applicationName, int blueprintId, int stopTime, int startupDelay,
        String preferredCloud, String preferredRegion, boolean startAllVms, boolean costOptimized)
        throws RavelloException, InterruptedException {
    JsonObject value = null;//from   www  .  j  av  a 2 s.  c om
    HttpResponse response = null;

    try {
        response = this.getBlueprint(blueprintId);
        if (!HttpUtil.verifyResponseWithoutConsuming(response)) {
            EntityUtils.consumeQuietly(response.getEntity());
            throw new RavelloException("Failed to get blueprint number " + blueprintId + " error: "
                    + response.getStatusLine().toString());
        }
        JsonObject vmTemp = HttpUtil.convertResponseToJson(response);
        EntityUtils.consume(response.getEntity());

        JsonBuilderFactory factory = Json.createBuilderFactory(null);
        Iterator<Map.Entry<String, JsonValue>> it = vmTemp.entrySet().iterator();
        JsonObjectBuilder builder = factory.createObjectBuilder();
        Map.Entry<String, JsonValue> ent;
        while (it.hasNext()) {
            ent = it.next();
            if (!ent.getKey().equals("id") && !ent.getKey().equals("owner")) {
                builder.add(ent.getKey(), ent.getValue());
            }
        }
        builder.add("name", applicationName);
        value = builder.build();
        vmTemp = null;

        response = this.createApplication(value);
        this.verifyResponseAndConsume(response, "Failed to create application - error: ");

        value = HttpUtil.convertResponseToJson(response);
        EntityUtils.consumeQuietly(response.getEntity());

        int appId = value.getInt("id");

        if (costOptimized) {
            value = factory.createObjectBuilder().add("startAllVms", startAllVms).build();
        } else {
            value = factory.createObjectBuilder().add("startAllVms", startAllVms)
                    .add("preferredCloud", preferredCloud).add("preferredRegion", preferredRegion)
                    .add("optimizationLevel", "PERFORMANCE_OPTIMIZED").build();
        }
        response = this.post("/applications/" + appId + "/publish", value);
        this.verifyResponseAndConsume(response, "Failed to publish application - error: ");

        value = factory.createObjectBuilder().add("expirationFromNowSeconds", stopTime).build();
        response = this.post("/applications/" + appId + "/setExpiration", value);
        if (!HttpUtil.verifyResponseAndConsume(response)) {
            throw new RavelloException("Failed to set expiration time for application - error: "
                    + response.getStatusLine().toString() + "\n"
                    + "THIS ERROR MAY CAUSE APPLICATION TO RUN INDEFINITELY - MAKE SURE TO CHECK IT STOPPED");
        }

        if (!startAllVms) {
            response = this.getApplication(appId);
            if (!HttpUtil.verifyResponseWithoutConsuming(response)) {
                EntityUtils.consumeQuietly(response.getEntity());
                throw new RavelloException(
                        "Failed to get application status - error: " + response.getStatusLine().toString());
            }
            value = HttpUtil.convertResponseToJson(response);

            return value;
        }

        String state;
        JsonArray jArr;
        boolean allStarted;
        while (true) {
            allStarted = true;
            response = this.getApplication(appId);
            if (!HttpUtil.verifyResponseWithoutConsuming(response)) {
                EntityUtils.consumeQuietly(response.getEntity());
                throw new RavelloException(
                        "Failed to get application status - error: " + response.getStatusLine().toString());
            }
            value = HttpUtil.convertResponseToJson(response);

            jArr = value.getJsonObject("deployment").getJsonArray("vms");
            for (int jt = 0; jt < jArr.size(); jt++) {
                state = jArr.getJsonObject(jt).getString("state");
                allStarted = state.equals("STARTED");
                if (state.equals("ERROR")) {
                    throw new RavelloException(
                            "vm" + jArr.getJsonObject(jt).getString("name") + " failed to start");
                }
                if (!allStarted) {
                    break;
                }
            }

            if (allStarted) {
                break;
            } else {
                EntityUtils.consumeQuietly(response.getEntity());
                Thread.sleep(20000);
            }
        }

    } catch (ClientProtocolException e) {
        throw new RavelloException("ClientProtocolException - " + e.getMessage());
    } catch (IOException e) {
        throw new RavelloException("IOException - " + e.getMessage());
    } catch (NullPointerException e) {
        throw new RavelloException("NullPointerException - " + e.getMessage());
    }

    Thread.sleep(startupDelay * 1000);

    return value;
}

From source file:eu.forgetit.middleware.component.Extractor.java

public void testZeedAnalysis(Exchange exchange) {

    logger.debug("New message retrieved");

    JsonObject jsonBody = MessageTools.getBody(exchange);

    JsonObjectBuilder job = Json.createObjectBuilder();

    for (Entry<String, JsonValue> entry : jsonBody.entrySet()) {
        job.add(entry.getKey(), entry.getValue());
    }//w  w  w  .ja va  2s  .c o  m

    if (jsonBody != null) {

        String diary = jsonBody.getString("diary");
        logger.debug("Retrieved Video Path: " + diary);

        job.add("diary", diary);

        String imagePath = jsonBody.getString("imgPath");
        logger.debug("Retrieved VAM: " + imagePath);

        job.add("imgPath", imagePath);

        // ONE video per call

        if (diary != null && !diary.isEmpty()) {
            if (imagePath != null && !imagePath.isEmpty()) {

                logger.debug(
                        "Executing Zero Example Event Detection Method for image collection: " + imagePath);

                String response = service.zeed_request(diary, imagePath);

                logger.debug("Zeed method for text file: " + imagePath + " result:\n" + response);

            } else {

                logger.debug("Unable to process image collection, wrong request");

            }

        } else {

            logger.debug("Unable to process textual information, wrong request");

        }

    }

}

From source file:eu.forgetit.middleware.component.Extractor.java

public void testVideoAnalysis(Exchange exchange) {

    logger.debug("New message retrieved");

    JsonObject jsonBody = MessageTools.getBody(exchange);

    JsonObjectBuilder job = Json.createObjectBuilder();

    for (Entry<String, JsonValue> entry : jsonBody.entrySet()) {
        job.add(entry.getKey(), entry.getValue());
    }/*  www .j a  va2s  .  c  o m*/

    if (jsonBody != null) {

        String videoPath = jsonBody.getString("videoPath");
        logger.debug("Retrieved Video Path: " + videoPath);

        job.add("videoPath", videoPath);

        String method = jsonBody.getString("method");
        logger.debug("Retrieved VAM: " + method);

        job.add("method", method);

        // ONE video per call

        if (videoPath != null && !videoPath.isEmpty()) {

            logger.debug("Executing Video Analysis Method: " + method);

            String result = service.video_request(videoPath, method);

            //System.out.println("VAM method "+method+" result:\n"+result);

            //  Video analysis service response
            String response = service.video_results(videoPath);

            logger.debug("VAM method " + method + " result:\n" + response);

            job.add("result", response);

        } else {

            logger.debug("Unable to process video, wrong request");

            job.add("result", "Unable to process video, wrong request");

        }

        exchange.getOut().setBody(job.build().toString());
        exchange.getOut().setHeaders(exchange.getIn().getHeaders());

    }

}