List of usage examples for org.json.simple JSONArray size
public int size()
From source file:moderation.Moderate.java
public List getInstapost() throws SQLException { List savedpost = getSavedList(album_id); List posts = new ArrayList(); try {//from w w w . ja v a2s.c o m String access_token = new Api().getInsta_token(); String tagname = this.hash; String url = "https://api.instagram.com/v1/tags/" + tagname + "/media/recent?access_token=" + access_token + "&count=50"; System.out.println(url); try { String genreJson = IOUtils.toString(new URL(url)); JSONObject genreJsonObject = (JSONObject) JSONValue.parseWithException(genreJson); String data = ""; JSONArray genreArray = (JSONArray) genreJsonObject.get("data"); JSONObject pagination = (JSONObject) genreJsonObject.get("pagination"); this.instanext = (String) pagination.get("next_url"); if (genreArray.size() > 0) { for (int i = 0; i < genreArray.size(); i++) { JSONObject firstGenre = (JSONObject) genreArray.get(i); PostModel post = new PostModel(); post.setAlbum_id(this.album_id); //parameter // post_id if (firstGenre.get("id") != null) { post.setPost_id(firstGenre.get("id").toString()); if (savedpost.contains(firstGenre.get("id"))) post.setStatus("old"); else post.setStatus("new"); } //post_creation time if (firstGenre.get("created_time") != null) post.setPost_time(firstGenre.get("created_time").toString()); // post type if (firstGenre.get("type") != null) post.setType(firstGenre.get("type").toString()); // post link if (firstGenre.get("link") != null) post.setLink(firstGenre.get("link").toString()); // sender details name, id, pic if (firstGenre.get("user") != null) { JSONObject user = (JSONObject) firstGenre.get("user"); post.setSender_id((String) user.get("id")); post.setSender_name((String) user.get("full_name")); post.setSender_pic((String) user.get("profile_picture")); } //post message JSONObject caption = (JSONObject) firstGenre.get("caption"); if (caption != null) post.setCaption_text(URLEncoder.encode((String) caption.get("text"), "UTF-8")); boolean ispic = false; String pic = ""; if (firstGenre.get("type").toString().equalsIgnoreCase("image")) { ispic = true; JSONObject images = (JSONObject) firstGenre.get("images"); if (images != null) { JSONObject low_resolution = (JSONObject) images.get("low_resolution"); JSONObject standard_resolution = (JSONObject) images.get("standard_resolution"); post.setImage_low((String) low_resolution.get("url")); post.setImage_standard((String) standard_resolution.get("url")); // out.println("<br/>original="+post_message+"<br/>encoded="+post_messageencode); post.setParam("post_id=" + post.getPost_id() + "&album_id=" + post.getAlbum_id() + "&type=" + post.getType() + "&post_time=" + post.getPost_time() + "&link=" + post.getLink() + "&pic_low=" + post.getImage_low() + "&pic_standard=" + post.getImage_standard() + "&post_message=" + post.getCaption_text() + "&sender_name=" + post.getSender_name() + "&sender_id=" + post.getSender_id() + "&sender_pic=" + post.getSender_pic()); } } if (ispic == true) posts.add(post); } } } catch (IOException | ParseException e) { System.err.println("Exception occure in getInstapost inner try catch" + e); } } catch (Exception e) { System.err.println("Exception in getinstapost method main try-catch" + e); } return posts; }
From source file:org.opencastproject.userdirectory.jpa.JpaUserAndRoleProvider.java
/** * Parses a User from a json representation. * /*from w ww .j a v a 2 s. c om*/ * @param json * the user as json * @return the user * @throws IOException * if the json can not be parsed */ protected User fromJson(String json) throws IOException { JSONObject jsonObject; try { jsonObject = (JSONObject) new JSONParser().parse(json); } catch (ParseException e) { throw new IOException(e); } String username = (String) jsonObject.get(USERNAME); String org = securityService.getOrganization().getId(); JSONArray roleArray = (JSONArray) jsonObject.get(ROLES); String[] roles = new String[roleArray.size()]; for (int i = 0; i < roleArray.size(); i++) { roles[i] = (String) roleArray.get(i); } return new User(username, org, roles); }
From source file:com.sforce.cd.apexUnit.client.codeCoverage.CodeCoverageComputer.java
private ApexClassCodeCoverageBean[] processJSONResponseAndConstructCodeCoverageBeans( PartnerConnection connection, JSONObject responseJsonObject) { int classCounter = 0; int coveredLinesForTheTeam = 0; int unCoveredLinesForTheTeam = 0; String responseStr = responseJsonObject.toJSONString(); LOG.debug(responseStr);/*from w w w .j a va 2 s .c om*/ JSONArray recordObject = (JSONArray) responseJsonObject.get("records"); if (recordObject != null && recordObject.size() > 0) { ApexClassCodeCoverageBean[] apexClassCodeCoverageBeans = new ApexClassCodeCoverageBean[recordObject .size()]; for (int i = 0; i < recordObject.size(); ++i) { ApexClassCodeCoverageBean apexClassCodeCoverageBean = new ApexClassCodeCoverageBean(); // The object below is one record from the ApexCodeCoverage // object JSONObject rec = (JSONObject) recordObject.get(i); // ApexClassOrTriggerId - The ID of the class or trigger under // test. String apexClassOrTriggerId = (String) rec.get("ApexClassOrTriggerId").toString(); if (apexClassOrTriggerId != null) { int coveredLines = 0; if (rec.get("NumLinesCovered") != null) { coveredLines = Integer.valueOf((String) rec.get("NumLinesCovered").toString()); coveredLinesForTheTeam += coveredLines; } else { LOG.debug(apexClassOrTriggerId + " has NumLinesCovered as NULL !!!!!!!!!"); } int unCoveredLines = 0; if (rec.get("NumLinesUncovered") != null) { unCoveredLines = Integer.valueOf((String) rec.get("NumLinesUncovered").toString()); unCoveredLinesForTheTeam += unCoveredLines; } else { LOG.debug(apexClassOrTriggerId + " has NumLinesUncovered as NULL !!!!!!!!!"); } if (rec.get("Coverage") != null) { JSONObject codeCoverageLineLists = (JSONObject) rec.get("Coverage"); JSONArray coveredLinesJsonArray = (JSONArray) codeCoverageLineLists.get("coveredLines"); JSONArray uncoveredLinesJsonArray = (JSONArray) codeCoverageLineLists.get("uncoveredLines"); List<Long> coveredLinesList = new ArrayList<Long>(); for (int j = 0; j < coveredLinesJsonArray.size(); j++) { coveredLinesList.add((Long) coveredLinesJsonArray.get(j)); LOG.debug("covered " + (Long) coveredLinesJsonArray.get(j)); } if (coveredLinesList.size() > 0) { apexClassCodeCoverageBean.setCoveredLinesList(coveredLinesList); } List<Long> uncoveredLinesList = new ArrayList<Long>(); for (int k = 0; k < uncoveredLinesJsonArray.size(); k++) { uncoveredLinesList.add((Long) uncoveredLinesJsonArray.get(k)); LOG.debug("uncovered " + (Long) uncoveredLinesJsonArray.get(k)); } if (uncoveredLinesList.size() > 0) { apexClassCodeCoverageBean.setUncoveredLinesList(uncoveredLinesList); } } apexClassCodeCoverageBean.setNumLinesCovered(coveredLines); apexClassCodeCoverageBean.setNumLinesUncovered(unCoveredLines); apexClassCodeCoverageBean.setApexClassorTriggerId(apexClassOrTriggerId); HashMap<String, String> apexClassInfoMap = ApexClassFetcherUtils .fetchApexClassInfoFromId(connection, apexClassOrTriggerId); String apexClassName = apexClassInfoMap.get("Name"); String apiVersion = apexClassInfoMap.get("ApiVersion"); String lengthWithoutComments = apexClassInfoMap.get("LengthWithoutComments"); apexClassCodeCoverageBean.setApexClassName(apexClassName); apexClassCodeCoverageBean.setApiVersion(apiVersion); apexClassCodeCoverageBean.setLengthWithoutComments(lengthWithoutComments); apexClassCodeCoverageBeans[classCounter++] = apexClassCodeCoverageBean; LOG.info("Record number # " + classCounter + " : coveredLines : " + coveredLines + " : unCoveredLines : " + unCoveredLines + " : code coverage % : " + apexClassCodeCoverageBean.getCoveragePercentage() + " : apexClassOrTriggerId : " + apexClassOrTriggerId + " : apexClassName : " + apexClassName + " : apiVersion : " + apiVersion + " : lengthWithoutComments : " + lengthWithoutComments); } } double totalLines = coveredLinesForTheTeam + unCoveredLinesForTheTeam; if (totalLines > 0.0) { ApexUnitCodeCoverageResults.teamCodeCoverage = (coveredLinesForTheTeam / (totalLines)) * 100.0; } else { ApexUnitCodeCoverageResults.teamCodeCoverage = 100.0; } LOG.info( "#################################### Summary of code coverage computation for the team.. #################################### "); LOG.info("Total Covered lines : " + coveredLinesForTheTeam + "\n Total Uncovered lines : " + unCoveredLinesForTheTeam); LOG.info("Team code coverage is : " + ApexUnitCodeCoverageResults.teamCodeCoverage + "%"); return apexClassCodeCoverageBeans; } else { // no code coverage record object found in the response. return null return null; } }
From source file:de.xaniox.heavyspleef.core.uuid.UUIDManager.java
private GameProfile fetchGameProfile(UUID uuid) throws IOException, ParseException { String uuidString = uuid.toString().replace("-", ""); URL url = new URL(String.format(UUID_BASE_URL, uuidString)); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); InputStream inputStream = connection.getInputStream(); JSONArray result = (JSONArray) parser.parse(new InputStreamReader(inputStream)); JSONObject current = (JSONObject) result.get(result.size() - 1); String name = (String) current.get("name"); if (name == null) { return null; }//from w w w . j a va2 s . c om GameProfile profile = new GameProfile(uuid, name); return profile; }
From source file:eu.seaclouds.platform.discoverer.crawler.CloudTypes.java
private void supports(String keyName, JSONObject feat, Offering offering) { if (feat.containsKey(keyName) == false) return;/*from w w w . ja v a 2 s . co m*/ JSONArray dbs = (JSONArray) feat.get(keyName); for (int i = 0; i < dbs.size(); i++) { String cloudHarmonySupportName = (String) dbs.get(i); String seaCloudsSupportName = externaltoSCTag.get(cloudHarmonySupportName); if (seaCloudsSupportName != null) offering.addProperty(seaCloudsSupportName + "_support", "true"); } }
From source file:hoot.services.nativeInterfaces.ProcessStreamInterface.java
/** * Creates direct exec call/*from w w w. jav a 2 s . co m*/ * like hoot --ogr2osm target input output if the "exectype" is "hoot" * * @param cmd * @return */ private String[] createCmdArray(JSONObject cmd) { ArrayList<String> execCmd = new ArrayList<String>(); try { execCmd.add("hoot"); execCmd.add("--" + (String) cmd.get("exec")); JSONArray params = (JSONArray) cmd.get("params"); int nParams = params.size(); for (int i = 0; i < nParams; i++) { JSONObject param = (JSONObject) params.get(i); Iterator iter = param.entrySet().iterator(); String arg = ""; while (iter.hasNext()) { Map.Entry mEntry = (Map.Entry) iter.next(); arg = (String) mEntry.getValue(); } execCmd.add(arg); } } catch (Exception ex) { log.error("Failed to parse job params. Reason: " + ex.getMessage()); } Object[] objectArray = execCmd.toArray(); return Arrays.copyOf(objectArray, objectArray.length, String[].class); }
From source file:functionaltests.RestSchedulerTagTest.java
@Test public void testTaskResultByTag() throws Exception { HttpResponse response = sendRequest("jobs/" + submittedJobId + "/tasks/tag/LOOP-T2-1/result"); JSONArray jsonArray = toJsonArray(response); System.out.println(jsonArray.toJSONString()); ArrayList<String> taskNames = new ArrayList<>(4); for (int i = 0; i < jsonArray.size(); i++) { JSONObject id = (JSONObject) ((JSONObject) jsonArray.get(i)).get("id"); String name = (String) id.get("readableName"); taskNames.add(name);// w w w .j a va 2 s .co m } assertTrue(taskNames.contains("T1#1")); assertTrue(taskNames.contains("Print1#1")); assertTrue(taskNames.contains("Print2#1")); assertTrue(taskNames.contains("T2#1")); assertEquals(4, jsonArray.size()); }
From source file:hoot.services.nativeInterfaces.ProcessStreamInterface.java
/** * @param cmd//from www. ja v a 2s .c om * @return */ private String[] createBashScriptCmdArray(JSONObject cmd) { ArrayList<String> execCmd = new ArrayList<String>(); try { execCmd.add("bash"); execCmd.add(coreScriptPath + "/" + (String) cmd.get("exec")); JSONArray params = (JSONArray) cmd.get("params"); int nParams = params.size(); for (int i = 0; i < nParams; i++) { JSONObject param = (JSONObject) params.get(i); Iterator iter = param.entrySet().iterator(); String arg = ""; String key = ""; while (iter.hasNext()) { Map.Entry mEntry = (Map.Entry) iter.next(); key = (String) mEntry.getKey(); arg = (String) mEntry.getValue(); } execCmd.add(arg); } if (cmd.get("jobId") != null) { String jobid = cmd.get("jobId").toString(); execCmd.add(jobid); } } catch (Exception ex) { log.error("Failed to parse job params. Reason: " + ex.getMessage()); } Object[] objectArray = execCmd.toArray(); return Arrays.copyOf(objectArray, objectArray.length, String[].class); }
From source file:hoot.services.nativeInterfaces.ProcessStreamInterface.java
/** * Creates command for make file script based call if exectype = "make" * output looks like make -f [some makefile] [any argument make file uses] * * @param cmd/*w w w . jav a 2 s . c o m*/ * @return */ private String[] createScriptCmdArray(JSONObject cmd) { ArrayList<String> execCmd = new ArrayList<String>(); try { execCmd.add("make"); execCmd.add("-f"); execCmd.add(coreScriptPath + "/" + (String) cmd.get("exec")); JSONArray params = (JSONArray) cmd.get("params"); int nParams = params.size(); for (int i = 0; i < nParams; i++) { JSONObject param = (JSONObject) params.get(i); Iterator iter = param.entrySet().iterator(); String arg = ""; String key = ""; while (iter.hasNext()) { Map.Entry mEntry = (Map.Entry) iter.next(); key = (String) mEntry.getKey(); arg = (String) mEntry.getValue(); } execCmd.add(key + "=" + arg + ""); } String jobid = cmd.get("jobId").toString(); execCmd.add("jobid=" + jobid); execCmd.add("DB_URL=" + dbUrl); } catch (Exception ex) { log.error("Failed to parse job params. Reason: " + ex.getMessage()); } Object[] objectArray = execCmd.toArray(); return Arrays.copyOf(objectArray, objectArray.length, String[].class); }
From source file:com.unilever.audit.services2.SyncUp.java
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public void saveVisit(JSONObject visitData) throws Exception { Map<String, Object> hm = new HashMap<String, Object>(); /***************Visit***********************/ Visit saveVisit = new Visit(); hm.put("id", visitData.get("visitId").toString()); if (visitFacadeREST.findOneByQuery("Visit.findById", hm) == null) { saveVisit.setId(visitData.get("visitId").toString()); Customers c = em.getReference(Customers.class, (Integer.parseInt(visitData.get("customerId").toString()))); saveVisit.setCustomerid(c);/*from www .j av a2s .c o m*/ Merchandisers m = em.getReference(Merchandisers.class, new BigDecimal(visitData.get("merchandiserId").toString())); saveVisit.setMerchandiserid(m); try { //Date date = new SimpleDateFormat("MM/dd/yyyy").parse(visitData.get("visitDate").toString()); Date date = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss") .parse(visitData.get("visitDate").toString()); saveVisit.setVisitdate(date); } catch (java.text.ParseException ex) { ex.printStackTrace(); } saveVisit.setSubmitteddate(new Date()); visitFacadeREST.create(saveVisit); /****************Product Result*********************/ JSONArray Productarray = (JSONArray) visitData.get("productResult"); for (Iterator<JSONObject> it1 = Productarray.iterator(); it1.hasNext();) { JSONObject ProductJson = it1.next(); ProductResult productResult = new ProductResult(); productResult.setQuantity(new BigInteger(ProductJson.get("quantity").toString())); productResult.setExsit(new BigInteger(ProductJson.get("exist").toString())); productResult.setVisitid(saveVisit); Productkpis ProductKPI = em.getReference(Productkpis.class, new BigDecimal(ProductJson.get("productKpiId").toString())); productResult.setProductid(ProductKPI); productResultFacadeREST.create(productResult); } /*********************Price Result*******************/ JSONArray Pricearray = (JSONArray) visitData.get("priceResult"); if (Pricearray.size() > 0) { for (Iterator<JSONObject> it2 = Pricearray.iterator(); it2.hasNext();) { JSONObject PriceJson = it2.next(); PriceResult priceResult = new PriceResult(); priceResult.setVisitid(saveVisit); priceResult.setPrice(new BigDecimal(PriceJson.get("pricevalue").toString())); priceResult.setPricetagexist(new BigInteger(PriceJson.get("pricetagcheck").toString())); Pricekpis PriceKPI = em.getReference(Pricekpis.class, new BigDecimal(PriceJson.get("priceKPIid").toString())); priceResult.setPriceid(PriceKPI); priceResultFacadeREST.create(priceResult); } } /*********************Question Result*****************/ JSONArray Questionarray = (JSONArray) visitData.get("questionResult"); for (Iterator<JSONObject> it3 = Questionarray.iterator(); it3.hasNext();) { JSONObject QuestionJson = it3.next(); QuestionResult questionResult = new QuestionResult(); questionResult.setVisitid(saveVisit); questionResult.setAnswertext(QuestionJson.get("answerText").toString()); Questionkpis questionKPI = em.getReference(Questionkpis.class, new BigDecimal(QuestionJson.get("questionId").toString())); questionResult.setQuestionid(questionKPI); questionResultFacadeREST.create(questionResult); } /*********************Promotion Result*********************/ JSONArray promotionarray = (JSONArray) visitData.get("promotionResult"); for (Iterator<JSONObject> it4 = promotionarray.iterator(); it4.hasNext();) { JSONObject PromotionJson = it4.next(); PromotionResult promotionResult = new PromotionResult(); promotionResult.setVisitid(saveVisit); promotionResult.setExist(new BigInteger(PromotionJson.get("exist").toString())); Promotionkpis promotionKPI = em.getReference(Promotionkpis.class, new BigDecimal(PromotionJson.get("promotionKPIid").toString())); promotionResult.setPromotionid(promotionKPI); promotionResultFacadeREST.create(promotionResult); } /***********************ShareOfFolder Result*********************/ JSONArray ShareOfFolderarray = (JSONArray) visitData.get("sofResult"); for (Iterator<JSONObject> it5 = ShareOfFolderarray.iterator(); it5.hasNext();) { JSONObject SofJson = it5.next(); ShareoffolderKpiResult SofResult = new ShareoffolderKpiResult(); SofResult.setVisitid(saveVisit); SofResult.setNoofpicture(new BigInteger(SofJson.get("noOfPicture").toString())); SofResult.setTotalofpicture(new BigInteger(SofJson.get("totalNoOfPicture").toString())); Shareoffolderkpis shareoffolderkpis = em.getReference(Shareoffolderkpis.class, new BigDecimal(SofJson.get("sofID").toString())); SofResult.setSofid(shareoffolderkpis); SofResult.setSofexist(new BigInteger(SofJson.get("sofExist").toString())); shareoffolderKpiResultFacadeREST.create(SofResult); } /***************************STOCK Result***********************/ JSONArray Stockarray = (JSONArray) visitData.get("stockResult"); for (Iterator<JSONObject> it8 = Stockarray.iterator(); it8.hasNext();) { JSONObject StockJson = it8.next(); StockResult stockResult = new StockResult(); stockResult.setQuantity(new BigInteger(StockJson.get("quantity").toString())); stockResult.setVisitid(saveVisit); stockResult.setStockquantity(new BigInteger(StockJson.get("stockQuantity").toString())); Stockkpis stockKPI = em.getReference(Stockkpis.class, new BigDecimal(StockJson.get("stockKpiId").toString())); stockResult.setStockid(stockKPI); stockResultFacadeREST.create(stockResult); } /********************NPD Result**************************/ JSONArray Npdarray = (JSONArray) visitData.get("npdResult"); for (Iterator<JSONObject> it6 = Npdarray.iterator(); it6.hasNext();) { JSONObject NpdJson = it6.next(); NpdResult npdResult = new NpdResult(); npdResult.setVisitid(saveVisit); npdResult.setExist(new BigInteger(NpdJson.get("exist").toString())); Npdkpis npdKPI = em.getReference(Npdkpis.class, new BigDecimal(NpdJson.get("npdid").toString())); npdResult.setNpdid(npdKPI); npdResultFacadeREST.create(npdResult); } /***********************share of shelf Result**********************/ JSONArray shareOfShelfarray = (JSONArray) visitData.get("shareOfShelfResult"); for (Iterator<JSONObject> it7 = shareOfShelfarray.iterator(); it7.hasNext();) { JSONObject ShareOfShelfJson = it7.next(); ShareofshelfKpiResult shareofshelfKpiResult = new ShareofshelfKpiResult(); shareofshelfKpiResult.setVisitid(saveVisit); shareofshelfKpiResult.setSosbrand(new BigInteger(ShareOfShelfJson.get("sosBrand").toString())); shareofshelfKpiResult.setSossegment(new BigInteger(ShareOfShelfJson.get("sosSegment").toString())); Shareofshelfkpi ShareOfShelfKPI = em.getReference(Shareofshelfkpi.class, new BigDecimal(ShareOfShelfJson.get("shareofShelfID").toString())); shareofshelfKpiResult.setShareofshelfid(ShareOfShelfKPI); shareofshelfKpiResultFacadeREST.create(shareofshelfKpiResult); } /***********************POS Result************************/ JSONArray Posarray = (JSONArray) visitData.get("posResult"); for (Iterator<JSONObject> it9 = Posarray.iterator(); it9.hasNext();) { JSONObject PosJson = it9.next(); PosmaterialResult posResult = new PosmaterialResult(); posResult.setVisitid(saveVisit); posResult.setExist(new BigInteger(PosJson.get("exist").toString())); Posmaterialkpi posmaterialKPI = em.getReference(Posmaterialkpi.class, new BigDecimal(PosJson.get("posid").toString())); posResult.setPosmaterialid(posmaterialKPI); posmaterialResultFacadeREST.create(posResult); } } }