Example usage for org.json.simple JSONObject JSONObject

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

Introduction

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

Prototype

JSONObject

Source Link

Usage

From source file:org.kitodo.data.elasticsearch.index.type.ProcessType.java

@SuppressWarnings("unchecked")
@Override//from w w w  . j  a va 2  s .c o m
public HttpEntity createDocument(Process process) {

    JSONObject processObject = new JSONObject();
    processObject.put("title", process.getTitle());
    processObject.put("outputName", process.getOutputName());
    String creationDate = process.getCreationDate() != null ? formatDate(process.getCreationDate()) : null;
    processObject.put("creationDate", creationDate);
    processObject.put("wikiField", process.getWikiField());
    processObject.put("sortHelperStatus", process.getSortHelperStatus());
    processObject.put("sortHelperImages", process.getSortHelperImages());
    processObject.put("processBaseUri", process.getProcessBaseUri());
    processObject.put("template", process.isTemplate());
    Integer project = process.getProject() != null ? process.getProject().getId() : null;
    processObject.put("project", project);
    Integer ruleset = process.getRuleset() != null ? process.getRuleset().getId() : null;
    processObject.put("ruleset", ruleset);
    Integer docket = process.getDocket() != null ? process.getDocket().getId() : null;
    processObject.put("docket", docket);
    processObject.put("batches", addObjectRelation(process.getBatches()));
    processObject.put("workpieces", addObjectRelation(process.getWorkpieces()));
    processObject.put("tasks", addObjectRelation(process.getTasks()));
    processObject.put("properties", addObjectRelation(process.getProperties()));

    return new NStringEntity(processObject.toJSONString(), ContentType.APPLICATION_JSON);
}

From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CRUDUsuarios.java

protected static void crearUsuario(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    System.out.println(request.getParameter("5"));
    ArrayList r = CtrlAdmin.crearUsuario(request.getParameter("1"), //Nombre
            request.getParameter("2"), //Apellidos
            request.getParameter("3"), //Tipo de documento
            request.getParameter("4"), //documento
            request.getParameter("5"), //Correo= usuario
            request.getParameter("6"), //passworld
            request.getParameter("7").charAt(0)//rol
    );/*from  w  w  w  .  j av  a2s  . c om*/

    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    if (r.get(0) == "error") {
        JSONObject obj = new JSONObject();
        if (r.get(1) == "usuario") {
            obj.put("isError", true);
            obj.put("errorDescrip", "El usuario ya existe");
        } else if (r.get(1) == "contrasena") {
            obj.put("isError", true);
            obj.put("errorDescrip", "La contrasea es invalida");
        } else if (r.get(1) == "documento") {
            obj.put("isError", true);
            obj.put("errorDescrip", "El documento ya est registrado");
        } else if (r.get(1) == "tipoDocumento") {
            obj.put("isError", true);
            obj.put("errorDescrip", "El tipo de documento es invalido");
        } else if (r.get(1) == "correo") {
            obj.put("isError", true);
            obj.put("errorDescrip", "El correo ya est registrado");
        } else if (r.get(1) == "correo1") {
            obj.put("isError", true);
            obj.put("errorDescrip", "El correo no es valido");
        } else if (r.get(1) == "nombre") {
            obj.put("isError", true);
            obj.put("errorDescrip", "Los nombres o apellidos son incorrectos");
        } else if (r.get(1) == "rol") {
            obj.put("isError", true);
            obj.put("errorDescrip", "El rol es invalido, los posibles valores son: E, P y A");
        } else
            Util.errordeRespuesta(r, out);
        out.print(obj);
    } else if (r.get(0) == "isExitoso") {
        JSONObject obj = new JSONObject();
        obj.put("Exitoso", true);
        out.print(obj);
    } else
        Util.errordeRespuesta(r, out);
}

From source file:com.aerothai.database.building.BuildingService.java

public JSONObject GetBuildingAll() throws Exception {

    Connection dbConn = null;/*from   w w w.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", "list");
    obj.put("msg", "error");
    obj.put("status", false);
    try {
        dbConn = DBConnection.createConnection();

        Statement stmt = dbConn.createStatement();
        String query = "SELECT * FROM building";
        System.out.println(query);
        ResultSet rs = stmt.executeQuery(query);

        while (rs.next()) {

            JSONObject jsonData = new JSONObject();
            jsonData.put("id", rs.getInt("idbuilding"));
            jsonData.put("name", rs.getString("name"));
            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.twitter.hdfsdu.data.NodeData.java

public JSONObject toJSON() {
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("path", this.path);
    jsonObject.put("fileSize", fileSize);
    jsonObject.put("nChildren", nChildren);
    jsonObject.put("leaf", leaf);
    return jsonObject;
}

From source file:org.kitodo.data.elasticsearch.index.type.PropertyType.java

@SuppressWarnings("unchecked")
@Override/*  ww w . jav a2 s .c o m*/
public HttpEntity createDocument(Property property) {

    JSONObject propertyObject = new JSONObject();
    propertyObject.put("title", property.getTitle());
    propertyObject.put("value", property.getValue());
    String creationDate = property.getCreationDate() != null ? formatDate(property.getCreationDate()) : null;
    propertyObject.put("creationDate", creationDate);
    propertyObject.put("processes", addObjectRelation(property.getProcesses()));
    propertyObject.put("templates", addObjectRelation(property.getTemplates()));
    propertyObject.put("workpieces", addObjectRelation(property.getWorkpieces()));

    String type = null;
    if (!property.getProcesses().isEmpty()) {
        type = "process";
    } else if (!property.getTemplates().isEmpty()) {
        type = "template";
    } else if (!property.getWorkpieces().isEmpty()) {
        type = "workpiece";
    }

    propertyObject.put("type", type);

    return new NStringEntity(propertyObject.toJSONString(), ContentType.APPLICATION_JSON);
}

From source file:at.rocworks.oa4j.logger.data.base.DataItem.java

@SuppressWarnings("unchecked")
public JSONObject toJSONObject() {
    SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
    JSONObject obj = new JSONObject();
    obj.put("Name", dp.getFQN());
    obj.put("Time", fmt.format(getDate()));
    obj.put("TimeMS", getTimeMS());
    return obj;/*from   ww  w . ja v a  2  s  .c  o m*/
}

From source file:com.oic.event.GetProfile.java

@Override
public void ActionEvent(JSONObject json, WebSocketListener webSocket) {
    JSONObject responseJSON = new JSONObject();
    if (!validation(json)) {
        responseJSON.put("status", "1");
        webSocket.sendJson(responseJSON);
        return;// w ww  . ja  v a  2s.  c  o  m
    }
    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
        String sql = "SELECT user.userid, name, avatarid, grade, sex, birth, comment, privategrade, privatesex, privatebirth FROM user JOIN setting ON (user.userid = setting.userid) WHERE user.userid = ?;";
        con = DatabaseConnection.getConnection();
        ps = con.prepareStatement(sql);
        ps.setLong(1, Long.parseLong(json.get("userid").toString()));
        rs = ps.executeQuery();

        if (rs.next()) {
            responseJSON.put("userid", rs.getLong("userid"));
            responseJSON.put("username", rs.getString("name"));
            responseJSON.put("avatarid", rs.getInt("avatarid"));
            if (rs.getString("privategrade").equals("public")) {
                responseJSON.put("grade", rs.getInt("grade"));
            }
            if (rs.getString("privatesex").equals("public")) {
                responseJSON.put("gender", OicGender.getGender(rs.getString("sex")).toString());
            }
            if (rs.getString("privatebirth").equals("public")) {
                responseJSON.put("birthday", Tools.convertData(rs.getDate("birth")));
            }
            responseJSON.put("comment", rs.getString("comment"));
            responseJSON.put("status", 0);
        } else {
            responseJSON.put("status", 1);
        }
    } catch (SQLException se) {
        responseJSON.put("status", 1);
        se.printStackTrace();
    } finally {
        try {
            rs.close();
        } catch (Exception e1) {
        }
        try {
            ps.close();
        } catch (Exception e1) {
        }
    }
    webSocket.sendJson(responseJSON);
}

From source file:de.metalcon.musicStorageServer.protocol.UpdateRequestTest.java

@SuppressWarnings("unchecked")
@Before//  w  ww  .  java  2  s . c o  m
public void setUp() {
    // meta data
    final JSONObject metaDataUpdate = new JSONObject();
    metaDataUpdate.put("title", "My Great Song");
    metaDataUpdate.put("album", "Testy Forever");
    metaDataUpdate.put("artist", "Testy");
    metaDataUpdate.put("license", "General Less AllYouCanEat License");
    metaDataUpdate.put("date", "1991-11-11");
    metaDataUpdate.put("description", "All your cookies belong to me!");
    VALID_UPDATE_META_DATA = metaDataUpdate.toJSONString();
}

From source file:modelo.AutenticacionManager.PermisosAcceso.java

public JSONObject insertarPermisos(int codigo_rol, int codigo_pantalla, String valor) throws Exception {

    InsertarPermisos insert = new InsertarPermisos(codigo_rol, codigo_pantalla, valor);

    insert.ejecutar();//from  w  ww.j  a  v a  2s  .c o m

    Integer respuesta = insert.getResultado();
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("resp", respuesta);

    return jsonObject;

}

From source file:com.gti.redirects.Redirects.Redirect.java

public JSONObject toJsonObject() {
    JSONObject redirect = new JSONObject();
    redirect.put("domain", domain);
    redirect.put("type", type);
    redirect.put("redirect_to", redirect_to);
    return redirect;
}