Example usage for org.json.simple JSONArray JSONArray

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

Introduction

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

Prototype

JSONArray

Source Link

Usage

From source file:ch.zhaw.icclab.tnova.expressionsolver.Base.java

@GET
@Produces(MediaType.APPLICATION_JSON)/*from  ww  w  . ja  v a 2 s. c  o m*/
public String homePage() {
    KPI.api_calls += 1;
    JSONObject obj = new JSONObject();
    obj.put("src", "t-nova expression evaluation service");
    obj.put("msg", "api summary list");
    JSONArray apiList = new JSONArray();
    JSONObject api = new JSONObject();
    api.put("uri", "/");
    api.put("method", "GET");
    api.put("purpose", "capability discovery");
    apiList.add(api);

    api = new JSONObject();
    api.put("uri", "/template/");
    api.put("method", "GET");
    api.put("purpose", "list of registered expression templates");
    apiList.add(api);

    api = new JSONObject();
    api.put("uri", "/template/");
    api.put("method", "POST");
    api.put("purpose", "registration of a new expression template");
    apiList.add(api);

    api = new JSONObject();
    api.put("uri", "/template/{id}");
    api.put("method", "GET");
    api.put("purpose", "get specific expression template details");
    apiList.add(api);

    api = new JSONObject();
    api.put("uri", "/expression/{id}");
    api.put("method", "DELETE");
    api.put("purpose", "delete specific expression template, all expression instantiation will be deleted");
    apiList.add(api);

    api = new JSONObject();
    api.put("uri", "/expression/");
    api.put("method", "GET");
    api.put("purpose", "list of registered expressions");
    apiList.add(api);

    api = new JSONObject();
    api.put("uri", "/expression/");
    api.put("method", "POST");
    api.put("purpose", "register a new expression");
    apiList.add(api);

    api = new JSONObject();
    api.put("uri", "/expression/{id}");
    api.put("method", "GET");
    api.put("purpose", "get specific expression details");
    apiList.add(api);

    api = new JSONObject();
    api.put("uri", "/expression/{id}");
    api.put("method", "PUT");
    api.put("purpose", "update a specific expression");
    apiList.add(api);

    api = new JSONObject();
    api.put("uri", "/expression/{id}");
    api.put("method", "POST");
    api.put("purpose", "execute a specific expression");
    apiList.add(api);

    api = new JSONObject();
    api.put("uri", "/expression/{id}");
    api.put("method", "DELETE");
    api.put("purpose", "delete a specific expression");
    apiList.add(api);

    api = new JSONObject();
    api.put("uri", "/kpi");
    api.put("method", "GET");
    api.put("purpose", "get the service key runtime metrics");
    apiList.add(api);

    api = new JSONObject();
    api.put("uri", "/otfly/");
    api.put("method", "POST");
    api.put("purpose", "on the fly stateless expression evaluation");
    api.put("op-supported", "lt, gt, add, max, min, avg");
    apiList.add(api);

    obj.put("api", apiList);

    logger.info("URI:/ Method:GET Request procesed.");
    KPI.api_calls_success += 1;
    return obj.toJSONString();
}

From source file:modelo.ParametrizacionManagers.TiposInformeVertimientos.java

/**
* 
* Llama al delegate para Eliminar un Laboratorio
* 
* @param codigo     //from  w  w  w .  jav  a  2 s  . c  o m
* @throws Exception 
*/
public JSONArray Eliminar(int codigo) throws Exception {

    JSONArray jsonArray = new JSONArray();
    JSONObject jsonObject = new JSONObject();

    Integer respError;

    EliminarTiposInformesVertimientos delete = new EliminarTiposInformesVertimientos(codigo);
    delete.ejecutar();

    respError = delete.getError();

    jsonObject.put("error", respError);

    jsonArray.add(jsonObject);

    return jsonArray;

}

From source file:com.megacasting_ppe.web.ServletOffreForDiffuseur.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*  ww w . j  ava 2s.co  m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("application/json;  charset=ISO-8859-1");
    response.setHeader("Cache-Control", "no-cache");
    JSONObject global = new JSONObject();
    JSONArray arrayoffre = new JSONArray();

    //on rcupre l'ensemble des offres de casting en BDD
    for (Offre offre : offreDAO.Lister()) {

        JSONObject object = new JSONObject();
        //Par dfaut il n'y a pas de fin de contrat, dans le cas si l'offre propos est un CDI
        String datefincontrat = "Aucune Date";
        if (offre.getDateFinContrat() != null) {

            datefincontrat = offre.getDateFinContrat().toString();

        }
        //on retourne les informations de l'offre
        object.put("Intitule", offre.getLibelle());
        object.put("Reference", offre.getReference());
        object.put("DateDebutPublication", offre.getDateDebutPublication().toString());
        object.put("DateFinPublication", offre.getDateFinPublication().toString());
        object.put("DateDebutContrat", offre.getDateDebutContrat().toString());
        object.put("DateFinContrat", datefincontrat);
        object.put("DescriptionPoste", offre.getDescriptionPoste());
        object.put("DescriptionProfil", offre.getDescriptionProfil());
        object.put("NombresPoste", offre.getNbPoste());
        object.put("NomEntreprise", offre.getClient().getNomEntreprise());
        object.put("NomResponsable", offre.getClient().getNomResponsable());
        object.put("PrenomResponsable", offre.getClient().getPrenomResponsable());
        object.put("CiviliteResponsable", offre.getClient().getCiviliteResponsable());
        object.put("RueEntreprise", offre.getClient().getRueEntreprise());
        object.put("CpEntreprise", offre.getClient().getCpEntreprise());
        object.put("VilleEntreprise", offre.getClient().getVilleEntreprise());
        object.put("MailEntreprise", offre.getClient().getMailEntreprise());
        object.put("FaxEntreprise", offre.getClient().getFaxEntreprise());
        object.put("TelephoneEntreprise", offre.getClient().getTelephoneEntreprise());
        object.put("Metier", offre.getMetier().getLibelle());
        object.put("Contrat", offre.getContrat().getLibelle());

        arrayoffre.add(object);

    }
    global.put("offres", arrayoffre);

    try (PrintWriter out = response.getWriter()) {
        out.println(global.toString());
    }

}

From source file:cat.tv3.eng.rec.recomana.lupa.visualization.ClustersToJson.java

public static JSONArray hashToJSONArrayRepresentationBinaryTree(String id, String hash, Jedis jedis, String id2,
        String hash2) {/*from ww w  .  ja  v  a 2  s  . c o  m*/
    JSONArray result = new JSONArray();
    JSONObject info;
    Map<String, String> attr_cluster = jedis.hgetAll(hash);
    String cluster_name = attr_cluster.get("cluster_ids_name");
    if (!cluster_name.equals("cluster_splited")) {
        info = new JSONObject();
        info.put("name", "Centroid " + id);
        String[] instance_group_keys = jedis.keys("Instances_centroid_ID_" + id).toArray(new String[0]);
        info.put("children", fullestoArray(instance_group_keys, jedis));
    } else {
        String id_left_centroid = attr_cluster.get("id_left_centroid");
        String id_right_centroid = attr_cluster.get("id_right_centroid");

        String hash_left = attr_cluster.get("hash_left");
        String hash_right = attr_cluster.get("hash_right");

        info = new JSONObject();
        info.put("name", "Centroid " + id);
        info.put("children", hashToJSONArrayRepresentationBinaryTree(id_left_centroid, hash_left, jedis,
                id_right_centroid, hash_right));
    }
    result.add(info);

    attr_cluster = jedis.hgetAll(hash2);
    cluster_name = attr_cluster.get("cluster_ids_name");

    if (!cluster_name.equals("cluster_splited")) {
        info = new JSONObject();
        info.put("name", "Centroid " + id2);

        String[] instance_group_keys = jedis.keys("Instances_centroid_ID_" + id2).toArray(new String[0]);
        info.put("children", fullestoArray(instance_group_keys, jedis));
    } else {
        String id_left_centroid = attr_cluster.get("id_left_centroid");
        String id_right_centroid = attr_cluster.get("id_right_centroid");

        String hash_left = attr_cluster.get("hash_left");
        String hash_right = attr_cluster.get("hash_right");

        info = new JSONObject();
        info.put("name", "Centroid " + id2);
        info.put("children", hashToJSONArrayRepresentationBinaryTree(id_left_centroid, hash_left, jedis,
                id_right_centroid, hash_right));
    }
    result.add(info);
    return result;
}

From source file:edu.iu.incntre.flowscale.util.JSONConverter.java

/**
 * convert List<OFStatistics> to JSONArray
 * @param ofs/*from ww  w .  j  av  a2 s . c  om*/
 * @return JSONArray
 */
public static JSONArray toTableStat(List<OFStatistics> ofs) {

    JSONArray jsonArray = new JSONArray();
    for (OFStatistics ofst : ofs) {

        OFTableStatistics st = (OFTableStatistics) ofst;
        // st.getPortNumber() st.getReceiveBytes();

        FlowscaleController.logger.debug("Maximum Entries {} and and Table id {}", st.getMaximumEntries(),
                st.getTableId());
        FlowscaleController.logger.debug("Name {} and and Table length {}", st.getName(), st.getLength());

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("match_count", st.getMatchedCount());
        jsonObject.put("maximum_entries", st.getMaximumEntries());
        jsonObject.put("name", st.getName());
        jsonObject.put("table_id", st.getTableId());
        jsonObject.put("active_count", st.getActiveCount());

        jsonArray.add(jsonObject);

    }

    return jsonArray;

}

From source file:bookUtilities.PopulateMyBooksServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
 *
 * @param request servlet request/*from  w  w w .j  a  va  2 s.  c om*/
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    String email;
    email = (String) request.getSession().getAttribute("email");
    JSONArray fileTypes = new JSONArray();
    JSONArray userBooks = getUserBooks(email, fileTypes);
    JSONArray infoToPush = new JSONArray();
    infoToPush.add(userBooks);
    infoToPush.add(fileTypes);
    PrintWriter printout = response.getWriter();
    printout.print(infoToPush);
    printout.flush();
}

From source file:com.opensoc.tagging.adapters.RegexTagger.java

/**
 * @param raw_message telemetry message to be tagged
 *///from   ww w. j a  va 2 s.co m
@SuppressWarnings("unchecked")
public JSONArray tag(JSONObject raw_message) {

    JSONArray ja = new JSONArray();
    String message_as_string = raw_message.toString();

    for (String rule : _rules.keySet()) {
        if (message_as_string.matches(rule)) {
            ja.add(_rules.get(rule));
        }
    }

    return ja;
}

From source file:at.uni_salzburg.cs.ckgroup.cscpp.mapper.json.ZonesQuery.java

@SuppressWarnings("unchecked")
public String execute(IServletConfig config, String[] parameters) {

    if (mapper == null) {
        return "";
    }// w ww .  ja  v a  2 s.  c  om

    Set<IZone> zones = mapper.getZones();

    JSONArray a = new JSONArray();
    for (IZone zone : zones) {
        a.add(zone);
    }

    return JSONValue.toJSONString(a);
}

From source file:bookUtilities.BookListServlet.java

private JSONArray getBooks() {
    JSONArray booksToReturn = new JSONArray();
    try {/*w w w  .  j av a 2 s . c  o m*/
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

        Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost;user=sa;password=nopw");

        Statement st = con.createStatement();

        String query = "SELECT * " + "FROM HardCover.dbo.Book " + "WHERE Active = 1";

        ResultSet rs = st.executeQuery(query);
        while (rs.next()) {
            JSONObject bookToAdd = new JSONObject();
            bookToAdd.put("bookId", rs.getString("BookUuid"));
            bookToAdd.put("title", rs.getString("Title"));
            booksToReturn.add(bookToAdd);
        }

    } catch (Exception e) {
        System.out.println(e.getMessage());
    }
    return booksToReturn;
}

From source file:com.facebook.tsdb.tsdash.server.data.DataTable.java

@SuppressWarnings("unchecked")
private JSONArray generateColumns() {
    JSONArray cols = new JSONArray();
    cols.add(newColumn("Date", "datetime"));
    for (Metric metric : metrics) {
        for (TagsArray timeSeries : metric.timeSeries.keySet()) {
            cols.add(newColumn(renderLineTitle(metric, timeSeries), "number"));
        }/*from  w w w  .  j a v  a2s .  c  om*/
    }
    return cols;
}