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.activiti.service.activiti.ProcessInstanceService.java

public List<String> getCompletedActivityInstancesAndProcessDefinitionId(ServerConfig serverConfig,
        String processInstanceId) {
    URIBuilder builder = clientUtil.createUriBuilder(HISTORIC_ACTIVITY_INSTANCE_LIST_URL);
    builder.addParameter("processInstanceId", processInstanceId);
    //builder.addParameter("finished", "true");
    builder.addParameter("sort", "startTime");
    builder.addParameter("order", "asc");
    builder.addParameter("size", DEFAULT_ACTIVITY_SIZE);

    HttpGet get = new HttpGet(clientUtil.getServerUrl(serverConfig, builder));
    JsonNode node = clientUtil.executeRequest(get, serverConfig);

    List<String> result = new ArrayList<String>();
    if (node.has("data") && node.get("data").isArray()) {
        ArrayNode data = (ArrayNode) node.get("data");
        ObjectNode activity = null;
        for (int i = 0; i < data.size(); i++) {
            activity = (ObjectNode) data.get(i);
            if (activity.has("activityType")) {
                result.add(activity.get("activityId").asText());
            }//from w w w.ja va2s  .  c  o m
        }
    }

    return result;
}

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

protected void recordFabricInterconnect(Element element) {
    ObjectNode n = toJson(element);

    if (n.path("model").asText().toUpperCase().startsWith("UCS-FI-")) {
        String serial = n.get("serial").asText();
        String mercatorId = Hashing.sha1().hashString(serial, Charsets.UTF_8).toString();
        n.put("mercatorId", mercatorId);

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

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

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

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

    }//from  w  ww.ja  v a2s  .  co  m
}

From source file:io.coala.eve3.Eve3Config.java

default AgentBuilderConfig forAgent(final LocalId localId, final Map<?, ?>... imports) {
    // default: servlet context is root ancestor of (recursive) local id
    String context = "/agents";
    String id = "";
    for (LocalId i = localId; i.parentRef() != null; i = i.parentRef()) {
        if (i.parentRef() != null && i.parentRef().parentRef() == null)
            context += "/" + i.parentRef();
        id = id.isEmpty() ? i.unwrap().toString() : i.unwrap().toString() + LocalId.ID_SEP_REGEX + id;
    }//w ww  .  j  a  v a 2 s  .  co m
    final Map<String, String> map = new HashMap<>();
    map.put(LocalConfig.ID_KEY, id);
    map.put(DefaultAgentBuilderConfig.HTTP_CONTEXT_KEY, context);

    // FIXME add default servlet context with links to each agent's GUI

    // start agent transports
    final DefaultAgentBuilderConfig defaults = ConfigFactory.create(DefaultAgentBuilderConfig.class,
            ConfigUtil.join(map, imports));
    // try agent with given id
    for (Map.Entry<String, AgentBuilderConfig> entry : agentConfigs(imports).entrySet()) {
        final ObjectNode agentConfig = (ObjectNode) entry.getValue().toJSON();
        // match (local) agent id
        if (!id.equals(agentConfig.get(AgentBuilderConfig.ID_KEY).asText()))
            continue;
        // expand 'extends' from templates
        if (agentConfig.has(AgentBuilderConfig.EXTENDS_KEY)) {
            final String tplName = agentConfig.get(AgentBuilderConfig.EXTENDS_KEY).asText();
            final AgentBuilderConfig tpl = templateConfigs(imports).get(tplName);
            if (tpl == null)
                getLogger().warn("Missing template '{}' for agent '{}'", tplName, id);
            copyMissing(tpl.toJSON(), agentConfig);
        }
        // add missing defaults
        copyMissing(defaults.toJSON(), agentConfig);
        return ConfigFactory.create(AgentBuilderConfig.class, ConfigUtil.flatten(agentConfig));
    }
    // no agent config, try template with given id
    final AgentBuilderConfig tpl = templateConfigs(imports).get(id);
    if (tpl != null) {
        getLogger().trace("Using template for agent '{}'", id, id);
        final ObjectNode agentConfig = (ObjectNode) tpl.toJSON();
        copyMissing(defaults.toJSON(), agentConfig);
        return ConfigFactory.create(AgentBuilderConfig.class, ConfigUtil.flatten(agentConfig));
    }
    // no agent or template of given id, return defaults
    getLogger().trace("Using defaults for agent '{}'", id);
    return defaults;
}

From source file:org.gitana.platform.client.plan.PlanImpl.java

private String _getString(String objectFieldId, String fieldId) {
    String value = null;/*from www  . j  a v  a 2 s. co  m*/

    ObjectNode object = getObject(objectFieldId);
    if (object != null && object.has(fieldId)) {
        value = object.get(fieldId).textValue();
    }

    return value;
}

From source file:org.gitana.platform.client.plan.PlanImpl.java

private int _getInt(String objectFieldId, String fieldId) {
    int value = -1;

    ObjectNode object = getObject(objectFieldId);
    if (object != null && object.has(fieldId)) {
        value = object.get(fieldId).intValue();
    }/*from  w w w  . ja  v  a  2 s. c o  m*/

    return value;
}

From source file:org.gitana.platform.client.plan.PlanImpl.java

private boolean _getBoolean(String objectFieldId, String fieldId) {
    boolean value = false;

    ObjectNode object = getObject(objectFieldId);
    if (object != null && object.has(fieldId)) {
        value = object.get(fieldId).booleanValue();
    }/*from www. j  av  a2 s.  c  o  m*/

    return value;
}

From source file:org.gitana.platform.client.plan.PlanImpl.java

private long _getLong(String objectFieldId, String fieldId) {
    long value = -1;

    ObjectNode object = getObject(objectFieldId);
    if (object != null && object.has(fieldId)) {
        value = object.get(fieldId).longValue();
    }/*from   w w  w  . j av  a  2 s .  c o  m*/

    return value;
}

From source file:de.thingweb.servient.MultiThingTests.java

@Test
public void multiThingServient() throws Exception {
    int nthings = 10;
    Thing[] things = new Thing[nthings];

    Action testAction = Action.getBuilder("testAction").build();
    Property testProp = Property.getBuilder("testProp").setWriteable(true).setValueType("xsd:string").build();

    for (int i = 0; i < nthings; i++) {
        things[i] = new Thing("thing" + i);
        things[i].addAction(testAction);
        things[i].addProperty(testProp);
        server.addThing(things[i]);//from   w  ww  .j  a va2s  .  c  om
    }

    ServientBuilder.start();

    JsonNode jsonNode = jsonMapper.readTree(new URL("http://localhost:8080/things/"));
    assertThat("should be an object", jsonNode.isObject(), is(true));

    final ObjectNode repo = (ObjectNode) jsonNode;

    assertThat("expected at least the same number of links under /things as things", repo.size(),
            greaterThanOrEqualTo(nthings));

    Arrays.stream(things).forEach(thing -> assertThat("should contain all things, misses " + thing.getName(),
            repo.get(thing.getName()), notNullValue()));

    //further checks
}

From source file:com.msopentech.odatajclient.engine.data.json.JSONPropertyDeserializer.java

@Override
protected JSONProperty doDeserializeV3(final JsonParser parser, final DeserializationContext ctxt)
        throws IOException, JsonProcessingException {

    final ObjectNode tree = (ObjectNode) parser.getCodec().readTree(parser);

    final JSONProperty property = new JSONProperty();

    if (tree.hasNonNull(ODataConstants.JSON_METADATA)) {
        property.setMetadata(URI.create(tree.get(ODataConstants.JSON_METADATA).textValue()));
        tree.remove(ODataConstants.JSON_METADATA);
    }//  w  ww . ja v a 2s  .com

    try {
        final DocumentBuilder builder = ODataConstants.DOC_BUILDER_FACTORY.newDocumentBuilder();
        final Document document = builder.newDocument();

        Element content = document.createElement(ODataConstants.ELEM_PROPERTY);

        if (property.getMetadata() != null) {
            final String metadataURI = property.getMetadata().toASCIIString();
            final int dashIdx = metadataURI.lastIndexOf('#');
            if (dashIdx != -1) {
                content.setAttribute(ODataConstants.ATTR_M_TYPE, metadataURI.substring(dashIdx + 1));
            }
        }

        JsonNode subtree = null;
        if (tree.has(ODataConstants.JSON_VALUE)) {
            if (tree.has(ODataConstants.JSON_TYPE)
                    && StringUtils.isBlank(content.getAttribute(ODataConstants.ATTR_M_TYPE))) {

                content.setAttribute(ODataConstants.ATTR_M_TYPE, tree.get(ODataConstants.JSON_TYPE).asText());
            }

            final JsonNode value = tree.get(ODataConstants.JSON_VALUE);
            if (value.isValueNode()) {
                content.appendChild(document.createTextNode(value.asText()));
            } else if (EdmSimpleType.isGeospatial(content.getAttribute(ODataConstants.ATTR_M_TYPE))) {
                subtree = tree.objectNode();
                ((ObjectNode) subtree).put(ODataConstants.JSON_VALUE, tree.get(ODataConstants.JSON_VALUE));
                if (StringUtils.isNotBlank(content.getAttribute(ODataConstants.ATTR_M_TYPE))) {
                    ((ObjectNode) subtree).put(ODataConstants.JSON_VALUE + "@" + ODataConstants.JSON_TYPE,
                            content.getAttribute(ODataConstants.ATTR_M_TYPE));
                }
            } else {
                subtree = tree.get(ODataConstants.JSON_VALUE);
            }
        } else {
            subtree = tree;
        }

        if (subtree != null) {
            DOMTreeUtilsV3.buildSubtree(content, subtree);
        }

        final List<Node> children = XMLUtils.getChildNodes(content, Node.ELEMENT_NODE);
        if (children.size() == 1) {
            final Element value = (Element) children.iterator().next();
            if (ODataConstants.JSON_VALUE.equals(XMLUtils.getSimpleName(value))) {
                if (StringUtils.isNotBlank(content.getAttribute(ODataConstants.ATTR_M_TYPE))) {
                    value.setAttribute(ODataConstants.ATTR_M_TYPE,
                            content.getAttribute(ODataConstants.ATTR_M_TYPE));
                }
                content = value;
            }
        }

        property.setContent(content);
    } catch (ParserConfigurationException e) {
        throw new JsonParseException("Cannot build property", parser.getCurrentLocation(), e);
    }

    return property;
}

From source file:com.baasbox.commands.LinksResource.java

@Override
protected JsonNode get(JsonNode command) throws CommandException {
    validateHasParams(command);//from  w ww  .jav a  2s .  c om
    String id = getLinkId(command);
    ODocument link = LinkService.getLink(id);
    if (link == null)
        return null;
    ObjectNode node = null;
    String s = JSONFormats.prepareDocToJson(link, JSONFormats.Formats.LINK);
    try {
        node = (ObjectNode) Json.mapper().readTree(s);
        node.remove(TO_REMOVE).remove("@rid");
        ((ObjectNode) node.get("in")).remove(TO_REMOVE).remove("@rid");
        ((ObjectNode) node.get("out")).remove(TO_REMOVE).remove("@rid");
    } catch (IOException e) {
        throw new CommandExecutionException(command, "error executing command: " + ExceptionUtils.getMessage(e),
                e);
    }
    return node;
}