List of usage examples for org.json.simple JSONArray add
public boolean add(E e)
From source file:net.duckling.ddl.web.controller.LynxSearchController.java
private JSONObject getResourceJSONObject(VWBContext context, TeamQuery query, int count) { List<Long> sphinxIds = searchService.query(query, TeamQuery.QUERY_FOR_RESOURCE); // List<Long> sphinxIdstemp = site.getLynxSearchService().query(query, TeamQuery.QUERY_FOR_RESOURCE); // List<Long> sphinxIds = site.getLynxSearchService().orderByInterest(sphinxIdstemp, query); //lizi if (sphinxIds != null && sphinxIds.size() > 0) { JSONObject result = new JSONObject(); result.put(SIZE, count);//from www.j a v a 2s . co m JSONArray array = new JSONArray(); for (int i = 0; i < sphinxIds.size(); i++) { Resource resource = resourceService.getResource(sphinxIds.get(i).intValue()); JSONObject resObj = getResourceJSONObject(context, i, resource, query.getKeyword()); array.add(resObj); } result.put(CONTENT, array); return result; } return null; }
From source file:analysers.ExportValidated.java
/** * Make the time axis for a given cell/*from w w w. j a v a 2 s . c om*/ * @param c * @return a JSON array containing all time values */ @SuppressWarnings("unchecked") private JSONArray makeCellTimeAxis(Cell c) { JSONArray a = new JSONArray(); while (c != null) { double t = (c.getFrame() - 1) * exp.getFrameInterval(); a.add(t); c = c.getNextCell(); } return a; }
From source file:modelo.UsuariosManagers.Usuarios.java
public JSONArray seleccionarUsuarios(String usuario, String rol, String codigo) throws SQLException { SeleccionarUsuarios select = new SeleccionarUsuarios(); ResultSet rset = select.getUsuarios(usuario, rol, codigo); //Creamos los JSONArray para guardar los objetos JSON JSONArray jsonArray = new JSONArray(); JSONArray jsonArreglo = new JSONArray(); //Recorremos el ResultSet, armamos el objeto JSON con la info y guardamos en el JSONArray. while (rset.next()) { //Armamos el objeto JSON con la informacion del registro JSONObject jsonObject = new JSONObject(); jsonObject.put("codigo", rset.getInt("PK_CODIGO")); jsonObject.put("descripcion", rset.getString("VAR_USUARIO")); jsonObject.put("rol", rset.getString("VAR_ROL")); jsonObject.put("idRol", rset.getInt("FK_ROL")); //Guardamos el JSONObject en el JSONArray y lo enviamos a la vista. jsonArray.add(jsonObject.clone()); }/*from ww w . jav a2 s . c o m*/ select.desconectar(); jsonArreglo.add(jsonArray); return jsonArreglo; }
From source file:com.web.mavenproject6.controller.CameraController.java
@ResponseBody @RequestMapping(value = "/camera", method = RequestMethod.POST) public String upload(@RequestParam(value = "imgdata", required = false) String imgdata, HttpServletRequest request)/*from ww w . java 2 s. c o m*/ throws FileNotFoundException, IOException, GeneralSecurityException, JSONException { if (StringUtils.isEmpty(imgdata)) { //return (new Date()).toString(); } JSONObject o = new JSONObject(imgdata); imgdata = new String(Base64.getDecoder().decode(o.getString("qr"))); JSONArray ar = new JSONArray(); JSONObject resultJson = new JSONObject(); JSONObject obj = new JSONObject(); obj.put("propNumber", "0000001"); obj.put("propDate", (new Date()).toString()); obj.put("fname", "?"); obj.put("sname", "");// obj.put("tname", "?");// obj.put("pasport", "898999");// obj.put("level", "10"); obj.put("userId", "10"); ar.add(obj); resultJson.put("user", ar); simpleLog.add(obj); return resultJson.toString(); }
From source file:control.ProcesoVertimientosServlets.RegistrarSuperviciones.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/*from w w w.j ava 2 s . 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 { JSONArray resp = new JSONArray(); try { //Obtenemos la cadena con la informacion y la convertimos en un //JSONArray String monitoreos = request.getParameter("monitoreos"); int tecnico = Integer.parseInt(request.getParameter("tecnico")); int resul; int codProceso; JSONObject jsonObject = new JSONObject(); JSONArray jsonArray = new JSONArray(); Object obj = JSONValue.parse(monitoreos); JSONArray monitoreosArray = new JSONArray(); monitoreosArray = (JSONArray) obj; //Recorremos el JSONArray y obtenemos la informacion. for (int i = 0; i < monitoreosArray.size(); i++) { codProceso = Integer.parseInt(monitoreosArray.get(i).toString()); ProgramarMonitoreo manager = new ProgramarMonitoreo(); resul = manager.registrarSupervision(codProceso, tecnico); jsonObject.put("monitoreo", codProceso); jsonObject.put("resultado", resul); jsonArray.add(jsonObject.clone()); } resp.add(jsonArray); //Armamos la respuesta JSON y la enviamos response.setContentType("application/json"); for (Object jsonObjectResp : resp) { response.getWriter().write(jsonObjectResp.toString()); } } catch (Exception ex) { } }
From source file:io.openvidu.java.client.Session.java
/** * Gets a new token associated to Session object configured with * <code>tokenOptions</code>. This always translates into a new request to * OpenVidu Server/*from ww w . ja v a2 s . co m*/ * * @return The generated token * * @throws OpenViduJavaClientException * @throws OpenViduHttpException */ @SuppressWarnings("unchecked") public String generateToken(TokenOptions tokenOptions) throws OpenViduJavaClientException, OpenViduHttpException { if (!this.hasSessionId()) { this.getSessionId(); } HttpPost request = new HttpPost(OpenVidu.urlOpenViduServer + OpenVidu.API_TOKENS); JSONObject json = new JSONObject(); json.put("session", this.sessionId); json.put("role", tokenOptions.getRole().name()); json.put("data", tokenOptions.getData()); if (tokenOptions.getKurentoOptions() != null) { JSONObject kurentoOptions = new JSONObject(); if (tokenOptions.getKurentoOptions().getVideoMaxRecvBandwidth() != null) { kurentoOptions.put("videoMaxRecvBandwidth", tokenOptions.getKurentoOptions().getVideoMaxRecvBandwidth()); } if (tokenOptions.getKurentoOptions().getVideoMinRecvBandwidth() != null) { kurentoOptions.put("videoMinRecvBandwidth", tokenOptions.getKurentoOptions().getVideoMinRecvBandwidth()); } if (tokenOptions.getKurentoOptions().getVideoMaxSendBandwidth() != null) { kurentoOptions.put("videoMaxSendBandwidth", tokenOptions.getKurentoOptions().getVideoMaxSendBandwidth()); } if (tokenOptions.getKurentoOptions().getVideoMinSendBandwidth() != null) { kurentoOptions.put("videoMinSendBandwidth", tokenOptions.getKurentoOptions().getVideoMinSendBandwidth()); } if (tokenOptions.getKurentoOptions().getAllowedFilters().length > 0) { JSONArray allowedFilters = new JSONArray(); for (String filter : tokenOptions.getKurentoOptions().getAllowedFilters()) { allowedFilters.add(filter); } kurentoOptions.put("allowedFilters", allowedFilters); } json.put("kurentoOptions", kurentoOptions); } StringEntity params; try { params = new StringEntity(json.toString()); } catch (UnsupportedEncodingException e1) { throw new OpenViduJavaClientException(e1.getMessage(), e1.getCause()); } request.setHeader(HttpHeaders.CONTENT_TYPE, "application/json"); request.setEntity(params); HttpResponse response; try { response = OpenVidu.httpClient.execute(request); } catch (IOException e2) { throw new OpenViduJavaClientException(e2.getMessage(), e2.getCause()); } try { int statusCode = response.getStatusLine().getStatusCode(); if ((statusCode == org.apache.http.HttpStatus.SC_OK)) { String token = (String) httpResponseToJson(response).get("id"); log.info("Returning a TOKEN: {}", token); return token; } else { throw new OpenViduHttpException(statusCode); } } finally { EntityUtils.consumeQuietly(response.getEntity()); } }
From source file:net.duckling.ddl.web.controller.pan.PanFileMoveController.java
private JSONArray getChildrenJSONArray(String rid, String ignoreRid, PanAcl panAcl) { JSONArray childrenJson = new JSONArray(); MeePoMeta root;/* www . j a va 2 s. c om*/ try { root = service.ls(panAcl, decode(rid), true); List<PanResourceBean> beans = getChildren(root, aoneUserService.getSimpleUserByUid(panAcl.getUid())); for (PanResourceBean child : beans) { if (child.getRid().equals(ignoreRid)) { continue; } childrenJson.add(resourceToJSONObject(child.getRid(), false)); } } catch (MeePoException e) { LOG.error("", e); } return childrenJson; }
From source file:com.des.paperbase.ManageData.java
public void update(String Tablename, Map<String, Object> Filter, Map<String, Object> updateValue, String FilterType) throws IOException, ParseException { String data = g.readFileToString(PATH_FILE + "\\" + Tablename + ".json"); JSONObject json = (JSONObject) new JSONParser().parse(data); List<String> keySet = g.getKeyFromMap(updateValue); if (!data.equalsIgnoreCase("{\"data\":[]}")) { JSONArray newValue = new JSONArray(); JSONArray OldValue = (JSONArray) json.get("data"); for (int s = 0; s < OldValue.size(); s++) { JSONObject record = (JSONObject) OldValue.get(s); if (MappingRecordAndKey(Filter, record, FilterType)) { for (int i = 0; i < keySet.size(); i++) { System.out.println("replace : " + keySet.get(i) + " to " + updateValue.get(keySet.get(i))); record.replace(keySet.get(i), updateValue.get(keySet.get(i))); }//from w ww .j a v a 2s. co m } newValue.add(record); } json.put("data", newValue); System.out.println(json.toJSONString()); g.writefile(json.toJSONString(), PATH_FILE + "\\" + Tablename + ".json"); } else { g.writefile(data, PATH_FILE + "\\" + Tablename + ".json"); } }
From source file:hoot.services.controllers.job.ExportJobResource.java
/** * <NAME>Export Service Get WFS List</NAME> * <DESCRIPTION>//from w ww. ja v a 2 s . c om * Lists all wfs resources * </DESCRIPTION> * <PARAMETERS> * </PARAMETERS> * <OUTPUT> * List of wfs resources * </OUTPUT> * <EXAMPLE> * <URL>http://localhost:8080/hoot-services/job/export/wfs/resources</URL> * <REQUEST_TYPE>GET</REQUEST_TYPE> * <INPUT> * </INPUT> * <OUTPUT>[{"id":"ex_eed379c0b9f7469d80ab32c71550883b"}]</OUTPUT> * </EXAMPLE> * @return */ @GET @Path("/wfs/resources") @Produces(MediaType.TEXT_PLAIN) public Response getWfsResources() { JSONArray srvList = new JSONArray(); try { WfsManager wfsMan = new WfsManager(); List<String> list = wfsMan.getAllWfsServices(); for (int i = 0; i < list.size(); i++) { String wfsResource = list.get(i); JSONObject o = new JSONObject(); o.put("id", wfsResource); srvList.add(o); } } catch (Exception ex) { ResourceErrorHandler.handleError("Error retrieving WFS resource list: " + ex.toString(), Status.INTERNAL_SERVER_ERROR, log); } return Response.ok(srvList.toString(), MediaType.TEXT_PLAIN).build(); }
From source file:hoot.services.controllers.ingest.FileUploadResource.java
protected JSONArray _createNativeRequest(final JSONArray reqList, final int zipCnt, final int shpZipCnt, final int fgdbZipCnt, final int osmZipCnt, final int shpCnt, final int fgdbCnt, final int osmCnt, final List<String> zipList, final String translation, final String jobId, final String etlName, final List<String> inputsList) throws Exception { JSONArray jobArgs = new JSONArray(); String curInputType = null;//w w w .jav a 2 s . c o m String inputs = ""; for (Object r : reqList) { JSONObject rr = (JSONObject) r; inputs += "\"" + rr.get("name").toString() + "\" "; } JSONObject param = new JSONObject(); // if fgdb zip > 0 then all becomes fgdb so it can be uzipped first // if fgdb zip == 0 and shp zip > then it is standard zip. // if fgdb zip == 0 and shp zip == 0 and osm zip > 0 then it is osm zip if (zipCnt > 0) { if (fgdbZipCnt > 0) { String mergedZipList = StringUtils.join(zipList.toArray(), ';'); param.put("UNZIP_LIST", mergedZipList); curInputType = "OGR"; } else { // Mix of shape and zip then we will unzip and treat it like OGR if (shpCnt > 0) // One or more all ogr zip + shape { curInputType = "OGR"; String mergedZipList = StringUtils.join(zipList.toArray(), ';'); param.put("UNZIP_LIST", mergedZipList); } else if (osmCnt > 0) // Mix of One or more all osm zip + osm { curInputType = "OSM"; String mergedZipList = StringUtils.join(zipList.toArray(), ';'); param.put("UNZIP_LIST", mergedZipList); } else //One or more zip (all ogr) || One or more zip (all osm) { // If contains zip of just shape or osm then we will etl zip directly curInputType = "ZIP"; // add zip extension for (int j = 0; j < zipList.size(); j++) { zipList.set(j, zipList.get(j) + ".zip"); } inputs = StringUtils.join(zipList.toArray(), ';'); } } } else if (shpCnt > 0) { curInputType = "OGR"; } else if (osmCnt > 0) { curInputType = "OSM"; } else if (fgdbCnt > 0) { curInputType = "FGDB"; } String translationPath = "translations/" + translation; if (translation.contains("/")) { translationPath = translation; } log.debug("Using Translation for ETL :" + translationPath); // Formulate request parameters param.put("TRANSLATION", translationPath); param.put("INPUT_TYPE", curInputType); param.put("INPUT_PATH", "upload/" + jobId); param.put("INPUT", inputs); param.put("INPUT_NAME", etlName); JSONArray commandArgs = parseParams(param.toJSONString()); JSONObject etlCommand = _createMakeScriptJobReq(commandArgs); // Density Raster String internalJobId = UUID.randomUUID().toString(); JSONArray rasterTilesArgs = new JSONArray(); JSONObject rasterTilesparam = new JSONObject(); rasterTilesparam.put("value", etlName); rasterTilesparam.put("paramtype", String.class.getName()); rasterTilesparam.put("isprimitivetype", "false"); rasterTilesArgs.add(rasterTilesparam); JSONObject ingestOSMResource = _createReflectionJobReq(rasterTilesArgs, "hoot.services.controllers.ingest.RasterToTilesService", "ingestOSMResourceDirect", internalJobId); jobArgs.add(etlCommand); jobArgs.add(ingestOSMResource); return jobArgs; }