Example usage for org.json.simple JSONArray toString

List of usage examples for org.json.simple JSONArray toString

Introduction

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

Prototype

@Override
    public String toString() 

Source Link

Usage

From source file:com.product.ProductResource.java

/**
 * Retrieves representation of an instance of com.oracle.products.ProductResource
 * @return an instance of java.lang.String
 *///from  ww w.j  a v  a  2 s  .c o m
@GET
@Produces(MediaType.APPLICATION_JSON)
public String getAllProducts() throws SQLException {
    if (conn == null) {
        return "not connected";
    } else {
        String query = "Select * from product";
        PreparedStatement pstmt = conn.prepareStatement(query);
        ResultSet rs = pstmt.executeQuery();
        String result = "";
        JSONArray productArr = new JSONArray();
        while (rs.next()) {
            JsonObjectBuilder prodMap = Json.createObjectBuilder();
            prodMap.add("productID", rs.getInt("product_id"));
            prodMap.add("name", rs.getString("name"));
            prodMap.add("description", rs.getString("description"));
            prodMap.add("quantity", rs.getInt("quantity"));
            productArr.add(prodMap);
        }
        result = productArr.toString();
        return result.replace("},", "},\n");
    }

}

From source file:com.products.ProductResource.java

/**
 * Retrieves representation of an instance of com.oracle.products.ProductResource
 * @return an instance of java.lang.String
 *//*from   ww w.  ja v a2s.  co m*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public String getAllProducts() throws SQLException {
    if (co == null) {
        return "not connected";
    } else {
        String query = "Select * from product";
        PreparedStatement pstmt = co.prepareStatement(query);
        ResultSet rs = pstmt.executeQuery();
        String result = "";
        JSONArray productArr = new JSONArray();
        while (rs.next()) {
            Map productMap = new LinkedHashMap();
            productMap.put("productID", rs.getInt("product_id"));
            productMap.put("name", rs.getString("name"));
            productMap.put("description", rs.getString("description"));
            productMap.put("quantity", rs.getInt("quantity"));
            productArr.add(productMap);
        }
        result = productArr.toString();
        return result.replace("},", "},\n");
    }

}

From source file:com.dubture.symfony.ui.preferences.ServiceConfigurationBlock.java

protected final void updateModel(DialogField field) {

    if (field == serviceList) {

        List list = serviceList.getElements();

        JSONArray data = new JSONArray();

        for (int i = 0; i < list.size(); i++) {

            SyntheticService elem = (SyntheticService) list.get(i);
            JSONObject jsonService = JsonUtils.createService(elem.name, elem.className);
            data.add(jsonService);/*  w  w  w . ja  v a 2  s.  c  o  m*/

        }

        setValue(SYNTHETIC_SERVICES, data.toString());
        validateSettings(SYNTHETIC_SERVICES, null, null);

    }
}

From source file:com.oracle.products.ProductResource.java

/**
 * Retrieves representation of an instance of com.oracle.products.ProductResource
 * @return an instance of java.lang.String
 *//*from w  w w .j a  v a 2s .  co m*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public String getAllProducts() throws SQLException {
    if (conn == null) {
        return "not connected";
    } else {
        String query = "Select * from product";
        PreparedStatement pstmt = conn.prepareStatement(query);
        ResultSet rs = pstmt.executeQuery();
        String result = "";
        JSONArray productArr = new JSONArray();
        while (rs.next()) {
            Map productMap = new LinkedHashMap();
            productMap.put("productID", rs.getInt("product_id"));
            productMap.put("name", rs.getString("name"));
            productMap.put("description", rs.getString("description"));
            productMap.put("quantity", rs.getInt("quantity"));
            productArr.add(productMap);
        }
        result = productArr.toString();
        return result.replace("},", "},\n");
    }

}

From source file:com.products.ProductResource.java

@GET
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)//from   w  ww .  j  a  va2 s.c  om
public String getproduct(@PathParam("id") int id) throws SQLException {

    if (co == null) {
        return "not connected";
    } else {
        String query = "Select * from product where product_id = ?";
        PreparedStatement pstmt = co.prepareStatement(query);
        pstmt.setInt(1, id);
        ResultSet rs = pstmt.executeQuery();
        String result = "";
        JSONArray productArr = new JSONArray();
        while (rs.next()) {
            Map productMap = new LinkedHashMap();
            productMap.put("productID", rs.getInt("product_id"));
            productMap.put("name", rs.getString("name"));
            productMap.put("description", rs.getString("description"));
            productMap.put("quantity", rs.getInt("quantity"));
            productArr.add(productMap);
        }
        result = productArr.toString();

        return result;
    }

}

From source file:com.oracle.products.ProductResource.java

@GET
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)//from  ww  w .jav a 2  s  . co m
public String getproduct(@PathParam("id") int id) throws SQLException {

    if (conn == null) {
        return "not connected";
    } else {
        String query = "Select * from product where product_id = ?";
        PreparedStatement pstmt = conn.prepareStatement(query);
        pstmt.setInt(1, id);
        ResultSet rs = pstmt.executeQuery();
        String result = "";
        JSONArray productArr = new JSONArray();
        while (rs.next()) {
            Map productMap = new LinkedHashMap();
            productMap.put("productID", rs.getInt("product_id"));
            productMap.put("name", rs.getString("name"));
            productMap.put("description", rs.getString("description"));
            productMap.put("quantity", rs.getInt("quantity"));
            productArr.add(productMap);
        }
        result = productArr.toString();

        return result;
    }

}

From source file:gov.nih.nci.ispy.web.ajax.ReporterLookup.java

/**
 * this ajax method looks up reporters using gexpannotation service
 * based on gene symbol and array platform. An addition parameter is 
 * provided so that the callback(javascript) knows where to put the collection
 * This last paramter is an id from the ui element.
 * NOTE: the id passed in WILL be used in the callback...make sure it is there!
 *///  ww w .  j  a v  a 2s.  com
public String lookup(String gene, String arrayPlatform, String uiElement) {
    Collection<String> reporters = new HashSet<String>();
    //set up geneCollection
    Collection<String> genes = new ArrayList<String>();
    genes.add(gene);
    //set up array platform by finding the appropriate type
    String[] uiString = arrayPlatform.split("#");
    String myClassName = uiString[0];
    String myValueName = uiString[1];
    Enum myType = EnumHelper.createType(myClassName, myValueName);

    if (myType instanceof ArrayPlatformType) {
        GeneExprAnnotationService gs = GeneExprAnnotationServiceFactory.getInstance();
        reporters = gs.getReporterNamesForGeneSymbols(genes, (ArrayPlatformType) myType);
    }
    /* reporterResultArray variable holds reporter objects like the result 
     * list of reporters (in its own array called reporterList), 
     * the results String, and the UIElement
    */
    JSONArray reporterResultArray = new JSONArray();
    JSONObject resultsObject = new JSONObject();

    JSONArray reporterList = new JSONArray();
    for (String reporter : reporters) {
        reporterList.add(reporter);
    }
    String results = "notFound";
    if (!reporterList.isEmpty()) {
        results = "found";
    }
    resultsObject.put("gene", gene);
    resultsObject.put("results", results);
    resultsObject.put("reporters", reporterList);
    resultsObject.put("elementId", uiElement);
    reporterResultArray.add(resultsObject);

    return reporterResultArray.toString();
}

From source file:gov.nih.nci.rembrandt.web.ajax.DynamicListHelper.java

public static String getGeneAliases(String gene) {
    JSONArray aliases = new JSONArray();
    try {/*w  w w .  j  av a2 s  .c  o  m*/
        if (!DataValidator.isGeneSymbolFound(gene)) {
            AllGeneAliasLookup[] allGeneAlias = DataValidator.searchGeneKeyWord(gene);
            // if there are aliases , set the array to be displayed in the form and return the showAlias warning
            if (allGeneAlias != null) {
                for (int i = 0; i < allGeneAlias.length; i++) {
                    JSONObject a = new JSONObject();

                    AllGeneAliasLookup alias = allGeneAlias[i];
                    a.put("alias", (alias.getAlias() != null) ? alias.getAlias() : "N/A");
                    a.put("symbol", (alias.getApprovedSymbol() != null) ? alias.getApprovedSymbol() : "N/A");
                    a.put("name", (alias.getApprovedName() != null) ? alias.getApprovedName() : "N/A");
                    //alias.getAlias()+"\t"+alias.getApprovedSymbol()+"\t"+alias.getApprovedName()
                    aliases.add(a);
                }
            } else {
                aliases.add("invalid");
            }
        } else {
            aliases.add("valid");
        }

    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return aliases.toString();
}

From source file:productClass.java

private String getResults(String query, String... params) {
    String result = new String();
    try (Connection conn = getConnection()) {
        PreparedStatement pstmt = conn.prepareStatement(query);
        for (int i = 1; i <= params.length; i++) {
            pstmt.setString(i, params[i - 1]);
        }/*from  w  w  w.  java  2 s.  c o m*/
        ResultSet rs = pstmt.executeQuery();
        JSONArray productArr = new JSONArray();
        while (rs.next()) {
            //Mapping the objects
            Map productMapping = new LinkedHashMap();
            productMapping.put("productID", rs.getInt("productID"));
            productMapping.put("name", rs.getString("name"));
            productMapping.put("description", rs.getString("description"));
            productMapping.put("quantity", rs.getInt("quantity"));
            productArr.add(productMapping);
        }
        result = productArr.toString();
    } catch (SQLException ex) {
        Logger.getLogger(productClass.class.getName()).log(Level.SEVERE, null, ex);
    }
    return result.replace("},", "},\n");
}

From source file:de.fhg.fokus.odp.middleware.unittest.xTestCKANGateway.java

/**
 * Test the getMostPopularTags method./* w w  w .  j a va 2s .c o  m*/
 * 
 * NOTE: this Test may fail on an productive system, where other tags were
 * more popular than the "test" tag. "Bundestag" tag is relevant only in OC
 * dev platform.
 */
@Test
public void testGetMostPopularTags() {
    log.fine("########### MOST POPULAR TAGS ###########");
    // get the most popular tags
    JSONArray arr = ckanGW.getMostPopularTags(10);
    // assertEquals(true, arr.toJSONString().contains("bundestag"));
    log.fine(arr.toString());
    assertEquals(10, arr.size());
}