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

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

Introduction

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

Prototype

public ObjectNode put(String paramString1, String paramString2) 

Source Link

Usage

From source file:com.almende.eve.test.TestConfigDOM.java

/**
 * Test agents from DOM./*from  ww w.  j  a v  a  2 s  . c o  m*/
 * 
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
@Test
public void testDOM() throws IOException {
    // First obtain the configuration:
    final Config config = YamlReader.load(new FileInputStream(new File("target/classes/test.yaml")));

    config.loadTemplates("templates");

    final ArrayNode agents = (ArrayNode) config.get("agents");
    ExampleAgent newAgent = null;
    for (final JsonNode agent : agents) {
        newAgent = (ExampleAgent) new AgentBuilder().with((ObjectNode) agent).build();
        LOG.info("Created agent:" + newAgent.getId());
    }
    final ObjectNode params = JOM.createObjectNode();
    params.put("message", "Hi There!");
    newAgent.pubSend(URIUtil.create("local:example"), "helloWorld", params, new AsyncCallback<String>() {

        @Override
        public void onSuccess(final String result) {
            LOG.warning("Received:'" + result + "'");
        }

        @Override
        public void onFailure(final Exception exception) {
            LOG.log(Level.SEVERE, "", exception);
            fail();
        }

    });

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
    }

    LOG.warning("Agent config:" + newAgent.getConfig());
}

From source file:com.redhat.lightblue.rest.metadata.hystrix.GetEntityVersionsCommand.java

@Override
protected String run() {
    LOGGER.debug("run: entity={}", entity);
    Error.reset();/*w w  w. j  av  a2s  .  co  m*/
    Error.push(getClass().getSimpleName());
    try {
        VersionInfo[] versions = getMetadata().getEntityVersions(entity);
        ArrayNode arr = NODE_FACTORY.arrayNode();

        for (VersionInfo x : versions) {
            ObjectNode obj = NODE_FACTORY.objectNode();
            obj.put("version", x.getValue());
            obj.put("changelog", x.getChangelog());
            ArrayNode ev = NODE_FACTORY.arrayNode();
            if (x.getExtendsVersions() != null) {
                for (String v : x.getExtendsVersions()) {
                    ev.add(NODE_FACTORY.textNode(v));
                }
            }
            obj.set("extendsVersions", ev);
            obj.put("status", MetadataParser.toString(x.getStatus()));
            obj.put("defaultVersion", x.isDefault());
            arr.add(obj);
        }
        return arr.toString();
    } catch (Error e) {
        return e.toString();
    } catch (Exception e) {
        LOGGER.error("Failure: {}", e);
        return Error.get(RestMetadataConstants.ERR_REST_ERROR, e.toString()).toString();
    }
}

From source file:com.rusticisoftware.tincan.Activity.java

@Override
public ObjectNode toJSONNode(TCAPIVersion version) {
    ObjectNode node = Mapper.getInstance().createObjectNode();
    node.put("objectType", this.getObjectType());

    if (this.id != null) {
        node.put("id", this.getId().toString());
    }//  w  ww  .ja v  a2  s.  co m
    if (this.definition != null) {
        node.put("definition", this.getDefinition().toJSONNode());
    }

    return node;
}

From source file:controllers.api.v1.Dataset.java

public static Result createLogicalDatasetFile(Long datasetId) {
    ObjectNode result = Json.newObject();
    // String username = session("user");
    Map<String, String[]> params = request().body().asFormUrlEncoded();
    //if (StringUtils.isNotBlank(username)) {
    String errorMsg = DatasetsDAO.createLogicalDatasetFile(datasetId, params);
    if (errorMsg.startsWith("success:")) {
        result.put("status", "success");
        Integer id = Integer.parseInt(errorMsg.split(":")[1]);
        result.put("id", id);
    } else {/*from  ww  w  .j  a v  a 2  s  .  com*/
        result.put("status", "failed");
        result.put("msg", errorMsg);
    }
    /*} else {
    result.put("status", "failed");
    result.put("msg", "Authentication Required");
    }*/
    return ok(result);
}

From source file:com.almende.eve.test.TestDelete.java

/**
 * Test agents./*w  ww  .  ja v a2  s .  c  om*/
 * 
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 * @throws URISyntaxException
 *             the URI syntax exception
 * @throws InterruptedException
 *             the interrupted exception
 */
@Test
public void testDelete() throws IOException, URISyntaxException, InterruptedException {

    HttpTransportConfig transportConfig = new HttpTransportConfig();
    transportConfig.setServletUrl("http://localhost:8080/agents/");

    transportConfig.setServletLauncher("JettyLauncher");
    ObjectNode jettyParms = JOM.createObjectNode();
    jettyParms.put("port", 8080);
    transportConfig.set("jetty", jettyParms);

    AgentConfig config = new AgentConfig("example");
    config.addTransport(transportConfig);

    ExampleAgent agent = new ExampleAgent();
    agent.setConfig(config);

    transportConfig = null;
    config = null;

    WeakReference<Agent> test = new WeakReference<Agent>(agent);
    agent.destroy();
    agent = null;

    System.gc();
    System.gc();
    try {
        Thread.sleep(1000);
    } catch (final InterruptedException e) {
    }
    System.gc();
    System.gc();

    assertNull(test.get());

    //      LOG.warning("Sleeping for profiler connection.");
    //      try {
    //         Thread.sleep(20000);
    //      } catch (final InterruptedException e) {}
}

From source file:com.stratio.ingestion.sink.druid.EventParserTest.java

private Event createEvent(String index) {
    ObjectNode jsonBody = new ObjectNode(JsonNodeFactory.instance);
    jsonBody.put("field1" + index, "foo");
    jsonBody.put("field2" + index, 32);

    Map<String, String> headers = new HashMap<String, String>();
    headers.put("header1" + index, "bar");
    headers.put("header2" + index, "64");
    headers.put("header3" + index, "true");
    headers.put("header4" + index, "1.0");
    headers.put("header5" + index, null);

    return EventBuilder.withBody(jsonBody.toString().getBytes(Charsets.UTF_8), headers);
}

From source file:net.sf.taverna.t2.activities.rshell.servicedescriptions.RshellTemplateService.java

@Override
public Configuration getActivityConfiguration() {
    Configuration configuration = new Configuration();
    configuration.setType(ACTIVITY_TYPE.resolve("#Config"));
    ObjectNode json = (ObjectNode) configuration.getJson();
    json.put("script", "");

    ObjectNode connection = json.objectNode();
    connection.put("hostname", DEFAULT_HOST);
    connection.put("port", DEFAULT_PORT);
    connection.put("keepSessionAlive", DEFAULT_KEEP_SESSION_ALIVE);
    json.put("connection", connection);
    return configuration;
}

From source file:com.github.fge.jsonschema.syntax.checkers.AbstractSyntaxCheckerTest.java

@Test(dataProvider = "validTypes")
public void syntaxCheckingSucceedsOnValidTypes(final JsonNode node) throws ProcessingException {
    final AbstractSyntaxChecker checker = spy(new DummyChecker());
    final ProcessingReport report = mock(ProcessingReport.class);
    final ObjectNode schema = FACTORY.objectNode();
    schema.put(KEYWORD, node);
    final SchemaTree tree = new CanonicalSchemaTree(schema);

    checker.checkSyntax(null, report, tree);
    verify(checker).checkValue(null, report, tree);
    verify(report, never()).error(anyMessage());
}

From source file:de.petendi.ethereum.secure.proxy.JsonRpcRequestListener.java

@Override
public void onBeforeRequestSent(JsonRpcClient jsonRpcClient, ObjectNode objectNode) {
    int id = Integer.valueOf(objectNode.get(ID).asText());
    objectNode.remove(ID);/* w  ww . ja v  a 2s.  co  m*/
    objectNode.put(ID, id);
}

From source file:org.activiti.rest.service.api.legacy.deployment.DeploymentArtifactsResource.java

@Get
public ObjectNode getDeploymentArtifacts() {
    if (authenticate() == false)
        return null;

    String deploymentId = (String) getRequest().getAttributes().get("deploymentId");

    if (deploymentId == null) {
        throw new ActivitiIllegalArgumentException("No deployment id provided");
    }/*from  w  w  w. java 2  s .  c om*/

    Deployment deployment = ActivitiUtil.getRepositoryService().createDeploymentQuery()
            .deploymentId(deploymentId).singleResult();
    List<String> resourceList = ActivitiUtil.getRepositoryService().getDeploymentResourceNames(deploymentId);

    ObjectNode responseJSON = new ObjectMapper().createObjectNode();
    responseJSON.put("id", deployment.getId());
    responseJSON.put("name", deployment.getName());
    responseJSON.put("deploymentTime", RequestUtil.dateToString(deployment.getDeploymentTime()));
    responseJSON.put("category", deployment.getCategory());

    ArrayNode resourceArray = new ObjectMapper().createArrayNode();

    for (String resourceName : resourceList) {
        resourceArray.add(resourceName);
    }

    responseJSON.put("resources", resourceArray);

    return responseJSON;
}