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

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

Introduction

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

Prototype

public String toString() 

Source Link

Usage

From source file:org.flowable.admin.service.engine.FormInstanceService.java

public JsonNode getFormInstances(ServerConfig serverConfig, ObjectNode objectNode) {

    JsonNode resultNode = null;/*from   www  .  java 2  s.  com*/

    try {
        URIBuilder builder = clientUtil.createUriBuilder("query/form-instances");
        HttpPost post = clientUtil.createPost(builder.toString(), serverConfig);
        post.setEntity(clientUtil.createStringEntity(objectNode.toString()));

        resultNode = clientUtil.executeRequest(post, serverConfig);
    } catch (Exception ex) {
        throw new FlowableServiceException(ex.getMessage(), ex);
    }

    return resultNode;
}

From source file:org.hekmatof.activiti.editor.ModelSaveRestResource.java

@RequestMapping(value = "/model/{modelId}/save", method = RequestMethod.PUT)
public void saveModel(@PathVariable String modelId, @RequestBody MultiValueMap<String, String> values) {
    try {/*from   w w w. j  a  v a  2s. c  o m*/

        Model model = repositoryService.getModel(modelId);

        ObjectNode modelJson = (ObjectNode) objectMapper.readTree(model.getMetaInfo());

        modelJson.put(MODEL_NAME, values.getFirst("name"));
        modelJson.put(MODEL_DESCRIPTION, values.getFirst("description"));
        model.setMetaInfo(modelJson.toString());
        model.setName(values.getFirst("name"));

        repositoryService.saveModel(model);

        repositoryService.addModelEditorSource(model.getId(), values.getFirst("json_xml").getBytes("utf-8"));

        InputStream svgStream = new ByteArrayInputStream(values.getFirst("svg_xml").getBytes("utf-8"));
        TranscoderInput input = new TranscoderInput(svgStream);

        PNGTranscoder transcoder = new PNGTranscoder();
        // Setup output
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        TranscoderOutput output = new TranscoderOutput(outStream);

        // Do the transformation
        transcoder.transcode(input, output);
        final byte[] result = outStream.toByteArray();
        repositoryService.addModelEditorSourceExtra(model.getId(), result);
        outStream.close();

    } catch (Exception e) {
        logger.error("Error saving model", e);
        throw new ActivitiException("Error saving model", e);
    }
}

From source file:org.activiti.rest.service.api.history.HistoricProcessInstanceCommentResourceTest.java

/**
 * Test creating a comment for a process instance. POST history/historic-process-instances/{processInstanceId}/comments
 *//*  ww w  . j  av  a  2s .  c o m*/
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testCreateComment() throws Exception {
    ProcessInstance pi = null;

    try {
        pi = runtimeService.startProcessInstanceByKey("oneTaskProcess");

        HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(
                RestUrls.URL_HISTORIC_PROCESS_INSTANCE_COMMENT_COLLECTION, pi.getId()));
        ObjectNode requestNode = objectMapper.createObjectNode();
        requestNode.put("message", "This is a comment...");
        httpPost.setEntity(new StringEntity(requestNode.toString()));

        CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED);

        assertEquals(HttpStatus.SC_CREATED, response.getStatusLine().getStatusCode());

        List<Comment> commentsOnProcess = taskService.getProcessInstanceComments(pi.getId());
        assertNotNull(commentsOnProcess);
        assertEquals(1, commentsOnProcess.size());

        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        assertNotNull(responseNode);
        assertEquals("kermit", responseNode.get("author").textValue());
        assertEquals("This is a comment...", responseNode.get("message").textValue());
        assertEquals(commentsOnProcess.get(0).getId(), responseNode.get("id").textValue());
        assertTrue(responseNode.get("processInstanceUrl").textValue()
                .endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_COMMENT,
                        pi.getId(), commentsOnProcess.get(0).getId())));
        assertEquals(pi.getProcessInstanceId(), responseNode.get("processInstanceId").asText());
        assertTrue(responseNode.get("taskUrl").isNull());
        assertTrue(responseNode.get("taskId").isNull());

    } finally {
        if (pi != null) {
            List<Comment> comments = taskService.getProcessInstanceComments(pi.getId());
            for (Comment c : comments) {
                taskService.deleteComment(c.getId());
            }
        }
    }
}

From source file:org.flowable.rest.service.api.history.HistoricProcessInstanceCommentResourceTest.java

/**
 * Test creating a comment for a process instance. POST history/historic-process-instances/{processInstanceId}/comments
 *//*from ww  w  .  j  a  v a 2 s . co m*/
@Deployment(resources = { "org/flowable/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testCreateComment() throws Exception {
    ProcessInstance pi = null;

    try {
        pi = runtimeService.startProcessInstanceByKey("oneTaskProcess");

        HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(
                RestUrls.URL_HISTORIC_PROCESS_INSTANCE_COMMENT_COLLECTION, pi.getId()));
        ObjectNode requestNode = objectMapper.createObjectNode();
        requestNode.put("message", "This is a comment...");
        httpPost.setEntity(new StringEntity(requestNode.toString()));

        CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED);

        assertEquals(HttpStatus.SC_CREATED, response.getStatusLine().getStatusCode());

        List<Comment> commentsOnProcess = taskService.getProcessInstanceComments(pi.getId());
        assertNotNull(commentsOnProcess);
        assertEquals(1, commentsOnProcess.size());

        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        assertNotNull(responseNode);
        assertEquals("kermit", responseNode.get("author").textValue());
        assertEquals("This is a comment...", responseNode.get("message").textValue());
        assertEquals(commentsOnProcess.get(0).getId(), responseNode.get("id").textValue());
        assertTrue(responseNode.get("processInstanceUrl").textValue()
                .endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_COMMENT,
                        pi.getId(), commentsOnProcess.get(0).getId())));
        assertEquals(pi.getProcessInstanceId(), responseNode.get("processInstanceId").asText());
        assertTrue(responseNode.get("taskUrl").isNull());
        assertTrue(responseNode.get("taskId").isNull());

    } finally {
        if (pi != null) {
            List<Comment> comments = taskService.getProcessInstanceComments(pi.getId());
            for (Comment c : comments) {
                taskService.deleteComment(c.getId());
            }
        }
    }
}

From source file:org.activiti.rest.conf.DemoDataConfiguration.java

protected void createModelData(String name, String description, String jsonFile) {
    List<Model> modelList = repositoryService.createModelQuery().modelName("Demo model").list();

    if (modelList == null || modelList.isEmpty()) {

        Model model = repositoryService.newModel();
        model.setName(name);/*from   w ww .j  a v a 2s  . c om*/

        ObjectNode modelObjectNode = new ObjectMapper().createObjectNode();
        modelObjectNode.put("name", name);
        modelObjectNode.put("description", description);
        model.setMetaInfo(modelObjectNode.toString());

        repositoryService.saveModel(model);

        try {
            InputStream svgStream = this.getClass().getClassLoader()
                    .getResourceAsStream("org/activiti/rest/demo/model/test.svg");
            repositoryService.addModelEditorSourceExtra(model.getId(), IOUtils.toByteArray(svgStream));
        } catch (Exception e) {
            LOGGER.warn("Failed to read SVG", e);
        }

        try {
            InputStream editorJsonStream = this.getClass().getClassLoader().getResourceAsStream(jsonFile);
            repositoryService.addModelEditorSource(model.getId(), IOUtils.toByteArray(editorJsonStream));
        } catch (Exception e) {
            LOGGER.warn("Failed to read editor JSON", e);
        }
    }
}

From source file:org.jolokia.client.request.J4pConnectionPoolingIntegrationTest.java

private String getJsonResponse(String message) {
    final ObjectMapper objectMapper = new ObjectMapper();
    final ObjectNode node = objectMapper.createObjectNode();

    final ArrayNode arrayNode = objectMapper.createArrayNode();
    arrayNode.add("java.lang:type=Memory");
    node.putArray("value").addAll(arrayNode);

    node.put("status", 200);
    node.put("timestamp", 1244839118);

    return node.toString();
}

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

private Event buildEvent(Channel channel) {
    final Event takenEvent = channel.take();
    final ObjectNode objectNode = new ObjectNode(JsonNodeFactory.instance);
    Event event = null;//from   www . jav a 2s .  c om
    if (takenEvent != null) {
        event = EventBuilder.withBody(objectNode.toString().getBytes(Charsets.UTF_8), takenEvent.getHeaders());
    }
    return event;
}

From source file:com.redhat.lightblue.query.ForEachExpression.java

/**
 * Parses a foreach expression from the given json object
 *//*from   w  w w. j a  va 2 s  .co  m*/
public static ForEachExpression fromJson(ObjectNode node) {
    if (node.size() == 1) {
        JsonNode argNode = node.get("$foreach");
        if (argNode instanceof ObjectNode) {
            ObjectNode objArg = (ObjectNode) argNode;
            if (objArg.size() == 2) {
                JsonNode updateNode = null;
                JsonNode queryNode = null;
                Path field = null;
                for (Iterator<Map.Entry<String, JsonNode>> itr = objArg.fields(); itr.hasNext();) {
                    Map.Entry<String, JsonNode> entry = itr.next();
                    if ("$update".equals(entry.getKey())) {
                        updateNode = entry.getValue();
                    } else {
                        field = new Path(entry.getKey());
                        queryNode = entry.getValue();
                    }
                }
                if (queryNode != null && updateNode != null && field != null) {
                    return new ForEachExpression(field, UpdateQueryExpression.fromJson(queryNode),
                            ForEachUpdateExpression.fromJson(updateNode));
                }
            }
        }
    }
    throw Error.get(QueryConstants.ERR_INVALID_ARRAY_UPDATE_EXPRESSION, node.toString());
}

From source file:org.flowable.app.rest.service.api.repository.AppDefinitionResourceTest.java

@AppDeployment(resources = { "org/flowable/app/rest/service/api/repository/oneApp.app" })
public void testUpdateAppDefinitionCategory() throws Exception {
    AppDefinition appDefinition = repositoryService.createAppDefinitionQuery().singleResult();
    assertEquals(1, repositoryService.createAppDefinitionQuery().count());

    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("category", "updatedcategory");

    HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX
            + AppRestUrls.createRelativeResourceUrl(AppRestUrls.URL_APP_DEFINITION, appDefinition.getId()));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);

    // Check "OK" status
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);//from  w  w w .  j  a va  2  s. co  m
    assertEquals("updatedcategory", responseNode.get("category").textValue());

    // Check actual entry in DB
    assertEquals(1,
            repositoryService.createAppDefinitionQuery().appDefinitionCategory("updatedcategory").count());

}