List of usage examples for org.json.simple JSONArray JSONArray
JSONArray
From source file:com.intuit.tweetstest.TweetsController.java
protected JSONArray retrieveTweetsFromDB(DB db, List<String> followingList, int count) throws ParseException { JSONArray tweetsArray = new JSONArray(); DBCollection tweetsCollection = db.getCollection("tweetscollection"); DBObject tweetsQuery = new BasicDBObject("user", new BasicDBObject("$in", followingList)); DBObject excludeId = new BasicDBObject("_id", 0); DBCursor cursor = tweetsCollection.find(tweetsQuery, excludeId).sort(new BasicDBObject("tweetedOn", -1)) .limit(count);/*from w w w .ja v a 2s.com*/ for (DBObject tweet : cursor) { JSONObject tweetJson = (JSONObject) new JSONParser().parse(tweet.toString()); tweetsArray.add(tweetJson); } return tweetsArray; }
From source file:net.sf.okapi.filters.drupal.Node.java
@SuppressWarnings("unchecked") public void setBody(String lang, String body, String summary) { JSONObject bodyVal = new JSONObject(); bodyVal.put("value", body); if (summary != null) { bodyVal.put("summary", summary); }/*from w ww . j av a 2s . c o m*/ JSONArray bodyArr = new JSONArray(); bodyArr.add(bodyVal); JSONObject bodyLang = new JSONObject(); bodyLang.put(lang, bodyArr); store.put("body", bodyLang); }
From source file:com.aerothai.database.job.JobService.java
public JSONObject GetJobAt(int id) throws Exception { Connection dbConn = null;/*from w ww.ja v a 2 s . com*/ JSONObject obj = new JSONObject(); JSONArray objList = new JSONArray(); int no = 1; //obj.put("draw", 2); obj.put("tag", "listat"); obj.put("msg", "error"); obj.put("status", false); try { dbConn = DBConnection.createConnection(); Statement stmt = dbConn.createStatement(); String query = "SELECT * FROM job where idjob = " + id; System.out.println(query); ResultSet rs = stmt.executeQuery(query); while (rs.next()) { JSONObject jsonData = new JSONObject(); jsonData.put("id", rs.getInt("idjob")); jsonData.put("iduser", rs.getString("iduser")); jsonData.put("idunit", rs.getString("idunit")); jsonData.put("iddevice", rs.getString("iddevice")); jsonData.put("service_method", rs.getString("service_method")); jsonData.put("service_type", rs.getString("service_type")); jsonData.put("details", rs.getString("details")); jsonData.put("action", rs.getString("action")); jsonData.put("remark", rs.getString("remark")); jsonData.put("idstatus", rs.getString("idstatus")); jsonData.put("receive_staff", rs.getString("receive_staff")); jsonData.put("action_staff", rs.getString("action_staff")); jsonData.put("close_staff", rs.getString("close_staff")); jsonData.put("wait_date", rs.getString("wait_date")); jsonData.put("receive_date", rs.getString("receive_date")); jsonData.put("action_date", rs.getString("action_date")); jsonData.put("finish_date", rs.getString("finish_date")); jsonData.put("eva_date", rs.getString("eva_date")); jsonData.put("close_date", rs.getString("close_date")); ; jsonData.put("no", no); objList.add(jsonData); no++; } obj.put("msg", "done"); obj.put("status", true); obj.put("data", objList); } catch (SQLException sqle) { throw sqle; } catch (Exception e) { // TODO Auto-generated catch block if (dbConn != null) { dbConn.close(); } throw e; } finally { if (dbConn != null) { dbConn.close(); } } return obj; }
From source file:com.conwet.silbops.model.AdvertiseTest.java
@Test @SuppressWarnings({ "unchecked" }) public void testJSONExport() { JSONArray json = new JSONArray(); json.add("attr1:double"); json.add("attr2:long"); json.add("attr3:str"); JSONArray newJSON = advertise.toJSON(); Collections.sort(newJSON);// w w w . j a v a 2 s.c o m Collections.sort(json); assertThat(newJSON).isEqualTo(json); assertThat(Advertise.fromJSON(json)).isEqualTo(advertise); }
From source file:hoot.services.controllers.ingest.FileUploadResourceTest.java
@Test @Category(UnitTest.class) public void TestBuildNativeRequestFgdbOgr() throws Exception { String jobId = "test-id-123"; String wkdirpath = homeFolder + "/upload/" + jobId; File workingDir = new File(wkdirpath); FileUtils.forceMkdir(workingDir);/*from w w w . java2s .com*/ org.junit.Assert.assertTrue(workingDir.exists()); File srcFile = new File(homeFolder + "/test-files/service/FileUploadResourceTest/fgdb_ogr.zip"); File destFile = new File(wkdirpath + "/fgdb_ogr.zip"); FileUtils.copyFile(srcFile, destFile); org.junit.Assert.assertTrue(destFile.exists()); FileUploadResource res = new FileUploadResource(); // Let's test zip JSONArray results = new JSONArray(); JSONObject zipStat = new JSONObject(); res._buildNativeRequest(jobId, "fgdb_ogr", "zip", "fgdb_ogr.zip", results, zipStat); org.junit.Assert.assertTrue(results.size() == 2); for (Object oRes : results) { JSONObject cnt = (JSONObject) oRes; if (cnt.get("type").toString().equals("FGDB_ZIP")) { org.junit.Assert.assertTrue(cnt.get("name").toString().equals("fgdb_ogr/DcGisRoads.gdb")); } else if (cnt.get("type").toString().equals("OGR_ZIP")) { org.junit.Assert .assertTrue(cnt.get("name").toString().equals("fgdb_ogr/jakarta_raya_coastline.shp")); } } FileUtils.forceDelete(workingDir); }
From source file:net.matthewauld.racetrack.server.WrSQL.java
@SuppressWarnings("unchecked") public String getJSONString(String query, String[] args) throws SQLException { connect();/*from w ww . j a v a 2 s . c o m*/ ps = con.prepareStatement(query); for (int i = 0; i < args.length; i++) { ps.setString(i + 1, args[i]); } rs = ps.executeQuery(); JSONObject json = new JSONObject(); JSONArray riders = new JSONArray(); while (rs.next()) { JSONObject riderJSON = new JSONObject(); riderJSON.put("id", rs.getInt("id")); riderJSON.put("first_name", rs.getString("first_name")); riderJSON.put("last_name", rs.getString("last_name")); riders.add(riderJSON); } if (riders.size() == 0) { json.put("riders", null); } else { json.put("riders", riders); } return json.toJSONString(); }
From source file:com.saludtec.web.UsuariosWeb.java
private JSONArray logout(HttpServletRequest request) { if (request.getSession().getAttribute("usuario") != null) { request.getSession().setAttribute("usuario", null); objArray = new JSONArray(); obj = new JSONObject(); obj.put("Exito", "1"); objArray.add(obj);//from www . java2s. c o m } return objArray; }
From source file:me.timothy.ddd.quests.QuestManager.java
@SuppressWarnings("unchecked") public QuestManager(Player player, AchievementManager aManager, EntityManager entManager) { logger = LogManager.getLogger(); entityManager = entManager;/*from w ww .j ava 2 s . c om*/ achievementManager = aManager; acceptedQuests = new ArrayList<>(); completedQuests = new ArrayList<>(); this.player = player; File questsFile = new File("quests.json"); if (questsFile.exists()) { try (FileReader fr = new FileReader(new File("quests.json"))) { JSONObject jObj = (JSONObject) (new JSONParser().parse(fr)); JSONArray questsArr = (JSONArray) jObj.get("current"); for (int i = 0; i < questsArr.size(); i++) { JSONObject questObj = (JSONObject) questsArr.get(i); String classStr = (String) questObj.get("class"); Class<?> cl = Class.forName(classStr); Quest quest = null; try { quest = (Quest) cl.getMethod("fromObject", getClass(), JSONObject.class).invoke(null, this, questObj); } catch (NoSuchMethodException nsme) { quest = (Quest) cl.getConstructor(QuestManager.class).newInstance(this); } acceptedQuests.add(quest); } JSONArray complete = (JSONArray) jObj.get("complete"); for (int i = 0; i < complete.size(); i++) { // completedQuests.add((Class<? extends Quest>) Class.forName((String) complete.get(i))); } } catch (Exception e) { logger.catching(e); } } Runnable saveQuests = new Runnable() { @Override public void run() { if (!DrunkDuckDispatch.ddd.save) return; JSONObject jObj = new JSONObject(); JSONArray questsArr = new JSONArray(); for (Quest qu : acceptedQuests) { questsArr.add(qu.asObject()); } jObj.put("current", questsArr); JSONArray completed = new JSONArray(); for (Class<? extends Quest> cl : completedQuests) { completed.add(cl.getCanonicalName()); } jObj.put("complete", completed); try (FileWriter fw = new FileWriter(new File("quests.json"))) { jObj.writeJSONString(fw); } catch (IOException ie) { } } }; Runtime.getRuntime().addShutdownHook(new Thread(saveQuests)); }
From source file:com.imagelake.android.download.Servlet_Download.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { PrintWriter out = response.getWriter(); try {//from ww w. j av a 2 s .com String type = request.getParameter("type"); if (type.equals("All_Cart_Items")) { String uid = request.getParameter("uid"); System.out.println(uid); System.out.println(type); jo = new JSONObject(); List<Cart> cartList = cdi.listCart(); List<CartHasImages> itemList = null; Images im = null; ImagesSub sim = null; Credits cre = null; if (!cartList.isEmpty()) { for (Cart c : cartList) { System.gc(); if (c.getUser_id() == Integer.parseInt(uid)) { itemList = cdi.listCartNewImages(c.getCart_id()); int i = 0; JSONArray ja = new JSONArray(); if (!itemList.isEmpty()) { for (CartHasImages ci : itemList) { System.gc(); System.out.println(".................................cartList is iii:" + i); if (c.getCart_id() == ci.getCart_id() && ci.getIs_purchase() == 0) { System.out.println( ".................................cartList is iii second:" + i); im = idi.getImageDetail(ci.getImg_id()); sim = idi.getSubImage(ci.getSubimg_id()); JSONObject joo = new JSONObject(); if (im.getImage_state_image_state_id() == 1) { i += ci.getCredits(); joo.put("imgid", im.getImages_id()); joo.put("sid", sim.getSub_images_id()); joo.put("dim", sim.getDimention()); joo.put("title", im.getTitle()); joo.put("crd", ci.getCredits()); joo.put("url", im.getImg_url()); joo.put("state", im.getImage_state_image_state_id()); joo.put("chid", ci.getCart_has_images_id()); String np = ""; System.out.println(sim.getImg_url()); int jj = 0; int kk = 0; adds: for (int j = 0; j < sim.getImg_url().length(); j++) { if (sim.getImg_url().charAt(j) == '\\') { jj++; } if (jj == 3) { if (kk > 0) { np += sim.getImg_url().charAt(j); } else { kk++; continue adds; } } } System.out.println(np); joo.put("surl", np); ja.add(joo); } else if (im.getImage_state_image_state_id() == 7) { joo.put("imgid", im.getImages_id()); joo.put("sid", sim.getSub_images_id()); joo.put("dim", sim.getDimention()); joo.put("title", im.getTitle()); joo.put("crd", ci.getCredits()); joo.put("url", im.getImg_url()); joo.put("state", im.getImage_state_image_state_id()); joo.put("chid", ci.getCart_has_images_id()); joo.put("surl", sim.getImg_url()); ja.add(joo); } } } } jo.put("cartList", ja); jo.put("total", i); } } System.out.println(jo.toJSONString()); out.write("json=" + jo.toJSONString()); } else { int i = 0; JSONArray ja = new JSONArray(); jo.put("cartList", ja); jo.put("total", i); out.write("json=" + jo.toJSONString()); } } else if (type.equals("Remove_DB")) { String imgID = request.getParameter("chiID"); String uid = request.getParameter("uid"); String crecount = request.getParameter("crec"); Cart c = cdi.getCart(Integer.parseInt(uid)); boolean ok = new CartDAOImp().removeFromCartHasimages(Integer.parseInt(imgID)); if (ok) { System.out.println("full imgcount:" + c.getImage_count()); int imgCount = c.getImage_count() - 1; System.out.println("After imgcount:" + imgCount); System.out.println("fill creditst:" + c.getCredit_count()); int creditCount = c.getCredit_count() - Integer.parseInt(crecount); System.out.println("After creditcount:" + creditCount); boolean k = new CartDAOImp().updateCartQty(imgCount, creditCount, c.getCart_id()); if (k) { out.write("msg=Successfuly_Remove"); } else { out.write("msg=Unable to complete the action."); } System.gc(); } else { out.write("msg=Internal server error,Please try again later."); } } else if (type.equals("Add_Light")) { String imgID = request.getParameter("chiID"); String uid = request.getParameter("uid"); String crecount = request.getParameter("crec"); System.out.println(imgID); System.out.println(uid); System.out.println(crecount); Cart c = cdi.getCart(Integer.parseInt(uid)); int imgCount = c.getImage_count() - 1; System.out.println("After imgcount:" + imgCount); System.out.println("fill creditst:" + c.getCredit_count()); int creditCount = c.getCredit_count() - Integer.parseInt(crecount); System.out.println("After creditcount:" + creditCount); String imgid = request.getParameter("img_id"); boolean dup = new CartDAOImp().imageAlradyHasImageInLightBox(Integer.parseInt(imgID), c.getCart_id(), 2); System.out.println("duplictio..." + dup); if (dup) { boolean k = new CartDAOImp().removeFromCartHasimages(Integer.parseInt(imgID)); boolean k2 = new CartDAOImp().updateCartQty(imgCount, creditCount, c.getCart_id()); if (k || k2) { System.gc(); out.write("msg=Successfully_Add_Lightbox"); } else { out.write("msg=Unable to complete the action,Please try again later."); System.gc(); } } else { boolean k = new CartDAOImp().updateCartQty(imgCount, creditCount, c.getCart_id()); boolean a = new CartDAOImp().updateToLightBox(Integer.parseInt(imgID), 2); if (k || a) { System.gc(); out.write("msg=Successfully_Add_Lightbox"); } else { out.write("msg=Unable to complete the action,Please try again later."); System.gc(); } } } else if (type.equals("Download")) { String uid = request.getParameter("uid"); Cart c = cdi.getCart(Integer.parseInt(uid)); List<CartHasImages> cList = cdi.listUserCartHasImages(c.getCart_id(), 0); List<CartHasImages> downloadList = new ArrayList<CartHasImages>(); boolean update; UserHasPackage up = null; Images im = null; User owner = null; ImagesSub is = null; ImagesSub minsub = null; Credits cd = null; int activeImagesCount = 0; int fullCreditCount = 0; up = uhdi.getUserActivePackage(Integer.parseInt(uid), 1); if (up != null) { System.out.println(":::::::::::::::::::::" + up.getPackage_id()); System.out.println(":::::::::::::::::::::" + up.getPackage_type()); if (up.getPackage_type() == 1 || up.getPackage_type() == 2 || up.getPackage_type() == 3) { System.out.println("This user have subscription package"); System.out.println(":::::::::::::::::::::" + up.getPackage_type()); //FreeTrial free=new FreeTrialDAOImp().getAFreeTrail(up.getPackage_type()); //check today is equel to the expire date of the package System.out.println("today: " + day); System.out.println("Expiredate: " + day.compareTo(up.getExpire_date())); System.out.println("Expire: " + up.getExpire_date()); if (day.compareTo(up.getExpire_date()) < 0 || day.compareTo(up.getExpire_date()) == 0) { System.out.println("expire date Not equal::::::::::"); //check today is equel to the last updated date // if(day.equals(up.getLast_date())){ System.out.println("last date Not equal::::::::::"); //check total image count of the cart is equal or less than the amount that can download in one day if (c.getImage_count() <= up.getDownload_count()) { System.out.println("expire date Not equal::::::::::"); int imgCount = 0; int totimgCount = 0; int creditCount = 0; int totcreditCount = 0; if (!cList.isEmpty()) { for (CartHasImages ch : cList) { if (up.getPackage_type() == 3 || up.getPackage_type() == 4) { im = idi.getImageDetail(ch.getImg_id());//get image //*****need to check current image is upload by a contributor or admin****** if (im.getImage_state_image_state_id() == 1) { activeImagesCount++;//adding 1 to active image count owner = udi.getUser(im.getUser_user_id()); is = idi.getSubImage(ch.getSubimg_id());//get sub image object cd = cdo.getCreditDetails(is.getCredits()); if (owner.getUser_type() == 2) { boolean income = spi.income(up, ch);//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ if (income) { imgCount++; creditCount += cd.getCredits(); boolean ok = cdi.updatePurchase(ch); if (ok) { downloadList.add(ch); } System.gc(); } else { System.out.println("loop breaks"); break; } } else { imgCount++; creditCount += cd.getCredits(); boolean ok = cdi.updatePurchase(ch); if (ok) { downloadList.add(ch); } System.gc(); } } /*else{ boolean ok=cdi.updatePurchaseToRemove(ch); System.gc(); }*/ totimgCount++; totcreditCount += ch.getCredits(); } else {//this is where we handle user trial packages++++++++++++++++++++++++++ System.out.println("this user has a free trial package"); im = idi.getImageDetail(ch.getImg_id()); //is=idi.getSubImage(ch.getSubimg_id());//get the subimage that use has add to cart if (im != null) { minsub = idi.getLowestQuality(ch.getImg_id()); System.out .println("min sub image id: " + minsub.getSub_images_id()); System.out.println("min sub image id=subimage id: " + (minsub.getSub_images_id() == ch.getSubimg_id())); if (im.getImage_state_image_state_id() == 1 && minsub.getSub_images_id() == ch.getSubimg_id()) { activeImagesCount++; imgCount++; is = idi.getSubImage(ch.getSubimg_id());//get the subimage that use has add to cart cd = cdo.getCreditDetails(is.getCredits()); creditCount += cd.getCredits(); boolean ok = cdi.updatePurchase(ch); if (ok) { downloadList.add(ch); } System.gc(); } /*else{ boolean ok=cdi.updatePurchaseToRemove(ch); System.gc(); }*/ } totimgCount++; totcreditCount += ch.getCredits(); System.out.println("total image count :" + totimgCount); System.out.println("image count :" + imgCount); System.out.println("active image count :" + activeImagesCount); System.out.println("total credit count :" + totcreditCount); System.out.println("credit count :" + creditCount); } } boolean ok = cdi.updateCartQty(c.getImage_count() - activeImagesCount, c.getCredit_count() - creditCount, c.getCart_id()); if (ok) { UserHasPackage uhp = new UserHasPackage(); if (up.getPackage_type() != 4) { uhp.setUhp_id(up.getUhp_id()); uhp.setCredit_count(0); uhp.setDownload_count(up.getDownload_count() - imgCount); uhp.setLast_date(day); update = uhdi.updatePackage(uhp); } else { uhp.setUhp_id(up.getUhp_id()); uhp.setCredit_count(up.getCredit_count() - creditCount); uhp.setDownload_count(0); uhp.setLast_date(day); update = uhdi.updatePackage(uhp); } System.out.println( "----------------------------------------------------------" + activeImagesCount); if (update && activeImagesCount > 0) { out.write("msg=Dwnloaded."); } else { out.write("msg=Unable to complete the action,Please try again later."); } } else { out.write("msg=Unable to complete the action,Please try again later."); } } else { out.write("msg=You'r cart is empty!"); } } else { out.write("msg=You have excided the limite of the downloads!"); } /*}else{ request.setAttribute("error", "You have excided the limite of the downloads!"); getServletContext().getRequestDispatcher("/cart.jsp").forward( request, response); System.gc(); } */ } else { out.write("msg=You'r current package has expired!"); } } else { System.out.println("This user have credit package"); //check today is equel to the expire date of the package if (day.compareTo(up.getExpire_date()) < 0 || day.compareTo(up.getExpire_date()) == 0) { System.out.println("expire date Not equal::::::::::"); //check today is equel to the last updated date // if(day.equals(up.getLast_date())){ for (CartHasImages ch : cList) { im = idi.getImageDetail(ch.getImg_id()); if (im.getImage_state_image_state_id() == 1) { is = idi.getSubImage(ch.getSubimg_id());//get the sub image cd = cdo.getCreditDetails(is.getCredits());//get the credits fullCreditCount += cd.getCredits(); } } System.out.println("last date Not equal::::::::::"); //check total image count of the cart is equal or less than the amount that can download in one day if (fullCreditCount <= up.getCredit_count()) { System.out.println("expire date Not equal::::::::::"); int imgCount = 0; int totimgCount = 0; int creditCount = 0; int totcreditCount = 0; if (!cList.isEmpty()) { for (CartHasImages ch : cList) { im = idi.getImageDetail(ch.getImg_id()); if (im.getImage_state_image_state_id() == 1) { activeImagesCount++; owner = udi.getUser(im.getUser_user_id());//check the image owner // is=idi.getSubImage(ch.getSubimg_id());//get the sub image // cd=cdo.getCreditDetails(is.getCredits());//get the credits System.out.println("owner is type " + owner.getUser_type()); if (owner.getUser_type() == 2) { boolean income = spi.income(up, ch);//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ System.out.println("Seller have income " + income); if (income) { imgCount++; // creditCount+=cd.getCredits(); System.gc(); boolean ok = cdi.updatePurchase(ch); if (ok) { downloadList.add(ch); } } else { System.out.println("loop breaks"); break; } } else { imgCount++; // creditCount+=cd.getCredits(); System.gc(); boolean ok = cdi.updatePurchase(ch); if (ok) { downloadList.add(ch); } } } /*else{ System.gc(); boolean ok=cdi.updatePurchaseToRemove(ch); System.out.println("removed of the purchase"+ok); }*/ totimgCount++; totcreditCount += ch.getCredits(); } boolean ok = cdi.updateCartQty(c.getImage_count() - activeImagesCount, c.getCredit_count() - fullCreditCount, c.getCart_id()); if (ok) { UserHasPackage uhp = new UserHasPackage(); if (up.getPackage_type() != 4) { uhp.setUhp_id(up.getUhp_id()); uhp.setCredit_count(0); uhp.setDownload_count(up.getDownload_count() - imgCount); uhp.setLast_date(day); update = uhdi.updatePackage(uhp); } else { uhp.setUhp_id(up.getUhp_id()); uhp.setCredit_count(up.getCredit_count() - fullCreditCount); uhp.setDownload_count(0); uhp.setLast_date(day); update = uhdi.updatePackage(uhp); System.gc(); } System.out.println( "-------------------------------------------" + activeImagesCount); if (update && activeImagesCount > 0) { out.write("msg=Dwnloaded."); } else { out.write("msg=Unable to complete the action,Please try again later."); } } else { out.write("msg=Unable to complete the action,Please try again later."); } } else { out.write("msg=You'r cart is empty!"); } } else { out.write("msg=You have excided the limite of the downloads!"); } } else { out.write("msg=You'r current package has expired!"); } } } else { out.write("msg=You have no package."); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:es.alrocar.jpe.writer.handler.MiniJPEWriterHandler.java
/** * {@inheritDoc}//from w w w. java2 s . c o m */ public Object startPoint() { Map geometry = new LinkedHashMap(); JSONArray coords = new JSONArray(); coords.add(0); coords.add(0); geometry.put("type", "Point"); geometry.put("coordinates", coords); return geometry; }