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.apache.taverna.scufl2.translator.t2flow.t23activities.TestXPathActivityParser.java

@Test
public void parseXPathActivityWorkflow() throws Exception {
    URL wfResource = getClass().getResource(XPATH_WORKFLOW_SANS_EXAMPLE_XML);
    assertNotNull("Could not find workflow " + XPATH_WORKFLOW_SANS_EXAMPLE_XML, wfResource);
    T2FlowParser parser = new T2FlowParser();
    parser.setStrict(false);/*from  w w  w .jav  a 2s  .  c  om*/
    WorkflowBundle wfBundle = parser.parseT2Flow(wfResource.openStream());
    Profile profile = wfBundle.getMainProfile();
    //XPath_height has missing xmlDocument from its configuration
    Processor heightProc = wfBundle.getMainWorkflow().getProcessors().getByName("XPath_height");
    ObjectNode heightConfig = scufl2Tools.configurationForActivityBoundToProcessor(heightProc, profile)
            .getJsonAsObjectNode();
    assertNotNull(heightConfig);
    assertEquals("//height/text()", heightConfig.get("xpathExpression").textValue());
    assertFalse(heightConfig.has("exampleXmlDocument"));
    //XPath_width has xmlDocument
    Processor widthProc = wfBundle.getMainWorkflow().getProcessors().getByName("XPath_width");
    ObjectNode widthConfig = scufl2Tools.configurationForActivityBoundToProcessor(widthProc, profile)
            .getJsonAsObjectNode();
    assertNotNull(widthConfig);
    assertEquals("//width/text()", widthConfig.get("xpathExpression").asText());
    assertTrue(widthConfig.has("exampleXmlDocument"));
}

From source file:com.squarespace.template.ReferenceScannerTest.java

@Test
public void testAlternates() throws CodeException {
    ObjectNode result = scan("{.odd? a}{a}{.or}{b}{.end}{.repeated section c}{.alternates with}{d}{.end}");
    render(result);//from ww  w  . j a  v a 2 s .  c o  m

    ObjectNode vars = (ObjectNode) result.get("variables");
    assertTrue(vars.get("a").isNull());
    assertTrue(vars.get("b").isNull());
    assertTrue(vars.get("c").isObject());
    assertEquals(((ObjectNode) vars.get("c")).size(), 1);
    assertTrue(vars.get("c").get("d").isNull());
}

From source file:org.apache.streams.rss.provider.RssStreamProviderTask.java

/**
 * Returns a link to the article to use as the id
 * @param node//from ww  w . j  a  va 2s.com
 * @return
 */
private String determineId(ObjectNode node) {
    String id = null;
    if (node.get(URI_KEY) != null && !node.get(URI_KEY).textValue().equals("")) {
        id = node.get(URI_KEY).textValue();
    } else if (node.get(LINK_KEY) != null && !node.get(LINK_KEY).textValue().equals("")) {
        id = node.get(LINK_KEY).textValue();
    }
    return id;
}

From source file:io.syndesis.connector.catalog.ConnectorCatalog.java

private String extractJavaType(String json) {
    try {/*from  www . j a va 2 s .c om*/
        ObjectNode node = (ObjectNode) new ObjectMapper().readTree(json);
        JsonNode c = node.get("component");
        if (c != null) {
            JsonNode ret = c.get("javaType");
            if (ret != null) {
                return ret.asText();
            }
        }
        return null;
    } catch (IOException e) {
        return null;
    }
}

From source file:models.ConnectionContext.java

/**
 * {@inheritDoc}//w  w  w  . ja  v  a  2  s .c  o m
 */
@Override
public void onReceive(final Object message) throws Exception {
    if (Logger.isTraceEnabled()) {
        Logger.trace(
                String.format("Received message on channel; message=%s, channel=%s", message, _connection));
    }
    if ("instrument".equals(message)) {
        periodicInstrumentation();
        return;
    }

    boolean messageProcessed = false;
    for (final MessagesProcessor messagesProcessor : _messageProcessors) {
        messageProcessed = messagesProcessor.handleMessage(message);
        if (messageProcessed) {
            break;
        }
    }
    if (!messageProcessed) {
        _metrics.incrementCounter(UNKNOWN_COUNTER);
        if (message instanceof Command) {
            _metrics.incrementCounter(UNKONOWN_COMMAND_COUNTER);
            final Command command = (Command) message;
            final ObjectNode commandNode = (ObjectNode) command.getCommand();
            final String commandString = commandNode.get("command").asText();
            Logger.warn(String.format("channel command unsupported; command=%s, channel=%s", commandString,
                    _connection));
            unhandled(message);
        } else {
            Logger.warn(String.format("Unsupported message; message=%s", message));
            unhandled(message);
        }
    }
}

From source file:org.openremote.server.inventory.DeviceLibraryService.java

protected boolean isTrue(ObjectNode properties, String propertyName) {
    return properties.has(propertyName) && properties.get(propertyName).asBoolean();
}

From source file:com.amediamanager.scheduled.ElasticTranscoderTasks.java

protected void handleMessage(final Message message) {
    try {//from   ww w.jav a2s.c om
        LOG.info("Handling message received from checkStatus");
        ObjectNode snsMessage = (ObjectNode) mapper.readTree(message.getBody());
        ObjectNode notification = (ObjectNode) mapper.readTree(snsMessage.get("Message").asText());
        String state = notification.get("state").asText();
        String jobId = notification.get("jobId").asText();
        String pipelineId = notification.get("pipelineId").asText();
        Video video = videoService.findByTranscodeJobId(jobId);
        if (video == null) {
            LOG.warn("Unable to process result for job {} because it does not exist.", jobId);
            Instant msgTime = Instant.parse(snsMessage.get("Timestamp").asText());
            if (Minutes.minutesBetween(msgTime, new Instant()).getMinutes() > 20) {
                LOG.error("Job {} has not been found for over 20 minutes, deleting message from queue", jobId);
                deleteMessage(message);
            }
            // Leave it on the queue for now.
            return;
        }
        if ("ERROR".equals(state)) {
            LOG.warn("Job {} for pipeline {} failed to complete. Body: \n{}", jobId, pipelineId,
                    notification.get("messageDetails").asText());
            video.setThumbnailKey(videoService.getDefaultVideoPosterKey());
            videoService.save(video);
        } else {
            // Construct our url prefix: https://bucketname.s3.amazonaws.com/output/key/
            String prefix = notification.get("outputKeyPrefix").asText();
            if (!prefix.endsWith("/")) {
                prefix += "/";
            }

            ObjectNode output = ((ObjectNode) ((ArrayNode) notification.get("outputs")).get(0));
            String previewFilename = prefix + output.get("key").asText();
            String thumbnailFilename = prefix
                    + output.get("thumbnailPattern").asText().replaceAll("\\{count\\}", "00002") + ".png";
            video.setPreviewKey(previewFilename);
            video.setThumbnailKey(thumbnailFilename);
            videoService.save(video);
        }
        deleteMessage(message);
    } catch (JsonProcessingException e) {
        LOG.error("JSON exception handling notification: {}", message.getBody(), e);
    } catch (IOException e) {
        LOG.error("IOException handling notification: {}", message.getBody(), e);
    }
}

From source file:com.almende.eve.transport.http.embed.JettyLauncher.java

/**
 * Inits the server.//w w w  .j ava 2  s .c om
 *
 * @param params
 *            the params
 * @throws ServletException
 *             the servlet exception
 */
public void initServer(final ObjectNode params) throws ServletException {
    int port = 8080;
    if (params != null && params.has("port")) {
        port = params.get("port").asInt();
    }
    server = new Server(port);
    context = new ServletContextHandler(ServletContextHandler.SESSIONS | ServletContextHandler.NO_SECURITY);

    context.setContextPath("/");
    server.setHandler(context);
    wscontainer = WebSocketServerContainerInitializer.configureContext(context);

    if (params != null && params.has("cors")) {
        String corsClass = "com.thetransactioncompany.cors.CORSFilter";
        if (params.get("cors").has("class")) {
            corsClass = params.get("cors").get("class").asText();
        }
        String corsPath = "/*";
        if (params.get("cors").has("path")) {
            corsPath = params.get("cors").get("path").asText();
        }
        addFilter(corsClass, corsPath);
    }

    try {
        server.start();
    } catch (final Exception e) {
        LOG.log(Level.SEVERE, "Couldn't start embedded Jetty server!", e);
    }

}

From source file:es.bsc.amon.controller.EventsDBMapper.java

public ObjectNode storeEvent(ObjectNode event) {
    long timestamp = System.currentTimeMillis();

    if (event.get(EventsDBMapper.TIMESTAMP) == null) {
        event.put(EventsDBMapper.TIMESTAMP, timestamp);
    } else {//from  www.j ava 2s . c om
        timestamp = event.get(EventsDBMapper.TIMESTAMP).asLong();
    }

    DBObject dbo = (DBObject) JSON.parse(event.toString());

    if (dbo.get(ENDTIME) == null) {
        dbo.put(ENDTIME, -1L);
    }
    colEvents.save(dbo);

    // return stored id and timestamp
    ObjectNode on = new ObjectNode(JsonNodeFactory.instance);
    on.put(_ID, dbo.get(_ID).toString());
    on.put(TIMESTAMP, timestamp);

    return on;
}

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

@Test
public void parseSimpleTell() throws Exception {
    WorkflowBundle researchObj = parseWorkflow(WF_SIMPLE_TELL);

    NamedSet<Profile> profiles = researchObj.getProfiles();
    Profile profile = profiles.getByName("taverna-biodiversity-2.5.0");
    assertNotNull("Could not find profile", profile);

    Processor tell = researchObj.getMainWorkflow().getProcessors().getByName("tell");
    assertNotNull("Could not find processor tell", tell);

    Configuration tellConfig = scufl2Tools.configurationForActivityBoundToProcessor(tell, profile);

    Activity tellAct = (Activity) tellConfig.getConfigures();
    assertEquals(ACTIVITY_URI, tellAct.getType());

    ObjectNode tellResource = tellConfig.getJsonAsObjectNode();
    assertEquals(ACTIVITY_URI.resolve("#Config"), tellConfig.getType());

    String presentationOrigin = tellResource.get("presentationOrigin").textValue();
    assertEquals("tell", presentationOrigin);

    String interactionActivityType = tellResource.get("interactionActivityType").textValue();
    assertEquals("VelocityTemplate", interactionActivityType);

    boolean progressNotification = tellResource.get("progressNotification").booleanValue();
    assertFalse(progressNotification);/*from   w  w w  . j a  v  a2s .  co m*/
}