List of usage examples for org.json.simple JSONArray add
public boolean add(E e)
From source file:com.imagelake.android.purchasemanagement.Servlet_purchaseViseImages.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { PrintWriter out = response.getWriter(); try {// www.j a va 2s . com String type = request.getParameter("type"); if (type != null && !type.equals("")) { if (type.equals("all")) { ja = new JSONArray(); li = new CartDAOImp().listdownloadedImages(); Images im; int i = 1; Categories c = null; Cart ct = null; User buyer = null; User Seller = null; if (!li.isEmpty()) { for (CartHasImages cartHasImages : li) { JSONObject jo = new JSONObject(); jo.put("cid", cartHasImages.getImg_id()); im = idi.getImageDetail(cartHasImages.getImg_id()); jo.put("title", im.getTitle()); jo.put("credit", cartHasImages.getCredits()); c = cadi.getCategory(im.getCategories_category_id()); jo.put("category", c.getCategory()); jo.put("date", cartHasImages.getDate()); ct = cdi.getACart(cartHasImages.getCart_id()); buyer = udi.getUser(ct.getUser_id()); Seller = udi.getUser(im.getUser_user_id()); jo.put("buyer", buyer.getUser_name()); jo.put("seller", Seller.getUser_name()); ja.add(jo); } System.out.println(ja.toJSONString()); out.write("json=" + ja.toJSONString()); } else { out.write("msg=No item found."); } } else if (type.equals("all_sort")) { ja = new JSONArray(); List<Categories> cli = cadi.listAllCategories(); JSONArray catAr = new JSONArray(); for (Categories categories : cli) { JSONObject jo = new JSONObject(); jo.put("id", categories.getCategory_id()); jo.put("category", categories.getCategory()); catAr.add(jo); } ja.add(catAr); List<User> usli = udi.listSellersBuyers(); JSONArray usAr = new JSONArray(); for (User user : usli) { JSONObject jo = new JSONObject(); jo.put("bid", user.getUser_id()); jo.put("bun", user.getUser_name()); usAr.add(jo); } ja.add(usAr); List<User> sli = udi.listAllSellers(); JSONArray seAr = new JSONArray(); for (User u : sli) { JSONObject jo = new JSONObject(); jo.put("sid", u.getUser_id()); jo.put("sun", u.getUser_name()); seAr.add(jo); } ja.add(seAr); System.out.println(ja.toJSONString()); out.write("json=" + ja.toJSONString()); } else if (type.equals("sort")) { ja = new JSONArray(); String imid, date, cat, buyer, seller, date2; imid = request.getParameter("imid"); date = request.getParameter("date"); date2 = request.getParameter("date2"); cat = request.getParameter("cat"); buyer = request.getParameter("buy"); seller = request.getParameter("sell"); System.out.println("imgid:" + imid); System.out.println("date:" + date); System.out.println("date2:" + date2); System.out.println("cat:" + cat); System.out.println("buyer:" + buyer); System.out.println("seller:" + seller); String sql = "SELECT SQL_CALC_FOUND_ROWS * FROM cart_has_images"; String where = ""; String tr = ""; if (imid.equals("0")) { imid = ""; } if (cat.equals("0")) { cat = ""; } if (buyer.equals("0")) { buyer = ""; } if (seller.equals("0")) { seller = ""; } if (!imid.equals("") && !imid.equals(null)) { if (where.equals("")) { where += " WHERE is_purchase!='0' AND is_purchase!='2' AND "; sql += where; } sql += " img_id='" + Integer.parseInt(imid) + "'"; if (!date.equals("") && !date.equals(null) && !date2.equals("") && !date2.equals(null) || !cat.equals("") && !cat.equals(null) || !buyer.equals("") && !buyer.equals(null) || !seller.equals("") && !seller.equals(null)) { sql += " AND "; } } if (!date.equals("") && !date.equals(null) && !date2.equals("") && !date2.equals(null)) { if (where.equals("")) { where += " WHERE is_purchase!='0' AND is_purchase!='2' AND "; sql += where; } String[] dt = date.split("-"); String[] dt2 = date2.split("-"); String orDate = dt[2] + "-" + dt[1] + "-" + dt[0]; String orDate2 = dt2[2] + "-" + dt2[1] + "-" + dt2[0]; System.out.println("date=" + orDate); sql += " date BETWEEN '" + orDate + "' AND '" + orDate2 + "'"; if (!cat.equals("") && !cat.equals(null) || !buyer.equals("") && !buyer.equals(null) || !seller.equals("") && !seller.equals(null)) { sql += " AND "; } } if (!cat.equals("") && !cat.equals(null)) { if (where.equals("")) { where += " WHERE is_purchase!='0' AND is_purchase!='2' AND "; sql += where; } sql += "img_id IN(SELECT images_id FROM images WHERE categories_category_id='" + cat + "')"; if (!buyer.equals("") && !buyer.equals(null) || !seller.equals("") && !seller.equals(null)) { sql += " AND "; } } if (!buyer.equals("") && !buyer.equals(null)) { if (where.equals("")) { where += " WHERE is_purchase!='0' AND is_purchase!='2' AND "; sql += where; } sql += "cart_id IN(SELECT cart_id FROM cart WHERE user_id='" + buyer + "')"; if (!seller.equals("") && !seller.equals(null)) { sql += " AND "; } } if (!seller.equals("") && !seller.equals(null)) { if (where.equals("")) { where += " WHERE is_purchase!='0' AND is_purchase!='2' AND "; sql += where; } sql += "img_id IN(SELECT images_id FROM images WHERE user_user_id='" + seller + "')"; } sql += " ORDER BY date DESC"; System.out.println("sql:" + sql); Images im; int i = 1; Categories cc = null; Cart ct = null; User buy = null; User Seller = null; try { PreparedStatement ps = DBFactory.getConnection().prepareStatement(sql); ResultSet rs = ps.executeQuery(); while (rs.next()) { JSONObject jo = new JSONObject(); jo.put("cid", rs.getInt(2)); im = idi.getImageDetail(rs.getInt(2)); jo.put("title", im.getTitle()); jo.put("credit", rs.getInt(7)); cc = cadi.getCategory(im.getCategories_category_id()); jo.put("category", cc.getCategory()); jo.put("date", rs.getDate(6)); ct = cdi.getACart(rs.getInt(5)); buy = udi.getUser(ct.getUser_id()); Seller = udi.getUser(im.getUser_user_id()); jo.put("buyer", buy.getUser_name()); jo.put("seller", Seller.getUser_name()); ja.add(jo); } out.write("json=" + ja.toJSONString()); } catch (Exception e) { e.printStackTrace(); out.write("msg=Internal server error,Please try again later."); } } } else { out.write("msg=Internal server error,Please try again later."); } } catch (Exception e) { e.printStackTrace(); out.write("msg=Internal server error,Please try again later."); } }
From source file:com.p000ison.dev.simpleclans2.converter.Converter.java
public void convertClans() throws SQLException { ResultSet result = from.query("SELECT * FROM `sc_clans`;"); while (result.next()) { JSONObject flags = new JSONObject(); String name = result.getString("name"); String tag = result.getString("tag"); boolean verified = result.getBoolean("verified"); boolean friendly_fire = result.getBoolean("friendly_fire"); long founded = result.getLong("founded"); long last_used = result.getLong("last_used"); String flagsString = result.getString("flags"); String cape = result.getString("cape_url"); ConvertedClan clan = new ConvertedClan(tag); clan.setPackedAllies(result.getString("packed_allies")); clan.serPackedRivals(result.getString("packed_rivals")); if (friendly_fire) { flags.put("ff", friendly_fire); }/* ww w . j av a2 s. c om*/ if (cape != null && !cape.isEmpty()) { flags.put("cape-url", cape); } JSONParser parser = new JSONParser(); try { JSONObject object = (JSONObject) parser.parse(flagsString); String world = object.get("homeWorld").toString(); if (!world.isEmpty()) { int x = ((Long) object.get("homeX")).intValue(); int y = ((Long) object.get("homeY")).intValue(); int z = ((Long) object.get("homeZ")).intValue(); flags.put("home", x + ":" + y + ":" + z + ":" + world + ":0:0"); } clan.setRawWarring((JSONArray) object.get("warring")); } catch (ParseException e) { Logging.debug(e, true); continue; } insertClan(name, tag, verified, founded, last_used, flags.isEmpty() ? null : flags.toJSONString(), result.getDouble("balance")); String selectLastQuery = "SELECT `id` FROM `sc2_clans` ORDER BY ID DESC LIMIT 1;"; ResultSet selectLast = to.query(selectLastQuery); selectLast.next(); clan.setId(selectLast.getLong("id")); selectLast.close(); insertBB(Arrays.asList(result.getString("packed_bb").split("\\s*(\\||$)")), clan.getId()); clans.add(clan); } for (ConvertedClan clan : clans) { JSONArray allies = new JSONArray(); JSONArray rivals = new JSONArray(); JSONArray warring = new JSONArray(); for (String allyTag : clan.getRawAllies()) { long allyID = getIDByTag(allyTag); if (allyID != -1) { allies.add(allyID); } } for (String rivalTag : clan.getRawAllies()) { long rivalID = getIDByTag(rivalTag); if (rivalID != -1) { rivals.add(rivalID); } } for (String warringTag : clan.getRawWarring()) { long warringID = getIDByTag(warringTag); if (warringID != -1) { warring.add(warringID); } } if (!allies.isEmpty()) { updateClan.setString(1, allies.toJSONString()); } else { updateClan.setNull(1, Types.VARCHAR); } if (!rivals.isEmpty()) { updateClan.setString(2, rivals.toJSONString()); } else { updateClan.setNull(2, Types.VARCHAR); } if (!warring.isEmpty()) { updateClan.setString(3, warring.toJSONString()); } else { updateClan.setNull(3, Types.VARCHAR); } updateClan.setLong(4, clan.getId()); updateClan.executeUpdate(); } }
From source file:modelo.ParametrizacionManagers.Tarifas.java
/** * // w w w . ja v a 2s.com * Obtiene la informacion de una unidad de medida y * guarda todo en un JSONArray para entregarselo a la vista. * * @return JSONArray * @throws SQLException */ public JSONArray getTarifa(int codigo) throws SQLException { //Ejecutamos la consulta y obtenemos el ResultSet SeleccionarTarifas select = new SeleccionarTarifas(); ResultSet rset = select.getTarifa(codigo); //Creamos los JSONArray para guardar los objetos JSON JSONArray jsonArray = new JSONArray(); //Recorremos el ResultSet, armamos el objeto JSON con la info y guardamos //en el JSONArray. while (rset.next()) { JSONObject jsonObject = new JSONObject(); //Armamos el objeto JSON con la informacion del registro jsonObject.put("codigo", rset.getString("CODIGO")); jsonObject.put("valor", rset.getString("VALOR")); jsonObject.put("codParm", rset.getString("FK_PARAMFISICOQUIMICO")); jsonObject.put("descpParm", rset.getString("DESPARM")); //Guardamos el JSONObject en el JSONArray y lo enviamos a la vista. jsonArray.add(jsonObject.clone()); } select.desconectar(); return jsonArray; }
From source file:com.piusvelte.hydra.UnidataConnection.java
@SuppressWarnings("unchecked") @Override// www . j ava 2 s.co m public JSONObject query(String object, String[] columns, String selection) { JSONObject response = new JSONObject(); JSONArray errors = new JSONArray(); UniFile uFile = null; try { JSONArray rows = new JSONArray(); UniCommand uCommand = mSession.command(); if (selection == null) uCommand.setCommand(String.format(SIMPLE_QUERY_FORMAT, object).toString()); else uCommand.setCommand(String.format(SELECTION_QUERY_FORMAT, object, selection).toString()); UniSelectList uSelect = mSession.selectList(0); uCommand.exec(); uFile = mSession.openFile(object); UniString recordID = null; while ((recordID = uSelect.next()).length() > 0) { uFile.setRecordID(recordID); // flatten out multi-values int maxSize = 1; ArrayList<String[]> colArr = new ArrayList<String[]>(); for (String column : columns) { String[] mvArr = uFile.readNamedField(column).toString().split(UniTokens.AT_VM, -1); if (mvArr.length > maxSize) maxSize = mvArr.length; colArr.add(mvArr); } for (int row = 0; row < maxSize; row++) { JSONArray rowData = new JSONArray(); for (int col = 0; col < columns.length; col++) { String[] mvArr = colArr.get(col); if (row < mvArr.length) rowData.add(mvArr[row]); else rowData.add(""); } rows.add(rowData); } } response.put("result", rows); } catch (UniSessionException e) { errors.add(e.getMessage()); } catch (UniCommandException e) { errors.add(e.getMessage()); } catch (UniFileException e) { errors.add(e.getMessage()); } catch (UniSelectListException e) { errors.add(e.getMessage()); } finally { if (uFile != null) { try { uFile.close(); } catch (UniFileException e) { errors.add(e.getMessage()); } } } response.put("errors", errors); if (!response.containsKey("result")) { JSONArray rows = new JSONArray(); JSONArray rowData = new JSONArray(); rows.add(rowData); response.put("result", rows); } return response; }
From source file:me.uni.sushilkumar.geodine.util.WhatsCooking.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * @param request servlet request/* w ww. jav a 2s . c om*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); PrintWriter out = response.getWriter(); try { JSONObject obj = new JSONObject(); JSONArray array = new JSONArray(); DBConnection con = new DBConnection(); ArrayList<String> cuisineList = con.getCuisineList(); Random generator = new Random(); int size = cuisineList.size(); for (int i = 0; i < 10; i++) { JSONObject temp = new JSONObject(); String title = cuisineList.get(generator.nextInt(size)); //title=WordUtils.capitalize(title); temp.put("title", title); title = title.replaceAll("\\s+", "-"); String link = "cuisine/" + title; temp.put("link", link); array.add(temp); } obj.put("links", array); out.println(obj.toJSONString()); } catch (SQLException ex) { Logger.getLogger(WhatsCooking.class.getName()).log(Level.SEVERE, null, ex); } finally { out.close(); } }
From source file:bookUtilities.BookListServlet.java
private JSONArray getBooks() { JSONArray booksToReturn = new JSONArray(); try {/*from w w w . j ava 2s. com*/ Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost;user=sa;password=nopw"); Statement st = con.createStatement(); String query = "SELECT * " + "FROM HardCover.dbo.Book " + "WHERE Active = 1"; ResultSet rs = st.executeQuery(query); while (rs.next()) { JSONObject bookToAdd = new JSONObject(); bookToAdd.put("bookId", rs.getString("BookUuid")); bookToAdd.put("title", rs.getString("Title")); booksToReturn.add(bookToAdd); } } catch (Exception e) { System.out.println(e.getMessage()); } return booksToReturn; }
From source file:edu.vt.vbi.patric.portlets.ProteomicsListPortlet.java
@SuppressWarnings("unchecked") public void serveResource(ResourceRequest request, ResourceResponse response) throws PortletException, IOException { String sraction = request.getParameter("sraction"); if (sraction != null && sraction.equals("save_params")) { Map<String, String> key = new HashMap<>(); String taxonId = ""; String cType = request.getParameter("context_type"); String cId = request.getParameter("context_id"); if (cType != null && cId != null && cType.equals("taxon") && !cId.equals("")) { taxonId = cId;//from w w w . j a va 2s . c om } String keyword = request.getParameter("keyword"); String state = request.getParameter("state"); if (!taxonId.equalsIgnoreCase("")) { key.put("taxonId", taxonId); } if (keyword != null) { key.put("keyword", keyword.trim()); } if (state != null) { key.put("state", state); } long pk = (new Random()).nextLong(); SessionHandler.getInstance().set(SessionHandler.PREFIX + pk, jsonWriter.writeValueAsString(key)); PrintWriter writer = response.getWriter(); writer.write("" + pk); writer.close(); } else { String need = request.getParameter("need"); switch (need) { case "0": { String pk = request.getParameter("pk"); // Map data = processExperimentTab(request); Map<String, String> key = (Map) data.get("key"); int numFound = (Integer) data.get("numFound"); List<Map> sdl = (List<Map>) data.get("experiments"); JSONArray docs = new JSONArray(); for (Map doc : sdl) { JSONObject item = new JSONObject(); item.putAll(doc); docs.add(item); } if (data.containsKey("facets")) { JSONObject facets = FacetHelper.formatFacetTree((Map) data.get("facets")); key.put("facets", facets.toJSONString()); SessionHandler.getInstance().set(SessionHandler.PREFIX + pk, jsonWriter.writeValueAsString(key)); } JSONObject jsonResult = new JSONObject(); jsonResult.put("results", docs); jsonResult.put("total", numFound); response.setContentType("application/json"); PrintWriter writer = response.getWriter(); jsonResult.writeJSONString(writer); writer.close(); break; } case "1": { String pk = request.getParameter("pk"); // Map data = processProteinTab(request); Map<String, String> key = (Map) data.get("key"); int numFound = (Integer) data.get("numFound"); List<Map> sdl = (List<Map>) data.get("proteins"); JSONArray docs = new JSONArray(); for (Map doc : sdl) { JSONObject item = new JSONObject(doc); docs.add(item); } if (data.containsKey("facets")) { JSONObject facets = FacetHelper.formatFacetTree((Map) data.get("facets")); key.put("facets", facets.toJSONString()); SessionHandler.getInstance().set(SessionHandler.PREFIX + pk, jsonWriter.writeValueAsString(key)); } JSONObject jsonResult = new JSONObject(); jsonResult.put("results", docs); jsonResult.put("total", numFound); response.setContentType("application/json"); PrintWriter writer = response.getWriter(); writer.write(jsonResult.toString()); writer.close(); break; } case "tree": { String pk = request.getParameter("pk"); String state; Map<String, String> key = jsonReader .readValue(SessionHandler.getInstance().get(SessionHandler.PREFIX + pk)); if (key.containsKey("state")) state = key.get("state"); else state = request.getParameter("state"); key.put("state", state); SessionHandler.getInstance().set(SessionHandler.PREFIX + pk, jsonWriter.writeValueAsString(key)); JSONArray tree = new JSONArray(); try { if (!key.containsKey("facets") && !key.get("facets").isEmpty()) { JSONObject facet_fields = (JSONObject) new JSONParser().parse(key.get("facets")); DataApiHandler dataApi = new DataApiHandler(request); tree = FacetHelper.processStateAndTree(dataApi, SolrCore.PROTEOMICS_EXPERIMENT, key, need, facet_fields, key.get("facet"), state, null, 4); } } catch (ParseException e) { LOGGER.error(e.getMessage(), e); } response.setContentType("application/json"); PrintWriter writer = response.getWriter(); tree.writeJSONString(writer); writer.close(); break; } case "getFeatureIds": { String keyword = request.getParameter("keyword"); Map<String, String> key = new HashMap<>(); key.put("keyword", keyword); DataApiHandler dataApi = new DataApiHandler(request); SolrQuery query = dataApi.buildSolrQuery(key, null, null, 0, -1, false); String apiResponse = dataApi.solrQuery(SolrCore.PROTEOMICS_PROTEIN, query); Map resp = jsonReader.readValue(apiResponse); Map respBody = (Map) resp.get("response"); JSONObject object = new JSONObject(respBody); // solr.setCurrentInstance(SolrCore.PROTEOMICS_PROTEIN); // JSONObject object = null; //solr.getData(key, null, facet, 0, -1, false, false, false); response.setContentType("application/json"); PrintWriter writer = response.getWriter(); object.writeJSONString(writer); // writer.write(object.get("response").toString()); writer.close(); break; } case "getPeptides": { String experiment_id = request.getParameter("experiment_id"); String na_feature_id = request.getParameter("na_feature_id"); Map<String, String> key = new HashMap<>(); key.put("keyword", "na_feature_id:" + na_feature_id + " AND experiment_id:" + experiment_id); key.put("fields", "peptide_sequence"); DataApiHandler dataApi = new DataApiHandler(request); SolrQuery query = dataApi.buildSolrQuery(key, null, null, 0, -1, false); String apiResponse = dataApi.solrQuery(SolrCore.PROTEOMICS_PEPTIDE, query); Map resp = jsonReader.readValue(apiResponse); Map respBody = (Map) resp.get("response"); JSONObject object = new JSONObject(); object.putAll(respBody); // solr.setCurrentInstance(SolrCore.PROTEOMICS_PEPTIDE); // JSONObject object = solr.getData(key, null, facet, 0, -1, false, false, false); // object = (JSONObject) object.get("response"); object.put("aa", FASTAHelper.getFASTASequence(request, Arrays.asList(na_feature_id), "protein")); response.setContentType("application/json"); PrintWriter writer = response.getWriter(); object.writeJSONString(writer); writer.close(); break; } } } }
From source file:hoot.services.controllers.ingest.CustomScriptResource.java
/** * <NAME>Custom Script Service Save</NAME> * <DESCRIPTION>Create or update user provided script into file.</DESCRIPTION> * <PARAMETERS>/*from w w w . j a v a 2s . c o m*/ * <SCRIPT_NAME> * Name of script. If exists then it will be updated * </SCRIPT_NAME> * <SCRIPT_DESCRIPTION> * Script description. * </SCRIPT_DESCRIPTION> * </PARAMETERS> * <OUTPUT> * JSON Array containing JSON of name and description of created script * </OUTPUT> * <EXAMPLE> * <URL>http://localhost:8080/hoot-services/ingest/customscript/save?SCRIPT_NAME=MyTest&SCRIPT_DESCRIPTION=my description</URL> * <REQUEST_TYPE>POST</REQUEST_TYPE> * <INPUT> * // A non-standard extension to include additional js files within the same dir * // sub-tree. * require("example") * * // an optional initialize function that gets called once before any * // translateAttribute calls. * function initialize() * { * // The print method simply prints the string representation to stdout * //print("Initializing.") * } * * // an optional finalize function that gets called once after all * // translateAttribute calls. * function finalize() * { * // the debug method prints to stdout when --debug has been specified on * // the hoot command line. (DEBUG log level) * debug("Finalizing."); * } * * // A translateAttributes method that is very similar to the python translate * // attributes * function translateAttributes(attrs, layerName) * { * tags = {}; * //print(layerName); * for (var key in attrs) * { * k = key.toLowerCase() * //print(k + ": " + attrs[key]); * tags[k] = attrs[key] * } * return tags; * } * </INPUT> * <OUTPUT>[{"NAME":"MyTest","DESCRIPTION":"my description"}]</OUTPUT> * </EXAMPLE> * @param script * @param scriptName * @param scriptDescription * @return */ @POST @Path("/save") @Consumes(MediaType.TEXT_PLAIN) @Produces(MediaType.TEXT_PLAIN) public Response processSave(String script, @QueryParam("SCRIPT_NAME") final String scriptName, @QueryParam("SCRIPT_DESCRIPTION") final String scriptDescription) { JSONArray saveArr = new JSONArray(); try { saveArr.add(saveScript(scriptName, scriptDescription, script)); } catch (Exception ex) { ResourceErrorHandler.handleError( "Error processing script save for: " + scriptName + " Error: " + ex.getMessage(), Status.INTERNAL_SERVER_ERROR, log); } return Response.ok(saveArr.toString(), MediaType.TEXT_PLAIN).build(); }
From source file:jp.aegif.nemaki.rest.UserResource.java
@SuppressWarnings("unchecked") private JSONObject convertUserToJson(User user) { SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); String created = new String(); try {//from ww w . jav a 2 s .c o m if (user.getCreated() != null) { created = sdf.format(user.getCreated().getTime()); } } catch (Exception ex) { ex.printStackTrace(); } String modified = new String(); try { if (user.getModified() != null) { modified = sdf.format(user.getModified().getTime()); } } catch (Exception ex) { ex.printStackTrace(); } JSONObject userJSON = new JSONObject(); userJSON.clear(); userJSON.put(ITEM_USERID, user.getUserId()); userJSON.put(ITEM_USERNAME, user.getName()); userJSON.put(ITEM_FIRSTNAME, user.getFirstName()); userJSON.put(ITEM_LASTNAME, user.getLastName()); userJSON.put(ITEM_EMAIL, user.getEmail()); userJSON.put(ITEM_TYPE, user.getType()); userJSON.put(ITEM_CREATOR, user.getCreator()); userJSON.put(ITEM_CREATED, created); userJSON.put(ITEM_MODIFIER, user.getModifier()); userJSON.put(ITEM_MODIFIED, modified); boolean isAdmin = (user.isAdmin() == null) ? false : user.isAdmin(); userJSON.put(ITEM_IS_ADMIN, isAdmin); JSONArray jfs = new JSONArray(); Set<String> ufs = user.getFavorites(); if (CollectionUtils.isNotEmpty(ufs)) { Iterator<String> ufsItr = ufs.iterator(); while (ufsItr.hasNext()) { jfs.add(ufsItr.next()); } } userJSON.put("favorites", jfs); return userJSON; }
From source file:modelo.ProcesoVertimientosManagers.VerificacionInfoCaracterizacion.java
public JSONArray getDevolucionCaracterizacion(String codigoPoceso) throws SQLException { JSONArray jsonArray = new JSONArray(); JSONObject jsonObject = new JSONObject(); SeleccionarVerificacionInfoCaracterizacion select = new SeleccionarVerificacionInfoCaracterizacion(); ResultSet rset = select.getDevolucionCaracterizacion(codigoPoceso); while (rset.next()) { jsonObject.put("tipoDevolCaracterizacion", rset.getString(("TIPO_DEVOLUCION"))); jsonObject.put("fechaEntDevolCaracterizacion", rset.getString(("FECHA_ENTREGA"))); jsonObject.put("observacionDevolCaracterizacion", rset.getString(("OBSERVACION"))); jsonObject.put("fechaDevolCaracterizacion", rset.getString(("FECHA_DEVOLUCION"))); }//ww w . j av a2s . co m jsonArray.add(jsonObject.clone()); return jsonArray; }