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:org.activiti.rest.service.api.runtime.TaskIdentityLinkResourceTest.java

/**
 * Test getting all identity links. GET runtime/tasks/{taskId}/identitylinks
 *///from w  ww  . j  a v a  2 s  . c  o m
@Deployment
public void testGetIdentityLinks() throws Exception {

    // Test candidate user/groups links + manual added identityLink
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("identityLinkProcess");
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.addUserIdentityLink(task.getId(), "john", "customType");

    assertEquals(3, taskService.getIdentityLinksForTask(task.getId()).size());

    // Execute the request
    HttpGet httpGet = new HttpGet(SERVER_URL_PREFIX
            + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_IDENTITYLINKS_COLLECTION, task.getId()));
    CloseableHttpResponse response = executeRequest(httpGet, HttpStatus.SC_OK);
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertTrue(responseNode.isArray());
    assertEquals(3, responseNode.size());

    boolean groupCandidateFound = false;
    boolean userCandidateFound = false;
    boolean customLinkFound = false;

    for (int i = 0; i < responseNode.size(); i++) {
        ObjectNode link = (ObjectNode) responseNode.get(i);
        assertNotNull(link);
        if (!link.get("user").isNull()) {
            if (link.get("user").textValue().equals("john")) {
                assertEquals("customType", link.get("type").textValue());
                assertTrue(link.get("group").isNull());
                assertTrue(link.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(
                        RestUrls.URL_TASK_IDENTITYLINK, task.getId(), "users", "john", "customType")));
                customLinkFound = true;
            } else {
                assertEquals("kermit", link.get("user").textValue());
                assertEquals("candidate", link.get("type").textValue());
                assertTrue(link.get("group").isNull());
                assertTrue(link.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(
                        RestUrls.URL_TASK_IDENTITYLINK, task.getId(), "users", "kermit", "candidate")));
                userCandidateFound = true;
            }
        } else if (!link.get("group").isNull()) {
            assertEquals("sales", link.get("group").textValue());
            assertEquals("candidate", link.get("type").textValue());
            assertTrue(link.get("user").isNull());
            assertTrue(link.get("url").textValue()
                    .endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_IDENTITYLINK, task.getId(),
                            RestUrls.SEGMENT_IDENTITYLINKS_FAMILY_GROUPS, "sales", "candidate")));
            groupCandidateFound = true;
        }
    }
    assertTrue(groupCandidateFound);
    assertTrue(userCandidateFound);
    assertTrue(customLinkFound);
}

From source file:org.lendingclub.mercator.aws.Route53Scanner.java

protected void projectHostedZoneResult(GetHostedZoneResult hostedZoneResult) {

    HostedZone hz = hostedZoneResult.getHostedZone();
    ObjectNode n = toJson(hostedZoneResult);

    getNeoRxClient().execCypher(//  w  ww  . jav a2  s. c o  m
            "merge (a:AwsRoute53HostedZone {aws_id:{aws_id}}) set a+={props}, a.updateTs=timestamp() return a",
            "aws_id", n.get("aws_id").asText(), "props", n);

    ListResourceRecordSetsRequest request = new ListResourceRecordSetsRequest();
    request.setHostedZoneId(hz.getId());
    ListResourceRecordSetsResult result;

    long timestamp = System.currentTimeMillis();

    do {
        rateLimit();
        result = getClient().listResourceRecordSets(request);
        request.setStartRecordName(result.getNextRecordName());

        for (ResourceRecordSet rs : result.getResourceRecordSets()) {

            projectResourceRecordSet(hz.getId(), rs, timestamp);

        }

    } while (result.isTruncated());

    getNeoRxClient().execCypher(
            "match (z:AwsRoute53HostedZone {aws_id:{aws_id}})--(r:AwsRoute53RecordSet) where r.updateTs<{ts} detach delete r",
            "ts", timestamp, "aws_id", hz.getId());
    getNeoRxClient().execCypher(
            "match (a:AwsRoute53RecordSet) where not (a)-[:CONTAINS]-(:AwsRoute53HostedZone) detach delete a");
}

From source file:edu.nwpu.gemfire.monitor.data.DataBrowser.java

/**
 * addQueryInHistory method adds user's query into query history file
 * //ww w  .j  a va 2s. c o m
 * @param userId
 *          Logged in User's Id
 * @param queryText
 *          Query text to execute
 */
public boolean addQueryInHistory(String queryText, String userId) {
    boolean operationStatus = false;
    if (StringUtils.isNotNullNotEmptyNotWhiteSpace(queryText)
            && StringUtils.isNotNullNotEmptyNotWhiteSpace(userId)) {

        // Fetch all queries from query log file
        ObjectNode queries = fetchAllQueriesFromFile();

        // Get user's query history list
        ObjectNode userQueries = (ObjectNode) queries.get(userId);
        if (userQueries == null) {
            userQueries = mapper.createObjectNode();
        }

        // Add query in user's query history list
        userQueries.put(Long.toString(System.currentTimeMillis()), queryText);
        queries.put(userId, userQueries);

        // Store queries in file back
        operationStatus = storeQueriesInFile(queries);
    }

    return operationStatus;
}

From source file:edu.nwpu.gemfire.monitor.data.DataBrowser.java

/**
 * deleteQueryById method deletes query from query history file
 * // w  ww .  j a  va  2  s. c  o  m
 * @param userId
 *          Logged in user's Unique Id
 * @param queryId
 *          Unique Id of Query to be deleted
 * @return boolean
 */
public boolean deleteQueryById(String userId, String queryId) {

    boolean operationStatus = false;
    if (StringUtils.isNotNullNotEmptyNotWhiteSpace(queryId)
            && StringUtils.isNotNullNotEmptyNotWhiteSpace(userId)) {

        // Fetch all queries from query log file
        ObjectNode queries = fetchAllQueriesFromFile();

        // Get user's query history list
        ObjectNode userQueries = (ObjectNode) queries.get(userId);

        if (userQueries != null) {
            // Remove user's query
            userQueries.remove(queryId);
            queries.put(userId, userQueries);

            // Store queries in file back
            operationStatus = storeQueriesInFile(queries);
        }
    }

    return operationStatus;
}

From source file:org.lendingclub.mercator.ucs.UCSScanner.java

protected void recordFabricExtender(Element element) {

    ObjectNode n = toJson(element);

    String serial = n.get("serial").asText();
    String mercatorId = Hashing.sha1().hashString(serial, Charsets.UTF_8).toString();
    n.put("mercatorId", mercatorId);

    String cypher = "merge (c:UCSFabricExtender {mercatorId:{mercatorId}}) set c+={props}, c.updateTs=timestamp()";

    getProjector().getNeoRxClient().execCypher(cypher, "mercatorId", mercatorId, "props", n);

    cypher = "match (m:UCSManager {mercatorId:{managerId}}), (c:UCSFabricExtender {mercatorId:{fexId}}) merge (m)-[r:MANAGES]->(c)";

    getProjector().getNeoRxClient().execCypher(cypher, "managerId", getUCSClient().getUCSManagerId(), "fexId",
            mercatorId);/*from   ww w.ja va  2 s.  co m*/

}

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

/**
 * {@inheritDoc}//from   www .j a  v a2 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:
            _connection.getTelemetry().tell(new MetricsListRequest(), _connection.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.walkmod.conf.providers.yml.AddIncludesOrExcludesYMLAction.java

private void setIncludesOrExcludesList(ObjectNode node) {

    ArrayNode wildcardArray = null;//from  w w  w  .j  a v a 2s . c om
    String label = "includes";
    if (isExcludes) {
        label = "excludes";
    }
    if (node.has(label)) {
        JsonNode wildcard = node.get(label);
        if (wildcard.isArray()) {
            wildcardArray = (ArrayNode) wildcard;
        }
    }
    if (wildcardArray == null) {
        wildcardArray = new ArrayNode(provider.getObjectMapper().getNodeFactory());
        node.set(label, wildcardArray);
    }
    for (String includesItem : includes) {
        wildcardArray.add(includesItem);
    }
}

From source file:edu.nwpu.gemfire.monitor.data.DataBrowser.java

/**
 * getQueryHistoryByUserId method reads and lists out the queries from history
 * file// w  ww. j  a v a 2s .c om
 * 
 * @param userId
 *          Logged in User's Id
 */
public ArrayNode getQueryHistoryByUserId(String userId) {

    ArrayNode queryList = mapper.createArrayNode();

    if (StringUtils.isNotNullNotEmptyNotWhiteSpace(userId)) {

        // Fetch all queries from query log file
        ObjectNode queries = fetchAllQueriesFromFile();

        // Get user's query history list
        ObjectNode userQueries = (ObjectNode) queries.get(userId);

        if (userQueries != null) {
            Iterator<String> it = userQueries.fieldNames();
            while (it.hasNext()) {
                String key = it.next();
                ObjectNode queryItem = mapper.createObjectNode();
                queryItem.put("queryId", key);
                queryItem.put("queryText", userQueries.get(key).toString());
                queryItem.put("queryDateTime", simpleDateFormat.format(Long.valueOf(key)));
                queryList.add(queryItem);
            }
        }
    }

    return queryList;
}

From source file:org.lendingclub.mercator.ucs.UCSScanner.java

protected void recordComputeBlade(String chassisMercatorId, Element element) {
    ObjectNode n = toJson(element);

    String mercatorId = n.get("uuid").asText();
    n.put("mercatorId", mercatorId);
    String cypher = "merge (c:UCSComputeBlade {mercatorId:{mercatorId}}) set c+={props}, c.updateTs=timestamp()";

    getProjector().getNeoRxClient().execCypher(cypher, "mercatorId", mercatorId, "props", n);

    cypher = "match (c:UCSChassis {mercatorId:{chassisMercatorId}}), (b:UCSComputeBlade {mercatorId:{bladeId}}) merge (c)-[r:CONTAINS]->(b) set r.updateTs=timestamp()";

    getProjector().getNeoRxClient().execCypher(cypher, "chassisMercatorId", chassisMercatorId, "bladeId",
            mercatorId);/*from   ww w . j a v  a2 s  . c o  m*/

    recordServerServiceProfileRelationship("UCSComputeBlade", n);

}

From source file:org.lendingclub.mercator.ucs.UCSScanner.java

protected void recordComputeRackUnit(Element element) {

    ObjectNode n = toJson(element);

    String mercatorId = n.get("uuid").asText();
    n.put("mercatorId", mercatorId);
    String cypher = "merge (c:UCSComputeRackUnit {mercatorId:{mercatorId}}) set c+={props}, c.updateTs=timestamp()";

    getProjector().getNeoRxClient().execCypher(cypher, "mercatorId", mercatorId, "props", n);

    cypher = "match (m:UCSManager {mercatorId:{managerId}}), (c:UCSComputeRackUnit {mercatorId:{rackUnitId}}) merge (m)-[r:MANAGES]->(c) set r.updateTs=timestamp()";

    getProjector().getNeoRxClient().execCypher(cypher, "managerId", getUCSClient().getUCSManagerId(),
            "rackUnitId", mercatorId);

    recordServerServiceProfileRelationship("UCSComputeRackUnit", n);
}