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:Cache.Cache2.java

public JSONObject fn(JSONObject request) {

    //String http_method = null;
    String string_busqueda = (String) request.get("busqueda");
    JSONObject respuesta = new JSONObject();
    //String resource = null;

    //OPERACIONES CON CACHE
    //=======================================================================================================
    // La hebra busca en la particin esttica del cache.
    // En caso de no encontrar la entrada, busca en la particin LRU correspondiente.
    // Si queda espacio en el cache esttico, la entrada se agrega al mismo.
    // Si no se encuentra en el LRU, se pide al IndexService.

    String estaEnCacheEstatico = cestatico.getEntryFromCache(string_busqueda); // Buscar en el cache esttico

    if (estaEnCacheEstatico == null) { // Si no esta en el cache estatico
        int lleno = cestatico.lleno();

        //************* MISS EN CACHE ESTATICO DEVUELVOO MISS*********************
        if (lleno == 0)// y an no esta lleno, agregar al mismo.
        {/*from www  . j a v a 2  s  .  c  o  m*/
            System.out.println("Miss en cache esttico");
            respuesta.put("id", string_busqueda);
            respuesta.put("estado", "miss");
            respuesta.put("respuesta", "");
            //***********************************************************
        } else //si no esta en el cache estatico y este esta lleno entonces pasamos al dinamico 
        {

            estaEnCacheEstatico = lru_cache1.getEntryFromCache(string_busqueda);// busco en el cache el id del request
            //*******************MISS EN EL CACHE DINAMICO RETORNO MISS************************
            if (estaEnCacheEstatico == null) { // MISS
                System.out.println("MISS :(");

                respuesta.put("id", string_busqueda);
                respuesta.put("estado", "miss");
                respuesta.put("respuesta", "");

                //****************************************************************

                // **********SI ESTA EN EL CACHE dinamico******************************
            } else {
                respuesta.put("estado", "hit");
                respuesta.put("id", string_busqueda);
                respuesta.put("respuesta", estaEnCacheEstatico);
                System.out.println("HIT!");

            }
            //****************************************************************
            lru_cache1.print(1);
            System.out.println("");

        }
    } else// si esta en el cache estatico
    {
        System.out.println("Hit en el cache estatico");
        respuesta.put("estado", "hit");
        respuesta.put("id", string_busqueda);
        respuesta.put("respuesta", estaEnCacheEstatico);

        cestatico.print();
    }

    return respuesta;

}

From source file:GenericResource.java

@GET
@Path("/{cal}")
public String fetch(@PathParam("cal") String sth, String charid) {
    JSONObject array = new JSONObject();
    String time = null;/*from  w w  w  .  ja va  2  s .  c  o m*/
    String[] tokens = sth.split(",");
    String username = tokens[0];
    String password = tokens[1];
    charid = tokens[2];

    try {
        Class.forName("com.mysql.jdbc.Driver");
        String unicode = "?useUnicode=yes&characterEncoding=UTF-8";

        java.sql.Connection connection = DriverManager
                .getConnection("jdbc:mysql://localhost:3306/finalproject" + unicode, "root", "");
        Statement statement = connection.createStatement();

        String x = "SELECT * from finalproject where username= '" + username + "' and password = '" + password
                + "'";

        ResultSet select = statement.executeQuery(x);
        while (select.next()) {
            //array.put("Test",select.getString("A"));
            time = select.getString(charid);
        }
        array.put("time", time);

    } catch (ClassNotFoundException | SQLException exs) {

    }
    return array + "";
}

From source file:com.aerothai.database.role.RoleService.java

public JSONObject GetRoleAll(String opt) throws Exception {

    Connection dbConn = null;// w  w w  .  j av  a2 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 role";
        if (isNotNull(opt)) {
            query = "SELECT * FROM role WHERE" + opt;
        }
        System.out.println(query);
        ResultSet rs = stmt.executeQuery(query);

        while (rs.next()) {

            JSONObject jsonData = new JSONObject();
            jsonData.put("id", rs.getInt("idrole"));
            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.p000ison.dev.simpleclans2.util.JSONUtil.java

public static String mapToJSON(Map map) {
    JSONObject JSONMap = new JSONObject();

    JSONMap.putAll(map);

    return JSONMap.toJSONString();
}

From source file:com.aerothai.database.devicetype.DeviceTypeService.java

public JSONObject GetDeviceTypeAll(String opt) throws Exception {

    Connection dbConn = null;// ww w. jav 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 device_type";
        if (isNotNull(opt)) {
            query = "SELECT * FROM device_type WHERE" + opt;
        }
        System.out.println(query);
        ResultSet rs = stmt.executeQuery(query);

        while (rs.next()) {

            JSONObject jsonData = new JSONObject();
            jsonData.put("id", rs.getInt("iddevice_type"));
            jsonData.put("details", rs.getString("details"));
            jsonData.put("idunit", rs.getString("idunit"));
            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:net.sourceforge.fenixedu.presentationTier.Action.externalServices.DomainObjectJSONSerializer.java

public static JSONObject getDomainObject(DomainObject obj) throws SecurityException, NoSuchMethodException,
        IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    final JSONObject jsonObject = new JSONObject();
    final Class<? extends DomainObject> clazz = obj.getClass();
    final String objClassName = clazz.getName();

    jsonObject.put("externalId", obj.getExternalId());
    jsonObject.put("className", objClassName);
    final DomainClass domainClass = getDomainClass(objClassName);
    if (domainClass == null) {
        return jsonObject;
    }/*from  www.  j a va  2 s . c  o  m*/
    for (Slot slot : getAllSlots(domainClass)) {
        final String slotName = slot.getName();
        final Method method = clazz.getMethod("get" + StringUtils.capitalize(slotName));
        final Object result = method.invoke(obj);
        jsonObject.put(slotName, result == null ? null : result.toString());
    }

    for (Role roleSlot : getAllRoleSlots(domainClass)) {
        final String slotName = roleSlot.getName();
        if (roleSlot.getMultiplicityUpper() == 1) {
            final Method method = clazz.getMethod("get" + StringUtils.capitalize(slotName));
            final AbstractDomainObject singleRelationObj = (AbstractDomainObject) method.invoke(obj);
            final JSONArray oneRelation = new JSONArray();
            if (singleRelationObj != null) {
                oneRelation.add(singleRelationObj.getExternalId());
            }
            jsonObject.put(slotName, oneRelation);
        } else {
            final Method method = clazz.getMethod("get" + StringUtils.capitalize(slotName) + "Set");
            final Set<? extends AbstractDomainObject> result = (Set<? extends AbstractDomainObject>) method
                    .invoke(obj);
            jsonObject.put(slotName, serializeRelation(result));
        }

    }

    return jsonObject;
}

From source file:com.aerothai.database.status.StatusService.java

public JSONObject GetStatusAll(String opt) throws Exception {

    Connection dbConn = null;//from ww 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 status";
        if (isNotNull(opt)) {
            query = "SELECT * FROM status WHERE" + opt;
        }
        System.out.println(query);
        ResultSet rs = stmt.executeQuery(query);

        while (rs.next()) {

            JSONObject jsonData = new JSONObject();
            jsonData.put("id", rs.getInt("idstatus"));
            jsonData.put("details", rs.getString("details"));
            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.aerothai.database.position.PositionService.java

public JSONObject GetPositionAll(String opt) throws Exception {

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

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

        Statement stmt = dbConn.createStatement();
        String query = "SELECT * FROM position";
        if (isNotNull(opt)) {
            query = "SELECT * FROM position WHERE" + opt;
        }
        System.out.println(query);
        ResultSet rs = stmt.executeQuery(query);

        while (rs.next()) {

            JSONObject jsonData = new JSONObject();
            jsonData.put("id", rs.getInt("idposition"));
            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.oic.login.TestLoginHandlerTest.java

@Override
protected void setUp() throws Exception {
    super.setUp();
    json = new JSONObject();
    testLogin = new TestLoginHandler();
}

From source file:com.oic.utils.Validators.java

public Validators(JSONObject json) {
    validationRule = new HashMap<>();
    errorJson = new JSONObject();
    this.json = json;
}