Example usage for com.fasterxml.jackson.databind.node ObjectNode get

List of usage examples for com.fasterxml.jackson.databind.node ObjectNode get

Introduction

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

Prototype

public JsonNode get(String paramString) 

Source Link

Usage

From source file:com.arpnetworking.metrics.proxy.models.protocol.v2.LogMessagesProcessor.java

/**
 * {@inheritDoc}/*w  w  w.j  av a2s  . c o m*/
 */
@Override
public boolean handleMessage(final Object message) {
    if (message instanceof Command) {
        //TODO(barp): Map with a POJO mapper [MAI-184]
        final Command command = (Command) message;
        final ObjectNode commandNode = (ObjectNode) command.getCommand();
        final String commandString = commandNode.get("command").asText();
        switch (commandString) {
        case COMMAND_GET_LOGS:
            _metrics.incrementCounter(GET_LOGS_COUNTER);
            _connection.getTelemetry().tell(new LogsListRequest(), _connection.getSelf());
            break;
        case COMMAND_SUBSCRIBE_LOG: {
            _metrics.incrementCounter(SUBSCRIBE_COUNTER);
            final Path log = Paths.get(commandNode.get("log").asText());
            final ArrayNode regexes = commandNode.withArray("regexes");
            subscribe(log, regexes);
            break;
        }
        case COMMAND_UNSUBSCRIBE_LOG: {
            _metrics.incrementCounter(UNSUBSCRIBE_COUNTER);
            final Path log = Paths.get(commandNode.get("log").asText());
            final ArrayNode regexes = commandNode.withArray("regexes");
            unsubscribe(log, regexes);
            break;
        }
        default:
            return false;
        }
    } else if (message instanceof LogLine) {
        final LogLine logReport = (LogLine) message;
        processLogReport(logReport);
    } else if (message instanceof NewLog) {
        final NewLog newLog = (NewLog) message;
        processNewLog(newLog);
    } else if (message instanceof LogsList) {
        final LogsList logsList = (LogsList) message;
        processLogsList(logsList);

    } else {
        return false;
    }
    return true;
}

From source file:eu.bittrade.libs.steemj.communication.jrpc.JsonRPCResponse.java

/**
 * Create a new {@link SteemResponseException} based on the Json response.
 * //from w w w  .  j  a  v  a 2  s .c om
 * @param response
 *            The response object to transform.
 * @return A {@link SteemResponseException} based on the Json response.
 * @throws SteemCommunicationException
 *             If the response does not contain the expected
 *             <code>id</code>.
 */
private SteemResponseException createThrowable(ObjectNode response) throws SteemCommunicationException {
    JsonNode errorNode = response.get(ERROR_FIELD_NAME);

    if (!errorNode.isObject()) {
        throw new SteemCommunicationException("The response does not have the expected structure.");
    }

    ObjectNode errorObject = ObjectNode.class.cast(errorNode);

    Integer errorCode = isFieldNullOrEmpty(ERROR_CODE_FIELD_NAME, errorObject) ? null
            : errorObject.get(ERROR_CODE_FIELD_NAME).asInt();
    String message = isFieldNullOrEmpty(ERROR_MESSAGE_FIELD_NAME, errorObject) ? null
            : errorObject.get(ERROR_MESSAGE_FIELD_NAME).asText();
    JsonNode data = isFieldNullOrEmpty(ERROR_DATA_FIELD_NAME, errorObject) ? null
            : errorObject.get(ERROR_DATA_FIELD_NAME);

    return new SteemResponseException(errorCode, message, data);
}

From source file:models.protocol.v2.MetricMessagesProcessor.java

/**
 * {@inheritDoc}//from  ww  w . ja v  a 2s .  c  o  m
 */
@Override
public boolean handleMessage(final Object message) {
    if (message instanceof Command) {
        //TODO(barp): Map with a POJO mapper [MAI-184]
        final Command command = (Command) message;
        final ObjectNode commandNode = (ObjectNode) command.getCommand();
        final String commandString = commandNode.get("command").asText();
        switch (commandString) {
        case COMMAND_GET_METRICS:
            _connectionContext.getContext().parent().tell(new MetricsListRequest(),
                    _connectionContext.getSelf());
            break;
        case COMMAND_SUBSCRIBE_METRIC: {
            _metrics.incrementCounter(SUBSCRIBE_COUNTER);
            final String service = commandNode.get("service").asText();
            final String metric = commandNode.get("metric").asText();
            final String statistic = commandNode.get("statistic").asText();
            subscribe(service, metric, statistic);
            break;
        }
        case COMMAND_UNSUBSCRIBE_METRIC: {
            _metrics.incrementCounter(UNSUBSCRIBE_COUNTER);
            final String service = commandNode.get("service").asText();
            final String metric = commandNode.get("metric").asText();
            final String statistic = commandNode.get("statistic").asText();
            unsubscribe(service, metric, statistic);
            break;
        }
        default:
            return false;
        }
    } else if (message instanceof NewMetric) {
        //TODO(barp): Map with a POJO mapper [MAI-184]
        _metrics.incrementCounter(NEW_METRIC_COUNTER);
        final NewMetric newMetric = (NewMetric) message;
        processNewMetric(newMetric);
    } else if (message instanceof MetricReport) {
        _metrics.incrementCounter(REPORT_COUNTER);
        final MetricReport report = (MetricReport) message;
        processMetricReport(report);
    } else if (message instanceof MetricsList) {
        _metrics.incrementCounter(METRICS_LIST_COUNTER);
        final MetricsList metricsList = (MetricsList) message;
        processMetricsList(metricsList);
    } else {
        return false;
    }
    return true;
}

From source file:org.gitana.platform.client.FileFolderTest.java

@Test
public void testCRUD() {
    Gitana gitana = new Gitana();

    // authenticate
    Platform platform = gitana.authenticate("admin", "admin");

    // create a repository
    Repository repository = platform.createRepository();

    // get the master branch
    Branch master = repository.readBranch("master");

    // create a tree structure from ROOT
    Node root = master.rootNode();

    // tree structure
    /**//from ww  w.  j  av a 2s.c o  m
     *
     *    /
     *    /a1
     *    /a1/b1
     *    /a1/b1/c1
     *    /a1/b1/c1/d1
     *    /a1/b1/c1/d2
     *    /a1/b1/c1/d3
     *    /a1/b1/c2
     *    /a1/b1/c2/d4
     *    /a1/b1/c2/d5
     *    /a1/b2
     *    /a2
     *    /a2/b3
     */
    Node a1 = createFolder(master, root, "a1");
    Node a2 = createFolder(master, root, "a2");
    Node b1 = createFolder(master, a1, "b1");
    Node b2 = createFolder(master, a1, "b2");
    Node b3 = createFolder(master, a2, "b2");
    Node c1 = createFolder(master, b1, "c1");
    Node c2 = createFolder(master, b1, "c2");
    Node d1 = createFile(master, c1, "d1");
    Node d2 = createFile(master, c1, "d2");
    Node d3 = createFile(master, c1, "d3");
    Node d4 = createFile(master, c2, "d4");
    Node d5 = createFile(master, c2, "d5");

    // read the WHOLE tree
    ObjectNode tree1 = root.fileFolderTree();
    System.out.println(JsonUtil.stringify(tree1, true));

    // a few tests to ensure this is good
    ArrayNode children = (ArrayNode) tree1.get("children");
    assertNotNull(children);
    assertEquals(2, children.size());
    assertTrue(children.get(0).get("container").booleanValue());
    assertNotNull(children.get(0).get("filename").textValue());
    assertNotNull(children.get(0).get("label").textValue());
    assertNotNull(children.get(0).get("path").textValue());
    assertNotNull(children.get(0).get("typeQName").textValue());
    assertNotNull(children.get(0).get("qname").textValue());

    // read the tree from root with the "/a1/b1/c1" path already expanded
    ObjectNode tree2 = root.fileFolderTree("/", "/a1/b1/c1");
    System.out.println(JsonUtil.stringify(tree2, true));

    // read the tree segment starting at "/a1/b1"
    ObjectNode tree3 = root.fileFolderTree("/a1/b1");
    System.out.println(JsonUtil.stringify(tree3, true));
}

From source file:com.ikanow.aleph2.graph.titan.services.SimpleGraphDecompService.java

@Override
public void onObjectBatch(Stream<Tuple2<Long, IBatchRecord>> batch, Optional<Integer> batch_size,
        Optional<JsonNode> grouping_key) {

    final HashSet<ObjectNode> mutable_dedup_set = new HashSet<>();

    batch.forEach(t2 -> {/*  w ww.  ja  v  a 2  s .  com*/
        Optionals.ofNullable(_config.get().elements()).forEach(el -> {
            final ObjectNode d_o = (ObjectNode) t2._2().getJson();
            final Stream<JsonNode> froms = Optionals.ofNullable(el.from_fields()).stream()
                    .<JsonNode>map(s -> d_o.get(s)).filter(j -> null != j);
            final Streamable<JsonNode> tos = Streamable.of(Optionals.ofNullable(el.to_fields()))
                    .<JsonNode>map(s -> d_o.get(s)).filter(j -> null != j);

            //TODO (ALEPH-15): hmm need at least some properties here....

            froms.flatMap(from -> tos.<Tuple2<JsonNode, JsonNode>>map(to -> Tuples._2T(from, to)).stream())
                    .forEach(from_to -> {

                        final JsonNode from = from_to._1();
                        final JsonNode to = from_to._2();

                        final ObjectNode mutable_from_key = _mapper.createObjectNode();
                        mutable_from_key.set(GraphAnnotationBean.name, from);
                        mutable_from_key.put(GraphAnnotationBean.type, el.from_type());
                        final ObjectNode mutable_to_key = _mapper.createObjectNode();
                        mutable_to_key.set(GraphAnnotationBean.name, to);
                        mutable_to_key.put(GraphAnnotationBean.type, el.to_type());

                        if (mutable_dedup_set.add(mutable_from_key)) {
                            final ObjectNode mutable_from_vertex = _mapper.createObjectNode();
                            mutable_from_vertex.put(GraphAnnotationBean.type,
                                    GraphAnnotationBean.ElementType.vertex.toString());
                            mutable_from_vertex.set(GraphAnnotationBean.id, mutable_from_key);
                            mutable_from_vertex.put(GraphAnnotationBean.label, from.asText());
                            mutable_from_vertex.set(GraphAnnotationBean.properties,
                                    mutable_from_key.deepCopy());
                            _context.get().emitImmutableObject(_context.get().getNextUnusedId(),
                                    mutable_from_vertex, Optional.empty(), Optional.empty(), Optional.empty());
                        }

                        if (mutable_dedup_set.add(mutable_to_key)) {
                            final ObjectNode mutable_to_vertex = _mapper.createObjectNode();
                            mutable_to_vertex.put(GraphAnnotationBean.type,
                                    GraphAnnotationBean.ElementType.vertex.toString());
                            mutable_to_vertex.set(GraphAnnotationBean.id, mutable_to_key);
                            mutable_to_vertex.put(GraphAnnotationBean.label, to.asText());
                            mutable_to_vertex.set(GraphAnnotationBean.properties, mutable_to_key.deepCopy());
                            _context.get().emitImmutableObject(_context.get().getNextUnusedId(),
                                    mutable_to_vertex, Optional.empty(), Optional.empty(), Optional.empty());
                        }

                        final ObjectNode mutable_edge = _mapper.createObjectNode();
                        mutable_edge.put(GraphAnnotationBean.type,
                                GraphAnnotationBean.ElementType.edge.toString());
                        mutable_edge.put(GraphAnnotationBean.label, el.edge_name());
                        mutable_edge.set(GraphAnnotationBean.outV, mutable_from_key);
                        mutable_edge.set(GraphAnnotationBean.inV, mutable_to_key);
                        _context.get().emitImmutableObject(_context.get().getNextUnusedId(), mutable_edge,
                                Optional.empty(), Optional.empty(), Optional.empty());
                    });
        });
    });
}

From source file:models.protocol.v1.MetricMessagesProcessor.java

/**
 * {@inheritDoc}/*  ww  w. j a v a 2 s  . c  o m*/
 */
@Override
public boolean handleMessage(final Object message) {
    if (message instanceof Command) {
        //TODO(barp): Map with a POJO mapper [MAI-184]
        final Command command = (Command) message;
        final ObjectNode commandNode = (ObjectNode) command.getCommand();
        final String commandString = commandNode.get("command").asText();
        switch (commandString) {
        case COMMAND_GET_METRICS:
            _metrics.incrementCounter(GET_METRICS_COUNTER);
            _connectionContext.getContext().parent().tell(new MetricsListRequest(),
                    _connectionContext.getSelf());
            break;
        case COMMAND_SUBSCRIBE_METRIC: {
            _metrics.incrementCounter(SUBSCRIBE_COUNTER);
            final String service = commandNode.get("service").asText();
            final String metric = commandNode.get("metric").asText();
            final String statistic = commandNode.get("statistic").asText();
            subscribe(service, metric, statistic);
            break;
        }
        case COMMAND_UNSUBSCRIBE_METRIC: {
            _metrics.incrementCounter(UNSUBSCRIBE_COUNTER);
            final String service = commandNode.get("service").asText();
            final String metric = commandNode.get("metric").asText();
            final String statistic = commandNode.get("statistic").asText();
            unsubscribe(service, metric, statistic);
            break;
        }
        default:
            return false;
        }
    } else if (message instanceof NewMetric) {
        //TODO(barp): Map with a POJO mapper [MAI-184]
        _metrics.incrementCounter(NEW_METRIC_COUNTER);
        final NewMetric newMetric = (NewMetric) message;
        processNewMetric(newMetric);
    } else if (message instanceof MetricReport) {
        _metrics.incrementCounter(METRIC_REPORT_COUNTER);
        final MetricReport report = (MetricReport) message;
        processMetricReport(report);
    } else if (message instanceof MetricsList) {
        _metrics.incrementCounter(METRIC_LIST_COUNTER);
        final MetricsList metricsList = (MetricsList) message;
        processMetricsList(metricsList);
    } else {
        return false;
    }
    return true;
}

From source file:com.google.api.server.spi.response.ServletResponseResultWriterTest.java

@Test
public void testTypeChangesInArrayAsString() throws Exception {
    Object[] array = new Object[] { 100L, 200L };
    String responseBody = writeToResponse(array);

    ObjectNode output = ObjectMapperUtil.createStandardObjectMapper().readValue(responseBody, ObjectNode.class);
    ArrayNode items = (ArrayNode) output.get("items");
    assertTrue(items.get(0).isTextual());
    assertEquals("100", items.get(0).asText());
    assertTrue(items.get(1).isTextual());
    assertEquals("200", items.get(1).asText());
}

From source file:org.createnet.raptor.db.mapdb.MapDBConnectionTest.java

private void populateObjectData(long dataLength) throws IOException {

    ObjectNode obj = loadData("model");

    obj.put("id", "test1");
    obj.put("userId", "test-user");
    objectStore.set(obj.get("id").asText(), obj, 0);

    obj.put("id", "test2");
    obj.put("userId", "test-user-x");
    objectStore.set(obj.get("id").asText(), obj, 0);

    obj.put("id", "test3");
    obj.put("userId", "test-user");
    objectStore.set(obj.get("id").asText(), obj, 0);

    // push data//from  w  ww.  j a  v  a  2s  . c  o  m
    for (int i = 0; i < dataLength; i++) {

        ObjectNode record = loadData("record");

        String streamId = "mylocation";
        String objId = "test1";
        String userId = "test-user";

        Long timestamp = Instant.now().getEpochSecond() + i;

        record.put("streamId", streamId);
        record.put("objectId", objId);
        record.put("userId", userId);

        record.put("timestamp", timestamp);

        String key = String.join("-", new String[] { objId, streamId, timestamp.toString() });
        dataStore.set(key, record, 0);

    }

}

From source file:br.com.ingenieux.mojo.simpledb.cmd.PutAttributesCommand.java

private Collection<ReplaceableAttribute> getAttributesFrom(ArrayNode attributesNode, boolean replaceP) {
    List<ReplaceableAttribute> attributeList = new ArrayList<ReplaceableAttribute>();

    for (int i = 0; i < attributesNode.size(); i++) {
        ObjectNode objectNode = (ObjectNode) attributesNode.get(i);

        Iterator<String> itFieldName = objectNode.fieldNames();
        while (itFieldName.hasNext()) {
            String key = itFieldName.next();
            JsonNode valueNode = objectNode.get(key);

            if (valueNode.isValueNode()) {
                attributeList.add(new ReplaceableAttribute(key, valueNode.asText(), replaceP));
            } else if (valueNode.isArray()) {
                for (int j = 0; j < valueNode.size(); j++) {
                    JsonNode scalarValueNode = valueNode.get(j);

                    attributeList.add(new ReplaceableAttribute(key, scalarValueNode.asText(), replaceP));
                }/*www . j a v  a2  s .c om*/
            }
        }
    }

    return attributeList;
}

From source file:org.jboss.aerogear.simplepush.server.datastore.CouchDBDataStore.java

@Override
public String updateVersion(final String endpointToken, final long version)
        throws VersionException, ChannelNotFoundException {
    final ViewResult viewResult = db.queryView(query(Views.TOKEN.viewName(), endpointToken));
    final List<Row> rows = viewResult.getRows();
    if (rows.isEmpty()) {
        throw new ChannelNotFoundException("Cound not find channel for endpointToken", endpointToken);
    }/* w ww  .  j a va 2s  .co  m*/
    final ObjectNode node = (ObjectNode) rows.get(0).getValueAsNode().get(DOC_FIELD);
    final long currentVersion = node.get(VERSION_FIELD).asLong();
    if (version <= currentVersion) {
        throw new VersionException(
                "version [" + version + "] must be greater than the current version [" + currentVersion + "]");
    }
    node.put(VERSION_FIELD, String.valueOf(version));
    db.update(node);
    return node.get(CHID_FIELD).asText();
}