List of usage examples for org.json.simple JSONArray iterator
public Iterator<E> iterator()
From source file:JSONParser.JSONOperations.java
public JSONArray WOESummGenForResponseJSONObject(JSONObject JSONObjectToParse, String departName, JSONArray WOERows, String rowName) { loggerObj.log(Level.INFO, "Inside WOESummGenForResponseJSONObject for parsing JSON data"); if (WOERows == null) { WOERows = new JSONArray(); }/* w w w. java 2 s. c o m*/ try { loggerObj.log(Level.INFO, "Going to get row data from the individual response JSON objects"); JSONArray row = getRowsFromSupportapiJSON(JSONObjectToParse, rowName); Iterator<JSONObject> iterator = row.iterator(); String[] dcMdmModules = new String[] { "MDM-Profile Mgmt", "MDM-App Mgmt", "MDM-Settings", "MDM-Enrollment", "MDM-Asset Mgmt", "App Mgmt", "Enrollment", "MDM Settings", "Geo-Location", "ProfileMgmt" }; while (iterator.hasNext()) { loggerObj.log(Level.INFO, "Going to iterate over individual field data from the row obatianed from parsing individual response json objects"); JSONArray rowIndex = (JSONArray) iterator.next().get("fl"); Iterator<JSONObject> innerIterator = rowIndex.iterator(); JSONObject WOERow = new JSONObject(); while (innerIterator.hasNext()) { JSONObject field = innerIterator.next(); // System.out.println(field.get("content") + "\t" + field.get("val")); if (field.get("val").toString().equals("URI")) { String content = (String) field.get("content"); if (content == null || content.equals("null")) { content = "--"; } WOERow.put("URI", content); } if (field.get("val").toString().equals("Email")) { String content = (String) field.get("content"); if (content == null || content.equals("null")) { content = "--"; } WOERow.put("Email", content); } if (field.get("val").toString().equals("Ticket Classification")) { String content = (String) field.get("content"); if (content == null || content.equals("null")) { content = "--"; } WOERow.put("Issue Type", content); } if (field.get("val").toString().equals("Status")) { if (field.get("content") != null) { if (field.get("content").toString().equals("Waiting on Engineering") || field.get("content").toString().contains("Need")) { if (departName.equals("Desktop Central")) { loggerObj.log(Level.INFO, "The status object is entered"); } WOERow.put("Status", field.get("content").toString()); } else { break; } } } if (field.get("val").toString().equals("Ticket Owner")) { String content = (String) field.get("content"); if (content == null || content.equals("null")) { content = "--"; } WOERow.put("Ticket Owner", content); } if (field.get("val").toString().equals("Case Owner")) { String content = (String) field.get("content"); if (content == null || content.equals("null")) { content = "--"; } WOERow.put("Case Owner", content); } if (field.get("val").toString().equals("Created Time")) { String content = (String) field.get("content"); if (content == null || content.equals("null")) { content = "--"; } WOERow.put("Created Time", content); } if (field.get("val").toString().equals("Ticket Id")) { String content = (String) field.get("content"); if (content == null || content.equals("null")) { content = "--"; } WOERow.put("Ticket Id", content); } if (field.get("val").toString().equals("Developers")) { String content = (String) field.get("content"); if (content == null || content.equals("null")) { content = "--"; } WOERow.put("Developers", content); } if (field.get("val").toString().equals("Modules")) { if (field.get("content").toString() != null) { loggerObj.log(Level.INFO, "Modules: " + field.get("content").toString()); String moduleName = field.get("content").toString(); if (departName.equals("Desktop Central")) { for (String i : dcMdmModules) { if (moduleName.equals(i)) { WOERow.put("Modules", moduleName); loggerObj.log(Level.INFO, "Module is " + moduleName); continue; } } } else { WOERow.put("Modules", moduleName); } } } if (field.get("val").toString().equals("Department Map")) { String content = (String) field.get("content"); if (content == null || content.equals("null")) { content = "--"; } WOERow.put("Department Map", content); } if (field.get("val").toString().equals("Due Date")) { String content = (String) field.get("content"); if (content == null || content.equals("null")) { content = "--"; } WOERow.put("Due Date", content); } if (field.get("val").toString().equals("Problem Description")) { String content = (String) field.get("content"); if (content == null || content.equals("null")) { content = "--"; } WOERow.put("Problem Description", content); } if (field.get("val").toString().equals("Modified Time")) { String content = (String) field.get("content"); if (content == null || content.equals("null")) { content = "--"; } WOERow.put("Last Updated At", content); } } if (WOERow.get("Status") != null && WOERow.get("Modules") != null) { loggerObj.log(Level.INFO, "WOEROw added: status" + WOERow.get("Status").toString() + "Modules" + WOERow.get("Modules").toString()); WOERows.add(WOERow); } } loggerObj.log(Level.INFO, "Successfully parsed the data"); return WOERows; } catch (Exception e) { loggerObj.log(Level.SEVERE, "Error in parsing the data", e); return null; } }
From source file:com.nubits.nubot.trading.wrappers.ExcoinWrapper.java
private ApiResponse getBalanceImpl(CurrencyPair pair, Currency currency) { ApiResponse apiResponse = new ApiResponse(); String url = API_BASE_URL + "/" + API_ACCOUNT + "/" + API_SUMMARY; ApiResponse response = getQuery(url); if (response.isPositive()) { JSONObject httpAnswerJson = (JSONObject) response.getResponseObject(); JSONArray activeWallets = (JSONArray) httpAnswerJson.get("active_wallets"); if (currency == null) { //get all balances Amount PEGAvail = new Amount(0, pair.getPaymentCurrency()); Amount NBTAvail = new Amount(0, pair.getOrderCurrency()); Amount PEGonOrder = new Amount(0, pair.getPaymentCurrency()); Amount NBTonOrder = new Amount(0, pair.getOrderCurrency()); for (Iterator<JSONObject> wallet = activeWallets.iterator(); wallet.hasNext();) { JSONObject thisWallet = wallet.next(); String thisCurrency = thisWallet.get("currency").toString(); if (thisCurrency.equals(pair.getPaymentCurrency().getCode().toUpperCase())) { PEGAvail.setQuantity(Double.parseDouble(thisWallet.get("available_balance").toString())); PEGonOrder.setQuantity(Double.parseDouble(thisWallet.get("order_balance").toString())); }//www .ja v a 2 s . c o m if (thisCurrency.equals(pair.getOrderCurrency().getCode().toUpperCase())) { NBTAvail.setQuantity(Double.parseDouble(thisWallet.get("available_balance").toString())); NBTonOrder.setQuantity(Double.parseDouble(thisWallet.get("order_balance").toString())); } } PairBalance balance = new PairBalance(PEGAvail, NBTAvail, PEGonOrder, NBTonOrder); balance = PairBalance.getSwappedBalance(balance); //Swap here for BTC_NBT apiResponse.setResponseObject(balance); } else { //get specific balance Amount total = new Amount(0, currency); for (Iterator<JSONObject> wallet = activeWallets.iterator(); wallet.hasNext();) { JSONObject thisWallet = wallet.next(); String thisCurrency = thisWallet.get("currency").toString(); if (thisCurrency.equals(currency.getCode().toUpperCase())) { total.setQuantity(Double.parseDouble(thisWallet.get("available_balance").toString())); } } apiResponse.setResponseObject(total); } } else { apiResponse = response; } return apiResponse; }
From source file:JSONParser.JSONOperations.java
public JSONArray WOESummGenForResponseArray(JSONArray JSONArrayToParse, String departName, String rowName) { loggerObj.log(Level.INFO, "Insied WOESummGenForResponseArray for parsing data"); JSONArray WOERows = new JSONArray(); try {/* w ww .ja v a 2s. c o m*/ loggerObj.log(Level.INFO, "Going to iterate over the responseJSONArray"); Iterator<JSONObject> jsonObjectItr = JSONArrayToParse.iterator(); while (jsonObjectItr.hasNext()) { loggerObj.log(Level.INFO, "Going to get row data from the individual JSON objects parsed from responseJSONArray"); JSONArray row = getRowsFromSupportapiJSON((JSONObject) jsonObjectItr.next(), rowName); Iterator<JSONObject> iterator = row.iterator(); while (iterator.hasNext()) { loggerObj.log(Level.INFO, "Going to iterate over individual field data from the row obatianed from parsing individual response json objects"); JSONArray rowIndex = (JSONArray) iterator.next().get("fl"); Iterator<JSONObject> innerIterator = rowIndex.iterator(); JSONObject WOERow = new JSONObject(); while (innerIterator.hasNext()) { JSONObject field = innerIterator.next(); // System.out.println(field.get("content") + "\t" + field.get("val")); if (field.get("val").toString().equals("URI")) { WOERow.put("URI", field.get("content").toString()); } if (field.get("val").toString().equals("Email")) { WOERow.put("Email", field.get("content").toString()); } if (field.get("val").toString().equals("Subject")) { WOERow.put("Subject", field.get("content").toString()); } if (field.get("val").toString().equals("Status")) { // System.out.println(field.get("content").toString()); if (!field.get("content").toString().equals("Waiting on Engineering") && !field.get("content").toString().contains("Need")) { break; } else { WOERow.put("Status", field.get("content").toString()); } } if (field.get("val").toString().equals("Ticket Owner")) { WOERow.put("Ticket Owner", field.get("content").toString()); } if (field.get("val").toString().equals("Case Owner")) { WOERow.put("Case Owner", field.get("content").toString()); } if (field.get("val").toString().equals("Created Time")) { WOERow.put("Created Time", field.get("content").toString()); } if (field.get("val").toString().equals("Ticket Id")) { //System.out.print("\t" + field.get("content").toString()); WOERow.put("Ticket Id", field.get("content").toString()); } if (field.get("val").toString().equals("Developers")) { WOERow.put("Developers", field.get("content").toString()); } if (field.get("val").toString().equals("Modules")) { String moduleName = field.get("content").toString(); if (departName.equals("Desktop Central")) { if (moduleName.equals("App Mgmt") || moduleName.equals("Enrollment") || moduleName.equals("MDM Settings") || moduleName.equals("Geo-Location") || moduleName.equals("ProfileMgmt")) { WOERow.put("Modules", field.get("content").toString()); } else { break; } } else { WOERow.put("Modules", field.get("content").toString()); } } if (field.get("val").toString().equals("Department Map")) { WOERow.put("Department Map", field.get("content").toString()); } if (field.get("val").toString().equals("Due Date")) { WOERow.put("Due Date", field.get("content").toString()); } if (field.get("val").toString().equals("Problem Description")) { if (field.get("content") == null || field.get("content").toString().equals("null")) { WOERow.put("Problem Description", "--"); } else { WOERow.put("Problem Description", field.get("content").toString()); } } } if (WOERow.get("Status") != null && WOERow.get("Modules") != null) { WOERows.add(WOERow); } } } loggerObj.log(Level.INFO, "Successfully parsed the data"); return WOERows; } catch (Exception e) { loggerObj.log(Level.INFO, "Error in parsing the data" + e.toString()); return null; } }
From source file:com.nubits.nubot.trading.wrappers.CcedkWrapper.java
private ApiResponse getBalanceImpl(Currency currency, CurrencyPair pair) { ApiResponse apiResponse = new ApiResponse(); String url = API_BASE_URL; String method = API_GET_INFO; boolean isGet = false; HashMap<String, String> query_args = new HashMap<>(); ApiResponse response = getQuery(url, method, query_args, true, isGet); if (response.isPositive()) { JSONObject httpAnswerJson = (JSONObject) response.getResponseObject(); JSONObject dataJson = (JSONObject) httpAnswerJson.get("response"); JSONArray entities = (JSONArray) dataJson.get("entities"); if (currency == null) { //Get all balances long NBTid = TradeUtilsCCEDK.getCCDKECurrencyId(pair.getOrderCurrency().getCode().toUpperCase()); long PEGid = TradeUtilsCCEDK.getCCDKECurrencyId(pair.getPaymentCurrency().getCode().toUpperCase()); Amount NBTAvail = new Amount(0, pair.getOrderCurrency()); Amount PEGAvail = new Amount(0, pair.getPaymentCurrency()); for (Iterator<JSONObject> entity = entities.iterator(); entity.hasNext();) { JSONObject thisEntity = entity.next(); long entityId = (Long) thisEntity.get("currency_id"); if (entityId == NBTid) { NBTAvail.setQuantity(Utils.getDouble(thisEntity.get("balance"))); }// www. ja v a 2s.c o m if (entityId == PEGid) { PEGAvail.setQuantity(Utils.getDouble(thisEntity.get("balance"))); } } //Get balance on Order by counting active orders ApiResponse activeOrdersResponse = getActiveOrders(pair); //Initialize Amounts double NBTonOrder = 0; double PEGonOrder = 0; Amount NBTOnOrderAmount = new Amount(NBTonOrder, pair.getOrderCurrency()); Amount PEGOnOrderAmount = new Amount(PEGonOrder, pair.getPaymentCurrency()); if (activeOrdersResponse.isPositive()) { ArrayList<Order> orderList = (ArrayList<Order>) activeOrdersResponse.getResponseObject(); for (int i = 0; i < orderList.size(); i++) { Order tempOrder = orderList.get(i); if (tempOrder.getType().equalsIgnoreCase(Constant.SELL)) { NBTonOrder += tempOrder.getAmount().getQuantity(); } else { PEGonOrder += tempOrder.getAmount().getQuantity() * tempOrder.getPrice().getQuantity(); } } NBTOnOrderAmount = new Amount(NBTonOrder, pair.getOrderCurrency()); PEGOnOrderAmount = new Amount(PEGonOrder, pair.getPaymentCurrency()); } else { return activeOrdersResponse; } PairBalance balance = new PairBalance(PEGAvail, NBTAvail, PEGOnOrderAmount, NBTOnOrderAmount); apiResponse.setResponseObject(balance); } else { //Specific currency requested long id = TradeUtilsCCEDK.getCCDKECurrencyId(currency.getCode().toUpperCase()); Amount total = new Amount(0, currency); for (Iterator<JSONObject> entity = entities.iterator(); entity.hasNext();) { JSONObject thisEntity = entity.next(); long entityId = (Long) thisEntity.get("currency_id"); if (entityId == id) { total.setQuantity(Utils.getDouble(thisEntity.get("balance"))); } } apiResponse.setResponseObject(total); } } else { apiResponse = response; } return apiResponse; }
From source file:com.paniclauncher.workers.InstanceInstaller.java
private ArrayList<MojangDownloadable> getNeededResources() { ArrayList<MojangDownloadable> downloads = new ArrayList<MojangDownloadable>(); // All the files // Read in the resources needed if (!isServer) { try {/*w w w .j a v a 2s.co m*/ boolean isTruncated; String marker = null; String add; do { if (marker == null) { add = ""; } else { add = "?marker=" + marker; } URL resourceUrl = new URL("https://s3.amazonaws.com/Minecraft.Resources/" + add); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(resourceUrl.openStream()); isTruncated = Boolean .parseBoolean(doc.getElementsByTagName("IsTruncated").item(0).getTextContent()); NodeList nodeLst = doc.getElementsByTagName("Contents"); for (int i = 0; i < nodeLst.getLength(); i++) { Node node = nodeLst.item(i); if (node.getNodeType() == 1) { Element element = (Element) node; String key = element.getElementsByTagName("Key").item(0).getChildNodes().item(0) .getNodeValue(); String etag = element.getElementsByTagName("ETag") != null ? element .getElementsByTagName("ETag").item(0).getChildNodes().item(0).getNodeValue() : "-"; etag = getEtag(etag); marker = key; long size = Long.parseLong(element.getElementsByTagName("Size").item(0).getChildNodes() .item(0).getNodeValue()); if (size > 0L) { File file; String filename; if (key.contains("/")) { filename = key.substring(key.lastIndexOf('/') + 1, key.length()); File directory = new File(App.settings.getResourcesDir(), key.substring(0, key.lastIndexOf('/'))); file = new File(directory, filename); } else { file = new File(App.settings.getResourcesDir(), key); filename = file.getName(); } if (!Utils.getMD5(file).equalsIgnoreCase(etag)) downloads.add(new MojangDownloadable( "https://s3.amazonaws.com/Minecraft.Resources/" + key, file, etag, this)); } } } } while (isTruncated); } catch (Exception e) { App.settings.getConsole().logStackTrace(e); } } // Now lets see if we have custom mainclass and extraarguments try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); InputSource is = new InputSource(new StringReader(pack.getXML(version, false))); Document document = builder.parse(is); document.getDocumentElement().normalize(); NodeList nodeList = document.getElementsByTagName("mainclass"); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; if (element.hasAttribute("depends")) { boolean found = false; for (Mod mod : selectedMods) { if (element.getAttribute("depends").equalsIgnoreCase(mod.getName())) { found = true; break; } } if (!found) { break; } } NodeList nodeList1 = element.getChildNodes(); this.mainClass = nodeList1.item(0).getNodeValue(); } } } catch (SAXException e) { App.settings.getConsole().logStackTrace(e); } catch (ParserConfigurationException e) { App.settings.getConsole().logStackTrace(e); } catch (IOException e) { App.settings.getConsole().logStackTrace(e); } try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); InputSource is = new InputSource(new StringReader(pack.getXML(version, false))); Document document = builder.parse(is); document.getDocumentElement().normalize(); NodeList nodeList = document.getElementsByTagName("extraarguments"); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; if (element.hasAttribute("depends")) { boolean found = false; for (Mod mod : selectedMods) { if (element.getAttribute("depends").equalsIgnoreCase(mod.getName())) { found = true; break; } } if (!found) { break; } } NodeList nodeList1 = element.getChildNodes(); this.extraArguments = nodeList1.item(0).getNodeValue(); } } } catch (SAXException e) { App.settings.getConsole().logStackTrace(e); } catch (ParserConfigurationException e) { App.settings.getConsole().logStackTrace(e); } catch (IOException e) { App.settings.getConsole().logStackTrace(e); } // Now read in the library jars needed from the pack try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); InputSource is = new InputSource(new StringReader(pack.getXML(version, false))); Document document = builder.parse(is); document.getDocumentElement().normalize(); NodeList nodeList = document.getElementsByTagName("library"); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; String url = element.getAttribute("url"); String file = element.getAttribute("file"); Download download = Download.direct; if (element.hasAttribute("download")) { download = Download.valueOf(element.getAttribute("download")); } String md5 = "-"; if (element.hasAttribute("md5")) { md5 = element.getAttribute("md5"); } if (element.hasAttribute("depends")) { boolean found = false; for (Mod mod : selectedMods) { if (element.getAttribute("depends").equalsIgnoreCase(mod.getName())) { found = true; break; } } if (!found) { continue; } } if (librariesNeeded == null) { this.librariesNeeded = file; } else { this.librariesNeeded += "," + file; } File downloadTo = null; if (isServer) { if (!element.hasAttribute("server")) { continue; } serverLibraries.add(new File( new File(getLibrariesDirectory(), element.getAttribute("server").substring(0, element.getAttribute("server").lastIndexOf('/'))), element.getAttribute("server").substring( element.getAttribute("server").lastIndexOf('/'), element.getAttribute("server").length()))); } downloadTo = new File(App.settings.getLibrariesDir(), file); if (download == Download.server) { downloads.add(new MojangDownloadable(App.settings.getFileURL(url), downloadTo, md5, this)); } else { downloads.add(new MojangDownloadable(url, downloadTo, md5, this)); } } } } catch (SAXException e) { App.settings.getConsole().logStackTrace(e); } catch (ParserConfigurationException e) { App.settings.getConsole().logStackTrace(e); } catch (IOException e) { App.settings.getConsole().logStackTrace(e); } // Now read in the library jars needed from Mojang if (!isServer) { JSONParser parser = new JSONParser(); try { Object obj = parser.parse(Utils.urlToString("https://s3.amazonaws.com/Minecraft.Download/versions/" + this.minecraftVersion + "/" + this.minecraftVersion + ".json")); JSONObject jsonObject = (JSONObject) obj; if (this.mainClass == null) { this.mainClass = (String) jsonObject.get("mainClass"); } this.minecraftArguments = (String) jsonObject.get("minecraftArguments"); JSONArray msg = (JSONArray) jsonObject.get("libraries"); Iterator<JSONObject> iterator = msg.iterator(); while (iterator.hasNext()) { boolean shouldDownload = false; JSONObject object = iterator.next(); String libraryName = (String) object.get("name"); String[] parts = ((String) object.get("name")).split(":"); String dir = parts[0].replace(".", "/") + "/" + parts[1] + "/" + parts[2]; String filename = null; if (object.containsKey("rules")) { JSONArray ruless = (JSONArray) object.get("rules"); Iterator<JSONObject> itt = ruless.iterator(); while (itt.hasNext()) { JSONObject rules = itt.next(); if (((String) rules.get("action")).equalsIgnoreCase("allow")) { if (rules.containsKey("os")) { JSONObject rule = (JSONObject) rules.get("os"); if (((String) rule.get("name")).equalsIgnoreCase(Utils.getOSName())) { Pattern pattern = Pattern.compile((String) rule.get("version")); Matcher matcher = pattern.matcher(System.getProperty("os.version")); if (matcher.matches()) { shouldDownload = true; } } } else { shouldDownload = true; } } else if (((String) rules.get("action")).equalsIgnoreCase("disallow")) { if (rules.containsKey("os")) { JSONObject rule = (JSONObject) rules.get("os"); if (((String) rule.get("name")).equalsIgnoreCase(Utils.getOSName())) { Pattern pattern = Pattern.compile((String) rule.get("version")); Matcher matcher = pattern.matcher(System.getProperty("os.version")); if (matcher.matches()) { shouldDownload = false; } } } } else { shouldDownload = true; } } } else { shouldDownload = true; } if (shouldDownload) { if (object.containsKey("natives")) { JSONObject nativesObject = (JSONObject) object.get("natives"); String nativesName; if (Utils.isWindows()) { nativesName = (String) nativesObject.get("windows"); } else if (Utils.isMac()) { nativesName = (String) nativesObject.get("osx"); } else { nativesName = (String) nativesObject.get("linux"); } filename = parts[1] + "-" + parts[2] + "-" + nativesName + ".jar"; if (nativesNeeded == null) { this.nativesNeeded = filename; } else { this.nativesNeeded += "," + filename; } } else { filename = parts[1] + "-" + parts[2] + ".jar"; if (librariesNeeded == null) { this.librariesNeeded = filename; } else { this.librariesNeeded += "," + filename; } } String url = "https://s3.amazonaws.com/Minecraft.Download/libraries/" + dir + "/" + filename; File file = new File(App.settings.getLibrariesDir(), filename); downloads.add(new MojangDownloadable(url, file, null, this)); } } } catch (ParseException e) { App.settings.getConsole().logStackTrace(e); } } if (isServer) { downloads.add(new MojangDownloadable( "https://s3.amazonaws.com/Minecraft.Download/versions/" + this.minecraftVersion + "/minecraft_server." + this.minecraftVersion + ".jar", new File(App.settings.getJarsDir(), "minecraft_server." + this.minecraftVersion + ".jar"), null, this)); } else { downloads.add(new MojangDownloadable( "https://s3.amazonaws.com/Minecraft.Download/versions/" + this.minecraftVersion + "/" + this.minecraftVersion + ".jar", new File(App.settings.getJarsDir(), this.minecraftVersion + ".jar"), null, this)); } return downloads; }
From source file:JSONParser.JSONOperations.java
public JSONArray ticketsForSpecificTimeHelper(JSONArray allTickets, Date start_date, Date end_date, String[] status, String rowName) { JSONArray moduleCountForTickets = new JSONArray(); for (int i = 0; i < status.length; i++) { JSONObject statusJSON = new JSONObject(); statusJSON.put("status", status[i]); statusJSON.put("moduleSummary", null); moduleCountForTickets.add(statusJSON); }// w ww .j a v a 2 s . c o m for (Iterator<JSONObject> it = allTickets.iterator(); it.hasNext();) { JSONObject twoHundredTickets = (JSONObject) it.next(); JSONArray row = getRowsFromSupportapiJSON(twoHundredTickets, rowName); for (Iterator<JSONObject> it1 = row.iterator(); it1.hasNext();) { JSONArray fl = (JSONArray) it1.next().get("fl"); String tempStatus = null; String tempModule = null; boolean isSpecifiedTime = false; JSONObject moduleToAdd = null; for (Iterator<JSONObject> it2 = fl.iterator(); it2.hasNext();) { JSONObject indiFieldVal = it2.next(); if (indiFieldVal.get("val").toString().equals("Status")) { for (Iterator<JSONObject> it3 = moduleCountForTickets.iterator(); it3.hasNext();) { moduleToAdd = it3.next(); if (indiFieldVal.get("content").toString().equals(moduleToAdd.get("status"))) { tempStatus = indiFieldVal.get("content").toString(); //System.out.println(moduleToAdd.get("status")); break; } else { moduleToAdd = null; } } } if (indiFieldVal.get("val").toString().equals("Module")) { tempModule = indiFieldVal.get("content").toString(); } if (indiFieldVal.get("val").toString().equals("Created At")) { Date createdDate = null; try { String createdTime = indiFieldVal.get("content").toString(); String createdTimeSplit[] = createdTime.split(" "); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); createdDate = (Date) formatter.parse(createdTimeSplit[0]); /*System.out.println("Current Date" + formatter.format(currDate)); System.out.println("Created Date" + formatter.format(createdDate)); System.out.println("One week back date" + formatter.format(lastWeekDate));*/ //2013-08-12 18:46:00 } catch (java.text.ParseException ex) { Logger.getLogger(JSONOperations.class.getName()).log(Level.SEVERE, null, ex); } isSpecifiedTime = createdDate.after(start_date) && createdDate.before(end_date); //System.out.print("\t" + isSpecifiedTime); } } if (moduleToAdd != null && isSpecifiedTime) { //System.out.print("\t" + tempModule); if (moduleToAdd.get("moduleSummary") == null) { JSONObject indiModuleSummary = new JSONObject(); indiModuleSummary.put("moduleName", tempModule); indiModuleSummary.put("moduleCount", 1); JSONArray moduleSummary = new JSONArray(); moduleSummary.add(indiModuleSummary); moduleToAdd.put("moduleSummary", moduleSummary); } else { JSONArray moduleSummary = (JSONArray) moduleToAdd.get("moduleSummary"); JSONObject indiModuleSummary = null; for (Iterator<JSONObject> it4 = moduleSummary.iterator(); it4.hasNext();) { indiModuleSummary = it4.next(); if (indiModuleSummary.get("moduleName").toString().equals(tempModule)) { indiModuleSummary.put("moduleCount", (Integer) indiModuleSummary.get("moduleCount") + 1); } else { indiModuleSummary = null; } } if (indiModuleSummary == null) { indiModuleSummary = new JSONObject(); indiModuleSummary.put("moduleName", tempModule); indiModuleSummary.put("moduleCount", 1); moduleSummary.add(indiModuleSummary); } } } } } return moduleCountForTickets; }
From source file:md.mclama.com.ModManager.java
@SuppressWarnings("unchecked") private void readData() { JSONParser parser = new JSONParser(); try {//from w ww. ja v a 2s. co m Object obj = parser.parse(new FileReader(workDir + "/McLauncher.json")); con.log("Log", "Running McLauncher from " + new File(ModManager.class.getProtectionDomain().getCodeSource().getLocation().getPath())); JSONObject jsonObject = (JSONObject) obj; JSONArray msg = (JSONArray) jsonObject.get("data"); Iterator<JSONObject> iterator = msg.iterator(); JSONObject factObj = iterator.next(); gamePath = (String) factObj.get("path"); if (gamePath == null) gamePath = (String) parser.parse(new FileReader(".")); txtGamePath.setText(gamePath); con.log("Log", "game path set to..." + gamePath); checkAccess(); validatePath(); con.log("Log", "Using mod path " + modPath); String lastProfile = (String) factObj.get("lastprofile"); //Options tab try { tglbtnNewModsFirst.setSelected((boolean) factObj.get("newModsFirst")); tglbtnCloseAfterLaunch.setSelected((boolean) factObj.get("closeAfterLaunch")); tglbtnCloseAfterUpdate.setSelected((boolean) factObj.get("closeAfterUpdate")); tglbtnSendAnonData.setSelected((boolean) factObj.get("sendAnonData")); tglbtnDeleteBeforeUpdate.setSelected((boolean) factObj.get("deleteBeforeUpdate")); tglbtnAlertOnModUpdateAvailable.setSelected((boolean) factObj.get("AlertOnModUpdateAvailable")); } catch (Exception e1) { con.log("Warning", "Failed to read some data. Was McLauncher updated?"); } msg = (JSONArray) jsonObject.get("profiles"); iterator = msg.iterator(); int count = 0; factObj = iterator.next(); msg = (JSONArray) factObj.get("profile" + count); Iterator<JSONObject> iter = msg.iterator(); while (iter.hasNext()) { JSONObject pObj = iter.next(); String name = (String) pObj.get("name"); String mods = (String) pObj.get("mods"); con.log("Log", "Profile: " + name + " with " + mods + " loaded."); Profile pfile = new Profile(name, null); profiles.add(pfile); profileListMdl.addElement(name); //Lets add its mods now //con.log("Log",mods.replace("[", "").replace("]", "")); String[] pmods = mods.replace("[", "").replace("]", "").split(", "); for (int i = 0; i < pmods.length; i++) { pfile.mods.add(pmods[i]); } try { if (lastProfile.equals(name)) { profileList.setSelectedValue(profileListMdl.lastElement(), true); selectedProfile(); } } catch (Exception e) { con.log("Error", " Last profile was null"); } count++; try { msg = (JSONArray) factObj.get("profile" + count); iter = msg.iterator(); } catch (NullPointerException e) { con.log("Log", count + " profiles loaded."); break; } } txtProfile.setText("Profile" + (profiles.size() + 1)); } catch (FileNotFoundException e) { con.log("Log", "McLauncher.json not found, Saving first-time info."); newProfile("First profile"); profileList.setSelectedValue(profileListMdl.lastElement(), true); selectedProfile(); writeData(); } catch (IOException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } }
From source file:main.MainClass.java
public String[] WOETicketsJSONArrToHTML(JSONArray WOETicketsJSONArray, String status) { String result = ""; Integer count = 0;//from ww w. j a v a 2 s .c om if (WOETicketsJSONArray == null) { return null; } Iterator itr = WOETicketsJSONArray.iterator(); while (itr.hasNext()) { JSONObject WOERow = (JSONObject) itr.next(); if (WOERow.get("Status").toString().equals(status)) { /*result += "<tr>\n" + " <td valign=\"top\" style=\"width: 11.111%;\" rowspan=\"1\">" + WOERow.get("Created Time").toString() + "</td> \n" + " <td valign=\"top\" style=\"width: 11.111%;\" rowspan=\"1\">" + "<a href= \"" + "https://support.zoho.com" + WOERow.get("URI") + "\" +>" + WOERow.get("Ticket Id").toString() + "</a>" + "</td> \n" + " <td valign=\"top\" style=\"width: 11.111%;\" rowspan=\"1\">" + WOERow.get("Email").toString() + "</td>\n" + " <td valign=\"top\" style=\"width: 11.111%;\" rowspan=\"1\">" + WOERow.get("Subject").toString() + "</td>\n" + " <td valign=\"top\" style=\"width: 11.111%;\" rowspan=\"1\">" + WOERow.get("Developers").toString() + "</td>\n" + " <td valign=\"top\" style=\"width: 11.111%;\" rowspan=\"1\">" + WOERow.get("Ticket Owner").toString() + "</td>\n" + " <td valign=\"top\" style=\"width: 11.111%;\" rowspan=\"1\">" + WOERow.get("Modules").toString() + "</td>\n" + " <td valign=\"top\" style=\"width: 11.111%;\" rowspan=\"1\">" + WOERow.get("Due Date").toString() + "</td>\n" + " <td valign=\"top\" style=\"width: 11.111%;\" rowspan=\"1\">" + WOERow.get("Problem Description").toString() + "</td>\n" + " </tr>"; }*/ result += "<tr>\n" + " <td valign=\"top\" >" + WOERow.get("Created Time").toString() + "</td> \n" + " <td valign=\"top\" >" + "<a href= \"" + "https://support.zoho.com" + WOERow.get("URI") + "\" +>" + WOERow.get("Ticket Id").toString() + "</a>" + "</td> \n" + " <td valign=\"top\" >" + WOERow.get("Email").toString() + "</td>\n" + " <td valign=\"top\" >" + WOERow.get("Problem Description").toString() + "</td>\n" + " <td valign=\"top\" >" + WOERow.get("Issue Type").toString() + "</td>\n" + " <td valign=\"top\" >" + WOERow.get("Modules").toString() + "</td>\n" + " <td valign=\"top\" >" + WOERow.get("Developers").toString() + "</td>\n" + " <td valign=\"top\" >" + WOERow.get("Ticket Owner").toString() + "</td>\n" + " <td valign=\"top\" >" + WOERow.get("Due Date").toString() + "</td>\n" + " <td valign=\"top\" >" + WOERow.get("Last Updated At").toString() + "</td>\n" + " </tr>"; count++; } } if (result.equals("")) { result += "<tr >\n" + "<td colspan=\"9\"><center style=\"color: rgb(255, 0, 0);\">" + "No pending tickets available" + "</center></td></tr> \n"; } return new String[] { result, count.toString() }; }
From source file:com.paniclauncher.data.Settings.java
@SuppressWarnings("unchecked") public void checkMojangStatus() { JSONParser parser = new JSONParser(); try {/* w w w .j av a 2s . c o m*/ Object obj = parser.parse(Utils.urlToString("http://status.mojang.com/check")); JSONArray jsonObject = (JSONArray) obj; Iterator<JSONObject> iterator = jsonObject.iterator(); while (iterator.hasNext()) { JSONObject object = iterator.next(); if (object.containsKey("login.minecraft.net")) { if (((String) object.get("login.minecraft.net")).equalsIgnoreCase("green")) { minecraftLoginServerUp = true; } } else if (object.containsKey("session.minecraft.net")) { if (((String) object.get("session.minecraft.net")).equalsIgnoreCase("green")) { minecraftSessionServerUp = true; } } } } catch (ParseException e) { this.console.logStackTrace(e); } }
From source file:com.ge.research.semtk.load.utility.ImportSpecHandler.java
/** * Populate nodegroup with a single record (row) of data */// w w w .ja v a 2s .c om public NodeGroup importRecord(NodeGroup ng, ArrayList<String> record) throws Exception { // this is a really naive implementation. it could probably be sped up drastically by caching // the digested template instead of re-processing it for eac incoming record. // the lack of conditional logic in this method would make that do-able. NodeGroup retval = ng; if (ng == null) { throw new Exception("Null nodegroup passed to ImportSpecHandler.getValues"); } if (record == null) { throw new Exception("incoming record cannot be null for ImportSpecHandler.getValues"); } if (this.headerPositioningInfo.isEmpty()) { throw new Exception("the header positions were never set for the importspechandler"); } JSONArray nodes = (JSONArray) this.importspec.get("nodes"); // the "nodes" part of the JSON int nodesArraySize = nodes.size(); for (int i = 0; i < nodesArraySize; i++) { // loop through all of the values and get the parts we need to fill in the nodegroup entries. JSONObject currnode = (JSONObject) nodes.get(i); JSONArray uriMap = (JSONArray) currnode.get("mapping"); JSONArray props = (JSONArray) currnode.get("props"); // get the related node from the NodeGroup String sparqlID = currnode.get("sparqlID").toString(); //System.out.println("sparqlID: " + sparqlID); Node curr = ng.getNodeBySparqlID(sparqlID); // generate the uri value. all of this can be simplified later into a structure that actually remembers the format // because position info will not drift as each line is processed. this was done for expedience of development. String uri = this.buildMappingString(uriMap, record); // check for a null column mapping having been found. if so, change the URI to a guid and make this a blank node. // encode uri and set it. if (StringUtils.isBlank(uri)) { curr.setInstanceValue(null); } else { uri = this.uriResolver.getInstanceUriWithPrefix(curr.getFullUriName(), uri); if (!SparqlToXUtils.isLegalURI(uri)) { throw new Exception("Attempting to insert ill-formed URI: " + uri); } curr.setInstanceValue(uri); } // set any applicable property values. again, this could be greatly simplified in terms of number of look ups and, // potentially, running time. it should be encapsulated into an object that understands the nodes itself and stores // this sort of info. this was done the hard way in the interest of simplifying implementation and debugging. ArrayList<PropertyItem> inScopeProperties = curr.getPropertyItems(); Iterator<JSONObject> pMap = props.iterator(); while (pMap.hasNext()) { String[] namesOfTransformsToApplyProp = null; // go through all the parts of the property as well. JSONObject currProp = pMap.next(); String uriRelation = currProp.get("URIRelation").toString(); JSONArray mapping = (JSONArray) currProp.get("mapping"); String instanceValue = this.buildMappingString(mapping, record); // find and set the actual property value. for (PropertyItem pi : inScopeProperties) { if (pi.getUriRelationship().equals(uriRelation)) { // e.g. http://research.ge.com/print/testconfig#cellId if (this.notEmpty(instanceValue)) { if (pi.getValueType().equalsIgnoreCase("string")) { instanceValue = SparqlToXUtils.safeSparqlString(instanceValue); } instanceValue = this.validateDataType(instanceValue, pi.getValueType()); pi.addInstanceValue(instanceValue); } break; } } } } // prune nodes that no longer belong (no uri and no properties) ng.pruneAllUnused(true); // set URI for nulls ng = this.setURIsForBlankNodes(ng); return retval; }