List of usage examples for org.json.simple JSONArray JSONArray
JSONArray
From source file:com.lifetime.util.TimeOffUtil.java
public static HttpEntity getTimeoffRequestEntity(int page, int pagesize) { if ((page <= 0) || (pagesize <= 0)) { return null; }/*ww w.j a v a2 s. c o m*/ JSONObject jsonObject = new JSONObject(); jsonObject.put("page", String.valueOf(page)); jsonObject.put("pagesize", String.valueOf(pagesize)); JSONArray columnUris = new JSONArray(); columnUris.add("urn:replicon:time-off-list-column:time-off"); columnUris.add("urn:replicon:time-off-list-column:time-off-type"); columnUris.add("urn:replicon:time-off-list-column:department-of-time-off-owner"); jsonObject.put("columnUris", columnUris); JSONArray sort = new JSONArray(); JSONObject sortObject = new JSONObject(); sortObject.put("columnUri", "urn:replicon:time-off-list-column:time-off"); sortObject.put("isAscending", "false"); sort.add(sortObject); JSONObject filter = new JSONObject(); JSONObject leftExpression = new JSONObject(); leftExpression.put("filterDefinitionUri", "urn:replicon:time-off-list-filter:time-off-type"); filter.put("leftExpression", leftExpression); filter.put("operatorUri", "urn:replicon:filter-operator:equal"); JSONObject value = new JSONObject(); value.put("string", "us-pto"); JSONObject rightExpression = new JSONObject(); rightExpression.put("value", value); filter.put("rightExpression", rightExpression); jsonObject.put("filterExpression", filter); HttpEntity entity = null; String jsonString = jsonObject.toJSONString(); try { entity = new StringEntity(jsonString); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return entity; }
From source file:modelo.ProcesoVertimientosManagers.ManejoLodos.java
public JSONArray Eliminar(int codigo) throws Exception { JSONArray jsonArray = new JSONArray(); JSONObject jsonObject = new JSONObject(); Integer respError;// www. j a v a 2 s .co m EliminarEntidadLodos delete = new EliminarEntidadLodos(codigo); delete.ejecutar(); respError = delete.getError(); jsonObject.put("error", respError); jsonArray.add(jsonObject); return jsonArray; }
From source file:control.ParametrizacionServlets.EliminarPuntoVertimiento.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/*from w w w .j a va 2s . c o m*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { //Obtenemos los paramtros enviados int codigo = Integer.parseInt(request.getParameter("codigo")); JSONArray respError = new JSONArray(); // uno significa que no hay error //Obtenemos La informacion del manager PuntosVertimiento manager = new PuntosVertimiento(); //Almacenamos el error que pueda resultar respError = manager.Eliminar(codigo); //Armamos la respuesta JSON y la enviamos response.setContentType("application/json"); for (Object jsonObject : respError) { response.getWriter().write(respError.toString()); } } catch (Exception e) { } }
From source file:productClass.java
private String getResults(String query, String... params) { String result = new String(); try (Connection conn = getConnection()) { PreparedStatement pstmt = conn.prepareStatement(query); for (int i = 1; i <= params.length; i++) { pstmt.setString(i, params[i - 1]); }//from ww w . j a v a 2 s . com ResultSet rs = pstmt.executeQuery(); JSONArray productArr = new JSONArray(); while (rs.next()) { //Mapping the objects Map productMapping = new LinkedHashMap(); productMapping.put("productID", rs.getInt("productID")); productMapping.put("name", rs.getString("name")); productMapping.put("description", rs.getString("description")); productMapping.put("quantity", rs.getInt("quantity")); productArr.add(productMapping); } result = productArr.toString(); } catch (SQLException ex) { Logger.getLogger(productClass.class.getName()).log(Level.SEVERE, null, ex); } return result.replace("},", "},\n"); }
From source file:model.SummaryList.java
public JSONArray toJSON() { JSONArray json = new JSONArray(); for (Summary s : summaryList) { json.add(s.toJSON()); } return json; }
From source file:gov.nih.nci.ispy.web.ajax.ReporterLookup.java
/** * this ajax method looks up reporters using gexpannotation service * based on gene symbol and array platform. An addition parameter is * provided so that the callback(javascript) knows where to put the collection * This last paramter is an id from the ui element. * NOTE: the id passed in WILL be used in the callback...make sure it is there! *//*ww w.ja v a2s. com*/ public String lookup(String gene, String arrayPlatform, String uiElement) { Collection<String> reporters = new HashSet<String>(); //set up geneCollection Collection<String> genes = new ArrayList<String>(); genes.add(gene); //set up array platform by finding the appropriate type String[] uiString = arrayPlatform.split("#"); String myClassName = uiString[0]; String myValueName = uiString[1]; Enum myType = EnumHelper.createType(myClassName, myValueName); if (myType instanceof ArrayPlatformType) { GeneExprAnnotationService gs = GeneExprAnnotationServiceFactory.getInstance(); reporters = gs.getReporterNamesForGeneSymbols(genes, (ArrayPlatformType) myType); } /* reporterResultArray variable holds reporter objects like the result * list of reporters (in its own array called reporterList), * the results String, and the UIElement */ JSONArray reporterResultArray = new JSONArray(); JSONObject resultsObject = new JSONObject(); JSONArray reporterList = new JSONArray(); for (String reporter : reporters) { reporterList.add(reporter); } String results = "notFound"; if (!reporterList.isEmpty()) { results = "found"; } resultsObject.put("gene", gene); resultsObject.put("results", results); resultsObject.put("reporters", reporterList); resultsObject.put("elementId", uiElement); reporterResultArray.add(resultsObject); return reporterResultArray.toString(); }
From source file:control.ParametrizacionServlets.EliminarParamfisicoquimicos.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//w w w . ja v a 2 s .c om * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { //Obtenemos los paramtros enviados int codigo = Integer.parseInt(request.getParameter("codigo")); JSONArray respError = new JSONArray(); // uno significa que no hay error //Obtenemos La informacion del manager ParamFisicoquimicos manager = new ParamFisicoquimicos(); //Almacenamos el error que pueda resultar respError = manager.Eliminar(codigo); //Armamos la respuesta JSON y la enviamos response.setContentType("application/json"); for (Object jsonObject : respError) { response.getWriter().write(respError.toString()); } } catch (Exception e) { } }
From source file:org.kitodo.data.index.elasticsearch.type.ProcessType.java
@SuppressWarnings("unchecked") @Override/*from w w w . j av a2 s. c o m*/ public HttpEntity createDocument(Process process) { LinkedHashMap<String, String> orderedProcessMap = new LinkedHashMap<>(); orderedProcessMap.put("name", process.getTitle()); orderedProcessMap.put("outputName", process.getOutputName()); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); String creationDate = process.getCreationDate() != null ? dateFormat.format(process.getCreationDate()) : null; orderedProcessMap.put("creationDate", creationDate); orderedProcessMap.put("wikiField", process.getWikiField()); String project = process.getProject() != null ? process.getProject().getId().toString() : "null"; orderedProcessMap.put("project", project); String ruleset = process.getRuleset() != null ? process.getRuleset().getId().toString() : "null"; orderedProcessMap.put("ruleset", ruleset); String ldapGroup = process.getDocket() != null ? process.getDocket().getId().toString() : "null"; orderedProcessMap.put("ldapGroup", ldapGroup); JSONObject processObject = new JSONObject(orderedProcessMap); JSONArray properties = new JSONArray(); List<ProcessProperty> processProperties = process.getProperties(); for (ProcessProperty property : processProperties) { JSONObject propertyObject = new JSONObject(); propertyObject.put("title", property.getTitle()); propertyObject.put("value", property.getValue()); properties.add(propertyObject); } processObject.put("properties", properties); return new NStringEntity(processObject.toJSONString(), ContentType.APPLICATION_JSON); }
From source file:control.ParametrizacionServlets.EliminarTiposPrmfisicoquimicos.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/*from w w w .jav a 2 s . c om*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { //Obtenemos los paramtros enviados int codigo = Integer.parseInt(request.getParameter("codigo")); JSONArray respError = new JSONArray(); // uno significa que no hay error //Obtenemos La informacion del manager TiposPrmfisicoquimicos manager = new TiposPrmfisicoquimicos(); //Almacenamos el error que pueda resultar respError = manager.Eliminar(codigo); //Armamos la respuesta JSON y la enviamos response.setContentType("application/json"); for (Object jsonObject : respError) { response.getWriter().write(respError.toString()); } } catch (Exception e) { } }
From source file:net.maxgigapop.mrs.driver.openstack.OpenStackRESTClient.java
public static JSONArray pullNovaConfig(String host, String tenantId, String token) throws IOException { // Get list of compute nodes String url = String.format("http://%s:8774/v2/%s/os-hosts", host, tenantId); URL obj = new URL(url); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); String responseStr = sendGET(obj, con, "", token); JSONObject responseJSON = (JSONObject) JSONValue.parse(responseStr); JSONArray novaDescription = new JSONArray(); JSONArray nodes = (JSONArray) responseJSON.get("hosts"); for (Object h : nodes) { if (((JSONObject) h).get("service").equals("compute")) { String nodeName = (String) ((JSONObject) h).get("host_name"); url = String.format("http://%s:8774/v2/%s/os-hosts/%s", host, tenantId, nodeName); obj = new URL(url); con = (HttpURLConnection) obj.openConnection(); responseStr = sendGET(obj, con, "", token); responseJSON = (JSONObject) JSONValue.parse(responseStr); novaDescription.add(responseJSON); } else if (((JSONObject) h).get("service").equals("network")) { String hostName = (String) ((JSONObject) h).get("host_name"); JSONObject networkNode = (JSONObject) JSONValue .parse(String.format("{\"network_host\": {\"host_name\": \"%s\", }}", hostName)); novaDescription.add(networkNode); }/* ww w . ja v a2s .c om*/ } return novaDescription; }