Example usage for javax.json JsonObject getString

List of usage examples for javax.json JsonObject getString

Introduction

In this page you can find the example usage for javax.json JsonObject getString.

Prototype

String getString(String name);

Source Link

Document

A convenience method for getJsonString(name).getString()

Usage

From source file:org.kuali.rice.krad.uif.layout.collections.DataTablesPagingHelper.java

/**
 * Get the sort type string from the parsed column definitions object.
 *
 * @param jsonColumnDefs the JsonArray representation of the aoColumnDefs property from the RichTable template
 * options//  ww  w.  ja  v a 2  s . com
 * @param sortCol the index of the column to get the sort type for
 * @return the name of the sort type specified in the template options, or the default of "string" if none is
 * found.
 */
private static String getSortType(JsonArray jsonColumnDefs, int sortCol) {
    String sortType = "string"; // default to string if nothing is spec'd

    if (jsonColumnDefs != null) {
        JsonObject column = jsonColumnDefs.getJsonObject(sortCol);

        if (column.containsKey("sType")) {
            sortType = column.getString("sType");
        }
    }
    return sortType;
}

From source file:com.buffalokiwi.aerodrome.jet.reports.ReportStatusRec.java

/**
 * Turn jet json into an instance of this object
 * @param reportId The report id /*from w ww. j a va 2 s .  c o m*/
 * @param json json 
 * @return object 
 */
public static ReportStatusRec fromJSON(final String reportId, final JsonObject json) {
    Utils.checkNullEmpty(reportId, "reportId");
    Utils.checkNull(json, "json");

    return new Builder().setMerchantId(json.getString("merchant_id"))
            .setProcessingEnd(JetDate.fromJetValueOrNull(json.getString("processing_end")))
            .setProcessingStart(JetDate.fromJetValueOrNull(json.getString("processing_start")))
            .setReportExpDate(JetDate.fromJetValueOrNull(json.getString("report_expiration_date")))
            .setReportId(reportId).setReportUrl(json.getString("report_url"))
            .setRequestedDate(JetDate.fromJetValueOrNull(json.getString("report_requested_date")))
            .setStatus(ReportStatus.fromText(json.getString("report_status")))
            .setType(ReportType.fromText(json.getString("report_type"))).build();
}

From source file:org.json.StackExchangeAPI.java

private static void parseStackExchange(String jsonStr) {
    JsonReader reader = null;// w  ww .ja va2 s .c o  m
    try {
        reader = Json.createReader(new StringReader(jsonStr));
        JsonObject jsonObject = reader.readObject();
        reader.close();
        JsonArray array = jsonObject.getJsonArray("items");
        for (JsonObject result : array.getValuesAs(JsonObject.class)) {

            JsonObject ownerObject = result.getJsonObject("owner");
            // int ownerReputation = ownerObject.getInt("reputation");
            //  System.out.println("Reputation:"+ownerReputation);
            int viewCount = result.getInt("view_count");
            System.out.println("View Count :" + viewCount);
            int answerCount = result.getInt("answer_count");
            System.out.println("Answer Count :" + answerCount);
            String link = result.getString("link");
            System.out.println("URL: " + link);
            String title = result.getString("title");
            System.out.println("Title: " + title);
            String body = result.getString("body");
            System.out.println("Body: " + body);
            JsonArray tagsArray = result.getJsonArray("tags");
            StringBuilder tagBuilder = new StringBuilder();
            int i = 1;
            for (JsonValue tag : tagsArray) {
                tagBuilder.append(tag.toString());
                if (i < tagsArray.size())
                    tagBuilder.append(",");
                i++;
            }

            System.out.println("Tags: " + tagBuilder.toString());
            System.out.println("------------------------------------------");
        }

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:de.tu_dortmund.ub.data.dswarm.TaskProcessingUnit.java

private static void doInit(final String resourceWatchFolder, final String initResourceFileName,
        final String serviceName, final Integer engineThreads, final Properties config,
        final Map<String, Triple<String, String, String>> inputDataModelsAndResources) throws Exception {

    final JsonObject initResultJSON = TPUUtil.doInit(resourceWatchFolder, initResourceFileName, serviceName,
            engineThreads, config, 0);//from   ww w. java 2  s  . c  o m

    final String inputDataModelID = initResultJSON.getString(Init.DATA_MODEL_ID);
    final String resourceID = initResultJSON.getString(Init.RESOURCE_ID);
    final String configurationID = initResultJSON.getString(Init.CONFIGURATION_ID);

    inputDataModelsAndResources.put(inputDataModelID, Triple.of(inputDataModelID, resourceID, configurationID));
}

From source file:de.tu_dortmund.ub.data.util.TPUUtil.java

private static void deleteObject(final JsonObject initResultJSON, final String identifier,
        final String objectType, final String serviceName, final String engineDswarmAPI, final int cnt)
        throws IOException {

    try {//from   w ww . j  a  va2  s  .  c om

        LOG.debug("try to clean-up metadata repository from temp {}", objectType);

        final String objectId = initResultJSON.getString(identifier);

        deleteObject(objectId, objectType, serviceName, engineDswarmAPI, cnt);

        LOG.debug("finished cleaning-up metadata repository from temp {}", objectType);
    } catch (final NullPointerException e) {

        LOG.debug("could not find identifier for '{}' in JSON object; cannot remove any '{}'", identifier,
                objectType);
    }
}

From source file:com.buffalokiwi.aerodrome.jet.JetAPIResponse.java

/**
 * Check the response body for errors/*w  w  w . j av a  2s.  c  o m*/
 * @param res JSON results
 * @throws JetException if there's an issue
 */
public static final void checkErrors(final JsonObject res, final IAPIResponse apiRes) throws JetException {
    if (res.containsKey("errors")) {
        final JsonArray errors = res.getJsonArray("errors");
        ArrayList<String> messages = new ArrayList<>();

        for (int i = 0; i < errors.size(); i++) {
            messages.add(errors.getString(i, ""));
        }

        throw new JetException(messages, null, apiRes);
    } else if (res.containsKey("error")) {
        throw new JetException(res.getString("error"), null, apiRes);
    }
}

From source file:com.buffalokiwi.aerodrome.Aerodrome.java

private static void testUpload(final APIHttpClient client, final JetConfig config) {

    final JetAPIBulkProductUpload up = new JetAPIBulkProductUpload(client, config);

    List<ProductRec> products = new ArrayList<>();
    products.add(getTestProduct());/*w  w  w .  ja v a2  s .  c  om*/

    //..The local filename to write the bulk product data to
    final File file = new File("/home/john/jetproducttext.json.gz");

    try (final BulkProductFileGenerator gen = new BulkProductFileGenerator(file)) {
        //..Write the product json to a gzip file
        for (final ProductRec pRec : products) {
            gen.writeLine(pRec);
        }
    } catch (IOException e) {
        fail("Failed to open output file", 0, e);
    }

    try {
        //..Get authorization to upload a file
        final BulkUploadAuthRec uploadToken = up.getUploadToken();

        //..Sends the authorized gzip file to the url specified in the uploadToken response.
        up.sendAuthorizedFile(uploadToken.getUrl(), new PostFile(file, ContentType.create("application/x-gzip"),
                "gzip", uploadToken.getJetFileId()));

        //..If you want to add an additional file to an existing authorization token/processing batch on jet, create a new PostFile instance for the new file
        final PostFile pf = new PostFile(file, ContentType.DEFAULT_BINARY, "gzip", file.getName());

        //..Post the request for a file addition to 
        JsonObject addRes = up
                .sendPostUploadedFiles(uploadToken.getUrl(), pf.getFilename(), BulkUploadFileType.MERCHANT_SKUS)
                .getJsonObject();

        //..Send the next file up to the batch 
        up.sendAuthorizedFile(addRes.getString("url"), pf);

        //..Get some stats for an uploaded file 
        up.getJetFileId(uploadToken.getJetFileId());

        //..And get some stats for the other uploaded file.
        up.getJetFileId(addRes.getString("jet_file_id"));

    } catch (Exception e) {
        fail("Failed to bulk", 0, e);
    }

    try {
        //System.out.println( up.getUploadToken().getUrl());
    } catch (Exception e) {
        fail("failed to do upload stuff", 0, e);
    }

}

From source file:org.hyperledger.fabric.sdk.ChaincodeCollectionConfiguration.java

private static String getJsonString(JsonObject obj, String prop)
        throws ChaincodeCollectionConfigurationException {
    JsonValue ret = obj.get(prop);// w w w  . j a  va2 s  .c  o m
    if (ret == null) {
        throw new ChaincodeCollectionConfigurationException(format("property %s missing", prop));
    }
    if (ret.getValueType() != JsonValue.ValueType.STRING) {
        throw new ChaincodeCollectionConfigurationException(
                format("property %s wrong type expected string got %s", prop, ret.getValueType().name()));
    }

    return obj.getString(prop);

}

From source file:org.apache.tamaya.etcd.EtcdAccessor.java

private static void parsePrevNode(String key, Map<String, String> result, JsonObject o) {
    if (o.containsKey("prevNode")) {
        final JsonObject prevNode = o.getJsonObject("prevNode");
        if (prevNode.containsKey("createdIndex")) {
            result.put("_" + key + ".prevNode.createdIndex", String.valueOf(prevNode.getInt("createdIndex")));
        }/* w  w w.  jav a 2 s .c o m*/
        if (prevNode.containsKey("modifiedIndex")) {
            result.put("_" + key + ".prevNode.modifiedIndex", String.valueOf(prevNode.getInt("modifiedIndex")));
        }
        if (prevNode.containsKey("expiration")) {
            result.put("_" + key + ".prevNode.expiration", String.valueOf(prevNode.getString("expiration")));
        }
        if (prevNode.containsKey("ttl")) {
            result.put("_" + key + ".prevNode.ttl", String.valueOf(prevNode.getInt("ttl")));
        }
        result.put("_" + key + ".prevNode.value", prevNode.getString("value"));
    }
}

From source file:org.jboss.as.test.integration.logging.formatters.JsonFormatterTestCase.java

private static void validateDefault(final JsonObject json, final Collection<String> expectedKeys,
        final String expectedMessage) {
    final Set<String> remainingKeys = new HashSet<>(json.keySet());

    // Check all the expected keys
    for (String key : expectedKeys) {
        checkNonNull(json, key);/*from   www.  j  av  a  2s .  co m*/
        Assert.assertTrue("Missing key " + key + " from JSON object: " + json, remainingKeys.remove(key));
    }

    // Should have no more remaining keys
    Assert.assertTrue("There are remaining keys that were not validated: " + remainingKeys,
            remainingKeys.isEmpty());

    Assert.assertEquals("org.jboss.logging.Logger", json.getString("loggerClassName"));
    Assert.assertEquals(LoggingServiceActivator.LOGGER.getName(), json.getString("loggerName"));
    Assert.assertTrue("Invalid level found in " + json.get("level"), isValidLevel(json.getString("level")));
    Assert.assertEquals(expectedMessage, json.getString("message"));
}