List of usage examples for org.json.simple JSONObject keySet
Set<K> keySet();
From source file:net.paissad.minus.api.TimelineUtils.java
/** * @param user// w ww . j a v a2 s. c o m * @param gallery - The readerId of the gallery to use. * @param key - The key for which we want its related value. * @param listener * @return The value for the specified key. * @throws MinusException If the key is unknown, or if the specified gallery * is not found, or if unable to connect correctly to Minus API. * @see MinusConstants */ static Object getValueFromGallery(final MinusUser user, final MinusGallery gallery, final String key) throws MinusException { try { MinusHttpResponse minusResp = HttpClientUtils.doGet(TIMELINE_HISTORY_URL, null, user.getSessionId(), null, STRING); String httpResponse = (String) minusResp.getHttpResponse(); MinusUtils.validateHttpResponse(httpResponse); Map<String, Object> jsonResult = JSONUtils.getMapFromJSONString(httpResponse); MinusUtils.validateJsonResult(jsonResult); @SuppressWarnings("unchecked") List<JSONObject> galleriesAsObjects = (List<JSONObject>) jsonResult.get(RESPONSE_KEY_GALLERIES); for (JSONObject obj : galleriesAsObjects) { String currentReaderId = (String) obj.get(RESPONSE_KEY_READER_ID); if (currentReaderId.equals(gallery.getReaderId())) { // We got the correct gallery ! if (!obj.keySet().contains(key)) { throw new MinusException("The key (" + key + ") is unknown for the entity -> " + obj); } return obj.get(key); } } throw new MinusException("Unable to find the gallery " + gallery); } catch (Exception e) { throw new MinusException(e.getMessage(), e); } }
From source file:at.ac.tuwien.dsg.rSybl.planningEngine.staticData.ActionEffects.java
public static void setActionEffects(String eff) { PlanningLogger.logger.info("~~~~~~~~~~Action effects set through web serv, setting the effects ! "); JSONParser parser = new JSONParser(); applicationSpecificActionEffects = new HashMap<String, List<ActionEffect>>(); Object obj;/*from ww w. ja v a 2 s .c o m*/ try { obj = parser.parse(eff); JSONObject jsonObject = (JSONObject) obj; for (Object actionName : jsonObject.keySet()) { String myaction = (String) actionName; JSONObject object = (JSONObject) jsonObject.get(myaction); for (Object actions : object.keySet()) { ActionEffect actionEffect = new ActionEffect(); actionEffect.setActionType((String) myaction); actionEffect.setActionName((String) actions); JSONObject scaleinDescription = (JSONObject) object.get(actions); if (scaleinDescription.containsKey("conditions")) { JSONArray conditions = (JSONArray) jsonObject.get("conditions"); for (int i = 0; i < conditions.size(); i++) { actionEffect.addCondition((String) conditions.get(i)); } } String targetUnit = (String) scaleinDescription.get("targetUnit"); actionEffect.setTargetedEntityID(targetUnit); JSONObject effects = (JSONObject) scaleinDescription.get("effects"); for (Object effectPerUnit : effects.keySet()) { //System.out.println(effects.toString()); String affectedUnit = (String) effectPerUnit; JSONObject metriceffects = (JSONObject) effects.get(affectedUnit); for (Object metric : metriceffects.keySet()) { String metricName = (String) metric; try { actionEffect.setActionEffectForMetric(metricName, (Double) metriceffects.get(metricName), affectedUnit); } catch (Exception e) { actionEffect.setActionEffectForMetric(metricName, ((Long) metriceffects.get(metricName)).doubleValue(), affectedUnit); } } } if (!applicationSpecificActionEffects.containsKey(actionEffect.getTargetedEntityID().trim())) { List<ActionEffect> l = new ArrayList<ActionEffect>(); l.add(actionEffect); applicationSpecificActionEffects.put(actionEffect.getTargetedEntityID().trim(), l); //PlanningLogger.logger.info("New Action effects "+actionEffect.getActionType()+" "+actionEffect.getActionName()+" "+actionEffect.getTargetedEntityID()); } else { applicationSpecificActionEffects.get(actionEffect.getTargetedEntityID().trim()) .add(actionEffect); //PlanningLogger.logger.info("Adding Action effects "+actionEffect.getActionType()+" "+actionEffect.getActionName()+" "+actionEffect.getTargetedEntityID()); } } } } catch (ParseException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
From source file:at.ac.tuwien.dsg.rSybl.planningEngine.staticData.ActionEffects.java
public static HashMap<String, List<ActionEffect>> getActionEffects() { if (applicationSpecificActionEffects.isEmpty()) { PlanningLogger.logger.info("~~~~~~~~~~Action effects is empty, reading the effects ! "); JSONParser parser = new JSONParser(); try {//from www .java 2 s . c om InputStream inputStream = Configuration.class.getClassLoader() .getResourceAsStream(Configuration.getEffectsPath()); Object obj = parser.parse(new InputStreamReader(inputStream)); JSONObject jsonObject = (JSONObject) obj; for (Object actionName : jsonObject.keySet()) { String myaction = (String) actionName; JSONObject object = (JSONObject) jsonObject.get(myaction); for (Object actions : object.keySet()) { ActionEffect actionEffect = new ActionEffect(); actionEffect.setActionType((String) myaction); actionEffect.setActionName((String) actions); JSONObject scaleinDescription = (JSONObject) object.get(actions); String targetUnit = (String) scaleinDescription.get("targetUnit"); actionEffect.setTargetedEntityID(targetUnit); JSONObject effects = (JSONObject) scaleinDescription.get("effects"); for (Object effectPerUnit : effects.keySet()) { //System.out.println(effects.toString()); String affectedUnit = (String) effectPerUnit; JSONObject metriceffects = (JSONObject) effects.get(affectedUnit); for (Object metric : metriceffects.keySet()) { String metricName = (String) metric; try { actionEffect.setActionEffectForMetric(metricName, (Double) metriceffects.get(metricName), affectedUnit); } catch (Exception e) { actionEffect.setActionEffectForMetric(metricName, ((Long) metriceffects.get(metricName)).doubleValue(), affectedUnit); } } } if (applicationSpecificActionEffects.get(actionEffect.getTargetedEntityID()) == null) { List<ActionEffect> l = new ArrayList<ActionEffect>(); l.add(actionEffect); applicationSpecificActionEffects.put(actionEffect.getTargetedEntityID(), l); } else { applicationSpecificActionEffects.get(actionEffect.getTargetedEntityID()) .add(actionEffect); } } } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } } return applicationSpecificActionEffects; }
From source file:at.ac.tuwien.dsg.rSybl.planningEngine.staticData.ActionEffects.java
public static HashMap<String, List<ActionEffect>> getActionConditionalEffects() { if (applicationSpecificActionEffects.isEmpty() && defaultActionEffects.isEmpty()) { PlanningLogger.logger.info("~~~~~~~~~~Action effects is empty, reading the effects ! "); JSONParser parser = new JSONParser(); try {/* w w w .j a v a 2 s . co m*/ InputStream inputStream = Configuration.class.getClassLoader() .getResourceAsStream(Configuration.getEffectsPath()); Object obj = parser.parse(new InputStreamReader(inputStream)); JSONObject jsonObject = (JSONObject) obj; for (Object actionName : jsonObject.keySet()) { String myaction = (String) actionName; JSONObject object = (JSONObject) jsonObject.get(myaction); for (Object actions : object.keySet()) { ActionEffect actionEffect = new ActionEffect(); actionEffect.setActionType((String) myaction); actionEffect.setActionName((String) actions); JSONObject scaleinDescription = (JSONObject) object.get(actions); if (scaleinDescription.containsKey("conditions")) { JSONArray conditions = (JSONArray) jsonObject.get("conditions"); for (int i = 0; i < conditions.size(); i++) { actionEffect.addCondition((String) conditions.get(i)); } } String targetUnit = (String) scaleinDescription.get("targetUnit"); actionEffect.setTargetedEntityID(targetUnit); JSONObject effects = (JSONObject) scaleinDescription.get("effects"); for (Object effectPerUnit : effects.keySet()) { //System.out.println(effects.toString()); String affectedUnit = (String) effectPerUnit; JSONObject metriceffects = (JSONObject) effects.get(affectedUnit); for (Object metric : metriceffects.keySet()) { String metricName = (String) metric; try { actionEffect.setActionEffectForMetric(metricName, (Double) metriceffects.get(metricName), affectedUnit); } catch (Exception e) { actionEffect.setActionEffectForMetric(metricName, ((Long) metriceffects.get(metricName)).doubleValue(), affectedUnit); } } } if (applicationSpecificActionEffects.get(actionEffect.getTargetedEntityID()) == null) { List<ActionEffect> l = new ArrayList<ActionEffect>(); l.add(actionEffect); applicationSpecificActionEffects.put(actionEffect.getTargetedEntityID(), l); } else { applicationSpecificActionEffects.get(actionEffect.getTargetedEntityID()) .add(actionEffect); } } } } catch (Exception e) { PlanningLogger.logger.info("~~~~~~~~~~Retrying reading the effects "); parser = new JSONParser(); try { InputStream inputStream = Configuration.class.getClassLoader() .getResourceAsStream(Configuration.getEffectsPath()); Object obj = parser.parse(new InputStreamReader(inputStream)); JSONObject jsonObject = (JSONObject) obj; for (Object actionName : jsonObject.keySet()) { String myaction = (String) actionName; ActionEffect actionEffect = new ActionEffect(); actionEffect.setActionType((String) myaction); actionEffect.setActionName((String) myaction); JSONObject object = (JSONObject) jsonObject.get(myaction); JSONObject metrics = (JSONObject) object.get("effects"); for (Object me : metrics.keySet()) { String metric = (String) me; Double metricEffect = (Double) metrics.get(metric); actionEffect.setActionEffectForMetric(metric, metricEffect, ""); } defaultActionEffects.put(myaction, actionEffect); } } catch (Exception ex) { PlanningLogger.logger .error("Error when reading the effects!!!!!!!!!!!!!!!!!!" + ex.getMessage()); } } } return applicationSpecificActionEffects; }
From source file:eu.wordnice.wnconsole.WNCUtils.java
public static Map<String, Object> sortObject(JSONObject jo) { Object[] names = new Object[jo.size()]; Object[] values = new Object[jo.size()]; boolean[] used = new boolean[jo.size()]; boolean curHas = false; Object[] in = jo.keySet().toArray(); int i = 0;//from w w w . j av a2s.c om int i2 = 0; for (; i < jo.size(); i++) { curHas = false; for (i2 = 0; i2 < jo.size(); i2++) { String cname = (String) in[i2]; if (!used[i2] && cname.startsWith("get")) { names[i] = ("" + cname); values[i] = jo.get(cname); used[i2] = true; curHas = true; break; } } if (!curHas) { break; } } i2 = 0; for (/* continue */; i < jo.size(); i++) { for (/* continue */; i2 < jo.size(); i2++) { String cname = (String) in[i2]; if (!used[i2]) { names[i] = cname; values[i] = jo.get(cname); used[i2] = true; curHas = true; break; } } } Map<String, Object> map = new Map<String, Object>(); map.names = names; map.values = values; map.size = names.length; return map; }
From source file:com.cisco.dbds.utils.report.CustomReport.java
/** * Reportparsejson./*from ww w . j a va2 s .c om*/ * * @return the string * @throws FileNotFoundException the file not found exception * @throws IOException Signals that an I/O exception has occurred. * @throws ParseException the parse exception * @throws AddressException the address exception */ public static String reportparsejson() throws FileNotFoundException, IOException, ParseException, AddressException { String failureReasonTable = "<table border style='width:100%'><tr style='background-color: rgb(70,116,209);'><colgroup><col span='1' style='width: 14%;'><col span='1' style='width: 40%;'><col span='1' style='width: 33%;'><col span='1' style='width: 13%;'></colgroup><th>Failed Test Case ID</th><th>Test Title</th><th>Failure Reason</th><th>Failure Category</th></tr>"; String head = "<html>"; head += "<head>"; head += "<style>"; head += "body{position:absolute;width:80%;height:100%;margin:0;padding:0}table,tbody{position:relative;width:100%;table-layout: auto}tr td,th{width:.5%;word-break:break-all;border:.5px solid black;} "; head += "</style>"; head += "</head>"; head += "<body border='2%'><table><tr><td style='background-color: rgb(170,187,204);'>"; JSONParser parser = new JSONParser(); int sno = 0; int pass = 0, fail = 0; int passed1 = 0, failed1 = 0; String headdetails = "<table><br><th style='background-color: rgb(25, 112, 193);'><center>Customized Automation Run Report</center></th><br></table><br><br>"; String version = ""; String bodydetailS = "<table> <tr style='background-color: rgb(70,116,209);'><th>#</th><th>Feature Name</th><th>TIMS ID</th><th>Test Type</th><th>Test Case Title</th><th>Status</th></tr>"; String Total = ""; Object obj = parser.parse(new FileReader("./target/reports/cucumber-report.json")); JSONArray msg = (JSONArray) obj; for (int i = 0; i < msg.size(); i++) { JSONObject jo = (JSONObject) msg.get(i); JSONArray msg1 = (JSONArray) jo.get("elements"); String uniid = ""; String nodeinfo = ""; String featureFile = null; String timsId = null; String serial = null; String testType = null; String testTitle = null; String mid = null, mid1 = null; for (int j = 0; j < msg1.size(); j++) { JSONObject jo1 = (JSONObject) msg1.get(j); System.out.println("Id" + jo1.get("id")); if (jo1.get("id") != null) { JSONArray msg2 = (JSONArray) jo1.get("tags"); String uniidstatus = "N"; int pf = -1; System.out.println("satsize" + msg2.size()); for (int j2 = 0; j2 < msg2.size(); j2++) { // Version JSONObject jo2 = (JSONObject) msg2.get(j2); if ((jo2.get("name").toString().contains("NodeInfo"))) { nodeinfo = "found"; } // Test case details if ((jo2.get("name").toString().contains("Ttv")) || (jo2.get("name").toString().contains("TBD"))) { String stype = ""; for (int typec = 0; typec < msg2.size(); typec++) { JSONObject jotype = (JSONObject) msg2.get(typec); if (jotype.get("name").toString().contains("Regression")) stype = "Regression"; else if (jotype.get("name").toString().contains("Sanity")) stype = "Sanity"; } if (!uniid.trim().equals(jo2.get("name").toString().trim())) { String feanmae[] = jo.get("uri").toString().split("/"); featureFile = feanmae[feanmae.length - 1]; serial = "" + (++sno); timsId = jo2.get("name").toString(); testType = stype; testTitle = jo1.get("name").toString(); mid = "<td><center>" + serial + "</center></td><td>" + featureFile + "</td><td><center>" + timsId.substring(1) + "</center></td><td><center>" + testType + "</center></td><td>" + testTitle + "</td>"; uniidstatus = "Y"; mid1 = "<td><center>" + timsId.substring(1) + "</center></td><td>" + testTitle + "</td>"; } uniid = jo2.get("name").toString(); } } // Begin Version details if (nodeinfo.equals("found")) { version = "<table border='2%' style='background-color: rgb(170,221,204);'>"; JSONArray msg5 = (JSONArray) jo1.get("steps"); System.out.println("Steps:" + msg5); for (int j5 = 0; j5 < msg5.size(); j5++) { JSONObject jo5 = (JSONObject) msg5.get(j5); System.out.println(jo5.keySet()); JSONArray msg6 = (JSONArray) jo5.get("output"); System.out.println(msg6); if (msg6 != null) { for (int j6 = 0; j6 < msg6.size(); j6++) { if (msg6.get(j6).toString().contains("cisco.conductor")) { System.out.println(msg6.get(j6)); version += "<tr><td colspan=4><font style='color:rgb(0,102,0);'>" + msg6.get(j6).toString() + "</font></td></tr>"; } else { String rr[] = msg6.get(j6).toString().split(";"); if (rr.length == 1) { version += "<tr><td colspan ='4'><center><b><font size=3 style='color:rgb(0,102,0);'>" + rr[0] + "</font></b></center></td></tr>"; } else { version += "<tr border=''><td colspan=4 style='height:20px' /></tr><tr style='background-color: rgb(70,116,209);'><center>"; for (int rr1 = 0; rr1 < rr.length; rr1++) { version += "<td colspan='" + (4 / rr.length) + "'>" + rr[rr1] + "</td>"; } version += "</center></tr>"; } } } } } version += "</table><br>"; System.out.println(version); } // End Version details JSONArray msg3 = (JSONArray) jo1.get("steps"); //int pf = -1; for (int j3 = 0; j3 < msg3.size(); j3++) { JSONObject jo3 = (JSONObject) msg3.get(j3); JSONObject jo4 = (JSONObject) jo3.get("result"); System.out.println(jo4.get("status")); if (jo4.get("status").equals("passed")) { pf = 0; } else { pf = 1; break; } } if (uniidstatus.equals("Y")) { if (pf == 0) { bodydetailS += "<tr style='background-color: rgb(107,144,70);'>" + mid + "<td><center>Passed</center></td></tr>"; pass++; } else if (pf == 1) { bodydetailS += "<tr style='background-color: rgb(216, 138, 138);'><center>" + mid + "<td><center>Failed</center></td></tr>"; if (!failureReasonTable .contains("<tr><td><center>" + mid1 + "</td><td></td><td></td></tr>")) failureReasonTable += "<tr>" + mid1 + "<td></td><td></td></tr>"; fail++; } } else if (mid != null) { if (bodydetailS.contains(mid)) { if (pf == 0) {/* if (bodydetailS.contains("<tr style='background-color: rgb(107,144,70);'>"+mid+"<td><center>Passed</center></td></tr>")) { bodydetailS=bodydetailS.replace( "<tr style='background-color: rgb(107,144,70);'>"+mid+"<td><center>Passed</center></td></tr>","<tr style='background-color: rgb(107,144,70);'>"+mid+"<td><center>Passed</center></td></tr>"); //passed1--; } if (bodydetailS.contains("<tr style='background-color: rgb(216, 138, 138);'><center>"+mid+ "<td><center>Failed</center></td></tr>")) { bodydetailS=bodydetailS.replace( "<tr style='background-color: rgb(216, 138, 138);'><center>"+mid+ "<td><center>Failed</center></td></tr>","<tr style='background-color: rgb(107,144,70);'>"+mid+"<td><center>Passed</center></td></tr>"); passed1++; failed1--; }*/ } else if (pf == 1) { if (bodydetailS.contains("<tr style='background-color: rgb(107,144,70);'>" + mid + "<td><center>Passed</center></td></tr>")) { failed1++; passed1--; bodydetailS = bodydetailS.replace( "<tr style='background-color: rgb(107,144,70);'>" + mid + "<td><center>Passed</center></td></tr>", "<tr style='background-color: rgb(216, 138, 138);'><center>" + mid + "<td><center>Failed</center></td></tr>"); } if (bodydetailS .contains("<tr style='background-color: rgb(216, 138, 138);'><center>" + mid + "<td><center>Failed</center></td></tr>")) { bodydetailS = bodydetailS.replace( "<tr style='background-color: rgb(216, 138, 138);'><center>" + mid + "<td><center>Failed</center></td></tr>", "<tr style='background-color: rgb(216, 138, 138);'><center>" + mid + "<td><center>Failed</center></td></tr>"); } if (!failureReasonTable .contains("<tr><td><center>" + mid1 + "</td><td></td><td></td></tr>")) failureReasonTable += "<tr>" + mid1 + "<<td></td><td></td></tr>"; } } /*if (pf == 0 && uniidstatus.equals("Y")) { bodydetailS += "<tr style='background-color: rgb(107,144,70);'>"+mid+"<td><center>Passed</center></td></tr>"; pass++; } else if (pf == 1) { bodydetailS += "<tr style='background-color: rgb(216, 138, 138);'><center>"+mid+ "<td><center>Failed</center></td></tr>"; failureReasonTable += "<tr><td><center>" // + timsId.substring(1) + "</center></td><td>" + timsId + testTitle + "</td><td></td><td></td></tr>"; fail++; }*/ } } } } Total = "<table><tr style='background-color: rgb(70,116,209);'><th>Total</th><td>Passed</th><th>Failed</th></tr>"; Total += "<center><tr style='background-color: rgb(170,204,204);'><td>" + sno + "</td><td>" + (pass + passed1) + "(" + String.format("%.2f", ((pass + passed1) * 100.0F / sno)) + "%)</td><td>" + (fail + failed1) + "(" + String.format("%.2f", ((fail + failed1) * 100.0F / sno)) + "%)</td></tr></center></table><br>"; bodydetailS += "</center></table><br><br><br>"; System.out.println(version); head += headdetails + Total + version + bodydetailS; if (fail > 0) { failureReasonTable += "</table>"; // System.out.println(failureReasonTable); head += failureReasonTable; } head += "</td></tr></table></body></html>"; return head; }
From source file:com.sat.dbds.utils.report.CustomReport.java
/** * Reportparsejson.//from w w w . j a v a 2 s .c om * * @return the string * @throws FileNotFoundException the file not found exception * @throws IOException Signals that an I/O exception has occurred. * @throws ParseException the parse exception * @throws AddressException the address exception */ public static String reportparsejson() throws FileNotFoundException, IOException, ParseException, AddressException { String failureReasonTable = "<table border style='width:100%'><tr style='background-color: rgb(70,116,209);'><colgroup><col span='1' style='width: 14%;'><col span='1' style='width: 40%;'><col span='1' style='width: 33%;'><col span='1' style='width: 13%;'></colgroup><th>Failed Test Case ID</th><th>Test Title</th><th>Failure Reason</th><th>Failure Category</th></tr>"; String head = "<html>"; head += "<head>"; head += "<style>"; head += "body{position:absolute;width:80%;height:100%;margin:0;padding:0}table,tbody{position:relative;width:100%;table-layout: auto}tr td,th{width:.5%;word-break:break-all;border:.5px solid black;} "; head += "</style>"; head += "</head>"; head += "<body border='2%'><table><tr><td style='background-color: rgb(170,187,204);'>"; JSONParser parser = new JSONParser(); int sno = 0; int pass = 0, fail = 0; int passed1 = 0, failed1 = 0; String headdetails = "<table><br><th style='background-color: rgb(25, 112, 193);'><center>Customized Automation Run Report</center></th><br></table><br><br>"; String version = ""; String bodydetailS = "<table> <tr style='background-color: rgb(70,116,209);'><th>#</th><th>Feature Name</th><th>TIMS ID</th><th>Test Type</th><th>Test Case Title</th><th>Status</th></tr>"; String Total = ""; Object obj = parser.parse(new FileReader("./target/reports/cucumber-report.json")); JSONArray msg = (JSONArray) obj; for (int i = 0; i < msg.size(); i++) { JSONObject jo = (JSONObject) msg.get(i); JSONArray msg1 = (JSONArray) jo.get("elements"); String uniid = ""; String nodeinfo = ""; String featureFile = null; String timsId = null; String serial = null; String testType = null; String testTitle = null; String mid = null, mid1 = null; for (int j = 0; j < msg1.size(); j++) { JSONObject jo1 = (JSONObject) msg1.get(j); System.out.println("Id" + jo1.get("id")); if (jo1.get("id") != null) { JSONArray msg2 = (JSONArray) jo1.get("tags"); String uniidstatus = "N"; int pf = -1; System.out.println("satize" + msg2.size()); for (int j2 = 0; j2 < msg2.size(); j2++) { // Version JSONObject jo2 = (JSONObject) msg2.get(j2); if ((jo2.get("name").toString().contains("NodeInfo"))) { nodeinfo = "found"; } // Test case details if ((jo2.get("name").toString().contains("Ttv")) || (jo2.get("name").toString().contains("TBD"))) { String stype = ""; for (int typec = 0; typec < msg2.size(); typec++) { JSONObject jotype = (JSONObject) msg2.get(typec); if (jotype.get("name").toString().contains("Regression")) stype = "Regression"; else if (jotype.get("name").toString().contains("Sanity")) stype = "Sanity"; } if (!uniid.trim().equals(jo2.get("name").toString().trim())) { String feanmae[] = jo.get("uri").toString().split("/"); featureFile = feanmae[feanmae.length - 1]; serial = "" + (++sno); timsId = jo2.get("name").toString(); testType = stype; testTitle = jo1.get("name").toString(); mid = "<td><center>" + serial + "</center></td><td>" + featureFile + "</td><td><center>" + timsId.substring(1) + "</center></td><td><center>" + testType + "</center></td><td>" + testTitle + "</td>"; uniidstatus = "Y"; mid1 = "<td><center>" + timsId.substring(1) + "</center></td><td>" + testTitle + "</td>"; } uniid = jo2.get("name").toString(); } } // Begin Version details if (nodeinfo.equals("found")) { version = "<table border='2%' style='background-color: rgb(170,221,204);'>"; JSONArray msg5 = (JSONArray) jo1.get("steps"); System.out.println("Steps:" + msg5); for (int j5 = 0; j5 < msg5.size(); j5++) { JSONObject jo5 = (JSONObject) msg5.get(j5); System.out.println(jo5.keySet()); JSONArray msg6 = (JSONArray) jo5.get("output"); System.out.println(msg6); if (msg6 != null) { for (int j6 = 0; j6 < msg6.size(); j6++) { if (msg6.get(j6).toString().contains("cisco.conductor")) { System.out.println(msg6.get(j6)); version += "<tr><td colspan=4><font style='color:rgb(0,102,0);'>" + msg6.get(j6).toString() + "</font></td></tr>"; } else { String rr[] = msg6.get(j6).toString().split(";"); if (rr.length == 1) { version += "<tr><td colspan ='4'><center><b><font size=3 style='color:rgb(0,102,0);'>" + rr[0] + "</font></b></center></td></tr>"; } else { version += "<tr border=''><td colspan=4 style='height:20px' /></tr><tr style='background-color: rgb(70,116,209);'><center>"; for (int rr1 = 0; rr1 < rr.length; rr1++) { version += "<td colspan='" + (4 / rr.length) + "'>" + rr[rr1] + "</td>"; } version += "</center></tr>"; } } } } } version += "</table><br>"; System.out.println(version); } // End Version details JSONArray msg3 = (JSONArray) jo1.get("steps"); //int pf = -1; for (int j3 = 0; j3 < msg3.size(); j3++) { JSONObject jo3 = (JSONObject) msg3.get(j3); JSONObject jo4 = (JSONObject) jo3.get("result"); System.out.println(jo4.get("status")); if (jo4.get("status").equals("passed")) { pf = 0; } else { pf = 1; break; } } if (uniidstatus.equals("Y")) { if (pf == 0) { bodydetailS += "<tr style='background-color: rgb(107,144,70);'>" + mid + "<td><center>Passed</center></td></tr>"; pass++; } else if (pf == 1) { bodydetailS += "<tr style='background-color: rgb(216, 138, 138);'><center>" + mid + "<td><center>Failed</center></td></tr>"; if (!failureReasonTable .contains("<tr><td><center>" + mid1 + "</td><td></td><td></td></tr>")) failureReasonTable += "<tr>" + mid1 + "<td></td><td></td></tr>"; fail++; } } else if (mid != null) { if (bodydetailS.contains(mid)) { if (pf == 0) {/* if (bodydetailS.contains("<tr style='background-color: rgb(107,144,70);'>"+mid+"<td><center>Passed</center></td></tr>")) { bodydetailS=bodydetailS.replace( "<tr style='background-color: rgb(107,144,70);'>"+mid+"<td><center>Passed</center></td></tr>","<tr style='background-color: rgb(107,144,70);'>"+mid+"<td><center>Passed</center></td></tr>"); //passed1--; } if (bodydetailS.contains("<tr style='background-color: rgb(216, 138, 138);'><center>"+mid+ "<td><center>Failed</center></td></tr>")) { bodydetailS=bodydetailS.replace( "<tr style='background-color: rgb(216, 138, 138);'><center>"+mid+ "<td><center>Failed</center></td></tr>","<tr style='background-color: rgb(107,144,70);'>"+mid+"<td><center>Passed</center></td></tr>"); passed1++; failed1--; }*/ } else if (pf == 1) { if (bodydetailS.contains("<tr style='background-color: rgb(107,144,70);'>" + mid + "<td><center>Passed</center></td></tr>")) { failed1++; passed1--; bodydetailS = bodydetailS.replace( "<tr style='background-color: rgb(107,144,70);'>" + mid + "<td><center>Passed</center></td></tr>", "<tr style='background-color: rgb(216, 138, 138);'><center>" + mid + "<td><center>Failed</center></td></tr>"); } if (bodydetailS .contains("<tr style='background-color: rgb(216, 138, 138);'><center>" + mid + "<td><center>Failed</center></td></tr>")) { bodydetailS = bodydetailS.replace( "<tr style='background-color: rgb(216, 138, 138);'><center>" + mid + "<td><center>Failed</center></td></tr>", "<tr style='background-color: rgb(216, 138, 138);'><center>" + mid + "<td><center>Failed</center></td></tr>"); } if (!failureReasonTable .contains("<tr><td><center>" + mid1 + "</td><td></td><td></td></tr>")) failureReasonTable += "<tr>" + mid1 + "<<td></td><td></td></tr>"; } } /*if (pf == 0 && uniidstatus.equals("Y")) { bodydetailS += "<tr style='background-color: rgb(107,144,70);'>"+mid+"<td><center>Passed</center></td></tr>"; pass++; } else if (pf == 1) { bodydetailS += "<tr style='background-color: rgb(216, 138, 138);'><center>"+mid+ "<td><center>Failed</center></td></tr>"; failureReasonTable += "<tr><td><center>" // + timsId.substring(1) + "</center></td><td>" + timsId + testTitle + "</td><td></td><td></td></tr>"; fail++; }*/ } } } } Total = "<table><tr style='background-color: rgb(70,116,209);'><th>Total</th><td>Passed</th><th>Failed</th></tr>"; Total += "<center><tr style='background-color: rgb(170,204,204);'><td>" + sno + "</td><td>" + (pass + passed1) + "(" + String.format("%.2f", ((pass + passed1) * 100.0F / sno)) + "%)</td><td>" + (fail + failed1) + "(" + String.format("%.2f", ((fail + failed1) * 100.0F / sno)) + "%)</td></tr></center></table><br>"; bodydetailS += "</center></table><br><br><br>"; System.out.println(version); head += headdetails + Total + version + bodydetailS; if (fail > 0) { failureReasonTable += "</table>"; // System.out.println(failureReasonTable); head += failureReasonTable; } head += "</td></tr></table></body></html>"; return head; }
From source file:com.walmartlabs.mupd8.application.Config.java
private static HashMap<String, JSONObject> extractWorkerJSONs(JSONObject configuration) { HashMap<String, JSONObject> performers = new HashMap<String, JSONObject>(); JSONObject applications = (JSONObject) getScopedValue(configuration, new String[] { "mupd8", "application" }); if (applications == null) { // Lost cause: No applications found. System.err.println("No mupd8:application found; Config.workerJSONs not set."); return performers; }/*from www . j av a2 s . c o m*/ Set<?> applicationNames = applications.keySet(); if (applicationNames.size() != 1) { System.err.println("Exactly one application definition expected, but got " + Integer.toString(applicationNames.size()) + " instead; Config.workerJSONs not set."); return performers; } String applicationName = applicationNames.toArray(new String[] {})[0]; JSONObject performerSection = (JSONObject) getScopedValue(applications, new String[] { applicationName, "performers" }); for (Object k : performerSection.keySet()) { String key = (String) k; performers.put(key, (JSONObject) performerSection.get(key)); } return performers; }
From source file:com.stratio.deep.commons.utils.CellsUtils.java
/** * converts from cell class to JSONObject * * @param Json the json//from ww w . java 2 s . co m * @param tableName the table name * @return cell from json * @throws IllegalAccessException the illegal access exception * @throws IllegalAccessException the instantiation exception * @throws IllegalAccessException the invocation target exception */ public static Cells getCellFromJson(JSONObject Json, String tableName) throws IllegalAccessException, InstantiationException, InvocationTargetException { Cells cells = tableName != null ? new Cells(tableName) : new Cells(); Set<String> entrySet = Json.keySet(); for (String key : entrySet) { try { Object value = Json.get(key); if (List.class.isAssignableFrom(value.getClass())) { List<Cells> innerCell = new ArrayList<>(); for (JSONObject innerBson : (List<JSONObject>) value) { innerCell.add(getCellFromJson(innerBson, null)); } cells.add(Cell.create(key, innerCell)); } else if (JSONObject.class.isAssignableFrom(value.getClass())) { Cells innerCells = getCellFromJson((JSONObject) value, null); cells.add(Cell.create(key, innerCells)); } else { if (key.equalsIgnoreCase("id")) { cells.add(Cell.create(key, value, true)); } else { cells.add(Cell.create(key, value)); } } } catch (IllegalAccessException | InstantiationException | InvocationTargetException | IllegalArgumentException e) { LOG.error("impossible to create a java cell from Json field:" + key); } } return cells; }
From source file:com.stratio.deep.commons.utils.CellsUtils.java
public static Cells getCellWithMapFromJson(JSONObject Json, String tableName) throws IllegalAccessException, InstantiationException, InvocationTargetException { Cells cells = tableName != null ? new Cells(tableName) : new Cells(); Set<String> entrySet = Json.keySet(); for (String key : entrySet) { try {// ww w . j a v a 2s .c om Object value = Json.get(key); if (List.class.isAssignableFrom(value.getClass())) { List<String> innerCell = new ArrayList<>(); for (String innerBson : (List<String>) value) { innerCell.add(innerBson); } cells.add(Cell.create(key, innerCell)); } else if (JSONObject.class.isAssignableFrom(value.getClass())) { Map<String, Object> map = new HashMap<>(); Cells innerCells = getCellFromJson((JSONObject) value, null); for (Cell cell : innerCells) { map.put(cell.getName(), cell.getValue()); } cells.add(Cell.create(key, map)); } else { if (key.equalsIgnoreCase("id")) { cells.add(Cell.create(key, value, true)); } else { cells.add(Cell.create(key, value)); } } } catch (IllegalAccessException | InstantiationException | InvocationTargetException | IllegalArgumentException e) { LOG.error("impossible to create a java cell from Json field:" + key); } } return cells; }