Example usage for javax.json Json createArrayBuilder

List of usage examples for javax.json Json createArrayBuilder

Introduction

In this page you can find the example usage for javax.json Json createArrayBuilder.

Prototype

public static JsonArrayBuilder createArrayBuilder() 

Source Link

Document

Creates a JSON array builder

Usage

From source file:edu.harvard.iq.dataverse.api.HarvestingServer.java

public static JsonArrayBuilder oaiSetsAsJsonArray(List<OAISet> oaiSets) {
    JsonArrayBuilder hdArr = Json.createArrayBuilder();

    for (OAISet set : oaiSets) {
        hdArr.add(oaiSetAsJson(set));//from  w w  w.  j  a  va2  s .  c o  m
    }
    return hdArr;
}

From source file:com.seniorproject.semanticweb.services.WebServices.java

public String prepareAdvancedSearchResult(String queryString, ArrayList<String> results)
        throws FileNotFoundException {
    JsonArrayBuilder out = Json.createArrayBuilder();
    JsonArrayBuilder resultArray = Json.createArrayBuilder();

    String words[] = queryString.split("\\s+");
    for (int i = 0; i < words.length; i++) {
        if (words[i].equalsIgnoreCase("select")) {
            int j = i + 1;
            if (words[j].equalsIgnoreCase("distinct")) {
                j++;/*from  w w  w.ja  va2 s .  c om*/
            }
            while (!words[j].equalsIgnoreCase("where")) {
                resultArray.add(words[j].substring(1));
                j++;
            }
            break;
        }
    }
    out.add(resultArray);

    for (String result : results) {
        List<String> matchList = new ArrayList<>();
        Pattern regex = Pattern.compile("[^\\s\"']+|\"[^\"]*\"|'[^']*'");
        Matcher regexMatcher = regex.matcher(result);
        while (regexMatcher.find()) {
            matchList.add(regexMatcher.group());
        }
        for (int i = 0; i < matchList.size(); i++) {
            resultArray.add(matchList.get(i));
        }
        out.add(resultArray);
    }
    return out.build().toString();
}

From source file:webservice.restful.creditcard.CreditCardAuthorizationService.java

@GET
@Produces(MediaType.APPLICATION_JSON)/*from   ww w  .ja  v a 2 s. c o  m*/
public JsonArray getStringList(@QueryParam("accountNumber") String accountNumber) {
    System.out.println("Getting String list with account number:" + accountNumber);
    JsonArrayBuilder arrayBld = Json.createArrayBuilder();
    List<String> strList = new ArrayList<>();
    strList.add("test 1");
    strList.add("test 2");
    strList.add("test 3");
    strList.add("test 4");
    strList.add("test 5");
    for (String str : strList) {
        arrayBld.add(str);
    }

    return arrayBld.build();
}

From source file:org.bsc.confluence.rest.AbstractRESTConfluenceService.java

/**
 *
 * @param inputData/*from  w  ww .j av a  2 s  .  co  m*/
 * @return
 */
protected final void rxAddLabels(String id, String... labels) {

    final JsonArrayBuilder inputBuilder = Json.createArrayBuilder();

    for (String name : labels) {

        inputBuilder.add(Json.createObjectBuilder().add("prefix", "global").add("name", name));

    }

    final JsonArray inputData = inputBuilder.build();

    final MediaType storageFormat = MediaType.parse("application/json");

    final RequestBody inputBody = RequestBody.create(storageFormat, inputData.toString());

    final HttpUrl url = urlBuilder().addPathSegment("content").addPathSegment(id).addPathSegment("label")
            .build();

    fromUrlPOST(url, inputBody, "add label");
}

From source file:com.buffalokiwi.aerodrome.jet.products.JetAPIProduct.java

/**
 * Adds product quantity and inventory data
 * @param product product data/*w w w  .  j a  v  a 2 s . co m*/
 * @return success
 * @throws APIException
 * @throws JetException
 */
@Override
public IJetAPIResponse sendPutProductInventory(final String sku, final List<FNodeInventoryRec> nodes)
        throws JetException, APIException {
    Utils.checkNull(sku, "sku");
    Utils.checkNull(nodes, "nodes");

    APILog.info(LOG, "Sending", sku, "inventory");

    final JsonObjectBuilder o = Json.createObjectBuilder();

    if (!nodes.isEmpty()) {
        final JsonArrayBuilder a = Json.createArrayBuilder();
        nodes.forEach(v -> a.add(v.toJSON()));
        o.add("fulfillment_nodes", a.build());
    }

    final IJetAPIResponse response = patch(config.getAddProductInventoryUrl(sku), o.build().toString(),
            getJSONHeaderBuilder().build());

    return response;
}

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

@Override
public Response get(@PathParam("id") Long item_id) throws ServiceException {
    Item i = itemsService.getById(item_id);
    JsonObjectBuilder jsonObjectBuilder = Json.createObjectBuilder();
    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 ww  w  . j a  v  a  2  s  .c  om
        jsonObjectBuilder.add("tags", jsonArrayBuilderInterest);
    }
    JsonObject build = jsonObjectBuilder.build();
    return Response.ok(build.toString()).build();

}

From source file:com.seniorproject.semanticweb.services.WebServices.java

public String prepareFacetedSearchResult(ArrayList<String> data, String category) throws FileNotFoundException {
    JsonArrayBuilder out = Json.createArrayBuilder();
    JsonObjectBuilder resultObject = Json.createObjectBuilder();
    for (String line : data) {
        List<String> matchList = new ArrayList<>();
        Pattern regex = Pattern.compile("[^\\s\"']+|\"[^\"]*\"|'[^']*'");
        Matcher regexMatcher = regex.matcher(line);
        while (regexMatcher.find()) {
            matchList.add(regexMatcher.group());
        }//from  w  ww . j  a v  a 2 s  . c o  m
        if (matchList.size() >= 2) {
            try (BufferedReader br = new BufferedReader(new FileReader(servletContext
                    .getRealPath("/WEB-INF/classes/hadoop/modified_isValueOfQuery/modified_isValueOfQuery_"
                            + category + ".txt")))) {
                String sCurrentLine;
                while ((sCurrentLine = br.readLine()) != null) {
                    if (matchList.get(0).equalsIgnoreCase(sCurrentLine)) {
                        matchList.set(0, "is " + matchList.get(0) + " of");
                        break;
                    }
                }
                resultObject.add("value", matchList.get(0));
                if (matchList.size() >= 2) {
                    resultObject.add("head", matchList.get(1).replace("\"", ""));
                } else {
                    resultObject.add("head", matchList.get(0).replace("\"", ""));
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            ;
        }
        out.add(resultObject);
    }
    return out.build().toString();
}

From source file:org.dcm4che3.tool.qc.QC.java

private static JsonArray initPatientObject(QC qc) {
    JsonArrayBuilder builder = Json.createArrayBuilder()
            .add(toAttributesObject(qc.getSourcePatientAttributes()))
            .add(toAttributesObject(qc.getTargetPatientAttributes()));
    return builder.build();
}

From source file:com.adobe.cq.wcm.core.components.extension.contentfragment.internal.models.v1.ContentFragmentImpl.java

@Nonnull
@Override//from  w ww  .  j ava  2s.  com
public String getEditorJSON() {
    JsonObjectBuilder jsonObjectBuilder = Json.createObjectBuilder();
    jsonObjectBuilder.add("title", fragment.getTitle());
    jsonObjectBuilder.add("path", path);
    if (variationName != null) {
        jsonObjectBuilder.add("variation", variationName);
    }
    if (elementNames != null) {
        JsonArrayBuilder arrayBuilder = Json.createArrayBuilder();
        for (String ele : elementNames) {
            arrayBuilder.add(ele);
        }
        jsonObjectBuilder.add("elements", arrayBuilder);
    }
    Iterator<Resource> associatedContentIter = fragment.getAssociatedContent();
    if (associatedContentIter.hasNext()) {
        JsonArrayBuilder associatedContentArray = Json.createArrayBuilder();
        while (associatedContentIter.hasNext()) {
            Resource resource = associatedContentIter.next();
            ValueMap vm = resource.adaptTo(ValueMap.class);
            JsonObjectBuilder contentObject = Json.createObjectBuilder();
            if (vm != null && vm.containsKey(JCR_TITLE)) {
                contentObject.add("title", vm.get(JCR_TITLE, String.class));
            }
            contentObject.add("path", resource.getPath());
            associatedContentArray.add(contentObject);
        }
        jsonObjectBuilder.add("associatedContent", associatedContentArray);
    }
    return jsonObjectBuilder.build().toString();
}

From source file:com.buffalokiwi.aerodrome.jet.products.JetAPIProduct.java

/**
 * Send shipping exceptions to jet //w  w  w.jav a 2s. c o  m
 * @param sku Sku 
 * @param nodes Filfillment nodes 
 * @return
 * @throws APIException
 * @throws JetException 
 */
@Override
public IJetAPIResponse sendPutProductShippingExceptions(final String sku, final List<FNodeShippingRec> nodes)
        throws APIException, JetException {
    checkSku(sku);

    if (nodes == null)
        throw new IllegalArgumentException("nodes cannot be null");

    APILog.info(LOG, "Sending", sku, "shipping exceptions");

    final JsonArrayBuilder b = Json.createArrayBuilder();
    for (final FNodeShippingRec node : nodes) {
        b.add(node.toJSON());
    }

    final JsonObjectBuilder o = Json.createObjectBuilder();
    o.add("fulfillment_nodes", b);

    final IJetAPIResponse response = put(config.getAddProductShipExceptionUrl(sku), o.build().toString(),
            getJSONHeaderBuilder().build());

    return response;
}