Example usage for org.json.simple JSONArray size

List of usage examples for org.json.simple JSONArray size

Introduction

In this page you can find the example usage for org.json.simple JSONArray size.

Prototype

public int size() 

Source Link

Document

Returns the number of elements in this list.

Usage

From source file:com.github.lgi2p.obirs.utils.JSONConverter.java

/**
 * {"log": "", "annotations" : [{ "text": "uranium", "startpos": 723,
 * "endpos":730, "uris":["http://www.cea.fr/ontotoxnuc#Uranium"] },{ "text":
 * "protein", "startpos": 1837, "endpos":1845,
 * "uris":["http://www.cea.fr/ontotoxnuc#Proteine"] },{ "text": "plant",
 * "startpos": 4661, "endpos":4666,//from   w  w w  .ja  va 2s.c  o m
 * "uris":["http://www.cea.fr/ontotoxnuc#Plante"] }]}
 *
 * @param jsonQuery
 * @return
 * @throws ParseException
 * @throws Exception
 */
protected static String toJSONindexFormat(int id, String title, String content, String href)
        throws ParseException, Exception {

    URIFactory f = URIFactoryMemory.getSingleton();

    content = content.replace("\n", "").replace("\r", "");
    Object obj = new JSONParser().parse(content);
    JSONObject jsonObject = (JSONObject) obj;
    JSONArray annotations = (JSONArray) jsonObject.get("annotations");

    Set<URI> concepts = new HashSet<URI>();

    if (annotations != null) {
        Iterator<JSONObject> iterator = annotations.iterator();
        while (iterator.hasNext()) {
            JSONObject concept = iterator.next();
            JSONArray uris = (JSONArray) concept.get("uris");
            for (int i = 0; i < uris.size(); i++) {
                concepts.add(f.getURI((String) uris.get(i)));
            }
        }

    }

    String urisAsString = "";
    for (URI u : concepts) {
        if (!urisAsString.isEmpty()) {
            urisAsString += ",";
        }
        urisAsString += "\"" + u.stringValue() + "\"";
    }
    return "{\"id\":\"" + id + "\",\"title\":\"" + title + "\",\"conceptIds\":[" + urisAsString
            + "],\"href\":\"" + href + "\"}";
}

From source file:com.netbase.insightapi.bestpractice.TopicDownloader.java

/**
 * Gets the earliest timestamp that would match the query. Returns
 * Integer.MAX_VALUE if the query matches no documents.
 * //from w ww .j a v  a 2 s . c o m
 * @param masterQuery
 * @param user
 * @return
 * @throws InsightAPIQueryException
 * @throws InterruptedException
 */
public static int getEarliestTimestamp(InsightAPIQuery masterQuery, UserChannel user)
        throws InsightAPIQueryException, InterruptedException {
    InsightAPIQuery query = new InsightAPIQuery(masterQuery);
    query.setOp("retrieveDocuments");
    query.setParameter("sort", "timestamp");
    query.setParameter("sizeNeeded", 1);
    user.run(query);
    JSONArray docs = (JSONArray) ((JSONObject) query.getParsedContent()).get("documents");
    if (docs == null || docs.size() == 0)
        return (Integer.MAX_VALUE);
    JSONObject doc = (JSONObject) docs.get(0);
    return (getDocTimestamp(doc));
}

From source file:com.netbase.insightapi.bestpractice.TopicDownloader.java

/**
 * gets the latest timestamp that would match the query. Returns
 * Integer.MIN_VALUE if the query matches no documents.
 * //from  www  .ja  v a2s  .c o  m
 * @param masterQuery
 * @param user
 * @return
 * @throws InsightAPIQueryException
 * @throws InterruptedException
 */
public static int getLatestTimestamp(InsightAPIQuery masterQuery, UserChannel user)
        throws InsightAPIQueryException, InterruptedException {
    InsightAPIQuery query = new InsightAPIQuery(masterQuery);
    query.setOp("retrieveDocuments");
    query.setParameter("sort", "-timestamp");
    query.setParameter("sizeNeeded", 1);
    user.run(query);
    JSONArray docs = (JSONArray) ((JSONObject) query.getParsedContent()).get("documents");

    if (docs == null || docs.size() == 0)
        return (Integer.MIN_VALUE);
    JSONObject doc = (JSONObject) docs.get(0);
    return (getDocTimestamp(doc));
}

From source file:configuration.Key.java

/**
 * Returns the keys provided in the JSON array.
 * /*from   w w w.  j a va  2 s.c o  m*/
 * @param array
 *            the JSON array to parse for keys.
 * @return the keys provided in the JSON array.
 */
public static Key[] parseKeys(JSONArray array) {
    List<Key> keys = new LinkedList<Key>();

    if (array == null) {
        throw new NullPointerException("array may not be null!");
    }

    for (int i = 0; i < array.size(); i++) {
        JSONObject object = (JSONObject) array.get(i);
        String key = (String) object.get(KEY_KEY);
        Long version = (Long) object.get(KEY_VERSION);
        int versionInt = version.intValue();
        String algorithm = (String) object.get(KEY_ALGORITHM);
        /*
         * getEncoded() returns the raw bytes of the key (s.
         * http://docs.oracle
         * .com/javase/7/docs/api/javax/crypto/SecretKey.html)
         */
        try {
            byte[] rawKey = Coder.decodeBASE64(key);
            SecretKey secretKey = new SecretKeySpec(rawKey, getSecretKeyAlgorithm(algorithm));
            keys.add(new Key(secretKey, versionInt, algorithm));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    return keys.toArray(new Key[0]);
}

From source file:gov.nih.nci.rembrandt.web.ajax.DynamicListHelper.java

public static String getRBTFeatures() {
    String jfeats = "";
    //get the features from the external props
    String feats = System.getProperty("rembrandt.feedback.features");
    List<String> f = Arrays.asList(feats.split(","));
    JSONArray fs = new JSONArray();
    for (String s : f) {
        s = s.trim();//w  w  w  . ja  v  a2  s  .co  m
        fs.add(s);
    }
    if (fs.size() > 0) {
        jfeats = fs.toString();
    }
    return jfeats;
}

From source file:com.sat.common.CustomReport.java

/**
 * Reportparsejson./*  www.  j a va  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>Test Case Title</th><th>TIMS ID</th><th>Test Type</th><th>Component Involved</th><th>Status</th></tr>";
    String Total = "";
    Object obj = parser
            .parse(new FileReader(System.getProperty("user.dir") + "/LMS/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("Stage2"))
                            || (jo2.get("name").toString().contains("TBD"))) {
                        String stype = "Functional";
                        for (int typec = 0; typec < msg2.size(); typec++) {
                            JSONObject jotype = (JSONObject) msg2.get(typec);
                            if (jotype.get("name").toString().contains("Functional"))
                                stype = "Functional";
                            else if (jotype.get("name").toString().contains("Sanity"))
                                stype = "Sanity";

                        }
                        if (!uniid.trim().equals(jo2.get("name").toString().trim())) {

                            String fnameuri[] = jo.get("uri").toString().split("/");
                            featureFile = fnameuri[fnameuri.length - 1];
                            System.out.println("feture file" + featureFile);
                            String[] featureFile1 = featureFile.split(".feature");
                            System.out.println("split feature" + featureFile1[0]);

                            serial = "" + (++sno);
                            timsId = jo2.get("name").toString();
                            testType = stype;
                            testTitle = jo1.get("name").toString();
                            mid = "<td><center>" + serial + "</center></td><td>" + featureFile1[0]
                                    + "</center></td><td>" + testTitle + "</center></td><td><center>"
                                    + timsId.substring(1) + "</center></td><td><center>" + testType + "</td>";
                            uniidstatus = "Y";

                            mid1 = "<td><center>" + timsId.substring(1) + "</center></td><td>" + testTitle
                                    + "</td>";

                        }

                        uniid = jo2.get("name").toString();

                    }
                }

                JSONArray msg3 = (JSONArray) jo1.get("steps");
                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;
                    }
                }

                String scenarioprint = null;
                JSONArray output = (JSONArray) jo1.get("steps");
                for (int outputj3 = 0; outputj3 < output.size(); outputj3++) {
                    JSONObject outputjo3 = (JSONObject) output.get(outputj3);
                    JSONArray outputjo4 = (JSONArray) outputjo3.get("output");
                    if (outputjo4 != null) {
                        for (int outputj33 = 0; outputj33 < outputjo4.size(); outputj33++) {
                            String tempscenarioprint = (String) outputjo4.get(outputj33);
                            tempscenarioprint = tempscenarioprint.replace("[", " ");
                            tempscenarioprint = tempscenarioprint.replace("]", " ").trim();
                            System.out.println(tempscenarioprint);
                            if (tempscenarioprint.startsWith("ComponentInvolved")) {
                                tempscenarioprint = tempscenarioprint.replace("ComponentInvolved", "Begin");
                                tempscenarioprint = tempscenarioprint.replace(",", " ");
                                scenarioprint = tempscenarioprint;
                            }
                            System.out.println("scenario" + scenarioprint);
                        }
                    }

                }

                if (uniidstatus.equals("Y")) {
                    if (pf == 0) {
                        bodydetailS += "<tr style='background-color: rgb(107,144,70);'>" + mid + "<td><center>"
                                + scenarioprint + "</center></td><td><center>Passed</center></td></tr>";
                        pass++;
                    } else if (pf == 1) {
                        bodydetailS += "<tr style='background-color: rgb(216, 138, 138);'><center>" + mid
                                + "<td><center>" + scenarioprint
                                + "</center></td><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) {

                        } else if (pf == 1) {
                            if (bodydetailS.contains("<tr style='background-color: rgb(107,144,70);'>" + mid
                                    + "<td><center>" + scenarioprint
                                    + "</center></td><td><center>Passed</center></td></tr>")) {
                                failed1++;
                                passed1--;
                                bodydetailS = bodydetailS.replace(
                                        "<tr style='background-color: rgb(107,144,70);'>" + mid + "<td><center>"
                                                + scenarioprint
                                                + "</center></td><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>" + scenarioprint
                                            + "</center></td><td><center>Failed</center></td></tr>")) {
                                bodydetailS = bodydetailS.replace(
                                        "<tr style='background-color: rgb(216, 138, 138);'><center>" + mid
                                                + "<td><center>" + scenarioprint
                                                + "</center></td><td><center>Failed</center></td></tr>",
                                        "<tr style='background-color: rgb(216, 138, 138);'><center>" + mid
                                                + "<td><center>" + scenarioprint
                                                + "</center></td><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>";
                        }

                    }

                }
            }
        }
    }

    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:cloudclient.Client.java

@SuppressWarnings("unchecked")
public static void batchSendTask(PrintWriter out, String workload)
        throws FileNotFoundException, MalformedURLException {

    FileInputStream input = new FileInputStream(workload);
    BufferedReader bin = new BufferedReader(new InputStreamReader(input));

    // Get task from workload file 
    String line;/*from   w  ww  .ja  va2  s . c  o m*/
    //       String sleepLength;
    String id;
    int count = 0;
    final int batchSize = 10;

    try {
        //Get client public IP
        String ip = getIP();
        //System.out.println(ip);

        //JSON object Array      
        JSONArray taskList = new JSONArray();

        while ((line = bin.readLine()) != null) {
            //sleepLength = line.replaceAll("[^0-9]", "");
            //System.out.println(sleepLength);
            count++;
            id = ip + ":" + count;

            JSONObject task = new JSONObject();
            task.put("task_id", id);
            task.put("task", line);

            taskList.add(task);

            if (taskList.size() == batchSize) {
                out.println(taskList.toString());
                taskList.clear();
            }
        }

        //System.out.println(taskList.toString());         
        if (!taskList.isEmpty()) {
            out.println(taskList.toString());
            taskList.clear();
        }

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

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  w  w  w  .  java 2s  . c  om*/
    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:com.cisco.dbds.utils.report.CustomReport.java

/**
 * Reportparsejson./*from  w  w  w  .jav  a  2 s.c  o m*/
 *
 * @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 .ja va 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;

}