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.jetbrains.webdemo.sessions.MyHttpSession.java

private void sendExistenceCheckResult() {
    try {/* ww  w. j  a v  a  2 s .c  o  m*/
        String id = request.getParameter("publicId");
        ObjectNode response = new ObjectNode(JsonNodeFactory.instance);
        response.put("exists", MySqlConnector.getInstance().isProjectExists(id));
        writeResponse(response.toString(), HttpServletResponse.SC_OK);
    } catch (NullPointerException e) {
        writeResponse("Can't get parameters", HttpServletResponse.SC_BAD_REQUEST);
    } catch (DatabaseOperationException e) {
        writeResponse(e.getMessage(), HttpServletResponse.SC_BAD_REQUEST);
    }
}

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

public JsonNode listProcesInstances(ObjectNode bodyNode, ServerConfig serverConfig) {
    JsonNode resultNode = null;/*from   w  ww  .  j ava  2 s  . co  m*/
    try {
        URIBuilder builder = new URIBuilder("query/historic-process-instances");

        String uri = clientUtil.getUriWithPagingAndOrderParameters(builder, bodyNode);
        HttpPost post = clientUtil.createPost(uri, serverConfig);

        post.setEntity(clientUtil.createStringEntity(bodyNode.toString()));
        resultNode = clientUtil.executeRequest(post, serverConfig);
    } catch (Exception e) {
        throw new FlowableServiceException(e.getMessage(), e);
    }
    return resultNode;
}

From source file:org.apache.olingo.fit.utils.AbstractJSONUtilities.java

@Override
public InputStream addEditLink(final InputStream content, final String title, final String href)
        throws Exception {
    final ObjectMapper mapper = new ObjectMapper();
    final ObjectNode srcNode = (ObjectNode) mapper.readTree(content);
    IOUtils.closeQuietly(content);/*from   w  ww . j  ava 2 s  .c  o m*/

    srcNode.set(JSON_EDITLINK_NAME, new TextNode(href));
    return IOUtils.toInputStream(srcNode.toString());
}

From source file:org.springframework.cloud.aws.messaging.listener.QueueMessageHandlerTest.java

@Test
public void receiveMessage_withNotificationMessageAndSubject_shouldResolveThem() throws Exception {
    // Arrange//from w w w  . j  a  v a 2 s  .  co  m
    StaticApplicationContext applicationContext = new StaticApplicationContext();
    applicationContext.registerSingleton("notificationMessageReceiver", NotificationMessageReceiver.class);
    applicationContext.registerSingleton("queueMessageHandler", QueueMessageHandler.class);
    applicationContext.refresh();

    QueueMessageHandler queueMessageHandler = applicationContext.getBean(QueueMessageHandler.class);
    NotificationMessageReceiver notificationMessageReceiver = applicationContext
            .getBean(NotificationMessageReceiver.class);

    ObjectNode jsonObject = JsonNodeFactory.instance.objectNode();
    jsonObject.put("Type", "Notification");
    jsonObject.put("Subject", "Hi!");
    jsonObject.put("Message", "Hello World!");
    String payload = jsonObject.toString();

    // Act
    queueMessageHandler.handleMessage(MessageBuilder.withPayload(payload)
            .setHeader(QueueMessageHandler.Headers.LOGICAL_RESOURCE_ID_MESSAGE_HEADER_KEY, "testQueue")
            .build());

    // Assert
    assertEquals("Hi!", notificationMessageReceiver.getSubject());
    assertEquals("Hello World!", notificationMessageReceiver.getMessage());
}

From source file:org.flowable.cmmn.rest.service.api.runtime.CaseInstanceVariableResourceTest.java

/**
 * Test updating a single process variable, including "not found" check.
 * //from  w w w.  j ava  2 s .c  o m
 * PUT cmmn-runtime/case-instances/{caseInstanceId}/variables/{variableName}
 */
@CmmnDeployment(resources = { "org/flowable/cmmn/rest/service/api/repository/oneHumanTaskCase.cmmn" })
public void testUpdateProcessVariable() throws Exception {
    CaseInstance caseInstance = runtimeService.createCaseInstanceBuilder().caseDefinitionKey("oneHumanTaskCase")
            .variables(Collections.singletonMap("overlappingVariable", (Object) "processValue")).start();
    runtimeService.setVariable(caseInstance.getId(), "myVar", "value");

    // Update variable
    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("name", "myVar");
    requestNode.put("value", "updatedValue");
    requestNode.put("type", "string");

    HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + CmmnRestUrls
            .createRelativeResourceUrl(CmmnRestUrls.URL_CASE_INSTANCE_VARIABLE, caseInstance.getId(), "myVar"));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);

    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals("updatedValue", responseNode.get("value").asText());

    // Try updating with mismatch between URL and body variableName
    requestNode.put("name", "unexistingVariable");
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPut, HttpStatus.SC_BAD_REQUEST));

    // Try updating unexisting property
    requestNode.put("name", "unexistingVariable");
    httpPut = new HttpPut(SERVER_URL_PREFIX + CmmnRestUrls.createRelativeResourceUrl(
            CmmnRestUrls.URL_CASE_INSTANCE_VARIABLE, caseInstance.getId(), "unexistingVariable"));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPut, HttpStatus.SC_OK));
}

From source file:org.activiti.rest.service.api.runtime.TaskIdentityLinkResourceTest.java

/**
 * Test getting all identity links. POST runtime/tasks/{taskId}/identitylinks
 *//*from ww w  .j a va2 s. c  o m*/
public void testCreateIdentityLink() throws Exception {
    try {
        Task task = taskService.newTask();
        taskService.saveTask(task);

        // Add user link
        ObjectNode requestNode = objectMapper.createObjectNode();
        requestNode.put("user", "kermit");
        requestNode.put("type", "myType");

        HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX
                + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_IDENTITYLINKS_COLLECTION, task.getId()));
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED);
        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        assertNotNull(responseNode);
        assertEquals("kermit", responseNode.get("user").textValue());
        assertEquals("myType", responseNode.get("type").textValue());
        assertTrue(responseNode.get("group").isNull());
        assertTrue(responseNode.get("url").textValue()
                .endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_IDENTITYLINK, task.getId(),
                        RestUrls.SEGMENT_IDENTITYLINKS_FAMILY_USERS, "kermit", "myType")));

        // Add group link
        requestNode = objectMapper.createObjectNode();
        requestNode.put("group", "sales");
        requestNode.put("type", "myType");

        httpPost.setEntity(new StringEntity(requestNode.toString()));
        response = executeRequest(httpPost, HttpStatus.SC_CREATED);
        responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        assertNotNull(responseNode);
        assertEquals("sales", responseNode.get("group").textValue());
        assertEquals("myType", responseNode.get("type").textValue());
        assertTrue(responseNode.get("user").isNull());
        assertTrue(responseNode.get("url").textValue()
                .endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_IDENTITYLINK, task.getId(),
                        RestUrls.SEGMENT_IDENTITYLINKS_FAMILY_GROUPS, "sales", "myType")));

        // Test with unexisting task
        httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls
                .createRelativeResourceUrl(RestUrls.URL_TASK_IDENTITYLINKS_COLLECTION, "unexistingtask"));
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeRequest(httpPost, HttpStatus.SC_NOT_FOUND));

        // Test with no user/group task
        requestNode = objectMapper.createObjectNode();
        requestNode.put("type", "myType");
        httpPost = new HttpPost(SERVER_URL_PREFIX
                + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_IDENTITYLINKS_COLLECTION, task.getId()));
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeRequest(httpPost, HttpStatus.SC_BAD_REQUEST));

        // Test with no user/group task
        requestNode = objectMapper.createObjectNode();
        requestNode.put("type", "myType");
        requestNode.put("user", "kermit");
        requestNode.put("group", "sales");

        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeRequest(httpPost, HttpStatus.SC_BAD_REQUEST));

        // Test with no type
        requestNode = objectMapper.createObjectNode();
        requestNode.put("group", "sales");

        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeRequest(httpPost, HttpStatus.SC_BAD_REQUEST));

    } finally {
        // Clean adhoc-tasks even if test fails
        List<Task> tasks = taskService.createTaskQuery().list();
        for (Task task : tasks) {
            taskService.deleteTask(task.getId(), true);
        }
    }
}

From source file:org.activiti.rest.service.api.runtime.TaskCommentResourceTest.java

@Deployment(resources = { "org/activiti/rest/service/api/oneTaskProcess.bpmn20.xml" })
public void testCreateCommentWithProcessInstanceId() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    Task task = taskService.createTaskQuery().singleResult();

    ObjectNode requestNode = objectMapper.createObjectNode();
    String message = "test";
    requestNode.put("message", message);
    requestNode.put("saveProcessInstanceId", true);

    HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX
            + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COMMENT_COLLECTION, task.getId()));
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED);

    List<Comment> commentsOnTask = taskService.getTaskComments(task.getId());
    assertNotNull(commentsOnTask);/*from ww  w .ja v a2s. c  o m*/
    assertEquals(1, commentsOnTask.size());

    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals(processInstance.getId(), responseNode.get("processInstanceId").asText());
    assertEquals(task.getId(), responseNode.get("taskId").asText());
    assertEquals(message, responseNode.get("message").asText());
    assertNotNull(responseNode.get("time").asText());

    assertTrue(responseNode.get("taskUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(
            RestUrls.URL_TASK_COMMENT, task.getId(), commentsOnTask.get(0).getId())));
    assertTrue(responseNode.get("processInstanceUrl").textValue()
            .endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_COMMENT,
                    processInstance.getId(), commentsOnTask.get(0).getId())));
}

From source file:org.flowable.rest.service.api.runtime.TaskCommentResourceTest.java

@Deployment(resources = { "org/flowable/rest/service/api/oneTaskProcess.bpmn20.xml" })
public void testCreateCommentWithProcessInstanceId() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    Task task = taskService.createTaskQuery().singleResult();

    ObjectNode requestNode = objectMapper.createObjectNode();
    String message = "test";
    requestNode.put("message", message);
    requestNode.put("saveProcessInstanceId", true);

    HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX
            + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COMMENT_COLLECTION, task.getId()));
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED);

    List<Comment> commentsOnTask = taskService.getTaskComments(task.getId());
    assertNotNull(commentsOnTask);/* w w  w .  j a  v  a 2s.c  om*/
    assertEquals(1, commentsOnTask.size());

    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals(processInstance.getId(), responseNode.get("processInstanceId").asText());
    assertEquals(task.getId(), responseNode.get("taskId").asText());
    assertEquals(message, responseNode.get("message").asText());
    assertNotNull(responseNode.get("time").asText());

    assertTrue(responseNode.get("taskUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(
            RestUrls.URL_TASK_COMMENT, task.getId(), commentsOnTask.get(0).getId())));
    assertTrue(responseNode.get("processInstanceUrl").textValue()
            .endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_COMMENT,
                    processInstance.getId(), commentsOnTask.get(0).getId())));
}

From source file:org.onlab.stc.Monitor.java

/**
 * Returns the scenario process flow as JSON data.
 *
 * @return scenario process flow data/*from   w  w w  . j  a  v  a2s.c om*/
 */
ObjectNode scenarioData() {
    ObjectNode root = mapper.createObjectNode();
    ArrayNode steps = mapper.createArrayNode();
    ArrayNode requirements = mapper.createArrayNode();

    ProcessFlow pf = compiler.processFlow();
    pf.getVertexes().forEach(step -> add(step, steps));
    pf.getEdges().forEach(requirement -> add(requirement, requirements));

    root.set("steps", steps);
    root.set("requirements", requirements);

    try (FileWriter fw = new FileWriter("/tmp/data.json"); PrintWriter pw = new PrintWriter(fw)) {
        pw.println(root.toString());
    } catch (IOException e) {
        e.printStackTrace();
    }
    return root;
}

From source file:org.activiti.rest.service.api.identity.UserInfoResourceTest.java

/**
 * Test update the info for an unexisting user.
 *///from ww  w  .  jav  a2s . c o  m
public void testUpdateInfoForUnexistingUser() throws Exception {
    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("value", "Updated value");

    HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX
            + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_INFO, "unexisting", "key1"));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPut, HttpStatus.SC_NOT_FOUND));
}