Example usage for com.google.gson JsonObject addProperty

List of usage examples for com.google.gson JsonObject addProperty

Introduction

In this page you can find the example usage for com.google.gson JsonObject addProperty.

Prototype

public void addProperty(String property, Character value) 

Source Link

Document

Convenience method to add a char member.

Usage

From source file:co.com.konrad.interbolsa.ws.AccionesFacadeREST.java

@POST
@Override//from   www .  j av  a  2s.c o m
@Path("create")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public String create(Acciones entity) throws Exception {
    //VAriable json
    JsonObject res = new JsonObject();
    Gson gson = new Gson();
    try {
        //retorno
        res.addProperty("codigo", 200);
        res.addProperty("mensaje", "operacion exitosa");
        super.create(entity);

        javax.persistence.criteria.CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
        javax.persistence.criteria.CriteriaQuery cq = cb.createQuery();
        javax.persistence.criteria.Root<Acciones> rt = cq.from(Acciones.class);
        /*cq.where(
            cb.equal(rt.get(Empresa_.empresaNit), entity.getEmpresaNit())
        );*/
        javax.persistence.TypedQuery<Acciones> q = getEntityManager().createQuery(cq);
        Acciones acciones = q.getSingleResult();
        res.add("data", gson.toJsonTree(acciones));

    } catch (Exception ex) {
        java.util.logging.Logger.getLogger(AbstractFacade.class.getName()).log(Level.SEVERE,
                "Erro guardando entidad", ex);
        res.addProperty("codigo", 400);
        res.addProperty("mensaje", "operacion fallida");
    }
    //return res.toString();
    return "{'hola':1}";

}

From source file:co.com.konrad.interbolsa.ws.CompraAccionesFacadeREST.java

@POST
@Override/*  w w  w.jav  a  2 s .com*/
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public String create(CompraAcciones entity) throws Exception {
    //VAriable json
    JsonObject res = new JsonObject();
    try {
        //retorno
        res.addProperty("codigo", 200);
        res.addProperty("mensaje", "operacion exitosa");
        super.create(entity);
    } catch (Throwable ex) {
        java.util.logging.Logger.getLogger(AbstractFacade.class.getName()).log(Level.SEVERE,
                "Erro guardando entidad", ex);
        res.addProperty("codigo", 400);
        res.addProperty("mensaje", "operacion fallida");
    }
    return res.toString();
}

From source file:co.com.konrad.interbolsa.ws.EmpresaFacadeREST.java

@POST
@Override/*from   w w  w.  j a v  a  2s . c om*/
@Path("create")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public String create(Empresa entity) throws Exception {
    //VAriable json
    JsonObject res = new JsonObject();
    Gson gson = new Gson();
    try {
        super.create(entity);
        //retorno
        res.addProperty("codigo", 200);
        res.addProperty("mensaje", "operacion exitosa");

        javax.persistence.criteria.CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
        javax.persistence.criteria.CriteriaQuery cq = cb.createQuery();
        javax.persistence.criteria.Root<Empresa> rt = cq.from(Empresa.class);
        cq.where(cb.equal(rt.get(Empresa_.empresaNit), entity.getEmpresaNit()));
        javax.persistence.TypedQuery<Empresa> q = getEntityManager().createQuery(cq);
        Empresa empresa = q.getSingleResult();
        res.add("data", gson.toJsonTree(empresa));

    } catch (Throwable ex) {
        java.util.logging.Logger.getLogger(AbstractFacade.class.getName()).log(Level.SEVERE,
                "Error guardando entidad", ex);
        res.addProperty("codigo", 400);
        res.addProperty("mensaje", "operacion fallida");
    }
    return res.toString();
}

From source file:co.com.konrad.interbolsa.ws.UsuarioFacadeREST.java

@POST
@Override/*www  . j a v  a 2 s.c  om*/
@Path("create")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public String create(Usuario entity) throws Exception {
    JsonObject res = new JsonObject();
    Gson gson = new Gson();
    try {
        super.create(entity);
        //retorno
        res.addProperty("codigo", 200);
        res.addProperty("mensaje", "operacion exitosa");

        javax.persistence.criteria.CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
        javax.persistence.criteria.CriteriaQuery cq = cb.createQuery();
        javax.persistence.criteria.Root<Usuario> rt = cq.from(Usuario.class);
        cq.where(cb.equal(rt.get(Usuario_.usuarioCedula), entity.getUsuarioCedula()));
        javax.persistence.TypedQuery<Usuario> q = getEntityManager().createQuery(cq);
        Usuario usuario = q.getSingleResult();
        res.add("data", gson.toJsonTree(usuario));
    } catch (Throwable ex) {
        java.util.logging.Logger.getLogger(AbstractFacade.class.getName()).log(Level.SEVERE,
                "Erro guardando entidad", ex);
        res.addProperty("codigo", 400);
        res.addProperty("mensaje", "operacion fallida");
    }
    return res.toString();
}

From source file:co.com.konrad.interbolsa.ws.UsuarioFacadeREST.java

@POST
@Path("login")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public String login(Usuario entity) {
    JsonObject res = new JsonObject();
    Gson gson = new Gson();
    System.out.println("Correo " + entity.getUsuarioCorreo());
    System.out.println("Clave " + entity.getUsuairoClave());
    try {//from  w  w w.  j  a  va2  s. com
        //retorno
        res.addProperty("codigo", 200);
        res.addProperty("mensaje", "operacion exitosa");
        /*
        javax.persistence.criteria.CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
        javax.persistence.criteria.CriteriaQuery cq = cb.createQuery();
        javax.persistence.criteria.Root<Usuario> rt = cq.from(Usuario.class);
        cq.where(
            cb.equal(rt.get(Usuario_.usuarioCorreo), entity.getUsuarioCorreo()),
            cb.equal(rt.get(Usuario_.usuairoClave), entity.getUsuairoClave())
        );
        javax.persistence.TypedQuery<Usuario> q = getEntityManager().createQuery(cq);
        Usuario usuario = q.getSingleResult();*/
        //res.add("data", gson.toJsonTree(usuario));

        String nativeQuery = " SELECT * FROM usuario INNER JOIN empresa ON empresa_id = empresa_empresa_id WHERE usuario_correo = ? AND usuairo_clave = ?";
        Query query = getEntityManager().createNativeQuery(nativeQuery);
        query.setParameter(1, entity.getUsuarioCorreo());
        query.setParameter(2, entity.getUsuairoClave());
        Object usuario = query.getSingleResult();
        res.add("data", gson.toJsonTree(usuario));
    } catch (Exception ex) {
        java.util.logging.Logger.getLogger(AbstractFacade.class.getName()).log(Level.SEVERE,
                "Erro guardando entidad", ex);
        res.addProperty("codigo", 300);
        res.addProperty("mensaje", "Error de autenticacin");
    }
    return res.toString();
}

From source file:co.com.konrad.interbolsa.ws.ValorAccionFacadeREST.java

@POST
@Override/*from www .  j  av a2  s .  c o m*/
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public String create(ValorAccion entity) throws Exception {
    //VAriable json
    JsonObject res = new JsonObject();
    try {
        //retorno
        res.addProperty("codigo", 200);
        res.addProperty("mensaje", "operacion exitosa");
        super.create(entity);
    } catch (Throwable ex) {
        java.util.logging.Logger.getLogger(AbstractFacade.class.getName()).log(Level.SEVERE,
                "Erro guardando entidad", ex);
        res.addProperty("codigo", 400);
        res.addProperty("mensaje", "operacion fallida");
    }
    return res.toString();
}

From source file:co.runrightfast.incubator.rx.impl.ObservableRingBufferImpl.java

License:Apache License

@Override
public String toString() {
    if (!isRunning()) {
        return "{}";
    }/*from  w w w. j a va2  s . c  om*/
    final JsonObject json = new JsonObject();
    json.addProperty("remainingCapacity", remainingCapacity());
    json.addProperty("observerCount", observerCount());
    json.addProperty("bufferSize", bufferSize());
    json.addProperty("cursor", cursor());
    json.addProperty("ringBufferDataType", ringBufferDataType.getName());
    return JsonUtils.prettyPrintingGson.toJson(json);
}

From source file:co.vaughnvernon.actormodel.util.serializer.PropertiesSerializer.java

License:Apache License

public String serialize(Properties aProperties) {
    JsonObject object = new JsonObject();

    for (Object keyObj : aProperties.keySet()) {
        String key = keyObj.toString();
        String value = aProperties.getProperty(key);
        object.addProperty(key, value);
    }/*from   w  w w.  ja va  2  s .  c  o  m*/

    return object.getAsString();
}

From source file:color.AddUpdateColorMaster.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.// w w w.j  a v  a 2 s .  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 {
    final DBHelper helper = DBHelper.GetDBHelper();
    final Connection dataConnection = helper.getConnMpAdmin();
    final Library lb = Library.getInstance();
    String colour_cd = request.getParameter("colour_cd");
    final String colour_name = request.getParameter("colour_name");
    final String user_id = request.getParameter("user_id");
    final JsonObject jResultObj = new JsonObject();

    if (dataConnection != null) {
        try {
            if (colour_cd.equalsIgnoreCase("")) {
                colour_cd = lb.generateKey(dataConnection, "COLOURMST", "COLOUR_CD", "C", 7);
                String sql = "insert into COLOURMST (COLOUR_CD,colour_name,user_id) values(?,?,?)";
                PreparedStatement pstLocal = dataConnection.prepareStatement(sql);
                pstLocal.setString(1, colour_cd);
                pstLocal.setString(2, colour_name);
                pstLocal.setString(3, user_id);
                pstLocal.executeUpdate();
            } else if (!colour_cd.equalsIgnoreCase("")) {
                String sql = "update COLOURMST set colour_name=?,edit_no=edit_no+1,user_id=?,time_stamp=current_timestamp where COLOUR_CD=?";
                PreparedStatement pstLocal = dataConnection.prepareStatement(sql);
                pstLocal.setString(1, colour_name);
                pstLocal.setString(2, user_id);
                pstLocal.setString(3, colour_cd);
                pstLocal.executeUpdate();
            }
            jResultObj.addProperty("result", 1);
            jResultObj.addProperty("Cause", "success");
            jResultObj.addProperty("colour_cd", colour_cd);
        } catch (SQLNonTransientConnectionException ex1) {
            jResultObj.addProperty("result", -1);
            jResultObj.addProperty("Cause", "Server is down");
        } catch (SQLException ex) {
            jResultObj.addProperty("result", -1);
            jResultObj.addProperty("Cause", ex.getMessage());
        }
    }
    response.getWriter().print(jResultObj);
}

From source file:color.GetColorMaster.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*www.  j  ava 2  s  .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 {
    final DBHelper helper = DBHelper.GetDBHelper();
    final Connection dataConnection = helper.getConnMpAdmin();
    final JsonObject jResultObj = new JsonObject();
    if (dataConnection != null) {
        try {
            String sql = "select COLOUR_CD,COLOUR_NAME,USER_ID from COLOURMST";
            PreparedStatement pstLocal = dataConnection.prepareStatement(sql);
            ResultSet rsLocal = pstLocal.executeQuery();
            JsonArray array = new JsonArray();
            while (rsLocal.next()) {
                JsonObject object = new JsonObject();
                object.addProperty("COLOUR_CD", rsLocal.getString("COLOUR_CD"));
                object.addProperty("COLOUR_NAME", rsLocal.getString("COLOUR_NAME"));
                object.addProperty("USER_ID", rsLocal.getInt("USER_ID"));
                array.add(object);
            }
            jResultObj.addProperty("result", 1);
            jResultObj.addProperty("Cause", "success");
            jResultObj.add("data", array);
        } catch (SQLNonTransientConnectionException ex1) {
            jResultObj.addProperty("result", -1);
            jResultObj.addProperty("Cause", "Server is down");
        } catch (SQLException ex) {
            jResultObj.addProperty("result", -1);
            jResultObj.addProperty("Cause", ex.getMessage());
        }
    }
    response.getWriter().print(jResultObj);
}