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.collective.celos.OozieExternalServiceTest.java

@Test
public void runPropertiesAreCorrectlySetup() {
    ScheduledTime t = new ScheduledTime("2013-11-26T17:23Z");
    SlotID id = new SlotID(new WorkflowID("test"), t);
    ObjectNode defaults = Util.newObjectNode();
    defaults.put("foo", "bar");
    defaults.put("uses-variables", "${year}-${month}-${day}-${hour}-${year}");
    defaults.put("another-one", "${year}-${month}-${day}T${hour}:${minute}:${second}.${millisecond}Z");
    Properties runProperties = makeOozieExternalService().setupRunProperties(defaults, id);
    Assert.assertEquals("bar", runProperties.getProperty("foo"));
    Assert.assertEquals("2013-11-26-17-2013", runProperties.getProperty("uses-variables"));
    Assert.assertEquals("2013-11-26T17:23:00.000Z", runProperties.getProperty("another-one"));
    Assert.assertEquals("2013", runProperties.getProperty(OozieExternalService.YEAR_PROP));
    Assert.assertEquals("11", runProperties.getProperty(OozieExternalService.MONTH_PROP));
    Assert.assertEquals("26", runProperties.getProperty(OozieExternalService.DAY_PROP));
    Assert.assertEquals("17", runProperties.getProperty(OozieExternalService.HOUR_PROP));
    Assert.assertEquals("23", runProperties.getProperty(OozieExternalService.MINUTE_PROP));
    Assert.assertEquals("00", runProperties.getProperty(OozieExternalService.SECOND_PROP));
    Assert.assertEquals("test@2013-11-26T17:23Z",
            runProperties.getProperty(OozieExternalService.WORKFLOW_NAME_PROP));
}

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

@Delete
public ObjectNode deleteDeployment() {
    if (authenticate(SecuredResource.ADMIN) == false)
        return null;
    String deploymentId = (String) getRequest().getAttributes().get("deploymentId");
    Boolean cascade = RequestUtil.getBoolean(getQuery(), "cascade", false);
    if (cascade) {
        ActivitiUtil.getRepositoryService().deleteDeployment(deploymentId, true);
    } else {//  ww w .  ja  v a 2  s.  c o m
        ActivitiUtil.getRepositoryService().deleteDeployment(deploymentId);
    }
    ObjectNode successNode = new ObjectMapper().createObjectNode();
    successNode.put("success", true);
    return successNode;
}

From source file:securesocial.core.java.DefaultSecuredActionResponses.java

public F.Promise<Result> notAuthenticatedResult(Http.Context ctx) {
    Http.Request req = ctx.request();
    Result result;/*from   w w w. j  a v a  2 s.  c o  m*/

    if (req.accepts("text/html")) {
        ctx.flash().put("error", play.i18n.Messages.get("securesocial.loginRequired"));
        ctx.session().put(SecureSocial.ORIGINAL_URL, ctx.request().uri());
        result = redirect(SecureSocial.env().routes().loginPageUrl(ctx._requestHeader()));
    } else if (req.accepts("application/json")) {
        ObjectNode node = Json.newObject();
        node.put("error", "Credentials required");
        result = unauthorized(node);
    } else {
        result = unauthorized("Credentials required");
    }
    return F.Promise.pure(result);
}

From source file:com.almende.test.dht.TestAgent.java

/**
 * Test agents./*  w w w  .j av a 2 s  .  c  o  m*/
 * 
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 * @throws URISyntaxException
 *             the URI syntax exception
 * @throws InterruptedException
 *             the interrupted exception
 */
@Test
public void testAgent() throws IOException, URISyntaxException, InterruptedException {

    final HttpTransportConfig transportConfig = new HttpTransportConfig();
    transportConfig.setServletUrl("http://localhost:8080/agents/");
    transportConfig.setServletClass(DebugServlet.class.getName());

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

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

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

    Thread.sleep(1000000);
}

From source file:yadarts.server.decoding.AbstractJSONReader.java

@Override
public T readFrom(Class<T> c, Type gt, Annotation[] a, MediaType mt, MultivaluedMap<String, String> h,
        InputStream in) throws IOException, WebApplicationException {
    try {//www  .ja va 2  s  . c om
        return decode(reader.readTree(in), mt);
    } catch (JsonParseException e) {
        ObjectNode error = factory.objectNode();
        error.put("error", e.getMessage());
        throw new WebApplicationException(Response.status(Status.BAD_REQUEST)
                .type(MediaType.APPLICATION_JSON_TYPE).entity(error).build());
    }
}

From source file:com.baasbox.service.scripting.ScriptingService.java

private static JsonNode callJsonSync(String url, String method, Map<String, List<String>> params,
        Map<String, List<String>> headers, JsonNode body, Integer timeout) throws Exception {
    try {//from ww  w.  ja  v  a2 s  .  c  o m
        ObjectNode node = Json.mapper().createObjectNode();
        WS.Response resp = null;

        long startTime = System.nanoTime();
        if (timeout == null) {
            resp = HttpClientService.callSync(url, method, params, headers,
                    body == null ? null : (body.isValueNode() ? body.toString() : body));
        } else {
            resp = HttpClientService.callSync(url, method, params, headers,
                    body == null ? null : (body.isValueNode() ? body.toString() : body), timeout);
        }
        long endTime = System.nanoTime();

        int status = resp.getStatus();
        node.put("status", status);
        node.put("execution_time", (endTime - startTime) / 1000000L);

        String header = resp.getHeader("Content-Type");
        if (header == null || header.startsWith("text")) {
            node.put("body", resp.getBody());
        } else if (header.startsWith("application/json")) {
            node.put("body", resp.asJson());
        } else {
            node.put("body", resp.getBody());
        }

        return node;
    } catch (Exception e) {
        BaasBoxLogger.error("failed to connect: " + ExceptionUtils.getMessage(e));
        throw e;
    }

}

From source file:com.github.fge.jsonschema.processors.validation.ArraySchemaDigester.java

@Override
public JsonNode digest(final JsonNode schema) {
    final ObjectNode ret = FACTORY.objectNode();
    ret.put("itemsSize", 0);
    ret.put("itemsIsArray", false);

    final JsonNode itemsNode = schema.path("items");
    final JsonNode additionalNode = schema.path("additionalItems");

    final boolean hasItems = !itemsNode.isMissingNode();
    final boolean hasAdditional = additionalNode.isObject();

    ret.put("hasItems", hasItems);
    ret.put("hasAdditional", hasAdditional);

    if (itemsNode.isArray()) {
        ret.put("itemsIsArray", true);
        ret.put("itemsSize", itemsNode.size());
    }//from  w w w  .j  a v a  2  s  .  c om

    return ret;
}

From source file:com.collective.celos.servlet.JSONWorkflowListServlet.java

ObjectNode createJSONObject(WorkflowConfiguration cfg) {
    // Make sure the IDs are sorted
    SortedSet<String> ids = new TreeSet<String>();
    for (Workflow wf : cfg.getWorkflows()) {
        ids.add(wf.getID().toString());//from  w w w  .  jav a  2 s . com
    }
    ArrayNode list = Util.MAPPER.createArrayNode();
    for (String id : ids) {
        list.add(id);
    }
    ObjectNode object = Util.MAPPER.createObjectNode();
    object.put(CelosClient.IDS_PARAM, list);
    return object;
}

From source file:transformation.CsvExportTest.java

@Test
public void testFlatFields() {
    ObjectNode node1 = Json.newObject();
    node1.put("field1", "org1-value1");
    node1.put("field2", "org1-value2");
    node1.put("field3", "org1-value3");
    ObjectNode node2 = Json.newObject();
    node2.put("field1", "org2-value1");
    node2.put("field2", "org2-value2");
    node2.put("field3", "org2-value3");
    List<ObjectNode> orgs = Arrays.asList(node1, node2);
    CsvExport export = new CsvExport(Json.stringify(Json.toJson(orgs)));
    String expected = String.format("%s,%s\n%s,%s\n%s,%s\n", //
            "field1", "field3", //
            "\"org1-value1\"", "\"org1-value3\"", //
            "\"org2-value1\"", "\"org2-value3\"");
    assertThat(export.of("field1,field3")).isEqualTo(expected);
}

From source file:com.clicktravel.infrastructure.messaging.aws.sqs.SqsTypedMessageQueue.java

@Override
protected String toSqsMessageBody(final TypedMessage typedMessage) {
    final ObjectMapper mapper = new ObjectMapper();
    final ObjectNode rootNode = mapper.createObjectNode();
    rootNode.put("Subject", typedMessage.getType());
    rootNode.put("Message", typedMessage.getPayload());
    try {/*from w w w .j  a va 2  s.c o m*/
        final String json = mapper.writeValueAsString(rootNode);
        return json;
    } catch (final Exception e) {
        throw new IllegalStateException("Could not serialize message for queue", e);
    }
}