Example usage for javax.json JsonObjectBuilder add

List of usage examples for javax.json JsonObjectBuilder add

Introduction

In this page you can find the example usage for javax.json JsonObjectBuilder add.

Prototype

JsonObjectBuilder add(String name, JsonArrayBuilder builder);

Source Link

Document

Adds a name/ JsonArray pair to the JSON object associated with this object builder.

Usage

From source file:org.grogshop.services.endpoints.impl.ShopItemsServiceImpl.java

@Override
public Response getAllItems() throws ServiceException {
    List<Item> allItems = itemsService.getAllItems();
    JsonArrayBuilder jsonArrayBuilder = Json.createArrayBuilder();
    JsonObjectBuilder jsonObjectBuilder = Json.createObjectBuilder();
    for (Item i : allItems) {
        jsonObjectBuilder.add("id", (i.getId() == null) ? "" : i.getId().toString())
                .add("user_id", (i.getUser().getId() == null) ? "" : i.getUser().getId().toString())
                .add("user_email", (i.getUser().getEmail() == null) ? "" : i.getUser().getEmail())
                .add("club_id", (i.getClub().getId() == null) ? "" : i.getClub().getId().toString())
                .add("type", (i.getType() == null) ? "" : i.getType().toString())
                .add("name", (i.getName() == null) ? "" : i.getName())
                .add("description", (i.getDescription() == null) ? "" : i.getDescription())
                .add("hasImage", i.hasImage())
                .add("minPrice", (i.getMinPrice() == null) ? "" : i.getMinPrice().toString())
                .add("maxPrice", (i.getMaxPrice() == null) ? "" : i.getMaxPrice().toString());

        if (i.getTags() != null) {
            JsonArrayBuilder jsonArrayBuilderInterest = Json.createArrayBuilder();
            for (String s : i.getTags()) {
                jsonArrayBuilderInterest.add(Json.createObjectBuilder().add("text", s));
            }//  w w w.  j a  v a2 s.  co m
            jsonObjectBuilder.add("tags", jsonArrayBuilderInterest);
        }
        jsonArrayBuilder.add(jsonObjectBuilder);
    }
    JsonArray jsonArray = jsonArrayBuilder.build();
    return Response.ok(jsonArray.toString()).build();

}

From source file:org.grogshop.services.endpoints.impl.ShopItemsServiceImpl.java

@Override
public Response getAllItemsByClub(@PathParam("id") Long club_id) throws ServiceException {
    List<Item> allItems = itemsService.getAllItemsByClub(club_id);
    JsonArrayBuilder jsonArrayBuilder = Json.createArrayBuilder();
    JsonObjectBuilder jsonObjectBuilder = Json.createObjectBuilder();
    for (Item i : allItems) {
        jsonObjectBuilder.add("id", (i.getId() == null) ? "" : i.getId().toString())
                .add("user_id", (i.getUser().getId() == null) ? "" : i.getUser().getId().toString())
                .add("user_email", (i.getUser().getEmail() == null) ? "" : i.getUser().getEmail())
                .add("club_id", (i.getClub().getId() == null) ? "" : i.getClub().getId().toString())
                .add("type", (i.getType() == null) ? "" : i.getType().toString())
                .add("name", (i.getName() == null) ? "" : i.getName())
                .add("description", (i.getDescription() == null) ? "" : i.getDescription())
                .add("hasImage", i.hasImage())
                .add("minPrice", (i.getMinPrice() == null) ? "" : i.getMinPrice().toString())
                .add("maxPrice", (i.getMaxPrice() == null) ? "" : i.getMaxPrice().toString());

        if (i.getTags() != null) {
            JsonArrayBuilder jsonArrayBuilderInterest = Json.createArrayBuilder();
            for (String s : i.getTags()) {
                jsonArrayBuilderInterest.add(Json.createObjectBuilder().add("text", s));
            }//from w w w  .j a v  a 2 s.  c o m
            jsonObjectBuilder.add("tags", jsonArrayBuilderInterest);

        }
        jsonArrayBuilder.add(jsonObjectBuilder);
    }
    JsonArray jsonArray = jsonArrayBuilder.build();
    return Response.ok(jsonArray.toString()).build();

}

From source file:org.grogshop.services.endpoints.impl.ShopItemsServiceImpl.java

@Override
public Response getAllItemsByUser(@PathParam("id") Long userId) throws ServiceException {
    List<Item> allItems = itemsService.getAllItemsByUser(userId);
    JsonArrayBuilder jsonArrayBuilder = Json.createArrayBuilder();
    JsonObjectBuilder jsonObjectBuilder = Json.createObjectBuilder();
    for (Item i : allItems) {
        jsonObjectBuilder.add("id", (i.getId() == null) ? "" : i.getId().toString())
                .add("user_id", (i.getUser().getId() == null) ? "" : i.getUser().getId().toString())
                .add("user_email", (i.getUser().getEmail() == null) ? "" : i.getUser().getEmail())
                .add("club_id", (i.getClub().getId() == null) ? "" : i.getClub().getId().toString())
                .add("type", (i.getType() == null) ? "" : i.getType().toString())
                .add("name", (i.getName() == null) ? "" : i.getName())
                .add("description", (i.getDescription() == null) ? "" : i.getDescription())
                .add("hasImage", i.hasImage())
                .add("minPrice", (i.getMinPrice() == null) ? "" : i.getMinPrice().toString())
                .add("maxPrice", (i.getMaxPrice() == null) ? "" : i.getMaxPrice().toString());

        if (i.getTags() != null) {
            JsonArrayBuilder jsonArrayBuilderInterest = Json.createArrayBuilder();
            for (String s : i.getTags()) {
                jsonArrayBuilderInterest.add(Json.createObjectBuilder().add("text", s));
            }/*  w  w  w  .j  av  a 2 s.  c om*/
            jsonObjectBuilder.add("tags", jsonArrayBuilderInterest);

        }
        jsonArrayBuilder.add(jsonObjectBuilder);
    }
    JsonArray jsonArray = jsonArrayBuilder.build();
    return Response.ok(jsonArray.toString()).build();

}

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());
    }/*  w  w w.j  a v  a  2  s  . c o 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:skillpro.asset.views.wizardpages.SEEResultPage.java

private void registerSEE(SEE see) throws ClientProtocolException, IOException {
    JsonObjectBuilder jsonBuilder = Json.createObjectBuilder();
    if (see.getSeeID() != null && !see.getSeeID().trim().isEmpty()) {
        jsonBuilder.add("seeId", see.getSeeID() == null ? UUID.randomUUID().toString() : see.getSeeID());
    }// w  w w  .ja va 2  s.c o  m

    if (see.getMESCommunication().getFirstElement() == MESCommType.OPCUA) {
        jsonBuilder.add("opcuaAddress", see.getMESCommunication().getSecondElement());
    }

    if (see.getResource() != null) {
        jsonBuilder.add("assetTypeNames", see.getResource().getName());
    }

    jsonBuilder.add("simulation", see.isSimulation() + "");

    String amlDescription = see.getAmlDescription();
    if (amlDescription != null && !amlDescription.trim().isEmpty()) {
        jsonBuilder.add("amlFile", amlDescription);
    }

    HttpPost request = new HttpPost(AMSServiceUtility.serviceAddress + "registerSEE");

    request.setEntity(new StringEntity(jsonBuilder.build().toString(), "UTF-8"));
    request.setHeader("Content-type", "application/json");

    HttpClient client = HttpClientBuilder.create().build();
    ;
    client.execute(request);
}

From source file:edu.harvard.iq.dataverse.mydata.MyDataFilterParams.java

public JsonObjectBuilder getDvObjectTypesAsJSON() {

    JsonArrayBuilder jsonArray = Json.createArrayBuilder();

    jsonArray/*from  w ww  .j  ava 2 s  . c o m*/
            .add(Json.createObjectBuilder().add("value", DvObject.DATAVERSE_DTYPE_STRING)
                    .add("label", SearchConstants.UI_DATAVERSES).add("selected", this.areDataversesIncluded()))
            .add(Json.createObjectBuilder().add("value", DvObject.DATASET_DTYPE_STRING)
                    .add("label", SearchConstants.UI_DATASETS).add("selected", this.areDatasetsIncluded()))
            .add(Json.createObjectBuilder().add("value", DvObject.DATAFILE_DTYPE_STRING)
                    .add("label", SearchConstants.UI_FILES).add("selected", this.areFilesIncluded()));

    JsonObjectBuilder jsonData = Json.createObjectBuilder();
    jsonData.add(SearchFields.TYPE, jsonArray);

    return jsonData;
}

From source file:searcher.CollStat.java

JsonArray constructJSONForDoc(IndexReader reader, Query q, int docid) throws Exception {
    Document doc = reader.document(docid);

    JsonArrayBuilder arrayBuilder = factory.createArrayBuilder();
    JsonObjectBuilder objectBuilder = factory.createObjectBuilder();
    objectBuilder.add("title", doc.get(WTDocument.WTDOC_FIELD_TITLE));
    objectBuilder.add("snippet", getSnippet(q, doc, docid));
    objectBuilder.add("id", doc.get(TrecDocIndexer.FIELD_ID));
    objectBuilder.add("url", doc.get(WTDocument.WTDOC_FIELD_URL));
    //objectBuilder.add("html", getBase64EncodedHTML(doc));
    arrayBuilder.add(objectBuilder);//from   w  ww. j  ava  2 s  .  co m
    return arrayBuilder.build();
}

From source file:com.open.shift.support.controller.SupportResource.java

@GET
@Produces(MediaType.APPLICATION_JSON)//from   w w  w.ja  va  2s .c  o  m
@Path("piechart")
public JsonObject generatePieChart() throws Exception {
    URL u = ctx.getResource("/WEB-INF/classes/templates/pie.json");
    String pieJson = null;
    if (OS.indexOf("win") >= 0) {
        pieJson = u.toString().substring(6);
    } else if (OS.indexOf("nux") >= 0) {
        pieJson = u.toString().substring(5);
    }

    JsonReader reader = Json.createReader(new FileReader(pieJson));
    JsonObject main = reader.readObject();
    JsonObjectBuilder title = Json.createObjectBuilder().add("text", "Companies Contribution in Deposits");
    JsonArrayBuilder data = Json.createArrayBuilder().add(Json.createArrayBuilder().add("Infosys").add(45.0))
            .add(Json.createArrayBuilder().add("TCS").add(26.8))
            .add(Json.createArrayBuilder().add("Oracle").add(8.5))
            .add(Json.createArrayBuilder().add("Accenture").add(6.2)).add(Json.createObjectBuilder()
                    .add("name", "IBM").add("y", 12.8).add("sliced", true).add("selected", true));
    JsonArrayBuilder series = Json.createArrayBuilder().add(
            Json.createObjectBuilder().add("type", "pie").add("name", "Deposit Contributed").add("data", data));

    JsonObjectBuilder mainJsonObj = Json.createObjectBuilder();
    for (Map.Entry<String, JsonValue> entrySet : main.entrySet()) {
        String key = entrySet.getKey();
        JsonValue value = entrySet.getValue();
        mainJsonObj.add(key, value);
    }
    mainJsonObj.add("title", title.build()).add("series", series.build());

    return mainJsonObj.build();
}

From source file:org.hyperledger.fabric_ca.sdk.HFCAIdentity.java

private JsonObject idToJsonObject() {
    JsonObjectBuilder ob = Json.createObjectBuilder();
    ob.add("id", enrollmentID);
    ob.add("type", type);
    if (null != maxEnrollments) {
        ob.add("max_enrollments", maxEnrollments);
    }//w w w  .j a  va 2  s.c  o  m
    if (affiliation != null) {
        ob.add("affiliation", affiliation);
    }
    JsonArrayBuilder ab = Json.createArrayBuilder();
    for (Attribute attr : attrs) {
        ab.add(attr.toJsonObject());
    }
    ob.add("attrs", ab.build());
    if (this.secret != null) {
        ob.add("secret", secret);
    }
    if (client.getCAName() != null) {
        ob.add(HFCAClient.FABRIC_CA_REQPROP, client.getCAName());
    }
    return ob.build();
}

From source file:co.runrightfast.vertx.orientdb.ODatabaseDocumentTxHealthCheck.java

@Override
protected Result check() throws Exception {
    try (final ODatabaseDocumentTx db = oDatabaseDocumentTxSupplier.get()) {
        final JsonObjectBuilder msgBuilder = Json.createObjectBuilder().add("db", getDatabaseInfo(db));
        if (CollectionUtils.isNotEmpty(documentObjects)) {
            final JsonObjectBuilder counts = Json.createObjectBuilder();
            documentObjects.stream().forEach(documentObject -> browseClass(db, documentObject, counts));
            msgBuilder.add("counts", counts);
        }//w  ww .jav a 2  s . c  om

        final JsonObject msg = msgBuilder.build();
        if (isHealthy(msg)) {
            return HealthCheck.Result.healthy(msg.toString());
        }
        return HealthCheck.Result.unhealthy(msg.toString());
    } catch (final Exception e) {
        final JsonObjectBuilder msg = Json.createObjectBuilder().add("db",
                Json.createObjectBuilder().add("name", databaseName).build());
        return HealthCheck.Result
                .unhealthy(new ODatabaseDocumentTxHealthCheckException(msg.build().toString(), e));
    }
}