Java Code Examples for org.flowable.task.api.Task#setParentTaskId()

The following examples show how to use org.flowable.task.api.Task#setParentTaskId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TaskBaseResource.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * Populate the task based on the values that are present in the given {@link TaskRequest}.
 */
protected void populateTaskFromRequest(Task task, TaskRequest taskRequest) {
    if (taskRequest.isNameSet()) {
        task.setName(taskRequest.getName());
    }
    if (taskRequest.isAssigneeSet()) {
        task.setAssignee(taskRequest.getAssignee());
    }
    if (taskRequest.isDescriptionSet()) {
        task.setDescription(taskRequest.getDescription());
    }
    if (taskRequest.isDuedateSet()) {
        task.setDueDate(taskRequest.getDueDate());
    }
    if (taskRequest.isOwnerSet()) {
        task.setOwner(taskRequest.getOwner());
    }
    if (taskRequest.isParentTaskIdSet()) {
        task.setParentTaskId(taskRequest.getParentTaskId());
    }
    if (taskRequest.isPrioritySet()) {
        task.setPriority(taskRequest.getPriority());
    }
    if (taskRequest.isCategorySet()) {
        task.setCategory(taskRequest.getCategory());
    }
    if (taskRequest.isTenantIdSet()) {
        task.setTenantId(taskRequest.getTenantId());
    }
    if (taskRequest.isFormKeySet()) {
        task.setFormKey(taskRequest.getFormKey());
    }

    if (taskRequest.isDelegationStateSet()) {
        DelegationState delegationState = getDelegationState(taskRequest.getDelegationState());
        task.setDelegationState(delegationState);
    }
}
 
Example 2
Source File: TaskBaseResource.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * Populate the task based on the values that are present in the given {@link TaskRequest}.
 */
protected void populateTaskFromRequest(Task task, TaskRequest taskRequest) {
    if (taskRequest.isNameSet()) {
        task.setName(taskRequest.getName());
    }
    if (taskRequest.isAssigneeSet()) {
        task.setAssignee(taskRequest.getAssignee());
    }
    if (taskRequest.isDescriptionSet()) {
        task.setDescription(taskRequest.getDescription());
    }
    if (taskRequest.isDuedateSet()) {
        task.setDueDate(taskRequest.getDueDate());
    }
    if (taskRequest.isOwnerSet()) {
        task.setOwner(taskRequest.getOwner());
    }
    if (taskRequest.isParentTaskIdSet()) {
        task.setParentTaskId(taskRequest.getParentTaskId());
    }
    if (taskRequest.isPrioritySet()) {
        task.setPriority(taskRequest.getPriority());
    }
    if (taskRequest.isCategorySet()) {
        task.setCategory(taskRequest.getCategory());
    }
    if (taskRequest.isTenantIdSet()) {
        task.setTenantId(taskRequest.getTenantId());
    }
    if (taskRequest.isFormKeySet()) {
        task.setFormKey(taskRequest.getFormKey());
    }

    if (taskRequest.isDelegationStateSet()) {
        DelegationState delegationState = getDelegationState(taskRequest.getDelegationState());
        task.setDelegationState(delegationState);
    }
}
 
Example 3
Source File: AsyncHistoryTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetTaskParentId() {
    Task parentTask1 = taskService.newTask();
    parentTask1.setName("Parent task 1");
    taskService.saveTask(parentTask1);

    Task parentTask2 = taskService.newTask();
    parentTask2.setName("Parent task 2");
    taskService.saveTask(parentTask2);

    Task childTask = taskService.newTask();
    childTask.setName("child task");
    childTask.setParentTaskId(parentTask1.getId());
    taskService.saveTask(childTask);
    assertThat(taskService.getSubTasks(parentTask1.getId())).hasSize(1);
    assertThat(taskService.getSubTasks(parentTask2.getId())).isEmpty();

    waitForHistoryJobExecutorToProcessAllJobs(7000L, 100L);

    HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery().taskId(childTask.getId()).singleResult();
    assertThat(historicTaskInstance.getParentTaskId()).isEqualTo(parentTask1.getId());

    childTask = taskService.createTaskQuery().taskId(childTask.getId()).singleResult();
    childTask.setParentTaskId(parentTask2.getId());
    taskService.saveTask(childTask);
    assertThat(taskService.getSubTasks(parentTask1.getId())).isEmpty();
    assertThat(taskService.getSubTasks(parentTask2.getId())).hasSize(1);

    waitForHistoryJobExecutorToProcessAllJobs(7000L, 100L);

    historicTaskInstance = historyService.createHistoricTaskInstanceQuery().taskId(childTask.getId()).singleResult();
    assertThat(historicTaskInstance.getParentTaskId()).isEqualTo(parentTask2.getId());

    taskService.deleteTask(parentTask1.getId(), true);
    taskService.deleteTask(parentTask2.getId(), true);
}
 
Example 4
Source File: TaskSubTaskCollectionResourceTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
/**
 * Test getting all sub tasks. GET runtime/tasks/{taskId}/subtasks
 */
public void testGetSubTasks() throws Exception {

    Task parentTask = taskService.newTask();
    parentTask.setName("parent task");
    taskService.saveTask(parentTask);

    Task subTask = taskService.newTask();
    subTask.setName("sub task 1");
    subTask.setParentTaskId(parentTask.getId());
    taskService.saveTask(subTask);

    Task subTask2 = taskService.newTask();
    subTask2.setName("sub task 2");
    subTask2.setParentTaskId(parentTask.getId());
    taskService.saveTask(subTask2);

    // Request all sub tasks
    CloseableHttpResponse response = executeRequest(
            new HttpGet(SERVER_URL_PREFIX + CmmnRestUrls.createRelativeResourceUrl(CmmnRestUrls.URL_TASK_SUBTASKS_COLLECTION, parentTask.getId())),
            HttpStatus.SC_OK);
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    
    closeResponse(response);
    assertThat(responseNode).isNotNull();
    assertThatJson(responseNode)
            .when(Option.IGNORING_EXTRA_FIELDS)
            .isEqualTo("["
                    + "{"
                    + "    name: 'sub task 1',"
                    + "    id: '" + subTask.getId() + "'"
                    + "},"
                    + "{"
                    + "    name: 'sub task 2',"
                    + "    id: '" + subTask2.getId() + "'"
                    + "}"
                    + "]");

    taskService.deleteTask(parentTask.getId());
    taskService.deleteTask(subTask.getId());
    taskService.deleteTask(subTask2.getId());

    historyService.deleteHistoricTaskInstance(parentTask.getId());
    historyService.deleteHistoricTaskInstance(subTask.getId());
    historyService.deleteHistoricTaskInstance(subTask2.getId());
}
 
Example 5
Source File: TaskSubTaskCollectionResourceTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
/**
 * Test getting all sub tasks. GET runtime/tasks/{taskId}/subtasks
 */
@Test
public void testGetSubTasks() throws Exception {

    Task parentTask = taskService.newTask();
    parentTask.setName("parent task");
    taskService.saveTask(parentTask);

    Task subTask = taskService.newTask();
    subTask.setName("sub task 1");
    subTask.setParentTaskId(parentTask.getId());
    taskService.saveTask(subTask);

    Task subTask2 = taskService.newTask();
    subTask2.setName("sub task 2");
    subTask2.setParentTaskId(parentTask.getId());
    taskService.saveTask(subTask2);

    // Request all sub tasks
    CloseableHttpResponse response = executeRequest(
            new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_SUBTASKS_COLLECTION, parentTask.getId())),
            HttpStatus.SC_OK);
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertThat(responseNode).isNotNull();
    assertThat(responseNode.isArray()).isTrue();

    assertThatJson(responseNode)
            .when(Option.IGNORING_ARRAY_ORDER, Option.IGNORING_EXTRA_FIELDS)
            .isEqualTo("["
                    + "{"
                    + "   name: 'sub task 1',"
                    + "   id: '" + subTask.getId() + "'"
                    + "},"
                    + "{"
                    + "   name: 'sub task 2',"
                    + "   id: '" + subTask2.getId() + "'"
                    + "}"
                    + "]"
            );

    taskService.deleteTask(parentTask.getId(), true);
    taskService.deleteTask(subTask.getId(), true);
    taskService.deleteTask(subTask2.getId(), true);
}
 
Example 6
Source File: SubTaskTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Test
public void testSubTask() {
    Task gonzoTask = taskService.newTask();
    gonzoTask.setName("gonzoTask");
    taskService.saveTask(gonzoTask);

    Task subTaskOne = taskService.newTask();
    subTaskOne.setName("subtask one");
    String gonzoTaskId = gonzoTask.getId();
    subTaskOne.setParentTaskId(gonzoTaskId);
    taskService.saveTask(subTaskOne);

    Task subTaskTwo = taskService.newTask();
    subTaskTwo.setName("subtask two");
    subTaskTwo.setParentTaskId(gonzoTaskId);
    taskService.saveTask(subTaskTwo);
    
    String subTaskId = subTaskOne.getId();
    assertTrue(taskService.getSubTasks(subTaskId).isEmpty());
    assertTrue(historyService.createHistoricTaskInstanceQuery().taskParentTaskId(subTaskId).list().isEmpty());

    List<Task> subTasks = taskService.getSubTasks(gonzoTaskId);
    Set<String> subTaskNames = new HashSet<>();
    for (Task subTask : subTasks) {
        subTaskNames.add(subTask.getName());
    }

    if (HistoryTestHelper.isHistoryLevelAtLeast(HistoryLevel.AUDIT, processEngineConfiguration)) {
        Set<String> expectedSubTaskNames = new HashSet<>();
        expectedSubTaskNames.add("subtask one");
        expectedSubTaskNames.add("subtask two");

        assertEquals(expectedSubTaskNames, subTaskNames);

        List<HistoricTaskInstance> historicSubTasks = historyService.createHistoricTaskInstanceQuery().taskParentTaskId(gonzoTaskId).list();

        subTaskNames = new HashSet<>();
        for (HistoricTaskInstance historicSubTask : historicSubTasks) {
            subTaskNames.add(historicSubTask.getName());
        }

        assertEquals(expectedSubTaskNames, subTaskNames);
    }

    taskService.deleteTask(gonzoTaskId, true);
}
 
Example 7
Source File: SubTaskTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Test
public void testSubTaskDeleteOnProcessInstanceDelete() {
    Deployment deployment = repositoryService.createDeployment()
            .addClasspathResource("org/flowable/engine/test/api/runtime/oneTaskProcess.bpmn20.xml")
            .deploy();

    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.setAssignee(task.getId(), "test");

    Task subTask1 = taskService.newTask();
    subTask1.setName("Sub task 1");
    subTask1.setParentTaskId(task.getId());
    subTask1.setAssignee("test");
    taskService.saveTask(subTask1);

    Task subTask2 = taskService.newTask();
    subTask2.setName("Sub task 2");
    subTask2.setParentTaskId(task.getId());
    subTask2.setAssignee("test");
    taskService.saveTask(subTask2);

    List<Task> tasks = taskService.createTaskQuery().taskAssignee("test").list();
    assertEquals(3, tasks.size());

    runtimeService.deleteProcessInstance(processInstance.getId(), "none");

    tasks = taskService.createTaskQuery().taskAssignee("test").list();
    assertEquals(0, tasks.size());

    if (HistoryTestHelper.isHistoryLevelAtLeast(HistoryLevel.ACTIVITY, processEngineConfiguration)) {
        List<HistoricTaskInstance> historicTasks = historyService.createHistoricTaskInstanceQuery().taskAssignee("test").list();
        assertEquals(3, historicTasks.size());

        historyService.deleteHistoricProcessInstance(processInstance.getId());
        
        waitForHistoryJobExecutorToProcessAllJobs(7000, 100);

        historicTasks = historyService.createHistoricTaskInstanceQuery().taskAssignee("test").list();
        assertEquals(0, historicTasks.size());
    }

    repositoryService.deleteDeployment(deployment.getId(), true);
    managementService.executeCommand(commandContext -> {
        CommandContextUtil.getHistoricTaskService(commandContext).deleteHistoricTaskLogEntriesForTaskId(subTask1.getId());
        CommandContextUtil.getHistoricTaskService(commandContext).deleteHistoricTaskLogEntriesForTaskId(subTask2.getId());
        return null;
    });
}