Example usage for com.fasterxml.jackson.databind JsonNode get

List of usage examples for com.fasterxml.jackson.databind JsonNode get

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind JsonNode get.

Prototype

public JsonNode get(String paramString) 

Source Link

Usage

From source file:au.org.ands.vocabs.toolkit.db.AccessPointUtils.java

/** Get the portal's uri setting for an apiSparql or sissvoc access point.
 * @param ap the access point//from w  w  w.ja  v  a 2  s .c  om
 * @return the access point's portal uri setting, if it has one,
 * or null otherwise.
 */
public static String getPortalUri(final AccessPoint ap) {
    if (!(AccessPoint.API_SPARQL_TYPE.equals(ap.getType())
            || (AccessPoint.SISSVOC_TYPE.equals(ap.getType())))) {
        // Not the right type.
        return null;
    }
    JsonNode dataJson = TaskUtils.jsonStringToTree(ap.getPortalData());
    JsonNode uri = dataJson.get("uri");
    if (uri == null) {
        return null;
    }
    return uri.asText();
}

From source file:au.org.ands.vocabs.toolkit.db.AccessPointUtils.java

/** Get the Toolkit's uri setting for a sesameDownload access point.
 * @param ap the access point//from  w  w w .  ja v  a  2  s .c om
 * @return the access point's Toolkit uri setting, if it has one,
 * or null otherwise.
 */
public static String getToolkitUri(final AccessPoint ap) {
    if (!AccessPoint.SESAME_DOWNLOAD_TYPE.equals(ap.getType())) {
        // Not the right type.
        return null;
    }
    JsonNode dataJson = TaskUtils.jsonStringToTree(ap.getToolkitData());
    JsonNode uri = dataJson.get("uri");
    if (uri == null) {
        return null;
    }
    return uri.asText();
}

From source file:au.org.ands.vocabs.toolkit.db.AccessPointUtils.java

/** Get the Toolkit's path setting for a file access point.
 * @param ap the access point// ww  w.  j  av a2s .c  o m
 * @return the access point's file setting, if it has one,
 * or null otherwise.
 */
public static String getToolkitPath(final AccessPoint ap) {
    if (!"file".equals(ap.getType())) {
        // Not the right type.
        return null;
    }
    JsonNode dataJson = TaskUtils.jsonStringToTree(ap.getToolkitData());
    JsonNode path = dataJson.get("path");
    if (path == null) {
        return null;
    }
    return path.asText();
}

From source file:au.org.ands.vocabs.toolkit.db.AccessPointUtils.java

/** Get the portal's format setting for a file access point.
 * @param ap the access point//from w  ww. j a  va2s .c om
 * @return the access point's format setting, if it has one,
 * or null otherwise.
 */
public static String getFormat(final AccessPoint ap) {
    if (!"file".equals(ap.getType())) {
        // Not the right type.
        return null;
    }
    JsonNode dataJson = TaskUtils.jsonStringToTree(ap.getPortalData());
    JsonNode format = dataJson.get("format");
    if (format == null) {
        return null;
    }
    return format.asText();
}

From source file:com.squarespace.template.plugins.platform.CommerceUtils.java

public static double getTotalStockRemaining(JsonNode item) {
    ProductType type = getProductType(item);
    JsonNode structuredContent = item.path("structuredContent");

    if (EnumSet.of(ProductType.DIGITAL, ProductType.GIFT_CARD).contains(type)) {
        return Double.POSITIVE_INFINITY;
    } else {//from   w  w  w  .j  a  v a 2  s  .  co m
        int total = 0;
        JsonNode variants = structuredContent.path("variants");
        for (int i = 0; i < variants.size(); i++) {
            JsonNode variant = variants.get(i);
            if (isTruthy(variant.path("unlimited"))) {
                return Double.POSITIVE_INFINITY;
            } else {
                total += variant.path("qtyInStock").asLong();
            }
        }
        return total;
    }
}

From source file:org.opendaylight.ovsdb.lib.schema.DatabaseSchema.java

public static DatabaseSchema fromJson(String dbName, JsonNode json) {
    if (!json.isObject() || !json.has("tables")) {
        throw new ParsingException("bad DatabaseSchema root, expected \"tables\" as child but was not found");
    }/*w  ww .  j  a  v  a  2 s .c  om*/
    if (!json.isObject() || !json.has("version")) {
        throw new ParsingException("bad DatabaseSchema root, expected \"version\" as child but was not found");
    }

    Version dbVersion = Version.fromString(json.get("version").asText());

    Map<String, TableSchema> tables = new HashMap<>();
    for (Iterator<Map.Entry<String, JsonNode>> iter = json.get("tables").fields(); iter.hasNext();) {
        Map.Entry<String, JsonNode> table = iter.next();
        logger.trace("Read schema for table[{}]:{}", table.getKey(), table.getValue());

        //todo : this needs to done by a factory
        tables.put(table.getKey(), new GenericTableSchema().fromJson(table.getKey(), table.getValue()));
    }

    return new DatabaseSchema(dbName, dbVersion, tables);
}

From source file:com.tda.sitefilm.allocine.JSONAllocineAPIHelper.java

private static String parseOriginalChannel(JsonNode rootNode) {
    JsonNode node = rootNode.get("originalChannel");
    if (node != null) {
        return getValueAsString(node.get("$"));
    }//  ww  w. j  a v  a2s .  c o m
    return null;
}

From source file:com.squarespace.template.plugins.platform.CommerceUtils.java

public static boolean isMultipleQuantityAllowedForServices(JsonNode websiteSettings) {

    boolean defaultValue = true;
    String fieldName = "multipleQuantityAllowedForServices";

    JsonNode storeSettings = websiteSettings.get("storeSettings");

    if (storeSettings == null || !storeSettings.hasNonNull(fieldName)) {
        return defaultValue;
    }/*ww w. j a v a 2s.  co m*/

    return storeSettings.get(fieldName).asBoolean(defaultValue);
}

From source file:com.tda.sitefilm.allocine.JSONAllocineAPIHelper.java

private static HtmlSynopsisType parseHtmlSynopsis(JsonNode rootNode) {
    JsonNode node = rootNode.get("synopsis");
    if (node != null) {
        HtmlSynopsisType synopsis = new HtmlSynopsisType();
        synopsis.getContent().add(getValueAsString(node));
        return synopsis;
    }//w w  w.j a v  a 2  s . c o  m
    return null;
}

From source file:com.meetingninja.csse.database.ProjectDatabaseAdapter.java

public static Project createProject(Project p) throws IOException, MalformedURLException {
    // Server URL setup
    String _url = getBaseUri().build().toString();

    // establish connection
    URL url = new URL(_url);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();

    conn.setRequestMethod("POST");
    addRequestHeader(conn, true);/*from  w  ww . ja  v a  2  s.c  o  m*/

    // prepare POST payload
    ByteArrayOutputStream json = new ByteArrayOutputStream();
    // this type of print stream allows us to get a string easily
    PrintStream ps = new PrintStream(json);
    // Create a generator to build the JSON string
    JsonGenerator jgen = JFACTORY.createGenerator(ps, JsonEncoding.UTF8);

    // Build JSON Object
    jgen.writeStartObject();
    jgen.writeStringField(Keys.Project.TITLE, p.getProjectTitle());
    jgen.writeArrayFieldStart(Keys.Project.MEETINGS);
    for (Meeting meeting : p.getMeetings()) {
        jgen.writeStartObject();
        jgen.writeStringField(Keys.Meeting.ID, meeting.getID());
        jgen.writeEndObject();

    }
    jgen.writeEndArray();
    jgen.writeArrayFieldStart(Keys.Project.NOTES);
    for (Note note : p.getNotes()) {
        jgen.writeStartObject();
        jgen.writeStringField(Keys.Note.ID, note.getID());
        jgen.writeEndObject();

    }
    jgen.writeEndArray();
    jgen.writeArrayFieldStart(Keys.Project.MEMBERS);
    for (User member : p.getMembers()) {
        jgen.writeStartObject();
        jgen.writeStringField(Keys.User.ID, member.getID());
        jgen.writeEndObject();

    }
    jgen.writeEndArray();
    jgen.writeEndObject();
    jgen.close();

    // Get JSON Object payload from print stream
    String payload = json.toString("UTF8");
    ps.close();

    // send payload
    sendPostPayload(conn, payload);
    String response = getServerResponse(conn);

    // prepare to get the id of the created Meeting
    // Map<String, String> responseMap = new HashMap<String, String>();

    /*
     * result should get valid={"meetingID":"##"}
     */
    String result = new String();
    if (!response.isEmpty()) {
        // responseMap = MAPPER.readValue(response,
        // new TypeReference<HashMap<String, String>>() {
        // });
        JsonNode projectNode = MAPPER.readTree(response);
        if (!projectNode.has(Keys.Project.ID)) {
            result = "invalid";
        } else
            result = projectNode.get(Keys.Project.ID).asText();
    }

    if (!result.equalsIgnoreCase("invalid"))
        p.setProjectID(result);

    conn.disconnect();
    return p;
}