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:org.kiji.rest.util.RowResourceUtil.java

/**
 * Util method to write a rest row into Kiji.
 *
 * @param kijiTable is the table to write into.
 * @param entityId is the entity id of the row to write.
 * @param kijiRestRow is the row model to write to Kiji.
 * @param schemaTable is the handle to the schema table used to resolve the KijiRestCell's
 *        writer schema if it was specified as a UID.
 * @throws IOException if there a failure writing the row.
 *///from w  w w.  j  ava  2  s.c om
public static void writeRow(KijiTable kijiTable, EntityId entityId, KijiRestRow kijiRestRow,
        KijiSchemaTable schemaTable) throws IOException {
    final KijiTableWriter writer = kijiTable.openTableWriter();
    // Default global timestamp.
    long globalTimestamp = System.currentTimeMillis();

    try {
        for (Entry<String, NavigableMap<String, List<KijiRestCell>>> familyEntry : kijiRestRow.getCells()
                .entrySet()) {
            String columnFamily = familyEntry.getKey();
            NavigableMap<String, List<KijiRestCell>> qualifiedCells = familyEntry.getValue();
            for (Entry<String, List<KijiRestCell>> qualifiedCell : qualifiedCells.entrySet()) {
                final KijiColumnName column = new KijiColumnName(columnFamily, qualifiedCell.getKey());
                if (!kijiTable.getLayout().exists(column)) {
                    throw new WebApplicationException(
                            new IllegalArgumentException("Specified column does not exist: " + column),
                            Response.Status.BAD_REQUEST);
                }

                for (KijiRestCell restCell : qualifiedCell.getValue()) {
                    final long timestamp;
                    if (null != restCell.getTimestamp()) {
                        timestamp = restCell.getTimestamp();
                    } else {
                        timestamp = globalTimestamp;
                    }
                    if (timestamp >= 0) {
                        // Put to either a counter or a regular cell.
                        if (SchemaType.COUNTER == kijiTable.getLayout().getCellSchema(column).getType()) {
                            JsonNode parsedCounterValue = BASIC_MAPPER.valueToTree(restCell.getValue());
                            if (parsedCounterValue.isIntegralNumber()) {
                                // Write the counter cell.
                                writer.put(entityId, column.getFamily(), column.getQualifier(), timestamp,
                                        parsedCounterValue.asLong());
                            } else if (parsedCounterValue.isContainerNode()) {
                                if (null != parsedCounterValue.get(COUNTER_INCREMENT_KEY)
                                        && parsedCounterValue.get(COUNTER_INCREMENT_KEY).isIntegralNumber()) {
                                    // Counter incrementation does not support timestamp.
                                    if (null != restCell.getTimestamp()) {
                                        throw new WebApplicationException(new IllegalArgumentException(
                                                "Counter incrementation does not support "
                                                        + "timestamp. Do not specify timestamp in request."));
                                    }
                                    // Increment counter cell.
                                    writer.increment(entityId, column.getFamily(), column.getQualifier(),
                                            parsedCounterValue.get(COUNTER_INCREMENT_KEY).asLong());
                                } else {
                                    throw new WebApplicationException(new IllegalArgumentException(
                                            "Counter increment could not be parsed " + "as long: "
                                                    + parsedCounterValue
                                                    + ". Provide a json node such as {\"incr\" : 123}."),
                                            Response.Status.BAD_REQUEST);
                                }
                            } else {
                                // Could not parse parameter to a long.
                                throw new WebApplicationException(new IllegalArgumentException(
                                        "Counter value could not be parsed as long: " + parsedCounterValue
                                                + ". Provide a long value to set the counter."),
                                        Response.Status.BAD_REQUEST);
                            }
                        } else {
                            // Write the cell.
                            String jsonValue = restCell.getValue().toString();
                            // TODO: This is ugly. Converting from Map to JSON to String.
                            if (restCell.getValue() instanceof Map<?, ?>) {
                                JsonNode node = BASIC_MAPPER.valueToTree(restCell.getValue());
                                jsonValue = node.toString();
                            }
                            Schema actualWriter = restCell.getWriterSchema(schemaTable);
                            if (actualWriter == null) {
                                throw new IOException("Unrecognized schema " + restCell.getValue());
                            }
                            putCell(writer, entityId, jsonValue, column, timestamp, actualWriter);
                        }
                    }
                }
            }
        }
    } finally {
        ResourceUtils.closeOrLog(writer);
    }
}

From source file:models.functions.ExistsFunction.java

public Boolean apply(JsonNode json) {
    return json.get("data").size() > 0;
}

From source file:org.calrissian.mango.json.deser.EntityDeserializer.java

@Override
public BaseEntity deserialize(JsonNode root) {
    String type = root.get("type").asText();
    String id = root.get("id").asText();

    return new BaseEntity(type, id);
}

From source file:org.emfjson.jackson.tests.uuids.UuidSupport.java

protected String uuid(JsonNode node) {
    return node.get("@id").asText();
}

From source file:managers.functions.SuccessFunction.java

public Boolean apply(WS.Response response) {
    JsonNode json = response.asJson();
    return json.get("errors").size() == 0;
}

From source file:controllers.api.v1.Dataset.java

public static Result assignCommentToColumn(int datasetId, int columnId) {
    ObjectNode json = Json.newObject();//  w w w . java2s .  co m
    ArrayNode res = json.arrayNode();
    JsonNode req = request().body().asJson();
    if (req == null) {
        return badRequest("Expecting JSON data");
    }
    if (req.isArray()) {
        for (int i = 0; i < req.size(); i++) {
            JsonNode obj = req.get(i);
            Boolean isSuccess = DatasetsDAO.assignColumnComment(obj.get("datasetId").asInt(),
                    obj.get("columnId").asInt(), obj.get("commentId").asInt());
            ObjectNode itemResponse = Json.newObject();
            if (isSuccess) {
                itemResponse.put("success", "true");
            } else {
                itemResponse.put("error", "true");
                itemResponse.put("datasetId", datasetId);
                itemResponse.put("columnId", columnId);
                itemResponse.set("commentId", obj.get("comment_id"));
            }
            res.add(itemResponse);
        }
    } else {
        Boolean isSuccess = DatasetsDAO.assignColumnComment(datasetId, columnId, req.get("commentId").asInt());
        ObjectNode itemResponse = Json.newObject();
        if (isSuccess) {
            itemResponse.put("success", "true");
        } else {
            itemResponse.put("error", "true");
            itemResponse.put("datasetId", datasetId);
            itemResponse.put("columnId", columnId);
            itemResponse.set("commentId", req.get("commentId"));
        }
        res.add(itemResponse);
    }
    ObjectNode result = Json.newObject();
    result.putArray("results").addAll(res);
    return ok(result);
}

From source file:org.emfjson.jackson.junit.support.UuidSupport.java

protected String uuid(JsonNode node) {
    return node.get(EJS_UUID_ANNOTATION).asText();
}

From source file:io.sqp.schemamatcher.fieldmatchers.FieldMatcher.java

public FieldMatcher(String fieldName, JsonNode schema) {
    _field = schema.get(fieldName);
    _fieldName = fieldName;
}

From source file:org.agorava.linkedin.jackson.CodeDeserializer.java

@Override
public String deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    JsonNode node = jp.readValueAsTree();
    return node.get(VALUE).textValue();
}

From source file:com.ibm.watson.catalyst.corpus.document.BasicDocumentFactory.java

public Document getDocument(JsonNode aNode) {
    File aFile = new File(aNode.get("file").asText());
    String aPauID = aNode.get("pauID").asText();
    String aPauTitle = aNode.get("pauTitle").asText();
    String aSourceDoc = aNode.get("sourceDoc").asText();
    List<String> aParagraphs = getParagraphs(aNode);
    return new Document(aFile, aPauID, aPauTitle, aSourceDoc, aParagraphs);
}