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:io.amient.kafka.metrics.Dashboard.java

public ObjectNode get(ObjectNode node, String fieldName) {
    return (ObjectNode) node.get(fieldName);
}

From source file:org.onosproject.sse.SseTopologyResource.java

private void addGeoData(ArrayNode array, String idField, String id, ObjectNode memento) {
    ObjectNode node = mapper.createObjectNode().put(idField, id);
    ObjectNode annot = mapper.createObjectNode();
    node.set("annotations", annot);
    try {//from  w ww  .  j a va 2 s.c  o m
        annot.put("latitude", memento.get("lat").asDouble()).put("longitude", memento.get("lng").asDouble());
        array.add(node);
    } catch (Exception e) {
        log.debug("Skipping geo entry");
    }
}

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

@Test
public void testTenantTeams() {
    /////////////////////////////////////////////////////////////////////////////////////////////
    //// w w w  .j a v  a  2  s  . co m
    // authenticate as ADMIN
    //

    Gitana gitana = new Gitana();

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

    // create user #1
    DomainUser user1 = platform.readDomain("default").createUser("user1-" + System.currentTimeMillis(), "pw");
    // create user #2
    DomainUser user2 = platform.readDomain("default").createUser("user1-" + System.currentTimeMillis(), "pw");

    // default registrar
    Registrar registrar = platform.readRegistrar("default");

    // create a tenant for user #1
    Tenant tenant1 = registrar.createTenant(user1, "unlimited");

    // create a tenant for user #2
    Tenant tenant2 = registrar.createTenant(user2, "unlimited");

    // verify that user1's identity has multiple users (user1 in default and user1prime in tenant1 domain)
    ResultMap<ObjectNode> userObjects = user1.readIdentity().findPolicyUserObjects();
    assertEquals(2, userObjects.size());

    // verify we can find tenants with this user
    ResultMap<ObjectNode> tenantObjects = user1.readIdentity().findPolicyTenantObjects(registrar);
    assertEquals(1, tenantObjects.size());

    // verify we can pick out the account this user has on tenant1
    ObjectNode foundTenantObject = tenantObjects.values().iterator().next();
    assertEquals(tenant1.getId(), foundTenantObject.get(Tenant.FIELD_ID).textValue());
    ObjectNode user1inTenant1Object = user1.readIdentity()
            .findPolicyUserObjectForTenant(foundTenantObject.get(Tenant.FIELD_ID).textValue());
    assertNotNull(user1inTenant1Object);
    assertNotNull(userObjects.get(user1inTenant1Object.get(Tenant.FIELD_ID).textValue()));

    // user1 has two identities right now
    userObjects = user1.readIdentity().findPolicyUserObjects();
    assertEquals(2, userObjects.size());

    /////////////////////////////////////////////////////////////////////////////////////////////
    //
    // authenticate as USER 2 (to tenant2)
    //

    // now sign into the tenant
    ObjectNode defaultClientObject2 = tenant2.readDefaultAllocatedClientObject();
    assertNotNull(defaultClientObject2);
    String clientKey2 = JsonUtil.objectGetString(defaultClientObject2, Client.FIELD_KEY);
    String clientSecret2 = JsonUtil.objectGetString(defaultClientObject2, Client.FIELD_SECRET);
    gitana = new Gitana(clientKey2, clientSecret2);
    platform = gitana.authenticateOnTenant(user2, "pw", tenant2.getId());

    // invite user 1 into user2's default domain
    DomainUser user1inTenant2 = platform.readPrimaryDomain().inviteUser(user1);

    /////////////////////////////////////////////////////////////////////////////////////////////
    //
    // authenticate as ADMIN
    //

    gitana = new Gitana();
    platform = gitana.authenticate("admin", "admin");

    // verify that user1's identity has multiple users (user1 in default, user1prime1 in tenant1 domain, user1prime2 in tenant2 domain)
    userObjects = user1.readIdentity().findPolicyUserObjects();
    assertEquals(3, userObjects.size());

    // verify we can find tenants with this user
    tenantObjects = user1.readIdentity().findPolicyTenantObjects(registrar);
    assertEquals(2, tenantObjects.size());

    // verify we can pick out the account this user has on tenant1
    ObjectNode userObject1inTenant1check = user1.readIdentity().findPolicyUserObjectForTenant(tenant1.getId());
    assertNotNull(userObject1inTenant1check);
    assertNotNull(userObjects.get(userObject1inTenant1check.get(DomainUser.FIELD_ID).textValue()));
    ObjectNode userObject1inTenant2check = user1.readIdentity().findPolicyUserObjectForTenant(tenant2.getId());
    assertNotNull(userObject1inTenant2check);
    assertNotNull(userObjects.get(userObject1inTenant2check.get(DomainUser.FIELD_ID).textValue()));

}

From source file:com.googlecode.jsonrpc4j.DefaultExceptionResolver.java

/**
 * {@inheritDoc}/*w  w  w .j  a v a2  s.c om*/
 */
public Throwable resolveException(ObjectNode response) {

    // get the error object
    ObjectNode errorObject = ObjectNode.class.cast(response.get("error"));

    // bail if we don't have a data object
    if (!errorObject.has("data") || errorObject.get("data").isNull() || !errorObject.get("data").isObject()) {
        return createJsonRpcClientException(errorObject);
    }

    // get the data object
    ObjectNode dataObject = ObjectNode.class.cast(errorObject.get("data"));

    // bail if it's not the expected format
    if (!dataObject.has("exceptionTypeName") || dataObject.get("exceptionTypeName") == null
            || dataObject.get("exceptionTypeName").isNull()
            || !dataObject.get("exceptionTypeName").isTextual()) {
        return createJsonRpcClientException(errorObject);
    }

    // get values
    String exceptionTypeName = dataObject.get("exceptionTypeName").asText();
    String message = dataObject.has("message") && dataObject.get("message").isTextual()
            ? dataObject.get("message").asText()
            : null;

    // create it
    Throwable ret = null;
    try {
        ret = createThrowable(exceptionTypeName, message);
    } catch (Exception e) {
        LOGGER.log(Level.WARNING, "Unable to create throwable", e);
    }

    // if we can't create it, create a default exception
    if (ret == null) {
        ret = createJsonRpcClientException(errorObject);
    }

    // return it
    return ret;
}

From source file:org.apache.taverna.scufl2.translator.t2flow.TestSpreadsheetActivityParser.java

@Test
public void parseSpreadsheetWorkflow() throws Exception {
    URL wfResource = getClass().getResource(SPREADSHEET_WF_WITH_DEFAULTS);
    assertNotNull("Could not find workflow " + SPREADSHEET_WF_WITH_DEFAULTS, wfResource);
    T2FlowParser parser = new T2FlowParser();
    parser.setValidating(true);// ww w .  j  ava 2s  . com
    parser.setStrict(true);
    WorkflowBundle wfBundle = parser.parseT2Flow(wfResource.openStream());
    Profile profile = wfBundle.getMainProfile();
    Processor proc = wfBundle.getMainWorkflow().getProcessors().getByName("SpreadsheetImport");
    ObjectNode config = scufl2Tools.configurationForActivityBoundToProcessor(proc, profile)
            .getJsonAsObjectNode();
    assertNotNull(config);
    //       System.out.println(config);
    assertEquals(0, config.get("columnRange").get("start").asInt());
    assertEquals(1, config.get("columnRange").get("end").asInt());

    assertEquals(0, config.get("rowRange").get("start").asInt());
    assertEquals(-1, config.get("rowRange").get("end").asInt());
    assertEquals("", config.get("emptyCellValue").asText());
    assertEquals("EMPTY_STRING", config.get("emptyCellPolicy").asText());
    assertTrue(config.get("allRows").asBoolean());
    assertFalse(config.get("excludeFirstRow").asBoolean());
    assertTrue(config.get("ignoreBlankRows").asBoolean());
    assertFalse(config.has("outputFormat"));
    assertFalse(config.has("csvDelimiter"));
}

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

/**
 * Check if the given <code>fieldName</code> has an empty or null value.
 * //from ww  w  .  j ava 2  s  .c o m
 * @param fieldName
 *            The field name to check.
 * @param response
 *            The response to check.
 * @return <code>true</code> if the <code>fieldName</code> has an empty or
 *         null value.
 */
public boolean isFieldNullOrEmpty(String fieldName, ObjectNode response) {
    return (response.get(fieldName) == null || response.get(fieldName).isNull());
}

From source file:com.almende.eve.transport.pubnub.PubNubTransport.java

private void subscribe() throws PubnubException {
    LOG.warning("pubnub subscribe to:" + myChannel);
    final Handler<Receiver> handler = super.getHandle();
    pubnub.subscribe(myChannel, new Callback() {

        @Override//  www .j  a  v  a 2  s  .  c om
        public void connectCallback(String channel, Object message) {
            LOG.fine("SUBSCRIBE : CONNECT on channel:" + channel + " : " + message.getClass() + " : "
                    + message.toString());
        }

        @Override
        public void disconnectCallback(String channel, Object message) {
            LOG.fine("SUBSCRIBE : DISCONNECT on channel:" + channel + " : " + message.getClass() + " : "
                    + message.toString());
        }

        public void reconnectCallback(String channel, Object message) {
            LOG.fine("SUBSCRIBE : RECONNECT on channel:" + channel + " : " + message.getClass() + " : "
                    + message.toString());
        }

        @Override
        public void successCallback(String channel, Object message) {
            LOG.fine("SUBSCRIBE : " + channel + " : " + message.getClass() + " : " + message.toString());
            // Received a message!
            if (message.toString().equals("")) {
                LOG.warning("received empty message!");
                return;
            }
            if (message.toString().startsWith("{")) {
                ObjectNode msg = JOM.getInstance().valueToTree(message);
                if (myChannel.equals(msg.get("to").asText())) {
                    handler.get().receive(msg.get("message").asText(),
                            URIUtil.create("pubnub:" + msg.get("from").asText()), null);
                } else {
                    LOG.fine("Received message for someone else, ignoring!");
                }
            } else {
                LOG.warning("Received non-json message:" + message);
            }
        }

        @Override
        public void errorCallback(String channel, PubnubError error) {
            LOG.warning("SUBSCRIBE : ERROR on channel " + channel + " : " + error.toString());
        }
    });
}

From source file:org.lendingclub.mercator.dynect.DynectScanner.java

private void scanAllRecordsByZone(List<String> zones) {

    Instant startTime = Instant.now();

    logger.info("Scanning all records in each available zones");

    for (String zone : zones) {
        logger.debug("Scanning all records in Dynect zone {} ", zone);

        ObjectNode response = getDynectClient().get("REST/AllRecord/" + zone);

        JsonNode recordsData = response.path("data");

        if (recordsData.isArray()) {
            recordsData.forEach(record -> {
                String recordFullName = record.asText();

                logger.debug("Scanning {} record for more information in {} zone", recordFullName, zone);
                ObjectNode recordResponse = getDynectClient().get(recordFullName);

                ObjectNode data = toRecordJson(recordResponse.get("data"));
                String recordId = Splitter.on("/").splitToList(recordFullName).get(5);

                String cypher = "MATCH (z:DynHostedZone {zoneName:{zone}})"
                        + "MERGE (m:DynHostedZoneRecord {recordId:{recordId}}) "
                        + "ON CREATE SET  m+={props}, m.createTs = timestamp(), m.updateTs=timestamp() "
                        + "ON MATCH SET m+={props}, m.updateTs=timestamp() " + "MERGE (z)-[:CONTAINS]->(m);";
                getProjector().getNeoRxClient().execCypher(cypher, "recordId", recordId, "props", data, "zone",
                        zone);//from  w w  w. j  a  va  2 s.  co  m
            });
        }
    }

    Instant endTime = Instant.now();
    logger.info("Updating neo4j with the latest information of all records from zones in Dynect took {} secs",
            Duration.between(startTime, endTime).getSeconds());
}

From source file:org.gitana.platform.client.document.DocumentImpl.java

protected void mergePropertyIfExists(ObjectNode source, ObjectNode target, String propertyName) {
    if (source.has(propertyName)) {
        target.put(propertyName, source.get(propertyName));
    }/*  w w w .j  ava 2  s .c o m*/
}

From source file:org.thevortex.lighting.jinks.client.AbstractWinkService.java

/**
 * {@inheritDoc}/* w  w w .  j av  a 2 s . c  o m*/
 * <p>
 * Also initializes listening for events if not already started. This implies the
 * service subscription does not change over the run-time of the application.
 * </p>
 */
@Override
public SortedSet<T> getAll() throws IOException {
    // TODO paginate
    SortedSet<T> result = new TreeSet<>();
    Set<Subscription> itemSubscriptions = new HashSet<>();
    Subscription serviceSubscription = null;

    ObjectNode data = (ObjectNode) client.doGet(ME + endpoint());
    if (data.has("data")) {
        ArrayNode jsonList = (ArrayNode) data.get("data");

        for (JsonNode jsonNode : jsonList) {
            T item = parseItem(jsonNode);
            if (item != null) {
                result.add(item);
                Subscription subscription = item.getSubscription();
                if (subscription != null)
                    itemSubscriptions.add(subscription);
            }
        }
    }

    if (data.has("subscription")) {
        serviceSubscription = WinkClient.MAPPER.convertValue(data.get("subscription"), Subscription.class);
    }

    // if the notifier is enabled, start it up
    if (enableNotify)
        notifier.init(serviceSubscription, itemSubscriptions);
    else if (notifier != null)
        notifier.close();
    return result;
}