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

The following examples show how to use org.flowable.task.api.Task#setName() . 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: FlowableTaskService.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public TaskRepresentation updateTask(String taskId, TaskUpdateRepresentation updated) {
    Task task = taskService.createTaskQuery().taskId(taskId).singleResult();

    if (task == null) {
        throw new NotFoundException("Task with id: " + taskId + " does not exist");
    }

    permissionService.validateReadPermissionOnTask(SecurityUtils.getCurrentUserObject(), task.getId());

    if (updated.isNameSet()) {
        task.setName(updated.getName());
    }

    if (updated.isDescriptionSet()) {
        task.setDescription(updated.getDescription());
    }

    if (updated.isDueDateSet()) {
        task.setDueDate(updated.getDueDate());
    }

    taskService.saveTask(task);

    return new TaskRepresentation(task);
}
 
Example 2
Source File: AsyncHistoryTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetTaskName() {
    Task task = startOneTaskprocess();
    assertThat(task.getName()).isEqualTo("The Task");

    waitForHistoryJobExecutorToProcessAllJobs(7000L, 100L);
    HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery().singleResult();
    assertThat(historicTaskInstance.getName()).isEqualTo("The Task");

    task.setName("new name");
    taskService.saveTask(task);

    waitForHistoryJobExecutorToProcessAllJobs(7000L, 100L);
    historicTaskInstance = historyService.createHistoricTaskInstanceQuery().singleResult();
    assertThat(historicTaskInstance.getName()).isEqualTo("new name");

    finishOneTaskProcess(task);
}
 
Example 3
Source File: AsyncHistoryUpgradeTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetTaskName() {
    Task task = startOneTaskprocess();
    assertThat(task.getName()).isEqualTo("The Task");

    waitForHistoryJobExecutorToProcessAllJobs(7000L, 100L);
    HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery().singleResult();
    assertThat(historicTaskInstance.getName()).isEqualTo("The Task");

    removeRuntimeActivityInstances(task.getProcessInstanceId());

    task.setName("new name");
    taskService.saveTask(task);

    downgradeHistoryJobConfigurations();

    waitForHistoryJobExecutorToProcessAllJobs(7000L, 100L);
    historicTaskInstance = historyService.createHistoricTaskInstanceQuery().singleResult();
    assertThat(historicTaskInstance.getName()).isEqualTo("new name");

    finishOneTaskProcess(task);
}
 
Example 4
Source File: TaskRepresentation.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public void fillTask(Task task) {
    task.setName(name);
    task.setDescription(description);
    if (assignee != null && assignee.getId() != null) {
        task.setAssignee(String.valueOf(assignee.getId()));
    }
    task.setDueDate(dueDate);
    if (priority != null) {
        task.setPriority(priority);
    }
    task.setCategory(category);
}
 
Example 5
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 6
Source File: TaskResource.java    From plumdo-work with Apache License 2.0 5 votes vote down vote up
@PutMapping(value = "/tasks/{taskId}", name = "任务修改")
public TaskResponse updateTask(@PathVariable String taskId, @RequestBody TaskEditRequest taskEditRequest) {
    Task task = getTaskFromRequest(taskId);
    task.setName(taskEditRequest.getName());
    task.setDescription(taskEditRequest.getDescription());
    task.setAssignee(taskEditRequest.getAssignee());
    task.setOwner(taskEditRequest.getOwner());
    task.setDueDate(taskEditRequest.getDueDate());
    task.setPriority(taskEditRequest.getPriority());
    task.setCategory(taskEditRequest.getCategory());
    taskService.saveTask(task);
    return restResponseFactory.createTaskResponse(task);
}
 
Example 7
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 8
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 9
Source File: CaseWithFormTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Test
public void completeTaskWithFormAndCheckTaskLogEntries() {
    CaseInstance caseInstance = cmmnRuntimeService.createCaseInstanceBuilder()
            .caseDefinitionKey("oneTaskCaseWithForm")
            .start();

    Task task = cmmnTaskService.createTaskQuery().caseInstanceId(caseInstance.getId()).singleResult();
    FormDefinition formDefinition = formRepositoryService.createFormDefinitionQuery().formDefinitionKey(task.getFormKey()).singleResult();

    task.setName("newName");
    task.setPriority(0);
    cmmnTaskService.saveTask(task);
    cmmnTaskService.setAssignee(task.getId(), "newAssignee");
    cmmnTaskService.setOwner(task.getId(), "newOwner");
    cmmnTaskService.setDueDate(task.getId(), new Date());
    cmmnTaskService.addUserIdentityLink(task.getId(), "testUser", IdentityLinkType.PARTICIPANT);
    cmmnTaskService.addGroupIdentityLink(task.getId(), "testGroup", IdentityLinkType.PARTICIPANT);
    cmmnTaskService.deleteUserIdentityLink(task.getId(), "testUser", IdentityLinkType.PARTICIPANT);
    cmmnTaskService.deleteGroupIdentityLink(task.getId(), "testGroup", IdentityLinkType.PARTICIPANT);
    cmmnTaskService.completeTaskWithForm(task.getId(), formDefinition.getId(), "__COMPLETE", Collections.singletonMap("doNotThrowException", ""));

    assertThat(cmmnHistoryService.createHistoricTaskLogEntryQuery().taskId(task.getId()).count()).isEqualTo(11);
    assertThat(cmmnHistoryService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type(HistoricTaskLogEntryType.USER_TASK_CREATED.name()).count())
            .isEqualTo(1);
    assertThat(
            cmmnHistoryService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type(HistoricTaskLogEntryType.USER_TASK_NAME_CHANGED.name()).count())
            .isEqualTo(1);
    assertThat(cmmnHistoryService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type(HistoricTaskLogEntryType.USER_TASK_PRIORITY_CHANGED.name())
            .count()).isEqualTo(1);
    assertThat(cmmnHistoryService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type(HistoricTaskLogEntryType.USER_TASK_ASSIGNEE_CHANGED.name())
            .count()).isEqualTo(1);
    assertThat(
            cmmnHistoryService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type(HistoricTaskLogEntryType.USER_TASK_OWNER_CHANGED.name()).count())
            .isEqualTo(1);
    assertThat(cmmnHistoryService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type(HistoricTaskLogEntryType.USER_TASK_DUEDATE_CHANGED.name())
            .count()).isEqualTo(1);
    assertThat(cmmnHistoryService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type(HistoricTaskLogEntryType.USER_TASK_IDENTITY_LINK_ADDED.name())
            .count()).isEqualTo(2);
    assertThat(
            cmmnHistoryService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type(HistoricTaskLogEntryType.USER_TASK_IDENTITY_LINK_REMOVED.name())
                    .count()).isEqualTo(2);
    assertThat(cmmnHistoryService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type(HistoricTaskLogEntryType.USER_TASK_COMPLETED.name()).count())
            .isEqualTo(1);
}
 
Example 10
Source File: AsyncHistoryTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Test
public void testAsynchUsertTaskLogEntries() {
    deployOneTaskTestProcess();
    ProcessInstance oneTaskProcess = runtimeService.startProcessInstanceByKey("oneTaskProcess");

    Task task = taskService.createTaskQuery().processInstanceId(oneTaskProcess.getId()).singleResult();
    task.setName("newName");
    task.setPriority(0);
    taskService.saveTask(task);
    taskService.setAssignee(task.getId(), "newAssignee");
    taskService.setOwner(task.getId(), "newOwner");
    taskService.setDueDate(task.getId(), new Date());
    taskService.addUserIdentityLink(task.getId(), "testUser", IdentityLinkType.PARTICIPANT);
    taskService.addGroupIdentityLink(task.getId(), "testGroup", IdentityLinkType.PARTICIPANT);
    taskService.deleteUserIdentityLink(task.getId(), "testUser", IdentityLinkType.PARTICIPANT);
    taskService.deleteGroupIdentityLink(task.getId(), "testGroup", IdentityLinkType.PARTICIPANT);
    runtimeService.suspendProcessInstanceById(oneTaskProcess.getId());
    runtimeService.activateProcessInstanceById(oneTaskProcess.getId());
    taskService.complete(task.getId());

    assertThat(historyService.createHistoricTaskLogEntryQuery().count()).isZero();
    assertThat(managementService.createHistoryJobQuery().count()).isEqualTo(12l);

    waitForHistoryJobExecutorToProcessAllJobs(7000, 200);

    assertThat(historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).count()).isEqualTo(13);
    assertThat(historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type(HistoricTaskLogEntryType.USER_TASK_CREATED.name()).count())
            .isEqualTo(1);
    assertThat(historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type(HistoricTaskLogEntryType.USER_TASK_NAME_CHANGED.name()).count())
            .isEqualTo(1);
    assertThat(
            historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type(HistoricTaskLogEntryType.USER_TASK_PRIORITY_CHANGED.name()).count())
            .isEqualTo(1);
    assertThat(
            historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type(HistoricTaskLogEntryType.USER_TASK_ASSIGNEE_CHANGED.name()).count())
            .isEqualTo(1);
    assertThat(historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type(HistoricTaskLogEntryType.USER_TASK_OWNER_CHANGED.name()).count())
            .isEqualTo(1);
    assertThat(
            historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type(HistoricTaskLogEntryType.USER_TASK_DUEDATE_CHANGED.name()).count())
            .isEqualTo(1);
    assertThat(historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type(HistoricTaskLogEntryType.USER_TASK_SUSPENSIONSTATE_CHANGED.name())
            .count()).isEqualTo(2);
    assertThat(historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type(HistoricTaskLogEntryType.USER_TASK_IDENTITY_LINK_ADDED.name())
            .count()).isEqualTo(2);
    assertThat(historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type(HistoricTaskLogEntryType.USER_TASK_IDENTITY_LINK_REMOVED.name())
            .count()).isEqualTo(2);
    assertThat(historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type(HistoricTaskLogEntryType.USER_TASK_COMPLETED.name()).count())
            .isEqualTo(1);
}
 
Example 11
Source File: TaskQueryTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Test
public void testQueryIgnoreAssigneeValueOr() {
    List<String> createdTasks = new ArrayList<>();
    Task kermitAssigneeTask = taskService.newTask();
    kermitAssigneeTask.setName("new kermit assignee task");
    taskService.saveTask(kermitAssigneeTask);
    taskService.setAssignee(kermitAssigneeTask.getId(), "kermit");
    createdTasks.add(kermitAssigneeTask.getId());

    Task magementTask = taskService.newTask();
    magementTask.setName("new management task");
    taskService.saveTask(magementTask);
    taskService.setAssignee(magementTask.getId(), "gozzie");
    taskService.addCandidateGroup(magementTask.getId(), "management");
    createdTasks.add(magementTask.getId());


    List<Task> kermitCandidateTasks = taskService.createTaskQuery()
            .taskCandidateUser("kermit")
            .taskName("testTask")
            .list();

    for (Task t : kermitCandidateTasks) {
        taskService.setAssignee(t.getId(), "gonzo");
    }

    List<Task> tasks = taskService.createTaskQuery()
            .or()
            .taskCandidateUser("kermit")
            .taskCandidateGroup("management")
            .endOr()
            .list();
    assertThat(tasks).hasSize(3);

    tasks = taskService.createTaskQuery()
            .or()
            .taskCandidateUser("kermit")
            .taskCandidateGroup("management")
            .ignoreAssigneeValue()
            .endOr()
            .list();
    assertThat(tasks).hasSize(10);

    tasks = taskService.createTaskQuery()
            .or()
            .taskCandidateOrAssigned("kermit")
            .endOr()
            .list();
    assertThat(tasks).hasSize(6);

    tasks = taskService.createTaskQuery()
            .or()
            .taskCandidateOrAssigned("kermit")
            .ignoreAssigneeValue()
            .endOr()
            .list();
    assertThat(tasks).hasSize(13);

    tasks = taskService.createTaskQuery()
            .or()
            .taskCandidateOrAssigned("gonzo")
            .taskCandidateGroup("management")
            .endOr()
            .list();
    assertThat(tasks).hasSize(10);

    tasks = taskService.createTaskQuery()
            .or()
            .taskCandidateOrAssigned("gonzo")
            .taskCandidateGroup("management")
            .ignoreAssigneeValue()
            .endOr()
            .list();
    assertThat(tasks).hasSize(11);

    taskService.deleteTasks(createdTasks, true);
}
 
Example 12
Source File: TaskQueryTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Test
public void testQueryIgnoreAssigneeValue() {
    List<String> createdTasks = new ArrayList<>();
    Task kermitAssigneeTask = taskService.newTask();
    kermitAssigneeTask.setName("new kermit assignee task");
    taskService.saveTask(kermitAssigneeTask);
    taskService.setAssignee(kermitAssigneeTask.getId(), "kermit");
    createdTasks.add(kermitAssigneeTask.getId());

    Task magementTask = taskService.newTask();
    magementTask.setName("new management task");
    taskService.saveTask(magementTask);
    taskService.setAssignee(magementTask.getId(), "gozzie");
    taskService.addCandidateGroup(magementTask.getId(), "management");
    createdTasks.add(magementTask.getId());


    List<Task> kermitCandidateTasks = taskService.createTaskQuery()
            .taskCandidateUser("kermit")
            .taskName("testTask")
            .list();

    for (Task t : kermitCandidateTasks) {
        taskService.setAssignee(t.getId(), "gonzo");
    }

    List<Task> tasks = taskService.createTaskQuery()
            .taskCandidateUser("kermit")
            .list();
    assertThat(tasks).hasSize(5);

    tasks = taskService.createTaskQuery()
            .taskCandidateUser("kermit")
            .ignoreAssigneeValue()
            .list();
    assertThat(tasks).hasSize(12);

    tasks = taskService.createTaskQuery()
            .taskCandidateOrAssigned("kermit")
            .list();
    assertThat(tasks).hasSize(6);

    tasks = taskService.createTaskQuery()
            .taskCandidateOrAssigned("kermit")
            .ignoreAssigneeValue()
            .list();
    assertThat(tasks).hasSize(13);

    tasks = taskService.createTaskQuery()
            .taskCandidateOrAssigned("gonzo")
            .taskCandidateGroup("management")
            .list();
    assertThat(tasks).hasSize(10);

    tasks = taskService.createTaskQuery()
            .taskCandidateOrAssigned("gonzo")
            .taskCandidateGroup("management")
            .ignoreAssigneeValue()
            .list();
    assertThat(tasks).hasSize(11);

    taskService.deleteTasks(createdTasks, true);
}
 
Example 13
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;
    });
}
 
Example 14
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 15
Source File: AsyncCmmnHistoryTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Test
public void createCmmnAsynchUserTaskLogEntries() {
    CaseInstance caseInstance = deployAndStartOneHumanTaskCaseModel();

    Task task = cmmnTaskService.createTaskQuery().caseInstanceId(caseInstance.getId()).singleResult();
    task.setName("newName");
    task.setPriority(0);
    cmmnTaskService.saveTask(task);
    cmmnTaskService.setAssignee(task.getId(), "newAssignee");
    cmmnTaskService.setOwner(task.getId(), "newOwner");
    cmmnTaskService.setDueDate(task.getId(), new Date());
    cmmnTaskService.addUserIdentityLink(task.getId(), "testUser", IdentityLinkType.PARTICIPANT);
    cmmnTaskService.addGroupIdentityLink(task.getId(), "testGroup", IdentityLinkType.PARTICIPANT);
    cmmnTaskService.deleteUserIdentityLink(task.getId(), "testUser", IdentityLinkType.PARTICIPANT);
    cmmnTaskService.deleteGroupIdentityLink(task.getId(), "testGroup", IdentityLinkType.PARTICIPANT);
    cmmnTaskService.complete(task.getId());

    assertThat(cmmnHistoryService.createHistoricTaskLogEntryQuery().count()).isZero();
    assertThat(cmmnManagementService.createHistoryJobQuery().count()).isEqualTo(10l);

    waitForAsyncHistoryExecutorToProcessAllJobs();

    assertThat(cmmnHistoryService.createHistoricTaskLogEntryQuery().taskId(task.getId()).count()).isEqualTo(11l);
    assertThat(cmmnHistoryService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type(HistoricTaskLogEntryType.USER_TASK_CREATED.name()).count())
            .isEqualTo(1);
    assertThat(
            cmmnHistoryService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type(HistoricTaskLogEntryType.USER_TASK_NAME_CHANGED.name()).count())
            .isEqualTo(1);
    assertThat(
            cmmnHistoryService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type(HistoricTaskLogEntryType.USER_TASK_PRIORITY_CHANGED.name())
                    .count())
            .isEqualTo(1);
    assertThat(
            cmmnHistoryService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type(HistoricTaskLogEntryType.USER_TASK_ASSIGNEE_CHANGED.name())
                    .count())
            .isEqualTo(1);
    assertThat(
            cmmnHistoryService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type(HistoricTaskLogEntryType.USER_TASK_OWNER_CHANGED.name()).count())
            .isEqualTo(1);
    assertThat(
            cmmnHistoryService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type(HistoricTaskLogEntryType.USER_TASK_DUEDATE_CHANGED.name())
                    .count())
            .isEqualTo(1);
    assertThat(cmmnHistoryService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type(HistoricTaskLogEntryType.USER_TASK_IDENTITY_LINK_ADDED.name())
            .count()).isEqualTo(2);
    assertThat(
            cmmnHistoryService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type(HistoricTaskLogEntryType.USER_TASK_IDENTITY_LINK_REMOVED.name())
                    .count()).isEqualTo(2);
    assertThat(cmmnHistoryService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type(HistoricTaskLogEntryType.USER_TASK_COMPLETED.name()).count())
            .isEqualTo(1);
}
 
Example 16
Source File: AsyncCmmnHistoryTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Test
@CmmnDeployment(resources = "org/flowable/cmmn/test/async/AsyncCmmnHistoryTest.testHumanTask.cmmn")
public void testHumanTaskWithNameDueDateAndDescription() {
    CaseInstance caseInstance = cmmnRuntimeService.createCaseInstanceBuilder().caseDefinitionKey("oneHumanTaskCase").start();
    Task task = cmmnTaskService.createTaskQuery().caseInstanceId(caseInstance.getId()).singleResult();
    assertThat(task).isNotNull();
    task.setName("Test name");
    task.setDescription("Test description");
    cmmnTaskService.saveTask(task);

    waitForAsyncHistoryExecutorToProcessAllJobs();

    // Create
    HistoricTaskInstance historicTaskInstance = cmmnHistoryService.createHistoricTaskInstanceQuery().caseInstanceId(caseInstance.getId()).singleResult();
    assertThat(historicTaskInstance).isNotNull();
    assertThat(historicTaskInstance.getName()).isEqualTo("Test name");
    assertThat(historicTaskInstance.getDescription()).isEqualTo("Test description");
    assertThat(historicTaskInstance.getDueDate()).isNull();

    // Set due date
    Date dueDate = Date.from(Instant.now().with(ChronoField.MILLI_OF_SECOND, 0));
    cmmnTaskService.setDueDate(task.getId(), dueDate);

    waitForAsyncHistoryExecutorToProcessAllJobs();

    historicTaskInstance = cmmnHistoryService.createHistoricTaskInstanceQuery().caseInstanceId(caseInstance.getId()).singleResult();
    assertThat(historicTaskInstance.getDueDate()).isEqualTo(dueDate);

    // Update name and description to null
    task = cmmnTaskService.createTaskQuery().caseInstanceId(caseInstance.getId()).singleResult();
    task.setName(null);
    task.setDescription(null);
    cmmnTaskService.saveTask(task);

    // Before the history jobs it has the old data
    historicTaskInstance = cmmnHistoryService.createHistoricTaskInstanceQuery().caseInstanceId(caseInstance.getId()).singleResult();
    assertThat(historicTaskInstance.getName()).isEqualTo("Test name");
    assertThat(historicTaskInstance.getDescription()).isEqualTo("Test description");

    waitForAsyncHistoryExecutorToProcessAllJobs();

    // After the history jobs it has the new data
    historicTaskInstance = cmmnHistoryService.createHistoricTaskInstanceQuery().caseInstanceId(caseInstance.getId()).singleResult();
    assertThat(historicTaskInstance.getName()).isNull();
    assertThat(historicTaskInstance.getDescription()).isNull();

    // Update dueDate to null
    cmmnTaskService.setDueDate(task.getId(), null);

    // Before the history jobs it has the old data
    historicTaskInstance = cmmnHistoryService.createHistoricTaskInstanceQuery().caseInstanceId(caseInstance.getId()).singleResult();
    assertThat(historicTaskInstance.getDueDate()).isEqualTo(dueDate);

    waitForAsyncHistoryExecutorToProcessAllJobs();

    // After the history jobs it has the new data
    historicTaskInstance = cmmnHistoryService.createHistoricTaskInstanceQuery().caseInstanceId(caseInstance.getId()).singleResult();
    assertThat(historicTaskInstance.getDueDate()).isNull();
}
 
Example 17
Source File: TaskQueryResourceTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
/**
 * Test querying tasks. GET runtime/tasks
 */
@Test
public void testQueryTasksWithPaging() throws Exception {
    try {
        Calendar adhocTaskCreate = Calendar.getInstance();
        adhocTaskCreate.set(Calendar.MILLISECOND, 0);

        processEngineConfiguration.getClock().setCurrentTime(adhocTaskCreate.getTime());
        List<String> taskIdList = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            Task adhocTask = taskService.newTask();
            adhocTask.setAssignee("gonzo");
            adhocTask.setOwner("owner");
            adhocTask.setDelegationState(DelegationState.PENDING);
            adhocTask.setDescription("Description one");
            adhocTask.setName("Name one");
            adhocTask.setDueDate(adhocTaskCreate.getTime());
            adhocTask.setPriority(100);
            taskService.saveTask(adhocTask);
            taskService.addUserIdentityLink(adhocTask.getId(), "misspiggy", IdentityLinkType.PARTICIPANT);
            taskIdList.add(adhocTask.getId());
        }
        Collections.sort(taskIdList);

        // Check filter-less to fetch all tasks
        String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_QUERY);
        ObjectNode requestNode = objectMapper.createObjectNode();
        String[] taskIds = new String[] { taskIdList.get(0), taskIdList.get(1), taskIdList.get(2) };
        assertResultsPresentInPostDataResponse(url + "?size=3&sort=id&order=asc", requestNode, taskIds);

        taskIds = new String[] { taskIdList.get(4), taskIdList.get(5), taskIdList.get(6), taskIdList.get(7) };
        assertResultsPresentInPostDataResponse(url + "?start=4&size=4&sort=id&order=asc", requestNode, taskIds);

        taskIds = new String[] { taskIdList.get(8), taskIdList.get(9) };
        assertResultsPresentInPostDataResponse(url + "?start=8&size=10&sort=id&order=asc", requestNode, taskIds);

    } finally {
        // Clean adhoc-tasks even if test fails
        List<Task> tasks = taskService.createTaskQuery().list();
        for (Task task : tasks) {
            if (task.getExecutionId() == null) {
                taskService.deleteTask(task.getId(), true);
            }
        }
    }
}
 
Example 18
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 19
Source File: TaskQueryResourceTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
/**
 * Test querying tasks. GET cmmn-runtime/tasks
 */
public void testQueryTasksWithPaging() throws Exception {
    try {
        Calendar adhocTaskCreate = Calendar.getInstance();
        adhocTaskCreate.set(Calendar.MILLISECOND, 0);

        cmmnEngineConfiguration.getClock().setCurrentTime(adhocTaskCreate.getTime());
        List<String> taskIdList = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            Task adhocTask = taskService.newTask();
            adhocTask.setAssignee("gonzo");
            adhocTask.setOwner("owner");
            adhocTask.setDelegationState(DelegationState.PENDING);
            adhocTask.setDescription("Description one");
            adhocTask.setName("Name one");
            adhocTask.setDueDate(adhocTaskCreate.getTime());
            adhocTask.setPriority(100);
            taskService.saveTask(adhocTask);
            taskService.addUserIdentityLink(adhocTask.getId(), "misspiggy", IdentityLinkType.PARTICIPANT);
            taskIdList.add(adhocTask.getId());
        }
        Collections.sort(taskIdList);

        // Check filter-less to fetch all tasks
        String url = CmmnRestUrls.createRelativeResourceUrl(CmmnRestUrls.URL_TASK_QUERY);
        ObjectNode requestNode = objectMapper.createObjectNode();
        String[] taskIds = new String[] { taskIdList.get(0), taskIdList.get(1), taskIdList.get(2) };
        assertResultsPresentInPostDataResponse(url + "?size=3&sort=id&order=asc", requestNode, taskIds);

        taskIds = new String[] { taskIdList.get(4), taskIdList.get(5), taskIdList.get(6), taskIdList.get(7) };
        assertResultsPresentInPostDataResponse(url + "?start=4&size=4&sort=id&order=asc", requestNode, taskIds);

        taskIds = new String[] { taskIdList.get(8), taskIdList.get(9) };
        assertResultsPresentInPostDataResponse(url + "?start=8&size=10&sort=id&order=asc", requestNode, taskIds);

    } finally {
        // Clean adhoc-tasks even if test fails
        List<Task> tasks = taskService.createTaskQuery().list();
        for (Task task : tasks) {
            if (task.getScopeId() == null) {
                taskService.deleteTask(task.getId(), true);
            }
        }
    }
}
 
Example 20
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());
}