List of usage examples for javax.json JsonArrayBuilder build
JsonArray build();
From source file:org.kitodo.production.forms.IndexingForm.java
/** * Return object types as JSONArray.//from www . j a v a 2 s .com * * @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:com.buffalokiwi.aerodrome.jet.products.JetAPIProduct.java
/** * Adds product quantity and inventory data * @param product product data/*from ww w .ja 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:com.open.shift.support.controller.SupportResource.java
@GET @Produces(MediaType.APPLICATION_JSON)/*from w w w . j a va 2 s .c om*/ @Path("areachart") public JsonObject generateAreaChart() throws Exception { System.out.println("The injected hashcode is " + this.supportDAO); int usa[] = { 0, 0, 0, 0, 0, 6, 11, 32, 110, 235, 369, 640, 1005, 1436, 2063, 3057, 4618, 6444, 9822, 15468, 20434, 24126, 27387, 29459, 31056, 31982, 32040, 31233, 29224, 27342, 26662, 26956, 27912, 28999, 28965, 27826, 25579, 25722, 24826, 24605, 24304, 23464, 23708, 24099, 24357, 24237, 24401, 24344, 23586, 22380, 21004, 17287, 14747, 13076, 12555, 12144, 11009, 10950, 10871, 10824, 10577, 10527, 10475, 10421, 10358, 10295, 10104 }; int ussr[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 25, 50, 120, 150, 200, 426, 660, 869, 1060, 1605, 2471, 3322, 4238, 5221, 6129, 7089, 8339, 9399, 10538, 11643, 13092, 14478, 15915, 17385, 19055, 21205, 23044, 25393, 27935, 30062, 32049, 33952, 35804, 37431, 39197, 45000, 43000, 41000, 39000, 37000, 35000, 33000, 31000, 29000, 27000, 25000, 24000, 23000, 22000, 21000, 20000, 19000, 18000, 18000, 17000, 16000 }; URL u = ctx.getResource("/WEB-INF/classes/templates/area.json"); String areaJson = null; if (OS.indexOf("win") >= 0) { areaJson = u.toString().substring(6); } else if (OS.indexOf("nux") >= 0) { areaJson = u.toString().substring(5); } System.out.println("The areaJson is " + areaJson); JsonReader reader = Json.createReader(new FileReader(areaJson)); JsonObject main = reader.readObject(); JsonObject yaxis = main.getJsonObject("yAxis"); JsonObjectBuilder title = Json.createObjectBuilder().add("text", "US and USSR Deposits"); JsonObjectBuilder ytitle = Json.createObjectBuilder().add("text", "Amount Deposisted"); JsonArrayBuilder usaData = Json.createArrayBuilder(); for (Integer usa1 : usa) { usaData.add(usa1); } JsonArrayBuilder ussrData = Json.createArrayBuilder(); for (Integer uss1 : ussr) { ussrData.add(uss1); } JsonObjectBuilder usaSeries = Json.createObjectBuilder().add("name", "USA").add("data", usaData); JsonObjectBuilder ussrSeries = Json.createObjectBuilder().add("name", "USSR").add("data", ussrData); JsonArrayBuilder series = Json.createArrayBuilder().add(usaSeries).add(ussrSeries); //main json object builder JsonObjectBuilder mainJsonObj = Json.createObjectBuilder(); for (Map.Entry<String, JsonValue> mainObj : main.entrySet()) { String key = mainObj.getKey(); JsonValue value = mainObj.getValue(); if (key.equalsIgnoreCase("yAxis")) { String yaxisLabel = "labels"; mainJsonObj.add(key, Json.createObjectBuilder().add(yaxisLabel, yaxis.getJsonObject(yaxisLabel)) .add("title", ytitle.build())); } else { mainJsonObj.add(key, value); } } mainJsonObj.add("title", title.build()).add("series", series.build()); return mainJsonObj.build(); }
From source file:csg.files.CSGFiles.java
public void saveCourseData(AppDataComponent courseData, String filePath) throws IOException { CourseData courseDataManager = (CourseData) courseData; JsonArrayBuilder courseArrayBuilder = Json.createArrayBuilder(); JsonArray courseArray = courseArrayBuilder.build(); CSGWorkspace workspace = (CSGWorkspace) app.getWorkspaceComponent(); JsonObject courseJson = Json.createObjectBuilder().add(JSON_SUBJECT, courseDataManager.getSubject()) .add(JSON_NUMBER, courseDataManager.getNumber()).add(JSON_SEMESTER, courseDataManager.getSemester()) .add(JSON_YEAR, courseDataManager.getYear()).add(JSON_TITLE, courseDataManager.getTitle()) .add(JSON_INSTRUCTORNAME, courseDataManager.getInsName()) .add(JSON_INSTRUCTORHOME, courseDataManager.getInsHome()) .add(JSON_BANNER, courseDataManager.getBannerLink()) .add(JSON_LEFTFOOTER, courseDataManager.getLeftFooterLink()) .add(JSON_RIGHTFOOTER, courseDataManager.getRightFooterLink()) .add(JSON_STYLESHEET, courseDataManager.getStyleSheet()).build(); ObservableList<CourseTemplate> templates = courseDataManager.getTemplates(); for (CourseTemplate template : templates) { JsonObject cJson = Json.createObjectBuilder().add(JSON_USE, template.isUse().getValue()) .add(JSON_NAVBAR, template.getNavbarTitle()).add(JSON_FILENAME, template.getFileName()) .add(JSON_SCRIPT, template.getScript()).build(); courseArrayBuilder.add(cJson);/*from w w w.ja v a2s. c o m*/ } courseArray = courseArrayBuilder.build(); JsonObject dataManagerJSO = Json.createObjectBuilder().add(JSON_COURSE, courseJson) .add(JSON_COURSETEMPLATE, courseArray).build(); // AND NOW OUTPUT IT TO A JSON FILE WITH PRETTY PRINTING Map<String, Object> properties = new HashMap<>(1); properties.put(JsonGenerator.PRETTY_PRINTING, true); JsonWriterFactory writerFactory = Json.createWriterFactory(properties); StringWriter sw = new StringWriter(); JsonWriter jsonWriter = writerFactory.createWriter(sw); jsonWriter.writeObject(dataManagerJSO); jsonWriter.close(); // INIT THE WRITER OutputStream os = new FileOutputStream(filePath); JsonWriter jsonFileWriter = Json.createWriter(os); jsonFileWriter.writeObject(dataManagerJSO); String prettyPrinted = sw.toString(); PrintWriter pw = new PrintWriter(filePath); pw.write(prettyPrinted); pw.close(); }
From source file:io.bibleget.HTTPCaller.java
public int isValidBook(String book) { try {/*ww w . ja v a2 s . co m*/ JsonArrayBuilder biblebooksBldr = Json.createArrayBuilder(); BibleGetDB bibleGetDB; bibleGetDB = BibleGetDB.getInstance(); for (int i = 0; i < 73; i++) { String usrprop = bibleGetDB.getMetaData("BIBLEBOOKS" + Integer.toString(i)); //System.out.println("value of BIBLEBOOKS"+Integer.toString(i)+": "+usrprop); JsonReader jsonReader = Json.createReader(new StringReader(usrprop)); JsonArray jsbooks = jsonReader.readArray(); biblebooksBldr.add(jsbooks); } JsonArray biblebooks = biblebooksBldr.build(); if (!biblebooks.isEmpty()) { return idxOf(book, biblebooks); } } catch (ClassNotFoundException ex) { Logger.getLogger(HTTPCaller.class.getName()).log(Level.SEVERE, null, ex); } return -1; }
From source file:servlets.SampleServlet.java
private String getResults(String query, String... params) { JsonArrayBuilder productArray = Json.createArrayBuilder(); String xxx = new String(); try (Connection conn = Credentials.getConnection()) { PreparedStatement pstmt = conn.prepareStatement(query); for (int i = 1; i <= params.length; i++) { pstmt.setString(i, params[i - 1]); }/*from w w w . ja v a2 s. c om*/ ResultSet rs = pstmt.executeQuery(); List list = new LinkedList(); while (rs.next()) { JsonObjectBuilder jsonobj = Json.createObjectBuilder().add("productID", rs.getInt("productID")) .add("Name", rs.getString("Name")).add("Description", rs.getString("Description")) .add("Quantity", rs.getInt("Quantity")); xxx = jsonobj.build().toString(); productArray.add(jsonobj); } } catch (SQLException ex) { Logger.getLogger(SampleServlet.class.getName()).log(Level.SEVERE, null, ex); } if (params.length == 0) { xxx = productArray.build().toString(); } return xxx; }
From source file:assignment5.ProductServlet.java
/** * json format taken from//from w w w.j a v a 2s . com * https://code.google.com/p/json-simple/wiki/EncodingExamples * * @param query * @param params * @return */ private String getResults(String query, String... params) { JsonArrayBuilder productArray = Json.createArrayBuilder(); String numChanges = new String(); try (Connection conn = credentials.getConnection()) { PreparedStatement pstmt = conn.prepareStatement(query); for (int i = 1; i <= params.length; i++) { pstmt.setString(i, params[i - 1]); } ResultSet rs = pstmt.executeQuery(); while (rs.next()) { JsonObjectBuilder jsonobj = Json.createObjectBuilder().add("productID", rs.getInt("productID")) .add("name", rs.getString("name")).add("description", rs.getString("description")) .add("quantity", rs.getInt("quantity")); numChanges = jsonobj.build().toString(); productArray.add(jsonobj); } } catch (SQLException ex) { Logger.getLogger(ProductServlet.class.getName()).log(Level.SEVERE, null, ex); } if (params.length == 0) { numChanges = productArray.build().toString(); } return numChanges; }
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. * // ww w . j a va 2 s . co m * @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; }
From source file:edu.harvard.hms.dbmi.bd2k.irct.ri.exac.EXACResourceImplementation.java
@Override public Result runProcess(SecureSession session, IRCTProcess process, Result result) throws ResourceInterfaceException { HttpClient client = createClient(session); try {// w w w.j a va2 s .c o m ResultSet resultSetField = (ResultSet) process.getObjectValues().get("RESULTSET"); String chromosomeColumn = process.getStringValues().get("CHROMOSOME"); String positionColumn = process.getStringValues().get("POSITION"); String referenceColumn = process.getStringValues().get("REFERENCE"); String variantColumn = process.getStringValues().get("VARIANT"); ResultSet rs = createResultSet(result, resultSetField); // Move to First resultSetField.first(); // Loop through all rows and get the data needed for the bulk // request resultSetField.beforeFirst(); JsonArrayBuilder jsonArray = Json.createArrayBuilder(); while (resultSetField.next()) { String queryString = resultSetField.getString(chromosomeColumn); queryString += "-" + resultSetField.getString(positionColumn); queryString += "-" + resultSetField.getString(referenceColumn); queryString += "-" + resultSetField.getString(variantColumn); // Run the Bulk request(s) jsonArray.add(queryString); } HttpPost post = new HttpPost(this.resourceURL + "/rest/bulk/variant"); // Set Header try { post.setEntity(new StringEntity(jsonArray.build().toString())); HttpResponse response = client.execute(post); JsonReader reader = Json.createReader(response.getEntity().getContent()); JsonObject responseObject = reader.readObject(); //Merge the results back into the result set resultSetField.beforeFirst(); rs.first(); while (resultSetField.next()) { rs.appendRow(); //Copy the original data over for (Column column : resultSetField.getColumns()) { rs.updateString(column.getName(), resultSetField.getString(column.getName())); } //Add the new data if it exists String queryString = resultSetField.getString(chromosomeColumn); queryString += "-" + resultSetField.getString(positionColumn); queryString += "-" + resultSetField.getString(referenceColumn); queryString += "-" + resultSetField.getString(variantColumn); if (responseObject.containsKey(queryString)) { JsonObject varObject = responseObject.getJsonObject(queryString).getJsonObject("variant"); for (String newColumnString : this.exacColumns) { String value = getValue(varObject, newColumnString); if (value != null) { rs.updateString(newColumnString, value.toString()); } } } } result.setData(rs); result.setResultStatus(ResultStatus.COMPLETE); } catch (IOException | PersistableException e) { e.printStackTrace(); result.setResultStatus(ResultStatus.ERROR); result.setMessage(e.getMessage()); } } catch (ResultSetException e) { e.printStackTrace(); result.setResultStatus(ResultStatus.ERROR); result.setMessage(e.getMessage()); } return result; }
From source file:de.tu_dortmund.ub.data.dswarm.Transform.java
private JsonArray getMappingsFromProjects(final Collection<String> projectIDs, final String serviceName, final String engineDswarmAPI) throws Exception { final JsonArrayBuilder mappingArrayBuilder = Json.createArrayBuilder(); for (final String projectID : projectIDs) { final JsonArray projectMappings = getMappingsFromProject(projectID, serviceName, engineDswarmAPI); if (projectMappings == null) { LOG.error(String.format("[%s][%d] couldn't determine mappings from project '%s'", serviceName, cnt, projectID));/*www . j a v a2 s . c o m*/ continue; } LOG.info(String.format("[%s][%d] retrieved '%d' mappings from project '%s'", serviceName, cnt, projectMappings.size(), projectID)); projectMappings.forEach(mappingArrayBuilder::add); } final JsonArray mappingsArray = mappingArrayBuilder.build(); LOG.info(String.format("[%s][%d] accumulated '%d' mappings from all projects", serviceName, cnt, mappingsArray.size())); return mappingsArray; }