Example usage for com.google.gson JsonArray iterator

List of usage examples for com.google.gson JsonArray iterator

Introduction

In this page you can find the example usage for com.google.gson JsonArray iterator.

Prototype

public Iterator<JsonElement> iterator() 

Source Link

Document

Returns an iterator to navigate the elements of the array.

Usage

From source file:edu.ufl.bmi.ontology.DtmJsonProcessor.java

License:Open Source License

public static void handlePublicationsThatUsedRelease(Map.Entry<String, JsonElement> e,
        HashMap<String, OWLNamedIndividual> niMap, OWLOntology oo, OWLDataFactory odf, IriLookup iriMap) {
    OWLNamedIndividual executableInd = niMap.get("executable");
    OWLNamedIndividual execInd = niMap.get("executionof");
    OWLNamedIndividual studyInd = niMap.get("studyexecution");

    JsonElement je = e.getValue();//  ww w .j av  a  2  s.  c o m
    if (je instanceof JsonArray) {
        JsonArray elemArray = (JsonArray) je;
        Iterator<JsonElement> elemIter = elemArray.iterator();

        ArrayList<String> pubInfo = new ArrayList<String>();
        ArrayList<OWLNamedIndividual> execInds = new ArrayList<OWLNamedIndividual>();
        ArrayList<OWLNamedIndividual> studyInds = new ArrayList<OWLNamedIndividual>();
        while (elemIter.hasNext()) {
            JsonElement elemi = elemIter.next();
            String value = ((JsonPrimitive) elemi).getAsString();

            if (value.contains("<li>")) {
                Document d = Jsoup.parse(value);
                Elements pubs = d.select("li");
                System.out.println("THERE ARE " + pubs.size() + " pubs that used release.");
                for (Element pub : pubs) {
                    pubInfo.add(pub.ownText().trim());
                    System.out.println("PUB USED: " + pub.ownText());
                }
            } else {
                String[] pubs = value.split(Pattern.quote(";"));
                //System.out.println("value = " + value);
                //System.out.println("THERE ARE " + pubs.length + " pubs that used release.");
                for (int i = 0; i < pubs.length; i++) {
                    pubInfo.add(pubs[i].trim());
                    System.out.println("PUB USED: " + pubs[i]);
                }
            }
        }

        addAnnotationToIndividual(execInd, iriMap.lookupAnnPropIri("label"),
                "execution of dtm for study described in " + pubInfo.get(0), odf, oo);
        addAnnotationToIndividual(studyInd, iriMap.lookupAnnPropIri("label"),
                "study process described in " + pubInfo.get(0), odf, oo);

        IRI pubIri = pubLinks.get(pubInfo.get(0));
        System.out.println("PUB USING IRI " + pubIri);
        if (pubIri != null) {
            OWLNamedIndividual pub = odf.getOWLNamedIndividual(pubIri);
            createOWLObjectPropertyAssertion(pub, iriMap.lookupObjPropIri("is about"), studyInd, odf, oo);
        }

        for (int i = 1; i < pubInfo.size(); i++) {
            OWLNamedIndividual execi = createNamedIndividualWithTypeAndLabel(odf, oo,
                    iriMap.lookupClassIri("executionof"), iriMap.lookupAnnPropIri("label"),
                    "execution of dtm for study described in " + pubInfo.get(i));
            OWLNamedIndividual studyi = createNamedIndividualWithTypeAndLabel(odf, oo,
                    iriMap.lookupClassIri("studyexecution"), iriMap.lookupAnnPropIri("label"),
                    "study process described in " + pubInfo.get(i));

            createOWLObjectPropertyAssertion(execi, iriMap.lookupObjPropIri("achieves objective"),
                    executableInd, odf, oo);
            createOWLObjectPropertyAssertion(execi, iriMap.lookupObjPropIri("is part of"), studyi, odf, oo);

            pubIri = pubLinks.get(pubInfo.get(i));
            System.out.println("PUB USING IRI " + pubIri);
            if (pubIri != null) {
                OWLNamedIndividual pub = odf.getOWLNamedIndividual(pubIri);
                createOWLObjectPropertyAssertion(pub, iriMap.lookupObjPropIri("is about"), studyi, odf, oo);
            }
        }

    } else {
        System.err.println("Publications that used release attribute has value that is not primitive.");
        throw new IllegalArgumentException(
                "value for pubsThatUsedRelease cannot be primitive (must be array).");
    }
}

From source file:edu.ufl.bmi.ontology.DtmJsonProcessor.java

License:Open Source License

public static void handleAvailableAt(Map.Entry<String, JsonElement> e,
        HashMap<String, OWLNamedIndividual> niMap, OWLOntology oo, OWLDataFactory odf, IriLookup iriMap) {
    OWLNamedIndividual executableInd = niMap.get("executable");
    OWLNamedIndividual execConcInd = niMap.get("executableConcretization");

    JsonElement je = e.getValue();//from  w w w .ja v  a 2s . c o  m
    if (je instanceof JsonArray) {
        JsonArray elemArray = (JsonArray) je;
        Iterator<JsonElement> elemIter = elemArray.iterator();
        int size = elemArray.size();
        while (elemIter.hasNext()) {
            JsonElement elemi = elemIter.next();
            if (elemi instanceof JsonPrimitive) {
                String value = ((JsonPrimitive) elemi).getAsString();
                if (value.equals("olympus")) {
                    createOWLObjectPropertyAssertion(olympus, iriMap.lookupObjPropIri("bearer"), execConcInd,
                            odf, oo);
                } else if (value.equals("udsi") || value.equals("uids")) {
                    handleUids(value, size, executableInd, execConcInd, iriMap, odf, oo);
                } else {
                    throw new IllegalArgumentException("value of availableAt must be 'olympus' or 'uids'");
                }
            } else {
                throw new IllegalArgumentException("value of availableAt must be primitive");
            }
        }
    } else {
        throw new IllegalArgumentException("value of availableAt must be array");
    }
}

From source file:edu.ufl.bmi.ontology.DtmJsonProcessor.java

License:Open Source License

public static void handleControlMeasures(Map.Entry<String, JsonElement> e,
        HashMap<String, OWLNamedIndividual> niMap, OWLOntology oo, OWLDataFactory odf, IriLookup iriMap) {
    /*//from   ww  w  .  java  2  s .  c o m
       Control measures are now an array of objects, not strings.
    */
    JsonElement je = e.getValue();
    if (je instanceof JsonArray) {
        JsonArray elemArray = (JsonArray) je;
        Iterator<JsonElement> elemIter = elemArray.iterator();
        int size = elemArray.size();
        while (elemIter.hasNext()) {
            JsonElement elemi = elemIter.next();
            JsonObject jo = (JsonObject) elemi;
            String value = jo.getAsJsonObject("identifier").getAsJsonPrimitive("identifierDescription")
                    .getAsString();

            uniqueCms.add(value);

            if (cmMap.containsKey(value)) {
                IRI classIri = cmMap.get(value);
                String cmInstanceLabel = value + " control measure by " + fullName;
                String simxInstanceLabel = "simulating of epidemic with " + value + " control measure by "
                        + fullName;
                OWLNamedIndividual simxInd = createNamedIndividualWithTypeAndLabel(odf, oo,
                        iriMap.lookupClassIri("simulatingx"), iriMap.lookupAnnPropIri("editor preferred"),
                        simxInstanceLabel);
                OWLNamedIndividual cmInd = createNamedIndividualWithTypeAndLabel(odf, oo, classIri,
                        iriMap.lookupAnnPropIri("editor preferred"), cmInstanceLabel);
                addAnnotationToIndividual(cmInd, iriMap.lookupAnnPropIri("label"), value, odf, oo);

                createOWLObjectPropertyAssertion(simxInd, iriMap.lookupObjPropIri("achieves objective"),
                        niMap.get("executable"), odf, oo);
                createOWLObjectPropertyAssertion(simxInd, iriMap.lookupObjPropIri("has specified output"),
                        cmInd, odf, oo);
            } else {
                System.err.println("Skipping " + value + " control measure.");
            }
        }
    } else {
        throw new IllegalArgumentException("value of controlMeasures attribute must be array");
    }
}

From source file:edu.ufl.bmi.ontology.DtmJsonProcessor.java

License:Open Source License

public static void handleDataInputFormats(Map.Entry<String, JsonElement> e,
        HashMap<String, OWLNamedIndividual> niMap, OWLOntology oo, OWLDataFactory odf, IriLookup iriMap) {

    ArrayList<String> inputs = null;
    if (ioInfo.getInputListForLabel(fullName) != null) {
        inputs = ioInfo.getInputListForLabel(fullName);
        System.out.println("Bypassing JSON data for curated software input data for: " + fullName + ", with "
                + inputs.size() + " inputs.");
    } else {/* w  ww.jav a  2  s .c o  m*/
        System.out.println("No curated software input data for: " + fullName);

        inputs = new ArrayList<String>();
        String values = "";
        JsonElement je = e.getValue();
        if (je instanceof JsonArray) {
            JsonArray elemArray = (JsonArray) je;
            Iterator<JsonElement> elemIter = elemArray.iterator();
            int size = elemArray.size();
            while (elemIter.hasNext()) {
                JsonElement elemi = elemIter.next();
                if (elemi instanceof JsonPrimitive) {
                    String value = ((JsonPrimitive) elemi).getAsString().trim();
                    if (value.trim().startsWith("<a href")) {
                        Document d = Jsoup.parse(value);
                        Elements links = d.select("a");
                        //String url = links.get(0).attr("href");
                        value = links.get(0).ownText();
                    }
                    values += value;
                    if (elemIter.hasNext())
                        values += ";"; //we're treating everything in the list as an alternative format for one input
                    uniqueInputFormats.add(value);
                } else {
                    System.err.println("Value of data input format attribute is not primitive.");
                }
            }
            inputs.add(values);
        }
    }

    //for each input we create a plan specification and relate it to the various data format specs that are options
    int iInput = 1;
    int cInput = inputs.size();
    Iterator<String> inputIter = inputs.iterator();
    while (inputIter.hasNext()) {
        //create the overall "data input plan specification"
        String planSpecPrefTerm = "data input #" + iInput + " of " + cInput + " for executable of " + fullName;
        OWLNamedIndividual planSpecInd = createNamedIndividualWithTypeAndLabel(odf, oo,
                iriMap.lookupClassIri("dataInputPlanSpecification"),
                iriMap.lookupAnnPropIri("editor preferred"), planSpecPrefTerm);
        //connect plan specification to executable.  The plan specification is part of the executable.
        createOWLObjectPropertyAssertion(planSpecInd, iriMap.lookupObjPropIri("is part of"),
                niMap.get("executable"), odf, oo);

        String inputFormatsConcat = inputIter.next();
        String[] inputFormats = inputFormatsConcat.split(Pattern.quote(";"));

        //for each format in the list for the current input, associate the input format with the input plan specification
        //  via a data parsing according to the input format specification.
        for (String inputFormat : inputFormats) {
            OWLNamedIndividual formatInd = formatInds.get(inputFormat);
            if (formatInd == null) {
                System.err.println("UNRECOGNIZED DATA INPUT FORMAT: " + inputFormat);

                /*
                   Go ahead and create a non-MDC-registered data format.  We just have to be careful when
                writing SPARQL queries that we do not count this format to the FAIR-o-meter metrics,
                both in terms of data formats in MDC, and in terms of the number of inputs with a data
                format registered in MDC. 
                */
                String formatSpecLabel = inputFormat
                        + ", a data format not cataloged in MDC, but that is used as " + "an input format to "
                        + fullName + ", which is a software that is cataloged in MDC.";
                formatInd = createNamedIndividualWithTypeAndLabel(odf, oo, iriMap.lookupClassIri("dataformat"),
                        iriMap.lookupAnnPropIri("editor preferred"), formatSpecLabel);

                formatInds.put(inputFormat, formatInd); //save just in case we encounter it again.                
            }

            addAnnotationToIndividual(formatInd, iriMap.lookupAnnPropIri("comment"),
                    "data input format for " + fullName, odf, oo);

            String dataParsingLabel = "data parsing of file in " + inputFormat + " format by " + fullName;
            OWLNamedIndividual dataParsingInd = createNamedIndividualWithTypeAndLabel(odf, oo,
                    iriMap.lookupClassIri("dataparsing"), iriMap.lookupAnnPropIri("editor preferred"),
                    dataParsingLabel);

            //connect parsing to format.  Parsing realizes data input format specification
            createOWLObjectPropertyAssertion(dataParsingInd, iriMap.lookupObjPropIri("achieves objective"),
                    formatInd, odf, oo);

            //connect parsing to plan specification.  Parsing realizes data input specification.
            createOWLObjectPropertyAssertion(dataParsingInd, iriMap.lookupObjPropIri("achieves objective"),
                    planSpecInd, odf, oo);
        }
        iInput++;
    }
}

From source file:edu.ufl.bmi.ontology.DtmJsonProcessor.java

License:Open Source License

public static void handleDataOutputFormats(Map.Entry<String, JsonElement> e,
        HashMap<String, OWLNamedIndividual> niMap, OWLOntology oo, OWLDataFactory odf, IriLookup iriMap) {
    ArrayList<String> outputs = null;
    if (ioInfo.getOutputListForLabel(fullName) != null) {
        outputs = ioInfo.getOutputListForLabel(fullName);
        System.out.println("Bypassing JSON data for curated software output data for: " + fullName + ", with "
                + outputs.size() + " outputs.");
    } else {//from w  w w .  jav a  2 s  .c  om
        outputs = new ArrayList<String>();
        JsonElement je = e.getValue();
        if (je instanceof JsonArray) {
            JsonArray elemArray = (JsonArray) je;
            Iterator<JsonElement> elemIter = elemArray.iterator();
            int size = elemArray.size();
            String values = "";
            while (elemIter.hasNext()) {
                JsonElement elemi = elemIter.next();
                if (elemi instanceof JsonPrimitive) {
                    String value = ((JsonPrimitive) elemi).getAsString();
                    uniqueOutputFormats.add(value);
                    if (!values.trim().toLowerCase().equals("n/a")) {
                        values += value;
                        if (elemIter.hasNext())
                            values += ";";
                    } else {
                        System.err.println("IGNORING BAD DATA OUTPUT FORMAT VALUE: " + value);
                    }
                } else { //end if instanceof JsonPrimitive
                    System.err.println("Value of dataOutputFormats attribute is not primitive: " + elemi);
                }
            } //end while
            outputs.add(values);
        } //end if instanceof JsonArraty
    } //end else

    int iOutput = 1;
    int cOutput = outputs.size();
    Iterator<String> outputIter = outputs.iterator();
    while (outputIter.hasNext()) {
        //create the overall "data output plan specification"
        String planSpecPrefTerm = "data output #" + iOutput + " of " + cOutput + " for executable of "
                + fullName;
        OWLNamedIndividual planSpecInd = createNamedIndividualWithTypeAndLabel(odf, oo,
                iriMap.lookupClassIri("dataOutputPlanSpecification"),
                iriMap.lookupAnnPropIri("editor preferred"), planSpecPrefTerm);
        //connect plan specification to executable.  The plan specification is part of the executable.
        createOWLObjectPropertyAssertion(planSpecInd, iriMap.lookupObjPropIri("is part of"),
                niMap.get("executable"), odf, oo);

        String outputFormatsConcat = outputIter.next();
        String[] outputFormats = outputFormatsConcat.split(Pattern.quote(";"));

        //for each format in the list for the current input, associate the input format with the input plan specification
        //  via a data encoding according to the input format specification.
        for (String outputFormat : outputFormats) {
            OWLNamedIndividual formatInd = formatInds.get(outputFormat);
            System.out.println("\nPROCESSING OUTPUT FORMAT: " + outputFormat);
            if (formatInd == null) {
                System.err.println("UNRECOGNIZED DATA OUTPUT FORMAT: " + outputFormat);

                /*
                   Go ahead and create a non-MDC-registered data format.  We just have to be careful when
                writing SPARQL queries that we do not count this format to the FAIR-o-meter metrics,
                both in terms of data formats in MDC, and in terms of the number of outputs with a data
                format registered in MDC. 
                */
                String formatSpecLabel = outputFormat
                        + ", a data format not cataloged in MDC, but that is used as " + "an output format by "
                        + fullName + ", which is a software that is cataloged in MDC.";
                formatInd = createNamedIndividualWithTypeAndLabel(odf, oo, iriMap.lookupClassIri("dataformat"),
                        iriMap.lookupAnnPropIri("editor preferred"), formatSpecLabel);

                formatInds.put(outputFormat, formatInd); //save just in case we encounter it again.                
            }

            addAnnotationToIndividual(formatInd, iriMap.lookupAnnPropIri("comment"),
                    "data output format for " + fullName, odf, oo);

            String dataEncodingLabel = "data encoding of file in " + outputFormat + " format by " + fullName;
            OWLNamedIndividual dataEncodingInd = createNamedIndividualWithTypeAndLabel(odf, oo,
                    iriMap.lookupClassIri("dataencoding"), iriMap.lookupAnnPropIri("editor preferred"),
                    dataEncodingLabel);

            //connect encoding to format.  Encoding realizes data output format specification
            createOWLObjectPropertyAssertion(dataEncodingInd, iriMap.lookupObjPropIri("achieves objective"),
                    formatInd, odf, oo);

            //connect encoding to plan specification.  Encoding realizes data output specification.
            createOWLObjectPropertyAssertion(dataEncodingInd, iriMap.lookupObjPropIri("achieves objective"),
                    planSpecInd, odf, oo);
        }
        iOutput++;
    }
}

From source file:edu.ufl.bmi.ontology.DtmJsonProcessor.java

License:Open Source License

public static void handlePublicationsAbout(Map.Entry<String, JsonElement> e,
        HashMap<String, OWLNamedIndividual> niMap, OWLOntology oo, OWLDataFactory odf, IriLookup iriMap) {
    JsonElement je = e.getValue();/*from w ww  .  j a v a 2 s  .co  m*/
    if (je instanceof JsonArray) {
        JsonArray elemArray = (JsonArray) je;
        Iterator<JsonElement> elemIter = elemArray.iterator();
        int size = elemArray.size();
        while (elemIter.hasNext()) {
            JsonElement elemi = elemIter.next();
            if (elemi instanceof JsonPrimitive) {
                String value = ((JsonPrimitive) elemi).getAsString();
                System.out.println("PUB ABOUT " + value);
                IRI pubIri = pubLinks.get(value);
                System.out.println("PUB ABOUT IRI = " + pubIri);
                if (pubIri != null) {
                    OWLNamedIndividual pub = odf.getOWLNamedIndividual(pubIri);
                    OWLNamedIndividual software = niMap.get("dtm");
                    createOWLObjectPropertyAssertion(pub, iriMap.lookupObjPropIri("is about"), software, odf,
                            oo);
                }
            }
        }
    } else {
        throw new IllegalArgumentException("value of publicationsAboutRelease must be array");
    }
}

From source file:edu.usmp.fia.taller.convalidacioncurso.servlet.RegistroDatos.java

@HttpMethod(HttpMethodType.POST)
@RequireLogin(false)//from   w w w . j  a  va  2 s.  c o m
public void registrarCursos() throws IOException, Exception {
    List<AlumnoConvalidacion> conalus;
    List<InsertConvalidacion> cons;
    String convalidacionesalumno = request.getParameter("convalidacionesalumno");
    String convalidaciones = request.getParameter("convalidaciones");

    JsonElement jsonConAlumno = new JsonParser().parse(convalidacionesalumno);
    JsonElement jsonConvalidaciones = new JsonParser().parse(convalidaciones);

    JsonArray array = jsonConAlumno.getAsJsonArray();
    JsonArray array1 = jsonConvalidaciones.getAsJsonArray();

    Iterator iterator = array.iterator();
    Iterator iterator1 = array1.iterator();

    conalus = new ArrayList<>();

    while (iterator.hasNext()) {
        JsonElement jsonconalu = (JsonElement) iterator.next();
        Gson gson = new Gson();
        AlumnoConvalidacion conalu = gson.fromJson(jsonconalu, AlumnoConvalidacion.class);
        conalus.add(conalu);

    }

    cons = new ArrayList<>();
    while (iterator1.hasNext()) {
        JsonElement jsoncon = (JsonElement) iterator1.next();
        Gson gson = new Gson();
        InsertConvalidacion con = gson.fromJson(jsoncon, InsertConvalidacion.class);
        cons.add(con);

    }

    DAOFactory oDAOFactory;
    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    Gson gson = new Gson();
    try {
        oDAOFactory = DAOFactory.getDAOFactory(DAOFactory.MYSQL);
        oDAOFactory.getConvalidacion().getHistoriaConvalidacion().registrarConvalidacionAlumno(conalus, cons);
        mensaje = "OK";
    } catch (Exception e) {

        mensaje = e.getMessage();
        throw e;
    } finally {
        out.print(gson.toJson(mensaje));
        out.close();
    }

}

From source file:edu.usmp.fia.taller.convalidacioncurso.servlet.RegistroDatos.java

@HttpMethod(HttpMethodType.POST)
@RequireLogin(false)/*  w  w w.  j a v  a 2  s  .  c  om*/
public void registrarConvalidacion() throws IOException, Exception {
    List<InsertConvalidacion> convalidaciones;
    String listjson = request.getParameter("listadata");

    JsonElement json = new JsonParser().parse(listjson);
    JsonArray array = json.getAsJsonArray();
    Iterator iterator = array.iterator();
    convalidaciones = new ArrayList<>();
    //System.out.println(convalidaciones);   
    while (iterator.hasNext()) {
        JsonElement json1 = (JsonElement) iterator.next();
        Gson gson = new Gson();
        InsertConvalidacion conva = gson.fromJson(json1, InsertConvalidacion.class);
        convalidaciones.add(conva);

    }

    DAOFactory oDAOFactory;
    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    Gson gson = new Gson();
    try {
        oDAOFactory = DAOFactory.getDAOFactory(DAOFactory.MYSQL);
        oDAOFactory.getConvalidacion().getHistoriaConvalidacion().registrarConvalidaciones(convalidaciones);
        ;
        mensaje = "OK";
    } catch (Exception e) {

        mensaje = e.getMessage();
        throw e;
    } finally {
        out.print(gson.toJson(mensaje));
        out.close();
    }

}

From source file:eu.seaclouds.platform.dashboard.resources.DeployerResource.java

License:Apache License

@GET
@Path("applications/{id}/sensors")
public Response availableSensors(@PathParam("id") String applicationId) {
    if (applicationId != null) {
        try {//from w ww  . jav a 2  s .c  o  m
            String rawEntityList = new HttpGetRequestBuilder().host(deployer.getEndpoint())
                    .setCredentials(deployer.getUser(), deployer.getPassword())
                    .path("/v1/applications/" + applicationId + "/entities").build();

            JsonArray entityList = new JsonParser().parse(rawEntityList).getAsJsonArray();
            JsonArray allMetricsList = new JsonArray();
            for (JsonElement entity : entityList) {
                String entityId = entity.getAsJsonObject().getAsJsonPrimitive("id").getAsString();
                String entityName = entity.getAsJsonObject().getAsJsonPrimitive("name").getAsString();

                // Creating entity object
                rawEntityList = new HttpGetRequestBuilder().host(deployer.getEndpoint())
                        .setCredentials(deployer.getUser(), deployer.getPassword())
                        .path("/v1/applications/" + applicationId + "/entities/" + entityId + "/sensors")
                        .build();

                JsonArray entityMetrics = new JsonParser().parse(rawEntityList).getAsJsonArray();
                Iterator<JsonElement> entityMetricsIterator = entityMetrics.iterator();

                while (entityMetricsIterator.hasNext()) {
                    JsonObject sensor = entityMetricsIterator.next().getAsJsonObject();
                    sensor.remove("links");

                    String rawSensorValue = new HttpGetRequestBuilder().host(deployer.getEndpoint())
                            .setCredentials(deployer.getUser(), deployer.getPassword())
                            .path("/v1/applications/" + applicationId + "/entities/" + entityId + "/sensors/"
                                    + sensor.get("name").getAsString())
                            .addParam("raw", "true").build();

                    sensor.addProperty("value", rawSensorValue);

                    if (rawSensorValue == null || rawSensorValue.isEmpty()) {
                        entityMetricsIterator.remove();

                    }

                }

                JsonObject entityJson = new JsonObject();
                entityJson.addProperty("id", entityId);
                entityJson.addProperty("name", entityName);
                entityJson.add("sensors", entityMetrics);

                allMetricsList.add(entityJson);
            }

            return Response.ok(allMetricsList.toString()).build();
        } catch (IOException | URISyntaxException e) {
            return Response.status(Response.Status.NOT_FOUND).build();
        }

    } else {
        return Response.status(Response.Status.BAD_REQUEST).build();
    }
}

From source file:eu.seaclouds.platform.dashboard.resources.DeployerResource.java

License:Apache License

private JsonArray retrieveMetrics(String applicationId, String entityId)
        throws IOException, URISyntaxException {
    String monitorResponse = new HttpGetRequestBuilder().host(deployer.getEndpoint())
            .setCredentials(deployer.getUser(), deployer.getPassword())
            .path("/v1/applications/" + applicationId + "/entities/" + entityId + "/sensors").build();

    JsonArray metricList = new JsonParser().parse(monitorResponse).getAsJsonArray();

    Iterator<JsonElement> metricIterator = metricList.iterator();

    while (metricIterator.hasNext()) {
        JsonObject metric = metricIterator.next().getAsJsonObject();
        metric.remove("links");
        if (!isNumberType(metric.getAsJsonPrimitive("type").getAsString())) {
            metricIterator.remove();//from w  ww.j  av  a 2  s.c o m
        }
    }

    return metricList.getAsJsonArray();

}