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.TaskResourceTest.java

/**
 * Test claiming a single task and all exceptional cases related to claiming. POST runtime/tasks/{taskId}
 *//*from ww w  .j  ava 2  s. c om*/
public void testClaimTask() throws Exception {
    try {

        Task task = taskService.newTask();
        taskService.saveTask(task);
        taskService.addCandidateUser(task.getId(), "newAssignee");

        assertEquals(1L, taskService.createTaskQuery().taskCandidateUser("newAssignee").count());
        // Add candidate group
        String taskId = task.getId();

        task.setAssignee("fred");
        // Claiming without assignee should set asisgnee to null
        ObjectNode requestNode = objectMapper.createObjectNode();
        requestNode.put("action", "claim");

        HttpPost httpPost = new HttpPost(
                SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, taskId));
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeRequest(httpPost, HttpStatus.SC_OK));
        task = taskService.createTaskQuery().taskId(taskId).singleResult();
        assertNotNull(task);
        assertNull(task.getAssignee());
        assertEquals(1L, taskService.createTaskQuery().taskCandidateUser("newAssignee").count());

        // Claim the task and check result
        requestNode.put("assignee", "newAssignee");
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeRequest(httpPost, HttpStatus.SC_OK));
        task = taskService.createTaskQuery().taskId(taskId).singleResult();
        assertNotNull(task);
        assertEquals("newAssignee", task.getAssignee());
        assertEquals(0L, taskService.createTaskQuery().taskCandidateUser("newAssignee").count());

        // Claiming with the same user shouldn't cause an exception
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeRequest(httpPost, HttpStatus.SC_OK));
        task = taskService.createTaskQuery().taskId(taskId).singleResult();
        assertNotNull(task);
        assertEquals("newAssignee", task.getAssignee());
        assertEquals(0L, taskService.createTaskQuery().taskCandidateUser("newAssignee").count());

        // Claiming with another user should cause exception
        requestNode.put("assignee", "anotherUser");
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeRequest(httpPost, HttpStatus.SC_CONFLICT));

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

        // Clean historic tasks with no runtime-counterpart
        List<HistoricTaskInstance> historicTasks = historyService.createHistoricTaskInstanceQuery().list();
        for (HistoricTaskInstance task : historicTasks) {
            historyService.deleteHistoricTaskInstance(task.getId());
        }
    }
}

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

/**
 * Test claiming a single task and all exceptional cases related to claiming. POST runtime/tasks/{taskId}
 *//*from  w  w  w.  j  a v  a2 s.  co m*/
public void testClaimTask() throws Exception {
    try {

        Task task = taskService.newTask();
        taskService.saveTask(task);
        taskService.addCandidateUser(task.getId(), "newAssignee");

        assertEquals(1L, taskService.createTaskQuery().taskCandidateUser("newAssignee").count());
        // Add candidate group
        String taskId = task.getId();

        task.setAssignee("fred");
        // Claiming without assignee should set assignee to null
        ObjectNode requestNode = objectMapper.createObjectNode();
        requestNode.put("action", "claim");

        HttpPost httpPost = new HttpPost(
                SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, taskId));
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeRequest(httpPost, HttpStatus.SC_OK));
        task = taskService.createTaskQuery().taskId(taskId).singleResult();
        assertNotNull(task);
        assertNull(task.getAssignee());
        assertEquals(1L, taskService.createTaskQuery().taskCandidateUser("newAssignee").count());

        // Claim the task and check result
        requestNode.put("assignee", "newAssignee");
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeRequest(httpPost, HttpStatus.SC_OK));
        task = taskService.createTaskQuery().taskId(taskId).singleResult();
        assertNotNull(task);
        assertEquals("newAssignee", task.getAssignee());
        assertEquals(0L, taskService.createTaskQuery().taskCandidateUser("newAssignee").count());

        // Claiming with the same user shouldn't cause an exception
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeRequest(httpPost, HttpStatus.SC_OK));
        task = taskService.createTaskQuery().taskId(taskId).singleResult();
        assertNotNull(task);
        assertEquals("newAssignee", task.getAssignee());
        assertEquals(0L, taskService.createTaskQuery().taskCandidateUser("newAssignee").count());

        // Claiming with another user should cause exception
        requestNode.put("assignee", "anotherUser");
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeRequest(httpPost, HttpStatus.SC_CONFLICT));

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

        // Clean historic tasks with no runtime-counterpart
        List<HistoricTaskInstance> historicTasks = historyService.createHistoricTaskInstanceQuery().list();
        for (HistoricTaskInstance task : historicTasks) {
            historyService.deleteHistoricTaskInstance(task.getId());
        }
    }
}

From source file:org.flowable.ui.modeler.service.FlowableModelQueryService.java

public ModelRepresentation importProcessModel(HttpServletRequest request, MultipartFile file) {

    String fileName = file.getOriginalFilename();
    if (fileName != null && (fileName.endsWith(".bpmn") || fileName.endsWith(".bpmn20.xml"))) {
        try {//w ww .  j a  v a 2  s .  c om
            XMLInputFactory xif = XmlUtil.createSafeXmlInputFactory();
            InputStreamReader xmlIn = new InputStreamReader(file.getInputStream(), "UTF-8");
            XMLStreamReader xtr = xif.createXMLStreamReader(xmlIn);
            BpmnModel bpmnModel = bpmnXmlConverter.convertToBpmnModel(xtr);
            if (CollectionUtils.isEmpty(bpmnModel.getProcesses())) {
                throw new BadRequestException("No process found in definition " + fileName);
            }

            if (bpmnModel.getLocationMap().size() == 0) {
                BpmnAutoLayout bpmnLayout = new BpmnAutoLayout(bpmnModel);
                bpmnLayout.execute();
            }

            ObjectNode modelNode = bpmnJsonConverter.convertToJson(bpmnModel);

            org.flowable.bpmn.model.Process process = bpmnModel.getMainProcess();
            String name = process.getId();
            if (StringUtils.isNotEmpty(process.getName())) {
                name = process.getName();
            }
            String description = process.getDocumentation();

            ModelRepresentation model = new ModelRepresentation();
            model.setKey(process.getId());
            model.setName(name);
            model.setDescription(description);
            model.setModelType(AbstractModel.MODEL_TYPE_BPMN);
            Model newModel = modelService.createModel(model, modelNode.toString(),
                    SecurityUtils.getCurrentUserObject());
            return new ModelRepresentation(newModel);

        } catch (BadRequestException e) {
            throw e;

        } catch (Exception e) {
            LOGGER.error("Import failed for {}", fileName, e);
            throw new BadRequestException(
                    "Import failed for " + fileName + ", error message " + e.getMessage());
        }
    } else {
        throw new BadRequestException(
                "Invalid file name, only .bpmn and .bpmn20.xml files are supported not " + fileName);
    }
}

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

/**
 * Test updating a single task without passing in any value, no values should be altered. PUT runtime/tasks/{taskId}
 *//*from ww w  .j  ava  2 s  .com*/
public void testUpdateTaskNoOverrides() throws Exception {
    try {
        Calendar now = Calendar.getInstance();
        Task parentTask = taskService.newTask();
        taskService.saveTask(parentTask);

        Task task = taskService.newTask();
        task.setParentTaskId(parentTask.getId());
        task.setName("Task name");
        task.setDescription("Description");
        task.setAssignee("kermit");
        task.setDelegationState(DelegationState.RESOLVED);
        task.setDescription("Description");
        task.setDueDate(now.getTime());
        task.setOwner("owner");
        task.setPriority(20);
        taskService.saveTask(task);

        ObjectNode requestNode = objectMapper.createObjectNode();

        // Execute the request with an empty request JSON-object
        HttpPut httpPut = new HttpPut(
                SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, task.getId()));
        httpPut.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeRequest(httpPut, HttpStatus.SC_OK));

        task = taskService.createTaskQuery().taskId(task.getId()).singleResult();
        assertEquals("Task name", task.getName());
        assertEquals("Description", task.getDescription());
        assertEquals("kermit", task.getAssignee());
        assertEquals("owner", task.getOwner());
        assertEquals(20, task.getPriority());
        assertEquals(DelegationState.RESOLVED, task.getDelegationState());
        assertEquals(now.getTime(), task.getDueDate());
        assertEquals(parentTask.getId(), task.getParentTaskId());

    } 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.TaskResourceTest.java

@Deployment
public void testReclaimTask() throws Exception {

    // Start process instance
    runtimeService.startProcessInstanceByKey("reclaimTest");

    // Get task id
    String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION);
    CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + url), HttpStatus.SC_OK);
    JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
    closeResponse(response);//  www.ja v  a2  s. c  o m
    String taskId = ((ArrayNode) dataNode).get(0).get("id").asText();
    assertNotNull(taskId);

    // Claim
    assertEquals(0L, taskService.createTaskQuery().taskAssignee("kermit").count());
    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("action", "claim");
    requestNode.put("assignee", "kermit");

    HttpPost httpPost = new HttpPost(
            SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, taskId));
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPost, HttpStatus.SC_OK));

    assertEquals(1L, taskService.createTaskQuery().taskAssignee("kermit").count());

    // Unclaim
    requestNode = objectMapper.createObjectNode();
    requestNode.put("action", "claim");
    httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, taskId));
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPost, HttpStatus.SC_OK));
    assertEquals(0L, taskService.createTaskQuery().taskAssignee("kermit").count());

    // Claim again
    requestNode = objectMapper.createObjectNode();
    requestNode.put("action", "claim");
    requestNode.put("assignee", "kermit");
    httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, taskId));
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPost, HttpStatus.SC_OK));
    assertEquals(1L, taskService.createTaskQuery().taskAssignee("kermit").count());
}

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

@Deployment(resources = { "org/activiti/rest/service/api/oneTaskProcess.bpmn20.xml" })
public void testStartProcessUsingKeyAndTenantId() throws Exception {
    org.activiti.engine.repository.Deployment tenantDeployment = null;

    try {/* w ww  . j  a  va2s. c  o m*/
        // Deploy the same process, in another tenant
        tenantDeployment = repositoryService.createDeployment()
                .addClasspathResource("org/activiti/rest/service/api/oneTaskProcess.bpmn20.xml")
                .tenantId("tenant1").deploy();

        ObjectNode requestNode = objectMapper.createObjectNode();

        // Start using process definition key, in tenant 1
        requestNode.put("processDefinitionKey", "oneTaskProcess");
        requestNode.put("tenantId", "tenant1");

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

        // Only one process should have been started
        ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().singleResult();
        assertNotNull(processInstance);
        assertEquals("tenant1", processInstance.getTenantId());

        // Start using an unexisting tenant
        requestNode.put("processDefinitionKey", "oneTaskProcess");
        requestNode.put("tenantId", "tenantThatDoesntExist");

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

    } finally {
        // Cleanup deployment in tenant
        if (tenantDeployment != null) {
            repositoryService.deleteDeployment(tenantDeployment.getId(), true);
        }
    }
}

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

@Deployment(resources = { "org/flowable/rest/service/api/oneTaskProcess.bpmn20.xml" })
public void testStartProcessUsingKeyAndTenantId() throws Exception {
    org.flowable.engine.repository.Deployment tenantDeployment = null;

    try {//from   ww  w . ja va 2 s .c o  m
        // Deploy the same process, in another tenant
        tenantDeployment = repositoryService.createDeployment()
                .addClasspathResource("org/flowable/rest/service/api/oneTaskProcess.bpmn20.xml")
                .tenantId("tenant1").deploy();

        ObjectNode requestNode = objectMapper.createObjectNode();

        // Start using process definition key, in tenant 1
        requestNode.put("processDefinitionKey", "oneTaskProcess");
        requestNode.put("tenantId", "tenant1");

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

        // Only one process should have been started
        ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().singleResult();
        assertNotNull(processInstance);
        assertEquals("tenant1", processInstance.getTenantId());

        // Start using an unexisting tenant
        requestNode.put("processDefinitionKey", "oneTaskProcess");
        requestNode.put("tenantId", "tenantThatDoesntExist");

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

    } finally {
        // Cleanup deployment in tenant
        if (tenantDeployment != null) {
            repositoryService.deleteDeployment(tenantDeployment.getId(), true);
        }
    }
}

From source file:com.msopentech.odatajclient.testservice.utils.JSONUtilities.java

@Override
public InputStream selectEntity(final InputStream src, final String[] propertyNames) throws Exception {
    final ObjectMapper mapper = new ObjectMapper();
    final ObjectNode srcNode = (ObjectNode) mapper.readTree(src);

    final Set<String> retain = new HashSet<String>();
    retain.add(JSON_ID_NAME);// w ww  .  j av  a  2s.  com
    retain.add(JSON_TYPE_NAME);
    retain.add(JSON_EDITLINK_NAME);
    retain.add(JSON_NEXTLINK_NAME);
    retain.add(JSON_ODATAMETADATA_NAME);
    retain.add(JSON_VALUE_NAME);

    for (String name : propertyNames) {
        retain.add(name);
        retain.add(name + JSON_NAVIGATION_SUFFIX);
        retain.add(name + JSON_MEDIA_SUFFIX);
        retain.add(name + JSON_TYPE_SUFFIX);
    }

    srcNode.retain(retain);

    return IOUtils.toInputStream(srcNode.toString());
}

From source file:io.gs2.stamina.Gs2StaminaClient.java

/**
 * ???<br>/*from w w  w  . ja va2 s.  co  m*/
 * ??????????<br>
 * ??????????????????<br>
 * <br>
 * - : 5<br>
 * <br>
 *
 * @param request 
        
 * @return ?
        
 */

public ConsumeStaminaResult consumeStamina(ConsumeStaminaRequest request) {

    ObjectNode body = JsonNodeFactory.instance.objectNode().put("variation", request.getVariation())
            .put("maxValue", request.getMaxValue());

    HttpPost post = createHttpPost(
            Gs2Constant.ENDPOINT_HOST + "/staminaPool/"
                    + (request.getStaminaPoolName() == null || request.getStaminaPoolName().equals("") ? "null"
                            : request.getStaminaPoolName())
                    + "/stamina/consume",
            credential, ENDPOINT, ConsumeStaminaRequest.Constant.MODULE,
            ConsumeStaminaRequest.Constant.FUNCTION, body.toString());
    if (request.getRequestId() != null) {
        post.setHeader("X-GS2-REQUEST-ID", request.getRequestId());
    }

    post.setHeader("X-GS2-ACCESS-TOKEN", request.getAccessToken());

    return doRequest(post, ConsumeStaminaResult.class);

}

From source file:org.onosproject.sse.SseTopologyViewWebSocket.java

protected synchronized void sendMessage(ObjectNode data) {
    try {//from  www  .  jav  a  2 s . c  o m
        if (connection.isOpen()) {
            connection.sendMessage(data.toString());
            //log.info("HLK SSE sendMessage run! data is {}",data.toString());
        }
    } catch (IOException e) {
        log.warn("Unable to send message {} to GUI due to {}", data, e);
        log.debug("Boom!!!", e);
    }
}