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:com.github.itoshige.testrail.client.TestRailClient.java

/************ results ************/
public static JSONArray addResults(TestResultStoreKey runId2Class) {
    Map<String, List<Map<String, Object>>> results = SyncManager.getJunitTestResults(runId2Class);
    if (results.isEmpty())
        return new JSONArray();

    logger.info("update testrail. runId:{}", runId2Class.getRunId());
    return (JSONArray) post(String.format("add_results/%s", runId2Class.getRunId()), results);
}

From source file:modelo.ProcesoVertimientosManagers.InformacionGeneral.java

public JSONArray getInformacionGeneral(int codigoProceso) throws SQLException {

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

    ResultSet rset;//www.j av  a2  s .co  m

    SeleccionarInformacionGeneral select = new SeleccionarInformacionGeneral();

    rset = select.getInformacionGeneral(codigoProceso);

    while (rset.next()) {

        jsonObject.put("codigoProceso", rset.getString("COD_PROCESO"));
        jsonObject.put("informo", rset.getString("INFORMA_MONITOREO"));
        jsonObject.put("tipoInforme", rset.getString("FK_TIPO_INFORME"));
        jsonObject.put("requiereVisita", rset.getString("REQUIERE_VISITA"));
        jsonObject.put("personaContacto", rset.getString("CONTACTO"));
        jsonObject.put("asunto", rset.getString("ASUNTO"));
        jsonObject.put("tipoContacto", rset.getString("FK_TIPO_CONTACTO"));
        jsonObject.put("razonSocial", rset.getString("RAZON_SOCIAL"));
        jsonObject.put("nit", rset.getString("NIT"));
        jsonObject.put("contrato", rset.getString("CONTRATO"));
        jsonObject.put("codigoAsesoria", rset.getString("COD_ASESORIA"));
        jsonObject.put("fechaAsesoria", rset.getString("FECHA_ASESORIA"));
        jsonObject.put("estadoProceso", rset.getString("ESTADO_PROCESO"));
        jsonObject.put("codigoCliente", rset.getString("COD_CLI"));
        jsonArray.add(jsonObject.clone());
    }

    jsonArreglo.add(jsonArray);

    //Se cierra el ResultSet
    select.desconectar();

    return jsonArreglo;
}

From source file:com.aerothai.database.accessory.AccessoryService.java

public JSONObject GetAccessoryAt(int id) throws Exception {

    Connection dbConn = null;// w ww  .j  a v  a  2  s .c o m
    JSONObject obj = new JSONObject();
    JSONArray objList = new JSONArray();

    int no = 1;
    //obj.put("draw", 2);
    obj.put("tag", "listat");
    obj.put("msg", "error");
    obj.put("status", false);
    try {
        dbConn = DBConnection.createConnection();

        Statement stmt = dbConn.createStatement();
        String query = "SELECT * FROM accessory where idaccessory = " + id;
        System.out.println(query);
        ResultSet rs = stmt.executeQuery(query);

        while (rs.next()) {

            JSONObject jsonData = new JSONObject();
            jsonData.put("id", rs.getInt("idaccessory"));
            jsonData.put("details", rs.getString("details"));
            jsonData.put("idunit", rs.getString("idunit"));
            jsonData.put("iddevice_type", rs.getString("iddevice_type"));
            jsonData.put("no", no);
            objList.add(jsonData);
            no++;
        }
        obj.put("msg", "done");
        obj.put("status", true);
        obj.put("data", objList);
    } catch (SQLException sqle) {
        throw sqle;
    } catch (Exception e) {
        // TODO Auto-generated catch block
        if (dbConn != null) {
            dbConn.close();
        }
        throw e;
    } finally {
        if (dbConn != null) {
            dbConn.close();
        }
    }
    return obj;
}

From source file:com.saludtec.web.EvolucionWeb.java

private JSONArray guardarEvolucion(HttpServletRequest request) {
    Evolucion evolucion = new Evolucion();
    Pacientes paciente = ejbPacientes.traer(Integer.parseInt(request.getParameter("idPaciente")));
    evolucion.setIdPaciente(paciente);//from   www .  ja va 2s  .  co m
    evolucion.setNombreModulo(request.getParameter("nombreModulo"));
    evolucion.setFecha(request.getParameter("fecha"));
    evolucion.setHora(request.getParameter("hora"));
    evolucion.setEvolucion(request.getParameter("evolucion"));
    evolucion.setIdUsuario(Integer.parseInt(request.getSession().getAttribute("usuario").toString()));//RECORDAR QUE ESTE VALOR ESTA QUEMADO Y HAY QUE CAMBIARLO CUANDO SE CREE LA TABLA USUARIOS
    evolucion = ejbEvolucion.crear(evolucion);
    obj = new JSONObject();
    objArray = new JSONArray();
    if (evolucion != null) {
        obj.put("idEvolucion", evolucion.getIdEvolucion());
        objArray.add(obj);
    } else {
        obj.put("error", "no se pudo guardar el evolucion");
        objArray.add(obj);
    }
    return objArray;
}

From source file:ca.mcgill.cs.creco.logic.ConcreteServiceFacade.java

@Override
public String getCompletions(String pInput) {
    if (pInput.length() <= MIN_NUMBER_OF_TYPED_LETTERS) {
        return "";
    }//from   w  w w .  ja  va2 s.co  m
    String[] result_set = new String[100];
    int pointer = 0;
    String temp = new String("");
    int index = 0;
    JSONArray response = new JSONArray();
    JSONObject obj = new JSONObject();

    for (Category category : aDataStore.getCategories()) {
        if (category.getNumberOfProducts() == 0) {
            continue;
        }
        if (category.getName().toLowerCase().contains(pInput.toLowerCase())) {
            result_set[pointer++] = category.getName().toLowerCase();
            result_set[pointer++] = "Category";
        }
    }
    Set<String> collectedbrandstillnow = new HashSet<String>();
    Set<String> collectedtexttillnow = new HashSet<String>();
    Set<String> brands = new HashSet<String>();
    Set<String> textSearch = new HashSet<String>();
    for (Product productname : aDataStore.getProducts()) {
        if (productname.getName().toLowerCase().contains(pInput.toLowerCase())) {
            for (String productspace : productname.getName().toLowerCase().split(" ")) {
                if (productspace.contains(pInput.toLowerCase())) {
                    if (productspace.equals(productname.getBrandName().toLowerCase())) {
                        if (collectedbrandstillnow.contains(productspace)) {

                        } else {
                            collectedbrandstillnow.add(productspace);
                            brands.add(productspace);
                        }
                    } else if (collectedtexttillnow.contains(productspace)
                            || collectedbrandstillnow.contains(productspace)) {
                    } else {
                        collectedtexttillnow.add(productspace);
                        int count = 0;
                        for (int i = 0; i < productspace.length(); i++) {
                            if (Character.isDigit(productspace.charAt(i))) {
                                count++;
                            }
                        }
                        if (count < 2 && !productspace.contains("(") && !productspace.contains(")")) {
                            textSearch.add(productspace);
                        }
                    }
                }
            }
        }
    }

    for (String brandname : brands) {
        if (Arrays.asList(result_set).contains(brandname)) {
            index = Arrays.asList(result_set).indexOf(brandname);
            result_set[index + 1] = result_set[index + 1].concat("|Brand");
            temp = result_set[0];
            result_set[0] = result_set[index];
            result_set[index] = temp;
            temp = result_set[1];
            result_set[1] = result_set[index + 1];
            result_set[index + 1] = temp;
        } else {
            result_set[pointer++] = brandname;
            result_set[pointer++] = "Brand";
        }
    }
    for (String textname : textSearch) {
        if (Arrays.asList(result_set).contains(textname)) {
            index = Arrays.asList(result_set).indexOf(textname);
            result_set[index + 1] = result_set[index + 1].concat("|Product");
            temp = result_set[0];
            result_set[0] = result_set[index];
            result_set[index] = temp;
            temp = result_set[1];
            result_set[1] = result_set[index + 1];
            result_set[index + 1] = temp;
        } else {
            result_set[pointer++] = textname;
            result_set[pointer++] = "Product";
        }
    }

    for (index = 0; index < result_set.length; index = index + 2) {
        obj.put("name", result_set[index]);
        obj.put("type", result_set[index + 1]);
        response.add(obj);
        obj = new JSONObject();
    }
    return response.toJSONString();
}

From source file:is.brendan.WarpMarkers.WarpMarkersWarpInfo.java

public JSONArray getUpdates(int updatesLife) {
    JSONArray jsonList = new JSONArray();

    final Iterator<HashMap> iterator = updates.iterator();

    while (iterator.hasNext()) {
        HashMap update = iterator.next();
        if (System.currentTimeMillis() - (Long) update.get("timestamp") < updatesLife) {
            jsonList.add(getUpdate(update));
        }//from www .ja  v  a 2s . c o  m
    }
    return jsonList;
}

From source file:compare.handler.get.TableInfoHandler.java

/**
 * Handle a request to get some metadata for a document
 * @param request the http request//  w ww . jav a 2  s  .  c  o  m
 * @param response the response
 * @param urn the current urn (ignored)
 * @throws CompareException if loading of MVD failed
 */
public void handle(HttpServletRequest request, HttpServletResponse response, String urn)
        throws CompareException {
    Map map = request.getParameterMap();
    docid = request.getParameter(JSONKeys.DOCID);
    version1 = getStringOption(map, Params.VERSION1, "");
    String json = "{}";
    try {
        if (docid != null && docid.length() > 0) {
            EcdosisMVD mvd = loadMVD(Database.CORTEX, docid);
            String selected = getStringOption(map, Params.SELECTED, ALL);
            String baseVersion = selectVersion1(mvd, selected);
            short base = mvd.getBaseVersion(baseVersion);
            int baseLen = getBaseVersionLen(mvd, base);
            int[] offsets = mvd.measureTable(base);
            int numSegs = Math.round((float) offsets.length / (float) CHUNK);
            if (numSegs == 0)
                numSegs = 1;
            int[] segs = new int[numSegs + 1];
            if (numSegs == 2) {
                segs[0] = 0;
                segs[1] = baseLen;
            } else {
                for (int i = 0; i < numSegs; i++)
                    segs[i] = offsets[i * CHUNK];
            }
            segs[segs.length - 1] = baseLen;
            JSONArray arr = new JSONArray();
            for (int i = 0; i < segs.length; i++)
                arr.add(segs[i]);
            json = arr.toJSONString();
        } else
            throw new Exception("CORTEX mvd " + docid + " not found");
        response.setContentType("application/json;charset=UTF-8");
        response.getWriter().println(json);
    } catch (Exception e) {
        throw new CompareException(e);
    }
}

From source file:net.duckling.ddl.web.controller.message.RecommendController.java

@SuppressWarnings("unchecked")
private void getTeamAllUser(VWBContext ctx, HttpServletResponse response) {
    List<SimpleUser> candidates = teamMemberService.getTeamMembersOrderByName(ctx.getTid());
    Collections.sort(candidates, comparator);
    JSONArray array = new JSONArray();
    for (SimpleUser current : candidates) {
        JSONObject temp = new JSONObject();
        temp.put("uid", current.getUid());
        temp.put("id", current.getId());
        temp.put("email", current.getEmail());
        temp.put("pinyin", current.getPinyin());
        if (StringUtils.isNotEmpty(current.getName())) {
            temp.put("name", current.getName());
        } else {//from   w  ww  . ja  va  2 s.  c  o m
            temp.put("name", current.getUid());
        }
        array.add(temp);
    }
    JsonUtil.writeJSONObject(response, array);
}

From source file:control.ParametrizacionServlets.EliminarAsociacionContrato.java

private void eliminarGrupoContratosAsociados(HttpServletRequest request, HttpServletResponse response) {

    try {//from  w  ww .j  a v  a 2s .co m
        //Obtenemos los paramtros enviados
        Double codigo = Double.parseDouble(request.getParameter("contrato"));

        JSONArray respError = new JSONArray(); // uno significa que no hay error

        //Obtenemos La informacion del manager
        AsociacionContratos manager = new AsociacionContratos();

        //Almacenamos el error que pueda resultar
        respError = manager.Eliminar(codigo);

        //Armamos la respuesta JSON y la enviamos
        response.setContentType("application/json");

        for (Object jsonObject : respError) {

            response.getWriter().write(respError.toString());

        }

    } catch (Exception e) {

    }
}

From source file:generate.ShowArticlesAction.java

public String execute() throws ClassNotFoundException, SQLException, IOException {
    List<DBObject> documents = new ArrayList<>();
    System.out.println("Mark 0");
    try {/* w w w . ja  va 2 s .c  om*/
        MongoClient mongo = new MongoClient();
        DB db = mongo.getDB("Major");
        DBCollection collection = db.getCollection("ConceptMap");
        DBCursor cursor = collection.find();
        documents = cursor.toArray();
        cursor.close();
    } catch (MongoException e) {
        System.out.println("ERRRRRORRR: " + e.getMessage());
        return ERROR;
    } catch (UnknownHostException ex) {
        Logger.getLogger(MapGenerateAction.class.getName()).log(Level.SEVERE, null, ex);
    }
    System.out.println("Mark 1");
    Map<String, ArrayList<String>> chap_to_section = new HashMap<>();
    Map<String, String> id_to_section = new HashMap<>();
    for (DBObject document : documents) {
        String c_name = document.get("ChapterName").toString();
        boolean has_key = chap_to_section.containsKey(c_name);
        ArrayList<String> sections = new ArrayList<>();
        sections.add(document.get("SectionName").toString());
        if (has_key) {
            sections.addAll(chap_to_section.get(c_name));
            chap_to_section.put(c_name, sections);
        } else {
            chap_to_section.put(c_name, sections);
        }
        id_to_section.put(document.get("SectionName").toString(), document.get("UniqueID").toString());
    }
    FileWriter file = null;
    try {
        file = new FileWriter("/home/chanakya/NetBeansProjects/Concepto/web/Chapters_Sections.json");
    } catch (IOException ex) {
        Logger.getLogger(ShowArticlesAction.class.getName()).log(Level.SEVERE, null, ex);
    }
    JSONArray jarr = new JSONArray();

    for (String key : chap_to_section.keySet()) {
        JSONObject jobj = new JSONObject();
        JSONArray arr = new JSONArray();

        for (String val : chap_to_section.get(key)) {
            JSONObject temp = new JSONObject();
            temp.put("name", val);
            temp.put("id", id_to_section.get(val).toString());
            arr.add(temp);
        }
        jobj.put("sname", arr);
        jobj.put("cname", key);
        jarr.add(jobj);
    }
    System.out.println("Mark 2");
    //JSONObject obj = new JSONObject();
    //obj.put("cmap", jarr);
    file.write(jarr.toJSONString());
    file.flush();
    file.close();
    System.out.println("Mark 3");
    return SUCCESS;
}