Search in sources :

Example 71 with ObjectNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project Activiti by Activiti.

the class DemoDataGenerator method createModelData.

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);
        ObjectNode modelObjectNode = new ObjectMapper().createObjectNode();
        modelObjectNode.put(MODEL_NAME, name);
        modelObjectNode.put(MODEL_DESCRIPTION, description);
        model.setMetaInfo(modelObjectNode.toString());
        repositoryService.saveModel(model);
        try {
            InputStream svgStream = this.getClass().getClassLoader().getResourceAsStream("org/activiti/explorer/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);
        }
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) InputStream(java.io.InputStream) Model(org.activiti.engine.repository.Model) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 72 with ObjectNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project Activiti by Activiti.

the class TaskResourceTest method testCompleteTask.

/**
   * Test completing a single task.
   * POST runtime/tasks/{taskId}
   */
@Deployment
public void testCompleteTask() throws Exception {
    try {
        Task task = taskService.newTask();
        taskService.saveTask(task);
        String taskId = task.getId();
        ObjectNode requestNode = objectMapper.createObjectNode();
        requestNode.put("action", "complete");
        HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, task.getId()));
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeRequest(httpPost, HttpStatus.SC_OK));
        // Task shouldn't exist anymore
        task = taskService.createTaskQuery().taskId(taskId).singleResult();
        assertNull(task);
        // Test completing with variables
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
        task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
        taskId = task.getId();
        requestNode = objectMapper.createObjectNode();
        ArrayNode variablesNode = objectMapper.createArrayNode();
        requestNode.put("action", "complete");
        requestNode.put("variables", variablesNode);
        ObjectNode var1 = objectMapper.createObjectNode();
        variablesNode.add(var1);
        var1.put("name", "var1");
        var1.put("value", "First value");
        ObjectNode var2 = objectMapper.createObjectNode();
        variablesNode.add(var2);
        var2.put("name", "var2");
        var2.put("value", "Second value");
        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();
        assertNull(task);
        if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
            HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery().taskId(taskId).singleResult();
            assertNotNull(historicTaskInstance);
            List<HistoricVariableInstance> updates = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getId()).list();
            assertNotNull(updates);
            assertEquals(2, updates.size());
            boolean foundFirst = false;
            boolean foundSecond = false;
            for (HistoricVariableInstance var : updates) {
                if (var.getVariableName().equals("var1")) {
                    assertEquals("First value", var.getValue());
                    foundFirst = true;
                } else if (var.getVariableName().equals("var2")) {
                    assertEquals("Second value", var.getValue());
                    foundSecond = true;
                }
            }
            assertTrue(foundFirst);
            assertTrue(foundSecond);
        }
    } 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());
        }
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) Task(org.activiti.engine.task.Task) HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) StringEntity(org.apache.http.entity.StringEntity) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Deployment(org.activiti.engine.test.Deployment)

Example 73 with ObjectNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project Activiti by Activiti.

the class TaskResourceTest method testReclaimTask.

@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);
    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());
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Deployment(org.activiti.engine.test.Deployment)

Example 74 with ObjectNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project Activiti by Activiti.

the class TaskVariablesCollectionResourceTest method testCreateSingleTaskVariableDefaultTypes.

/**
   * Test creating a single task variable, testing default types when omitted. 
   * POST runtime/tasks/{taskId}/variables
   */
public void testCreateSingleTaskVariableDefaultTypes() throws Exception {
    try {
        Task task = taskService.newTask();
        taskService.saveTask(task);
        // String type detection
        ArrayNode requestNode = objectMapper.createArrayNode();
        ObjectNode varNode = requestNode.addObject();
        varNode.put("name", "stringVar");
        varNode.put("value", "String value");
        varNode.put("scope", "local");
        HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId()));
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeBinaryRequest(httpPost, HttpStatus.SC_CREATED));
        assertEquals("String value", taskService.getVariable(task.getId(), "stringVar"));
        // Integer type detection
        varNode.put("name", "integerVar");
        varNode.put("value", 123);
        varNode.put("scope", "local");
        httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId()));
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeBinaryRequest(httpPost, HttpStatus.SC_CREATED));
        assertEquals(123, taskService.getVariable(task.getId(), "integerVar"));
        // Double type detection
        varNode.put("name", "doubleVar");
        varNode.put("value", 123.456);
        varNode.put("scope", "local");
        httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId()));
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeBinaryRequest(httpPost, HttpStatus.SC_CREATED));
        assertEquals(123.456, taskService.getVariable(task.getId(), "doubleVar"));
        // Boolean type detection
        varNode.put("name", "booleanVar");
        varNode.put("value", Boolean.TRUE);
        varNode.put("scope", "local");
        httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId()));
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeBinaryRequest(httpPost, HttpStatus.SC_CREATED));
        assertEquals(Boolean.TRUE, taskService.getVariable(task.getId(), "booleanVar"));
    } finally {
        // Clean adhoc-tasks even if test fails
        List<Task> tasks = taskService.createTaskQuery().list();
        for (Task task : tasks) {
            taskService.deleteTask(task.getId(), true);
        }
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) Task(org.activiti.engine.task.Task) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 75 with ObjectNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project Activiti by Activiti.

the class TaskVariablesCollectionResourceTest method testCreateSingleTaskVariableEdgeCases.

/**
   * Test creating a single task variable, testing edge case exceptions. 
   * POST runtime/tasks/{taskId}/variables
   */
public void testCreateSingleTaskVariableEdgeCases() throws Exception {
    try {
        // Test adding variable to unexisting task
        ArrayNode requestNode = objectMapper.createArrayNode();
        ObjectNode variableNode = requestNode.addObject();
        variableNode.put("name", "existingVariable");
        variableNode.put("value", "simple string value");
        variableNode.put("scope", "local");
        variableNode.put("type", "string");
        HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, "unexisting"));
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeBinaryRequest(httpPost, HttpStatus.SC_NOT_FOUND));
        // Test trying to create already existing variable
        Task task = taskService.newTask();
        taskService.saveTask(task);
        taskService.setVariable(task.getId(), "existingVariable", "Value 1");
        httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId()));
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeBinaryRequest(httpPost, HttpStatus.SC_CONFLICT));
        // Test same thing but using PUT (create or update)
        HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId()));
        httpPut.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeBinaryRequest(httpPut, HttpStatus.SC_CREATED));
        // Test setting global variable on standalone task
        variableNode.put("name", "myVariable");
        variableNode.put("value", "simple string value");
        variableNode.put("scope", "global");
        variableNode.put("type", "string");
        httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId()));
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeBinaryRequest(httpPost, HttpStatus.SC_BAD_REQUEST));
        // Test creating nameless variable
        variableNode.removeAll();
        variableNode.put("value", "simple string value");
        httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId()));
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeBinaryRequest(httpPost, HttpStatus.SC_BAD_REQUEST));
        // Test passing in empty array
        requestNode.removeAll();
        httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId()));
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeBinaryRequest(httpPost, HttpStatus.SC_BAD_REQUEST));
        // Test passing in object instead of array
        httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId()));
        httpPost.setEntity(new StringEntity(objectMapper.createObjectNode().toString()));
        closeResponse(executeBinaryRequest(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);
        }
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) Task(org.activiti.engine.task.Task) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) HttpPut(org.apache.http.client.methods.HttpPut)

Aggregations

ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2446 JsonNode (com.fasterxml.jackson.databind.JsonNode)556 Test (org.junit.Test)556 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)509 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)370 IOException (java.io.IOException)214 ArrayList (java.util.ArrayList)119 HashMap (java.util.HashMap)107 Map (java.util.Map)106 List (java.util.List)96 StringEntity (org.apache.http.entity.StringEntity)94 Deployment (org.activiti.engine.test.Deployment)85 Test (org.testng.annotations.Test)81 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)69 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)65 HttpPost (org.apache.http.client.methods.HttpPost)57 AbstractRpcLwM2MIntegrationTest (org.thingsboard.server.transport.lwm2m.rpc.AbstractRpcLwM2MIntegrationTest)54 TextNode (com.fasterxml.jackson.databind.node.TextNode)52 File (java.io.File)51 Task (org.activiti.engine.task.Task)51