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.activiti.rest.service.api.runtime.ExecutionVariableResourceTest.java

/**
 * Test updating a single execution variable, including "not found" check.
 *//*w  w w  .  j av a2  s.  c om*/
@Deployment(resources = {
        "org/activiti/rest/service/api/runtime/ExecutionResourceTest.process-with-subprocess.bpmn20.xml" })
public void testUpdateExecutionVariable() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne",
            Collections.singletonMap("overlappingVariable", (Object) "processValue"));
    runtimeService.setVariableLocal(processInstance.getId(), "myVar", "processValue");

    Execution childExecution = runtimeService.createExecutionQuery().parentId(processInstance.getId())
            .singleResult();
    assertNotNull(childExecution);
    runtimeService.setVariableLocal(childExecution.getId(), "myVar", "childValue");

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

    HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls
            .createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE, childExecution.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());
    assertEquals("local", responseNode.get("scope").asText());

    // Global value should be unaffected
    assertEquals("processValue", runtimeService.getVariable(processInstance.getId(), "myVar"));
    assertEquals("updatedValue", runtimeService.getVariableLocal(childExecution.getId(), "myVar"));

    // Update variable global
    requestNode = objectMapper.createObjectNode();
    requestNode.put("name", "myVar");
    requestNode.put("value", "updatedValueGlobal");
    requestNode.put("type", "string");
    requestNode.put("scope", "global");

    httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls
            .createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE, childExecution.getId(), "myVar"));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    response = executeRequest(httpPut, HttpStatus.SC_OK);
    responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals("updatedValueGlobal", responseNode.get("value").asText());
    assertEquals("global", responseNode.get("scope").asText());

    // Local value should be unaffected
    assertEquals("updatedValueGlobal", runtimeService.getVariable(processInstance.getId(), "myVar"));
    assertEquals("updatedValue", runtimeService.getVariableLocal(childExecution.getId(), "myVar"));

    requestNode.put("name", "unexistingVariable");

    httpPut.setEntity(new StringEntity(requestNode.toString()));
    response = executeRequest(httpPut, HttpStatus.SC_BAD_REQUEST);
    closeResponse(response);

    httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(
            RestUrls.URL_EXECUTION_VARIABLE, childExecution.getId(), "unexistingVariable"));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    response = executeRequest(httpPut, HttpStatus.SC_NOT_FOUND);
    closeResponse(response);
}

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

/**
 * Test updating a single execution variable, including "not found" check.
 *///from  w w w.j ava  2  s .  c  om
@Deployment(resources = {
        "org/flowable/rest/service/api/runtime/ExecutionResourceTest.process-with-subprocess.bpmn20.xml" })
public void testUpdateExecutionVariable() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne",
            Collections.singletonMap("overlappingVariable", (Object) "processValue"));
    runtimeService.setVariableLocal(processInstance.getId(), "myVar", "processValue");

    Execution childExecution = runtimeService.createExecutionQuery().parentId(processInstance.getId())
            .singleResult();
    assertNotNull(childExecution);
    runtimeService.setVariableLocal(childExecution.getId(), "myVar", "childValue");

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

    HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls
            .createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE, childExecution.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());
    assertEquals("local", responseNode.get("scope").asText());

    // Global value should be unaffected
    assertEquals("processValue", runtimeService.getVariable(processInstance.getId(), "myVar"));
    assertEquals("updatedValue", runtimeService.getVariableLocal(childExecution.getId(), "myVar"));

    // Update variable global
    requestNode = objectMapper.createObjectNode();
    requestNode.put("name", "myVar");
    requestNode.put("value", "updatedValueGlobal");
    requestNode.put("type", "string");
    requestNode.put("scope", "global");

    httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls
            .createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE, childExecution.getId(), "myVar"));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    response = executeRequest(httpPut, HttpStatus.SC_OK);
    responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals("updatedValueGlobal", responseNode.get("value").asText());
    assertEquals("global", responseNode.get("scope").asText());

    // Local value should be unaffected
    assertEquals("updatedValueGlobal", runtimeService.getVariable(processInstance.getId(), "myVar"));
    assertEquals("updatedValue", runtimeService.getVariableLocal(childExecution.getId(), "myVar"));

    requestNode.put("name", "unexistingVariable");

    httpPut.setEntity(new StringEntity(requestNode.toString()));
    response = executeRequest(httpPut, HttpStatus.SC_BAD_REQUEST);
    closeResponse(response);

    httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(
            RestUrls.URL_EXECUTION_VARIABLE, childExecution.getId(), "unexistingVariable"));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    response = executeRequest(httpPut, HttpStatus.SC_NOT_FOUND);
    closeResponse(response);
}

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

public JsonNode listProcesInstancesForProcessDefinition(ObjectNode bodyNode, ServerConfig serverConfig) {
    JsonNode resultNode = null;//from w  w w .  ja va2s.  c o  m
    try {
        URIBuilder builder = new URIBuilder("query/historic-process-instances");

        builder.addParameter("size", DEFAULT_PROCESSINSTANCE_SIZE);
        builder.addParameter("sort", "startTime");
        builder.addParameter("order", "desc");

        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.jetbrains.webdemo.handlers.ServerHandler.java

private void sendUserName(HttpServletRequest request, HttpServletResponse response, SessionInfo sessionInfo) {
    try {/* w ww  .jav a2 s . c om*/
        ObjectNode responseBody = new ObjectNode(JsonNodeFactory.instance);
        if (sessionInfo.getUserInfo().isLogin()) {
            responseBody.put("isLoggedIn", true);
            responseBody.put("userName", URLEncoder.encode(sessionInfo.getUserInfo().getName(), "UTF-8"));
            responseBody.put("type", sessionInfo.getUserInfo().getType());
        } else {
            responseBody.put("isLoggedIn", false);
        }
        writeResponse(request, response, responseBody.toString(), HttpServletResponse.SC_OK);
    } catch (Throwable e) {
        ErrorWriter.ERROR_WRITER.writeExceptionToExceptionAnalyzer(e, "UNKNOWN", sessionInfo.getOriginUrl(),
                request.getRequestURI() + "?" + request.getQueryString());
    }
}

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

/**
 * Test signalling a single execution, without signal event and variables.
 *//*from   www.jav a  2s  .  c  o  m*/
@Deployment(resources = {
        "org/activiti/rest/service/api/runtime/ExecutionResourceTest.process-with-message-event.bpmn20.xml" })
public void testMessageEventExecution() throws Exception {
    Execution execution = runtimeService.startProcessInstanceByKey("processOne");
    assertNotNull(execution);

    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("action", "messageEventReceived");
    requestNode.put("messageName", "unexisting");
    Execution waitingExecution = runtimeService.createExecutionQuery().activityId("waitState").singleResult();
    assertNotNull(waitingExecution);

    HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX
            + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION, waitingExecution.getId()));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_INTERNAL_SERVER_ERROR);
    closeResponse(response);

    requestNode.put("messageName", "paymentMessage");

    // Sending signal event causes the execution to end (scope-execution for
    // the catching event)
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    response = executeRequest(httpPut, HttpStatus.SC_OK);
    closeResponse(response);

    // Check if process is moved on to the other wait-state
    waitingExecution = runtimeService.createExecutionQuery().activityId("anotherWaitState").singleResult();
    assertNotNull(waitingExecution);
}

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

/**
 * Test signalling a single execution, without signal event and variables.
 *//*from   w  w w  .ja v  a2s . c om*/
@Deployment(resources = {
        "org/flowable/rest/service/api/runtime/ExecutionResourceTest.process-with-message-event.bpmn20.xml" })
public void testMessageEventExecution() throws Exception {
    Execution execution = runtimeService.startProcessInstanceByKey("processOne");
    assertNotNull(execution);

    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("action", "messageEventReceived");
    requestNode.put("messageName", "unexisting");
    Execution waitingExecution = runtimeService.createExecutionQuery().activityId("waitState").singleResult();
    assertNotNull(waitingExecution);

    HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX
            + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION, waitingExecution.getId()));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_INTERNAL_SERVER_ERROR);
    closeResponse(response);

    requestNode.put("messageName", "paymentMessage");

    // Sending signal event causes the execution to end (scope-execution for
    // the catching event)
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    response = executeRequest(httpPut, HttpStatus.SC_OK);
    closeResponse(response);

    // Check if process is moved on to the other wait-state
    waitingExecution = runtimeService.createExecutionQuery().activityId("anotherWaitState").singleResult();
    assertNotNull(waitingExecution);
}

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

/**
 * Test signalling a single execution, without signal name.
 *///w w  w . ja v  a2 s .co  m
@Deployment(resources = {
        "org/activiti/rest/service/api/runtime/ExecutionResourceTest.process-with-signal-event.bpmn20.xml" })
public void testSignalEventExecution() throws Exception {
    Execution signalExecution = runtimeService.startProcessInstanceByKey("processOne");
    assertNotNull(signalExecution);

    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("action", "signalEventReceived");
    requestNode.put("signalName", "unexisting");

    Execution waitingExecution = runtimeService.createExecutionQuery().activityId("waitState").singleResult();
    assertNotNull(waitingExecution);

    HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX
            + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION, waitingExecution.getId()));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_INTERNAL_SERVER_ERROR);
    closeResponse(response);

    requestNode.put("signalName", "alert");

    // Sending signal event causes the execution to end (scope-execution for
    // the catching event)
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    response = executeRequest(httpPut, HttpStatus.SC_OK);
    closeResponse(response);

    // Check if process is moved on to the other wait-state
    waitingExecution = runtimeService.createExecutionQuery().activityId("anotherWaitState").singleResult();
    assertNotNull(waitingExecution);

}

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

/**
 * Test signalling a single execution, without signal name.
 */// w  w  w .j  a  v a2s  .  co m
@Deployment(resources = {
        "org/flowable/rest/service/api/runtime/ExecutionResourceTest.process-with-signal-event.bpmn20.xml" })
public void testSignalEventExecution() throws Exception {
    Execution signalExecution = runtimeService.startProcessInstanceByKey("processOne");
    assertNotNull(signalExecution);

    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("action", "signalEventReceived");
    requestNode.put("signalName", "unexisting");

    Execution waitingExecution = runtimeService.createExecutionQuery().activityId("waitState").singleResult();
    assertNotNull(waitingExecution);

    HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX
            + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION, waitingExecution.getId()));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_INTERNAL_SERVER_ERROR);
    closeResponse(response);

    requestNode.put("signalName", "alert");

    // Sending signal event causes the execution to end (scope-execution for
    // the catching event)
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    response = executeRequest(httpPut, HttpStatus.SC_OK);
    closeResponse(response);

    // Check if process is moved on to the other wait-state
    waitingExecution = runtimeService.createExecutionQuery().activityId("anotherWaitState").singleResult();
    assertNotNull(waitingExecution);

}

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

@Override
public InputStream deleteProperty(final InputStream src, final List<String> path) throws IOException {

    final ObjectNode srcNode = (ObjectNode) mapper.readTree(src);
    IOUtils.closeQuietly(src);//from  w  ww. j ava 2  s  .com

    JsonNode node = srcNode;
    for (int i = 0; i < path.size() - 1; i++) {
        node = node.get(path.get(i));
        if (node == null) {
            throw new NotFoundException();
        }
    }

    ((ObjectNode) node).set(path.get(path.size() - 1), null);

    return IOUtils.toInputStream(srcNode.toString(), Constants.ENCODING);
}

From source file:org.flowable.app.service.editor.BaseAppDefinitionService.java

protected String getAppDefinitionJson(Model appDefinitionModel, AppDefinition appDefinition) {
    ObjectNode appDefinitionNode = objectMapper.createObjectNode();
    appDefinitionNode.put("key", appDefinitionModel.getKey());
    appDefinitionNode.put("name", appDefinitionModel.getName());
    appDefinitionNode.put("description", appDefinitionModel.getDescription());
    appDefinitionNode.put("theme", appDefinition.getTheme());
    appDefinitionNode.put("icon", appDefinition.getIcon());
    appDefinitionNode.put("usersAccess", appDefinition.getUsersAccess());
    appDefinitionNode.put("groupsAccess", appDefinition.getGroupsAccess());
    return appDefinitionNode.toString();
}