List of usage examples for javax.json JsonArrayBuilder add
JsonArrayBuilder add(JsonArrayBuilder builder);
From source file:com.buffalokiwi.aerodrome.jet.orders.OrderItemRec.java
/** * Turn this object into jet json //from w ww . ja v a 2 s . c o m * @return json */ public JsonObject toJSON() { JsonArrayBuilder adj = Json.createArrayBuilder(); for (FeeAdjRec f : adjustments) { adj.add(f.toJSON()); } return Json.createObjectBuilder().add("order_item_id", orderItemId).add("alt_order_item_id", altOrderItemId) .add("merchant_sku", merchantSku).add("product_title", title) .add("request_order_quantity", requestOrderQty) .add("request_order_cancel_qty", requestOrderCancelQty).add("adjustment_reason", adjReason) .add("item_tax_code", taxCode).add("url", url).add("price_adjustment", priceAdj.asBigDecimal()) .add("item_fees", fees.asBigDecimal()).add("tax_info", taxInfo).add("fee_adjustments", adj.build()) .add("regulatory_fees", regFees.asBigDecimal()) .add("order_item_acknowledgement_status", itemAckStatus.getText()) .add("item_price", itemPrice.toJSON()).build(); }
From source file:ch.bfh.abcvote.util.controllers.CommunicationController.java
/** * Posts the given ballot to the bulletin board * @param ballot Ballot to be posted to the bulletin board * @param useTor Boolean indicating if Ballot should be posted over the Tor network *//*from www.j a v a2 s .c o m*/ public void postBallot(Ballot ballot, Boolean useTor) { JsonObjectBuilder jBuilder = Json.createObjectBuilder(); //Translate ballot object into a json string JsonArrayBuilder optionsBuilder = Json.createArrayBuilder(); for (String option : ballot.getSelectedOptions()) { optionsBuilder.add(option); } jBuilder.add("e", optionsBuilder); jBuilder.add("u_Hat", ballot.getU_HatString()); jBuilder.add("c", ballot.getCString()); jBuilder.add("d", ballot.getDString()); jBuilder.add("pi1", ballot.getPi1String()); jBuilder.add("pi2", ballot.getPi2String()); jBuilder.add("pi3", ballot.getPi3String()); JsonObject model = jBuilder.build(); //josn gets posted to the bulletin board try { boolean requestOK = postJsonStringToURL( bulletinBoardUrl + "/elections/" + ballot.getElection().getId() + "/ballots", model.toString(), useTor); if (requestOK) { System.out.println("Ballot posted!"); } else { System.out.println("Was not able to post Ballot!"); } } catch (IOException ex) { System.out.println("Was not able to post Ballot!"); } }
From source file:ch.bfh.abcvote.util.controllers.CommunicationController.java
/** * Converts the given election object to a Json String. The Json string is then signed. * The resulting JWS gets posted to the bulletin board * @param election/* w w w . j a va 2 s . co m*/ * election object to be posted to the bulletin board */ public void postElection(Election election) { JsonObjectBuilder jBuilder = Json.createObjectBuilder(); DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); //Add Header information to the json object //TODO get email address from certificate jBuilder.add("author", "alice@bfh.ch"); jBuilder.add("electionTitle", election.getTitle()); jBuilder.add("beginDate", election.getStartDate().format(format)); jBuilder.add("endDate", election.getEndDate().format(format)); //toDo: get AppVersion dynamically from build jBuilder.add("appVersion", "0.15"); jBuilder.add("coefficients", election.getCredentialPolynomialString()); jBuilder.add("electionGenerator", election.getH_HatString()); //Add votingTopic to the Json Object JsonObjectBuilder votingTopicBuilder = Json.createObjectBuilder(); votingTopicBuilder.add("topic", election.getTopic().getTitle()); votingTopicBuilder.add("pick", election.getTopic().getPick()); JsonArrayBuilder optionsBuilder = Json.createArrayBuilder(); for (String option : election.getTopic().getOptions()) { optionsBuilder.add(option); } votingTopicBuilder.add("options", optionsBuilder); jBuilder.add("votingTopic", votingTopicBuilder); //Add the list of selected Voters to the Json object JsonArrayBuilder votersBuilder = Json.createArrayBuilder(); for (Voter voter : election.getVoterList()) { JsonObjectBuilder voterBuilder = Json.createObjectBuilder(); voterBuilder.add("email", voter.getEmail()); voterBuilder.add("publicCredential", voter.getPublicCredential()); voterBuilder.add("appVersion", voter.getAppVersion()); votersBuilder.add(voterBuilder); } jBuilder.add("voters", votersBuilder); JsonObject model = jBuilder.build(); //finished Json gets singed SignatureController signController = new SignatureController(); JsonObject signedModel = null; try { signedModel = signController.signJson(model); } catch (Exception ex) { Logger.getLogger(CommunicationController.class.getName()).log(Level.SEVERE, null, ex); } //JWS gets posted to the bulletin board try { boolean requestOK = postJsonStringToURL(bulletinBoardUrl + "/elections", signedModel.toString(), false); if (requestOK) { System.out.println("Election posted!"); } else { System.out.println("Was not able to post Election! Did not receive expected http 200 status."); } } catch (IOException ex) { System.out.println("Was not able to post Election! IOException"); } }
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++;/* ww w. ja v a 2s . 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:org.kitodo.production.forms.IndexingForm.java
/** * Return object types as JSONArray.//from www . ja va 2 s. co m * * @return JSONArray containing objects type constants. */ @SuppressWarnings("unused") public JsonArray getObjectTypesAsJson() { JsonArrayBuilder objectsTypesJson = Json.createArrayBuilder(); for (ObjectType objectType : objectTypes) { objectsTypesJson.add(objectType.toString()); } return objectsTypesJson.build(); }
From source file:info.dolezel.jarss.rest.v1.FeedsService.java
private JsonObjectBuilder getFeedCategory(EntityManager em, FeedCategory fc) { JsonObjectBuilder obj = Json.createObjectBuilder(); int fcUnread = 0; Collection<Feed> feeds; JsonArrayBuilder nodes = Json.createArrayBuilder(); obj.add("id", fc.getId()); obj.add("title", fc.getName()); feeds = fc.getFeeds();/*w ww.j ava2 s . co m*/ for (Feed feed : feeds) { JsonObject objFeed = getFeed(em, feed).build(); fcUnread = objFeed.getInt("unread"); nodes.add(objFeed); } obj.add("unread", fcUnread); obj.add("nodes", nodes); obj.add("isCategory", true); return obj; }
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); return arrayBuilder.build(); }
From source file:sg.edu.ntu.hrms.service.EmployeeListService.java
private String convertToJson(List<UserDTO> userList, HashMap map) { JsonArrayBuilder array = Json.createArrayBuilder(); for (int i = 0; i < userList.size(); i++) { UserDTO user = userList.get(i);// ww w . jav a 2s . c o m Date datejoin = user.getDateJoin(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); String joinDateStr = formatter.format(datejoin); String approver = ""; if (map.containsKey(user.getApprover())) { UserDTO mgr = (UserDTO) map.get(user.getApprover()); approver = mgr.getName(); } String deptDescr = ""; if (user.getDept() != null) { deptDescr = user.getDept().getDept().getDescription(); } System.out.println("approver: " + approver); array.add(Json.createObjectBuilder().add("id", user.getLogin()).add("name", user.getName()) .add("email", user.getEmail()).add("dept", deptDescr) //.add("dept", user.getDept().getDept().getDescription()) .add("title", user.getTitle().getDescription()) //.add("category","coming") .add("manager", approver).add("datejoin", joinDateStr)); } return array.build().toString(); }
From source file:com.buffalokiwi.aerodrome.jet.products.JetAPIProduct.java
/** * Adds product quantity and inventory data * @param product product data/*from w w w .j av a 2 s .c om*/ * @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:com.buffalokiwi.aerodrome.jet.products.JetAPIProduct.java
/** * The returns exceptions call is used to set up specific methods that will * overwrite your default settings on a fulfillment node level for returns. * This exception will be used to determine how and to where a product is * returned unless the merchant specifies otherwise in the Ship Order message. * /* w w w.ja v a 2 s.com*/ * @param sku Product SKU to modify * @param hashes A list of md5 hashes - Each hash is the ID of the returns * node that was created on partner.jet.com under fulfillment settings. * * Must be a valid return node ID set up by the merchant * * @return response * @throws APIException * @throws JetException */ @Override public IJetAPIResponse sendPutReturnsException(final String sku, final List<String> hashes) throws APIException, JetException { checkSku(sku); if (hashes == null) throw new IllegalArgumentException("hashes cannot be null"); final JsonArrayBuilder b = Json.createArrayBuilder(); for (final String s : hashes) { b.add(s); } APILog.info(LOG, "Sending", sku, "returns exceptions"); final IJetAPIResponse res = put(config.getProductReturnsExceptionUrl(sku), Json.createObjectBuilder().add("return_location_ids", b.build()).build().toString(), getJSONHeaderBuilder().build()); return res; }