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.dnastack.ga4gh.impl.BeaconizeVariantImpl.java

/**
 * Queries the Variant API implementation for variants at the given position
 *
 * @param reference The reference (or chromosome)
 * @param position  Position on the reference
 * @param alt       The alternate allele to match against (currently not supported by GASearchVariantsRequest)
 * @return A JSON Object containing a GASearchVariantsResponse
 * @throws IOException    Problems contacting API
 * @throws ParseException Problems parsing response
 *//*from w  w w . j av  a2  s. co m*/
private JSONObject submitVariantSearchRequest(String reference, long position, String alt)
        throws IOException, ParseException {
    JSONObject obj = new JSONObject();

    JSONArray list = new JSONArray();
    list.addAll(Arrays.asList(variantSetIds));

    obj.put("variantSetIds", list);
    obj.put("referenceName", reference);
    obj.put("start", position);
    obj.put("end", (position + 1));

    String json = obj.toJSONString();

    URL url = new URL(fullVariantSearchURL);

    StringBuilder postData = new StringBuilder();
    postData.append(json);

    byte[] postDataBytes = postData.toString().getBytes("UTF-8");

    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setRequestMethod("POST");
    conn.setRequestProperty("Content-Type", "application/json");
    conn.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
    conn.setDoOutput(true);
    conn.getOutputStream().write(postDataBytes);

    StringBuilder sb = new StringBuilder();

    Reader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
    for (int c; (c = in.read()) >= 0;) {
        sb.append((char) c);
    }

    String jsonString = sb.toString();

    return (JSONObject) JSONValue.parseWithException(jsonString);
}

From source file:kmlvalidator.KmlValidatorServlet.java

/**
 * Handles POST requests for the servlet.
 *///from www  .j a  v  a2  s .c  o m
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
    // Our response is always JSON.
    response.setContentType("application/json");

    // Create the JSON response objects to be filled in later.
    JSONObject responseObj = new JSONObject();
    JSONArray responseErrors = new JSONArray();

    try {
        // Load XSD files here. Note that the Java runtime should be caching
        // these files.
        Object[] schemas = {
                new URL("http://schemas.opengis.net/kml/2.2.0/atom-author-link.xsd").openConnection()
                        .getInputStream(),
                new URL("http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd").openConnection().getInputStream(),
                new URL("http://code.google.com/apis/kml/schema/kml22gx.xsd").openConnection()
                        .getInputStream() };

        // Create a SAX parser factory (not a DOM parser, we don't need the
        // overhead) and set it to validate and be namespace aware, for
        // we want to validate against multiple XSDs.
        SAXParserFactory parserFactory = SAXParserFactory.newInstance();
        parserFactory.setValidating(true);
        parserFactory.setNamespaceAware(true);

        // Create a SAX parser and prepare for XSD validation.
        SAXParser parser = parserFactory.newSAXParser();
        parser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
        parser.setProperty(JAXP_SCHEMA_SOURCE, schemas);

        // Create a parser handler to trap errors during parse.
        KmlValidatorParserHandler parserHandler = new KmlValidatorParserHandler();

        // Parse the KML and send all errors to our handler.
        parser.parse(request.getInputStream(), parserHandler);

        // Check our handler for validation results.
        if (parserHandler.getErrors().size() > 0) {
            // There were errors, enumerate through them and create JSON objects
            // for each one.
            for (KmlValidationError e : parserHandler.getErrors()) {
                JSONObject error = new JSONObject();

                switch (e.getType()) {
                case KmlValidationError.VALIDATION_WARNING:
                    error.put("type", "warning");
                    break;

                case KmlValidationError.VALIDATION_ERROR:
                    error.put("type", "error");
                    break;

                case KmlValidationError.VALIDATION_FATAL_ERROR:
                    error.put("type", "fatal_error");
                    break;

                default:
                    error.put("type", "fatal_error");
                }

                // fill in parse exception details
                SAXParseException innerException = e.getInnerException();
                error.put("message", innerException.getMessage());

                if (innerException.getLineNumber() >= 0)
                    error.put("line", innerException.getLineNumber());

                if (innerException.getColumnNumber() >= 0)
                    error.put("column", innerException.getColumnNumber());

                // add this error to the list
                responseErrors.add(error);
            }

            // The KML wasn't valid.
            responseObj.put("status", "invalid");
        } else {
            // The KML is valid against the XSDs.
            responseObj.put("status", "valid");
        }
    } catch (SAXException e) {
        // We should never get here due to regular parse errors. This error
        // must've been thrown by the schema factory.
        responseObj.put("status", "internal_error");

        JSONObject error = new JSONObject();
        error.put("type", "fatal_error");
        error.put("message", "Internal error: " + e.getMessage());
        responseErrors.add(error);

    } catch (ParserConfigurationException e) {
        // Internal error at this point.
        responseObj.put("status", "internal_error");

        JSONObject error = new JSONObject();
        error.put("type", "fatal_error");
        error.put("message", "Internal parse error.");
        responseErrors.add(error);
    }

    // If there were errors, add them to the final response JSON object.
    if (responseErrors.size() > 0) {
        responseObj.put("errors", responseErrors);
    }

    // output the JSON object as the HTTP response and append a newline for
    // prettiness
    response.getWriter().print(responseObj);
    response.getWriter().println();
}

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

private JSONArray guardarDescripcionPlanDeTratamiento(HttpServletRequest request) {
    DescripcionPlanDeTratamiento descripcionPlanTratamiento = new DescripcionPlanDeTratamiento();
    PlanesDeTratamiento planTratamiento = ejbPlanTratamiento
            .traer(Integer.parseInt(request.getParameter("idPlanTratamiento")));
    descripcionPlanTratamiento.setIdPlanTratamiento(planTratamiento);
    descripcionPlanTratamiento/*from  ww  w.java 2  s  .  c  o m*/
            .setTextoDescripcionPlanTratamiento(request.getParameter("textoDescripcionPlanTratamiento"));
    descripcionPlanTratamiento
            .setValorDescripcionPlanTratamiento(request.getParameter("valorDescripcionPlanTratamiento"));
    descripcionPlanTratamiento
            .setIdUsuario(Integer.parseInt(request.getSession().getAttribute("usuario").toString()));//RECORDAR QUE ESTE VALOR ESTA QUEMADO Y HAY QUE CAMBIARLO CUANDO SE CREE LA TABLA USUARIOS
    descripcionPlanTratamiento = ejbDescripcionPlanTratamiento.crear(descripcionPlanTratamiento);
    obj = new JSONObject();
    objArray = new JSONArray();
    if (descripcionPlanTratamiento != null) {
        obj.put("idDescripcionPlanDeTratamiento", descripcionPlanTratamiento.getIdDescripcionPlanTratamiento());
        objArray.add(obj);
    } else {
        obj.put("error", "no se pudo guardar la descripcion del tratamiento");
        objArray.add(obj);
    }
    return objArray;
}

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

private JSONArray listarEvolucion1(HttpServletRequest request) {
    List<Evolucion> evoluciones = ejbEvolucion.listar(Integer.parseInt(request.getParameter("idPaciente")));
    objArray = new JSONArray();
    if (evoluciones != null) {
        for (Evolucion evolucion : evoluciones) {
            obj = new JSONObject();
            obj.put("idEvolucion", evolucion.getIdEvolucion());
            obj.put("idPaciente", evolucion.getIdPaciente().getIdPaciente());
            obj.put("nombreModulo", evolucion.getNombreModulo());
            obj.put("fecha", evolucion.getFecha());
            obj.put("hora", evolucion.getHora());
            obj.put("evolucion", evolucion.getEvolucion());
            objArray.add(obj);/*from   ww  w .ja v  a2s . co m*/
        }
    }
    return objArray;
}

From source file:com.imagelake.android.uploadmanagement.Servlet_UploadManagement.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    PrintWriter out = response.getWriter();

    Date d = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    String date = sdf.format(d);//from   w ww .  j a v  a 2 s .c  o  m

    SimpleDateFormat sdf2 = new SimpleDateFormat("hh:mm:ss");
    String Time = sdf2.format(d);
    String timeStamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime());

    try {

        String type = request.getParameter("type");
        System.out.println("type:" + type);
        if (type != null && !type.equals("")) {

            if (type.equals("all")) {
                ja = new JSONArray();
                String category;
                String seller;
                List<Images> allList = idi.getNewUploadList();
                if (!allList.isEmpty()) {
                    for (Images images : allList) {

                        JSONObject jo = new JSONObject();
                        jo.put("img_id", images.getImages_id());
                        jo.put("title", images.getTitle());
                        jo.put("date", images.getDate());
                        jo.put("url", images.getImg_url());
                        category = idi.getCategoryName(images.getCategories_category_id());
                        jo.put("cat", category);
                        seller = idi.getSellerName(images.getUser_user_id());
                        jo.put("sel", seller);
                        ja.add(jo);
                    }
                    System.out.println(ja.toJSONString());
                    out.write("json=" + ja.toJSONString());
                } else {
                    out.write("msg=No item found.");
                }

            } else if (type.equals("single_details")) {
                ja = new JSONArray();
                String imgid = request.getParameter("imgid");

                System.out.println("imgid:" + imgid);

                if (imgid != null && !imgid.equals("")) {
                    Images im = idi.getImageDetail(Integer.parseInt(imgid));

                    if (im.getImage_state_image_state_id() == 3 || im.getImage_state_image_state_id() == 1
                            || im.getImage_state_image_state_id() == 5) {
                        JSONObject jo = new JSONObject();
                        jo.put("img_id", im.getImages_id());
                        jo.put("title", im.getTitle());
                        jo.put("url", im.getImg_url());
                        //--------------------------------

                        List<ImagesSub> sublist = idi.getImagedescription(Integer.parseInt(imgid));
                        JSONArray jk = new JSONArray();
                        if (!sublist.isEmpty()) {
                            for (ImagesSub imagesSub : sublist) {

                                String dim = imagesSub.getDimention();
                                String dimArray[] = dim.split(" x ");
                                String width = dimArray[0];
                                if (!width.equals("400")) {
                                    JSONObject jso = new JSONObject();
                                    jso.put("dimention", dim);
                                    Credits c = crdi.getCreditDetails(imagesSub.getCredits());
                                    jso.put("size", c.getSize());
                                    jso.put("crd", c.getCredits());
                                    jk.add(jso);
                                }

                                jo.put("subs", jk.toJSONString());
                            }
                        } else {
                            jo.put("subs", jk.toJSONString());
                        }
                        //--------------------------------
                        List<Images> imgList = new ImageRec().imgDiff(im);
                        JSONArray na = new JSONArray();
                        if (!imgList.isEmpty()) {

                            for (Images images : imgList) {
                                if (images.getImage_state_image_state_id() != 3) {
                                    JSONObject jso = new JSONObject();
                                    jso.put("equaltitle", images.getTitle());
                                    jso.put("equalurl", images.getImg_url());
                                    jso.put("equalseller", idi.getSellerName(images.getUser_user_id()));
                                    jso.put("equalstate", images.getImage_state_image_state_id());
                                    na.add(jso);
                                }
                            }
                            jo.put("equal", na.toJSONString());
                        } else {
                            jo.put("equal", na.toJSONString());
                        }

                        ja.add(jo);
                        System.out.println(ja.toJSONString());
                        out.write("json=" + ja.toJSONString());
                    } else {
                        System.out.println(ja.toJSONString());
                        out.write("json=" + ja.toJSONString());
                    }
                    //--------------------------------
                } else {
                    out.write("msg=Internal server error,Please try again later.");
                }
            } else if (type.equals("keywords")) {
                String imgid = request.getParameter("imgid");

                System.out.println("imgid:" + imgid);

                if (imgid != null && !imgid.equals("")) {
                    List<KeyWords> listKeyWords = new KeyWordsDAOImp().getkeyWordList(Integer.parseInt(imgid));
                    JSONArray jsa = new JSONArray();
                    if (!listKeyWords.isEmpty()) {
                        for (KeyWords keyWords : listKeyWords) {
                            JSONObject jso = new JSONObject();
                            jso.put("kid", keyWords.getKey_words_id());
                            jso.put("key", keyWords.getKey_word());
                            jsa.add(jso);
                        }
                        System.out.println(jsa.toJSONString());
                        out.write("json=" + jsa.toJSONString());
                    } else {
                        out.write("json" + jsa.toJSONString());
                    }
                } else {
                    out.write("msg=Internal server error,Please try again later.");
                }

            } else if (type.equals("add_keywords")) {
                String key = request.getParameter("key");
                String imgId = request.getParameter("imgid");

                System.out.println("key:" + key);
                System.out.println("img ID:" + imgId);

                if (key != null && !key.equals("") && imgId != null && !imgId.equals("")) {

                    String mx[] = key.trim().split(",");
                    String nk = "";
                    for (int i = 0; i < mx.length; i++) {
                        if (i == (mx.length - 1)) {
                            nk += mx[i];
                        } else {
                            nk += mx[i] + " ";
                        }
                    }

                    key = nk;

                    boolean duplicate = new KeyWordsDAOImp().getKeyWords(key, Integer.parseInt(imgId));
                    if (duplicate) {

                        boolean add = new KeyWordsDAOImp().addKeyWords(Integer.parseInt(imgId), key);
                        if (add) {
                            out.write("msg=Key_Successful...");
                        } else {
                            out.write("msg=Unable to complete,Please try again later.");
                        }

                    } else {
                        out.write("msg=The keyword is already entered.");
                    }
                } else {
                    out.write("msg=Internal server error,Please try again later.");
                }

            } else if (type.equals("confirem")) {

                String imgid = request.getParameter("imgid");
                String userid = request.getParameter("userid");

                if (imgid != null && !imgid.equals("") && userid != null && !userid.equals("")) {

                    User user = udi.getUser(Integer.parseInt(userid));

                    Images im = idi.getImageDetail(Integer.parseInt(imgid));

                    boolean k = new ImageRec().isDuplicate(im);
                    if (k) {
                        if (im.getImage_state_image_state_id() != 1) {
                            List<KeyWords> keyList = new KeyWordsDAOImp()
                                    .getkeyWordList(Integer.parseInt(imgid));
                            if (!keyList.isEmpty()) {

                                System.out.println(imgid + "llll");
                                System.out.println(userid + "kkkkkkkkkk");
                                System.out.println("");
                                boolean ok = idi.adminUpdateImages(Integer.parseInt(imgid), 1);
                                System.out.println(ok + " admin update image");
                                if (ok) {
                                    //boolean notified = new NotificationDAOImp().addNotification(noti, date, Time, im.getUser_user_id(), 1, 4);
                                    System.out.println("image title:" + im.getTitle());
                                    System.out.println("(((((((((((((" + im.getUser_user_id() + ")))))))))))");
                                    String noti = "Admin " + user.getUser_name() + " has Confirmed your upload "
                                            + im.getTitle() + " image.";
                                    boolean notiok = ndi.addNotification(noti, date, Time, im.getUser_user_id(),
                                            1, 4);

                                    AdminNotification a = new AdminNotification();
                                    a.setUser_id(user.getUser_id());
                                    a.setDate(timeStamp);

                                    a.setShow(1);
                                    a.setType(1);
                                    String not = "Admin " + user.getUser_name() + " has Confirmed upload "
                                            + im.getTitle() + " image.";
                                    a.setNotification(not);

                                    int an = andi.insertNotificaation(a);
                                    System.out.println("PPPPPPPPPPPPPPPPPPPPPPPPPPPPPP " + an);

                                    boolean kl = ahndi.insertNotification(udi.notMeList(user.getUser_id()), an,
                                            1);

                                    if (notiok && kl) {
                                        out.write("msg=Con_Successful...");
                                    } else {
                                        out.write("msg=Unable to send notifications.");
                                    }

                                } else {
                                    out.write("msg=Unable to confirem upload.");
                                }

                            } else {
                                out.write("msg=Key words are empty.");
                            }
                        } else {
                            out.write("msg=This image is already uploaded.");
                        }
                    } else {
                        out.write("msg=This image has a duplicate.");
                    }

                } else {
                    out.write("msg=Internal server error,Please try again later.");
                }

            } else if (type.equals("cancel")) {

                String imgid = request.getParameter("imgid");
                String userid = request.getParameter("userid");

                if (imgid != null && !imgid.equals("") && userid != null && !userid.equals("")) {

                    User user = udi.getUser(Integer.parseInt(userid));

                    Images im = idi.getImageDetail(Integer.parseInt(imgid));

                    if (im != null) {

                        //if(imok){
                        List<ImagesSub> imsub = new ImagesDAOImp().getImagedescription(Integer.parseInt(imgid));
                        System.out.println(imsub.isEmpty());
                        /* for (ImagesSub imagesSub : imsub) {
                         boolean subok=new DeleteImage().deleteImage(imagesSub.getImg_url());
                                
                         System.gc();
                         }*/

                        boolean ok = new ImagesDAOImp().removeAdminImage(Integer.parseInt(imgid));
                        if (ok) {

                            System.out.println("image title:" + im.getTitle());
                            System.out.println("(((((((((((((" + im.getUser_user_id() + ")))))))))))");
                            String noti = "Admin " + user.getUser_name() + " has canceled your upload "
                                    + im.getTitle() + " image.";
                            boolean notiok = ndi.addNotification(noti, date, Time, im.getUser_user_id(), 1, 3);

                            AdminNotification a = new AdminNotification();
                            a.setUser_id(user.getUser_id());
                            a.setDate(timeStamp);

                            a.setShow(1);
                            a.setType(1);
                            String not = "Admin " + user.getUser_name() + " has canceled upload "
                                    + im.getTitle() + " image.";
                            a.setNotification(not);

                            int an = andi.insertNotificaation(a);
                            System.out.println("PPPPPPPPPPPPPPPPPPPPPPPPPPPPPP " + an);

                            boolean kl = ahndi.insertNotification(udi.notMeList(user.getUser_id()), an, 1);

                            if (notiok && kl) {

                                out.write("msg=Can_Successful...");

                            } else {
                                out.write("msg=Unable to send notifications.");
                            }
                        } else {

                            out.write("msg=Unable to cancel upload.");
                        }

                    } else {
                        out.write("msg=Unable to find image.");
                    }

                } else {
                    out.write("msg=Internal server error,Please try again later.");
                }

            } else if (type.equals("state")) {

                String imid = request.getParameter("imgid");
                String state = request.getParameter("state");
                String userid = request.getParameter("userid");

                System.out.println("imid:" + imid);
                System.out.println("usid:" + userid);
                System.out.println("state:" + state);

                User user = udi.getUser(Integer.parseInt(userid));

                Images im = idi.getImageDetail(Integer.parseInt(imid));
                if (!imid.equals("") && !imid.equals(null) && !state.equals("") && !state.equals(null)) {
                    boolean b = idi.updateState(Integer.parseInt(imid), Integer.parseInt(state));
                    if (b) {

                        System.out.println("image title:" + im.getTitle());
                        System.out.println("(((((((((((((" + im.getUser_user_id() + ")))))))))))");
                        boolean notiok = false;
                        if (state.equals("5")) {
                            String noti = "Admin " + user.getUser_name() + " has blocked your " + im.getTitle()
                                    + " image.";
                            notiok = ndi.addNotification(noti, date, Time, im.getUser_user_id(), 1, 2);
                        } else if (state.equals("1")) {
                            String noti = "Admin " + user.getUser_name() + " has activated your "
                                    + im.getTitle() + " image.";
                            notiok = ndi.addNotification(noti, date, Time, im.getUser_user_id(), 1, 4);
                        }
                        AdminNotification a = new AdminNotification();
                        a.setUser_id(user.getUser_id());
                        a.setDate(timeStamp);

                        a.setShow(1);
                        if (state.equals("5")) {
                            a.setType(2);
                            String not = "Admin " + user.getUser_name() + " has blocked " + im.getTitle()
                                    + " image.";
                            a.setNotification(not);
                        } else if (state.equals("1")) {
                            a.setType(4);
                            String not = "Admin " + user.getUser_name() + " has activated " + im.getTitle()
                                    + " image.";
                            a.setNotification(not);
                        }

                        int an = andi.insertNotificaation(a);
                        System.out.println("PPPPPPPPPPPPPPPPPPPPPPPPPPPPPP " + an);

                        boolean kl = ahndi.insertNotification(udi.notMeList(user.getUser_id()), an, 1);

                        if (notiok && kl) {
                            out.write("msg=Sta_Successful...");
                        } else {
                            out.write("msg=Unable to send notifications.");
                        }

                    } else {
                        out.write("msg=Unable to update state.");
                    }
                } else {
                    out.write("msg=Internal server error,Please try again later.");
                }

            }

        } else {
            out.write("msg=Internal server error,Please try again later.");
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:biomine.bmvis2.pipeline.GraphOperationSerializer.java

public static void saveList(Collection<GraphOperation> ops, File f, Map<String, Double> queryNodes)
        throws IOException {
    FileWriter wr = new FileWriter(f);
    JSONArray arr = new JSONArray();
    for (GraphOperation op : ops) {
        JSONObject obj = op.toJSON();//from  w w  w.ja v  a  2  s. com
        JSONObject mark = new JSONObject();
        mark.put("class", op.getClass().getName());
        mark.put("object", obj);
        arr.add(mark);
    }

    JSONArray noi = new JSONArray();
    for (String z : queryNodes.keySet()) {
        JSONObject jo = new JSONObject();
        jo.put("node", z);
        Double val = queryNodes.get(z);
        jo.put("value", val);
        noi.add(jo);
    }
    arr.add(noi);

    arr.writeJSONString(wr);
    wr.close();
}

From source file:GraphController.java

@RequestMapping("/graphs")
public @ResponseBody Graph graph(
        @RequestParam(value = "authentication", required = false, defaultValue = "Error") String authentication,
        @RequestParam(value = "hostid", required = false, defaultValue = "") String hostid)
        throws FileNotFoundException, UnsupportedEncodingException, IOException {
    Properties props = new Properties();
    FileInputStream fis = new FileInputStream("properties.xml");
    //loading properites from properties file
    props.loadFromXML(fis);//from   w  ww .j  a va 2s.  c om

    String server_ip = props.getProperty("server_ip");
    String ZABBIX_API_URL = "http://" + server_ip + "/api_jsonrpc.php"; // 1.2.3.4 is your zabbix_server_ip

    JSONParser parser = new JSONParser();
    HttpClient client = new HttpClient();

    PutMethod putMethod = new PutMethod(ZABBIX_API_URL);
    putMethod.setRequestHeader("Content-Type", "application/json-rpc"); // content-type is controlled in api_jsonrpc.php, so set it like this

    // create json object for apiinfo.version 
    JSONObject jsonObj = new JSONObject();
    JSONArray list = new JSONArray();
    jsonObj.put("jsonrpc", "2.0");
    jsonObj.put("method", "graph.get");
    JSONObject params = new JSONObject();
    params.put("output", "extend");
    params.put("hostids", hostid);
    params.put("sortfield", "name");
    jsonObj.put("params", params);
    jsonObj.put("auth", authentication);// todo
    jsonObj.put("id", new Integer(1));

    putMethod.setRequestBody(jsonObj.toString()); // put the json object as input stream into request body 

    String loginResponse = "";

    try {
        client.executeMethod(putMethod); // send to request to the zabbix api

        loginResponse = putMethod.getResponseBodyAsString(); // read the result of the response
        Object obj = parser.parse(loginResponse);
        JSONObject obj2 = (JSONObject) obj;
        String jsonrpc = (String) obj2.get("jsonrpc");
        JSONArray array = (JSONArray) obj2.get("result");

        //         System.out.println(array);
        for (int i = 0; i < array.size(); i++) {
            JSONObject tobj = (JSONObject) array.get(i);

            JSONObject objret = new JSONObject();

            objret.put("graphId", tobj.get("graphid"));
            objret.put("graphName", tobj.get("name"));

            String type = (String) tobj.get("graphtype");

            if (type.equals("0")) {
                objret.put("graphType", "normal");
            } else if (type.equals("1")) {
                objret.put("graphType", "stacked");
            } else if (type.equals("2")) {
                objret.put("graphType", "pie");
            } else if (type.equals("3")) {
                objret.put("graphType", "exploded");
            }

            list.add(objret);

        }

        return new Graph(list);

    } catch (HttpException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ParseException pe) {
        pe.printStackTrace();
    }
    return new Graph(
            "Error: please provide the appropriate input parameters of the metric you are looking for its corresponding monitoring data:");
}

From source file:co.mcme.animations.triggers.BlockInteractTrigger.java

@Override
public JSONObject toJSON() {
    JSONObject result = new JSONObject();
    JSONObject data = new JSONObject();
    JSONArray blocks = new JSONArray();
    for (Vector v : triggerLocation) {
        JSONObject blockData = new JSONObject();
        JSONArray vect = new JSONArray();
        vect.add((int) v.getX());
        vect.add((int) v.getY());
        vect.add((int) v.getZ());
        blockData.put("block", vect);
        blocks.add(blockData);/*from  w  ww .ja va2s  .co  m*/
    }
    data.put("frame", frame);
    data.put("blocks", blocks);
    result.put("block_interaction", data);
    return result;
}

From source file:net.duckling.ddl.web.controller.LynxTeamInfoController.java

/**
 * teamCode/*from  ww  w .java  2  s .co m*/
 * @param 
 * */
@RequestMapping(params = "func=getMyTemCodes")
public void getMyTemCodes(HttpServletRequest req, HttpServletResponse resp) {
    VWBContainer container = VWBContainerImpl.findContainer();
    if (!validateRequest(req, container)) {
        resp.setStatus(401);
        return;
    }
    String uid = req.getParameter("uid");
    if (StringUtils.isEmpty(uid)) {
        resp.setStatus(400);
        return;
    }
    List<Team> myTeams = teamService.getAllUserTeams(uid);
    JSONArray teamArray = new JSONArray();
    for (Team team : myTeams) {
        if (Team.PESONAL_TEAM.equals(team.getType())) {
            continue;
        }
        teamArray.add(team.getName());
    }
    JsonUtil.writeJSONObject(resp, teamArray);

}

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

private JSONArray guardarTratamiento(HttpServletRequest request) {
    Tratamientos tratamiento = new Tratamientos();
    Pacientes paciente = ejbPacientes.traer(Integer.parseInt(request.getParameter("idPaciente")));
    tratamiento.setIdPaciente(paciente);
    tratamiento.setDesTratamiento(request.getParameter("desTratamiento"));
    tratamiento.setFechaTratamiento(request.getParameter("fechaTratamiento"));
    tratamiento.setHoraTratamiento(request.getParameter("horaTratamiento"));
    tratamiento.setIdUsuario(Integer.parseInt(request.getSession().getAttribute("usuario").toString()));//RECORDAR QUE ESTE VALOR ESTA QUEMADO Y HAY QUE CAMBIARLO CUANDO SE CREE LA TABLA USUARIOS
    tratamiento = ejbTratamientos.crear(tratamiento);
    obj = new JSONObject();
    objArray = new JSONArray();
    if (tratamiento != null) {
        obj.put("idTratamiento", tratamiento.getIdTratamiento());
        objArray.add(obj);/*from  w  w  w  . j  av a  2  s  .c o  m*/
    } else {
        obj.put("error", "no se pudo guardar el tratamiento");
        objArray.add(obj);
    }
    return objArray;
}