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:io.personium.client.BoxManager.java

/**
 * This method is used to create a Box from Box object.
 * @param obj Box object/*from   ww w . ja v a  2s.  co m*/
 * @return Box object that is created
 * @throws DaoException Exception thrown
 */
@SuppressWarnings("unchecked")
public Box create(Box obj) throws DaoException {
    JSONObject body = new JSONObject();
    body.put("Name", obj.getName());
    body.put("Schema", obj.getSchema());
    JSONObject json = internalCreate(body);
    String path = UrlUtils.append(accessor.getCurrentCell().getUrl(), (String) body.get("Name"));
    obj.initialize(this.accessor, json, path);
    return obj;
}

From source file:io.personium.client.RoleManager.java

/**
 * This method creates a Role using a Role object.
 * @param obj Role object/*from w  w w.ja v  a2s.  c o  m*/
 * @return Role object that is created
 * @throws DaoException Exception thrown
 */
@SuppressWarnings("unchecked")
public Role create(Role obj) throws DaoException {
    JSONObject body = new JSONObject();
    body.put("Name", obj.getName());
    body.put("_Box.Name", obj.getBoxName());
    JSONObject json = internalCreate(body);
    obj.initialize(this.accessor, json);
    return obj;
}

From source file:com.unilever.audit.services2.NewUser.java

@POST
@Path("AddUser")
@Produces("application/json")
@Consumes("text/plain")
public String NewUser(String json) throws IOException {
    boolean status = true;
    String error = null;//from w  w w . java2  s  .  c  o  m
    Map<String, Object> hm = new HashMap<String, Object>();

    JSONObject result = new JSONObject();
    Merchandisers merchandiser;
    try {
        JSONObject user = (JSONObject) new JSONParser().parse(json);

        ////////////check if this user already exist bec w cant check it from internal exception
        hm.put("email", (String) user.get("email"));
        merchandiser = (Merchandisers) merchandisersFacadeREST.findOneByQuery("Merchandisers.checkMerchandiser",
                hm);
        //////////if dont exist 
        if (merchandiser == null) {
            merchandiser = (Merchandisers) merchandisersFacadeREST.findOneByQuery("Merchandisers.findByEmail",
                    hm);
            if (merchandiser != null) {
                merchandiser.setActive("Y");
                merchandiser.setPassword((String) user.get("password"));
                try {
                    merchandisersFacadeREST.edit(merchandiser);
                    status = true;
                    error = "User registered successfully, Congrats :)";
                } catch (TransactionRequiredException ex) {
                    status = false;
                    error = "Can't add merchandiser problem with server";
                } catch (IllegalArgumentException ex) {
                    status = false;
                    error = "Wrong data Please try again";
                }
            } else {
                status = false;
                error = "Your email is not registered in our system, Please contact the system admin.";
            }
        } else {
            status = true;
            error = "You are already active please login directly.";
        }
    } catch (Exception e) {
        Logger.getLogger(NewUser.class.getName()).log(Level.SEVERE, null, e);
    }
    result.put("status", status);
    result.put("error", error);
    System.out.println("----------------" + result.toString());
    return result.toString();
}

From source file:com.conwet.silbops.msg.Message.java

@Override
@SuppressWarnings("unchecked")
public final JSONObject toJSON() {

    JSONObject json = new JSONObject();
    json.put("type", type.toJSON());
    json.put("payload", getPayloadAsJSON());

    return json;//from   ww w .j  a  v  a 2s .c o m
}

From source file:com.tjackiw.graylog2.plugin.jira.JiraIssue.java

public String toJSONString() {
    JSONObject project = new JSONObject();
    project.put("key", projectKey);

    JSONObject issuetype = new JSONObject();
    issuetype.put("name", issueType);

    JSONObject level = new JSONObject();
    level.put("name", priority);

    JSONArray labelList = new JSONArray();
    String[] labelArr = labels.split("\\,");
    for (String s : labelArr) {
        labelList.add(s);/*from  w w w  .j a v  a2s  .co m*/
    }

    JSONArray componentList = new JSONArray();
    String[] compArr = components.split("\\,");
    for (String s : compArr) {
        JSONObject hash = new JSONObject();
        hash.put("name", s);
        componentList.add(hash);
    }

    JSONObject obj = new JSONObject();
    obj.put("summary", title);
    obj.put("description", description);
    obj.put("project", project);
    obj.put("issuetype", issuetype);
    obj.put("labels", labelList);
    obj.put("components", componentList);
    obj.put("priority", level);

    JSONObject fields = new JSONObject();
    fields.put("fields", obj);

    return fields.toJSONString();
}

From source file:bookUtilities.BookListServlet.java

private JSONArray getBooks() {
    JSONArray booksToReturn = new JSONArray();
    try {/*from w w w . j av  a 2 s  . com*/
        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:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.Cuenta.VisRegistro.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from  w  ww . j  av a  2  s  . c  om
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
private void crearSesion(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    System.out.println(request.getParameter("5"));
    ArrayList r = CtrlRegistro.crearCuenta(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
    );

    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:ch.newscron.newscronjsp.ShortUrlCreator.java

private JSONObject createJSON(String customerId, String rew1, String rew2, String val) {
    JSONObject obj = new JSONObject();
    obj.put("custID", customerId);
    obj.put("rew1", rew1);
    obj.put("rew2", rew2);
    obj.put("val", val);
    return obj;//from w ww.jav a2 s  .  c o  m
}

From source file:co.mcme.animations.actions.ChainAnimationAction.java

@Override
public JSONObject toJSON() {
    JSONObject result = new JSONObject();
    JSONObject data = new JSONObject();
    data.put("frame", frame);
    data.put("target", targetName);
    result.put("chain_animation", data);
    return result;
}

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

public JSONObject toJSON() {
    JSONObject ret = new JSONObject();
    ret.put("grouper", this.grouper.getClass().getName());
    return ret;
}