Example usage for org.json.simple JSONArray get

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

Introduction

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

Prototype

public E get(int index) 

Source Link

Document

Returns the element at the specified position in this list.

Usage

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 .  j a va 2 s  .  co 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:freebase.api.FreebaseAPI2.java

private static List<Film> encodeJSON(JSONArray results) {
    List<Film> films = new ArrayList<>();
    for (Object flmObj : results) {
        JSONObject flmJObj = (JSONObject) flmObj;
        Film film = new Film(getId((String) flmJObj.get("mid"), film_map), (String) flmJObj.get("mid"),
                (String) flmJObj.get("name"));

        JSONArray directed_by_arr = (JSONArray) flmJObj.get("directed_by");
        JSONObject directed_by = (JSONObject) directed_by_arr.get(0);
        Directedby directedby = new Directedby();
        directedby.setId(directedbyIDs.next());

        Director director = new Director(getId((String) directed_by.get("mid"), director_map),
                (String) directed_by.get("mid"), (String) directed_by.get("name"));
        directedby.setDirector(director);
        film.setDirectedBy(directedby);//from   w  ww . jav  a2s .  c  o  m

        JSONArray starrings = (JSONArray) flmJObj.get("starring");
        for (Object starringObj : starrings) {
            JSONObject starringJObj = (JSONObject) starringObj;
            Starring starring = new Starring();
            starring.setMid((String) starringJObj.get("mid"));
            starring.setId(getId((String) starringJObj.get("mid"), starring_map));

            JSONArray actorJObj_arr = (JSONArray) starringJObj.get("actor");
            JSONObject actorJObj = (JSONObject) actorJObj_arr.get(0);
            Actor actor = new Actor(getId((String) actorJObj.get("mid"), actor_map),
                    (String) actorJObj.get("mid"), (String) actorJObj.get("name"));
            starring.setActor(actor);

            JSONArray characterJObj_arr = (JSONArray) starringJObj.get("character");
            JSONObject characterJObj = (JSONObject) characterJObj_arr.get(0);
            freebase.api.entity.movie.FCharacter character = new freebase.api.entity.movie.FCharacter(
                    getId((String) characterJObj.get("mid"), character_map), (String) characterJObj.get("mid"),
                    (String) characterJObj.get("name"));
            starring.setCharacter(character);

            starring.setFilm(film);
            film.addStarring(starring);
        }

        films.add(film);
    }
    return films;
}

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

/**
 * Reportparsejson.//from  w w w.ja  v  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>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:com.jilk.ros.rosbridge.implementation.JSON.java

private static Message convertJSONArrayToMessage(JSONArray ja, Class c, Registry<Class> r) {
    try {// ww w  .  j av a2s. co m
        Message result = (Message) c.newInstance();
        int arrayIndex = 0;
        for (Field f : c.getFields()) {
            Class fc = getFieldClass(result, null, f, r);
            Object lookup = ja.get(arrayIndex++); // yes we are assuming that the fields are delivered in order
            if (lookup != null) {
                Object value = convertElementToField(lookup, fc, f, r);
                f.set(result, value);
            }
        }

        return result;
    } catch (Exception ex) {
        ex.printStackTrace();
        return null;
    }
}

From source file:de.minestar.minestarlibrary.utils.PlayerUtils.java

public static String getPlayerNameFromMojang(String uuid) {
    JSONArray array = getHTTPGetRequestAsArray("https://api.mojang.com/user/profiles/" + uuid + "/names");
    JSONObject object = (JSONObject) array.get(array.size() - 1);
    return (String) object.get("name");
}

From source file:net.drgnome.virtualpack.util.Util.java

public static boolean hasUpdate(int projectID, String version) {
        try {/* www  .ja v  a2  s.c om*/
            HttpURLConnection con = (HttpURLConnection) (new URL(
                    "https://api.curseforge.com/servermods/files?projectIds=" + projectID)).openConnection();
            con.setConnectTimeout(5000);
            con.setRequestMethod("GET");
            con.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; JVM)");
            con.setRequestProperty("Pragma", "no-cache");
            con.connect();
            JSONArray json = (JSONArray) JSONValue.parse(new InputStreamReader(con.getInputStream()));
            String[] cdigits = ((String) ((JSONObject) json.get(json.size() - 1)).get("name")).toLowerCase()
                    .split("\\.");
            String[] vdigits = version.toLowerCase().split("\\.");
            int max = vdigits.length > cdigits.length ? cdigits.length : vdigits.length;
            int a;
            int b;
            for (int i = 0; i < max; i++) {
                a = b = 0;
                try {
                    a = Integer.parseInt(cdigits[i]);
                } catch (Exception e1) {
                    char[] c = cdigits[i].toCharArray();
                    for (int j = 0; j < c.length; j++) {
                        a += (c[j] << ((c.length - (j + 1)) * 8));
                    }
                }
                try {
                    b = Integer.parseInt(vdigits[i]);
                } catch (Exception e1) {
                    char[] c = vdigits[i].toCharArray();
                    for (int j = 0; j < c.length; j++) {
                        b += (c[j] << ((c.length - (j + 1)) * 8));
                    }
                }
                if (a > b) {
                    return true;
                } else if (a < b) {
                    return false;
                } else if ((i == max - 1) && (cdigits.length > vdigits.length)) {
                    return true;
                }
            }
        } catch (Exception e) {
        }
        return false;
    }

From source file:com.cisco.dbds.utils.report.CustomReport.java

/**
 * Reportparsejson.//from   w  w w.j a  v a 2s .  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.//w w  w. j  a va 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("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: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;/* w  ww  . j a v a 2  s  .  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:crossbear.convergence.ConvergenceConnector.java

/**
 * Transfer the Notary's answer from a JSON-representation into a HashSet of ConvergenceCertObservation
 * //from   ww  w  . j ava  2  s. c  om
 * @param notaryAnswer The Response-String that the Notary sent as an answer. It should contain a JSON-encoded list of ConvergenceCertificateObservations 
 * @param hostPort The Hostname and port of the server on which the information about the certificate observations is desired.
 * @return The Notary's answer as a Set of ConvergenceCertObservations
 * @throws ParseException
 */
private static HashSet<ConvergenceCertObservation> parseNotaryAnswer(String notaryAnswer, String hostPort)
        throws ParseException {

    // Create a empty Set of ConvergenceCertObservations
    HashSet<ConvergenceCertObservation> re = new HashSet<ConvergenceCertObservation>();

    // Try to decode the Notary's answer as a JSONObject
    JSONParser parser = new JSONParser();
    JSONObject obj = (JSONObject) parser.parse(notaryAnswer);

    // If that worked extract the field called fingerprintList (which is basically a list of ConvergenceCertObservations in JSON encoding)
    JSONArray array = (JSONArray) obj.get("fingerprintList");

    // Go through the list ...
    for (int i = 0; i < array.size(); i++) {

        // ... read each entry ...
        JSONObject entry = (JSONObject) array.get(i);

        // .. extract its content ...
        byte[] fingerprint = Message.hexStringToByteArray(((String) entry.get("fingerprint")).replace(":", ""));
        JSONObject ts = (JSONObject) entry.get("timestamp");
        Timestamp firstObservation = new Timestamp(1000 * Long.valueOf((String) ts.get("start")));
        Timestamp lastObservation = new Timestamp(1000 * Long.valueOf((String) ts.get("finish")));
        Timestamp lastUpdate = new Timestamp(System.currentTimeMillis());

        // ... and create a new ConvergenceCertObservation-object based on that content.
        re.add(new ConvergenceCertObservation(hostPort, Message.byteArrayToHexString(fingerprint),
                firstObservation, lastObservation, lastUpdate));
    }

    // Finally return the Set containing all of the extracted ConvergenceCertObservations.
    return re;
}