org.flowable.task.api.history.HistoricTaskInstance Java Examples

The following examples show how to use org.flowable.task.api.history.HistoricTaskInstance. 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: HistoricTaskQueryEscapeClauseTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void testQueryByProcessDefinitionKeyLike() {
    if (HistoryTestHelper.isHistoryLevelAtLeast(HistoryLevel.ACTIVITY, processEngineConfiguration)) {
        // processDefinitionKeyLike
        List<HistoricTaskInstance> list = historyService.createHistoricTaskInstanceQuery().processDefinitionKeyLike("%|%%").list();
        assertThat(list).isEmpty();

        list = historyService.createHistoricTaskInstanceQuery().processDefinitionKeyLike("%|_%").list();
        assertThat(list).isEmpty();

        // orQuery
        list = historyService.createHistoricTaskInstanceQuery().or().processDefinitionKeyLike("%|%%").processDefinitionId("undefined").list();
        assertThat(list).isEmpty();

        list = historyService.createHistoricTaskInstanceQuery().or().processDefinitionKeyLike("%|_%").processDefinitionId("undefined").list();
        assertThat(list).isEmpty();
    }
}
 
Example #2
Source File: AsyncHistoryTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetTaskFormKey() {
    Task task = startOneTaskprocess();
    assertThat(task.getFormKey()).isNull();

    waitForHistoryJobExecutorToProcessAllJobs(7000L, 100L);
    HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery().singleResult();
    assertThat(historicTaskInstance.getFormKey()).isNull();
    task.setFormKey("test form key");
    taskService.saveTask(task);

    waitForHistoryJobExecutorToProcessAllJobs(7000L, 100L);
    historicTaskInstance = historyService.createHistoricTaskInstanceQuery().singleResult();
    assertThat(historicTaskInstance.getFormKey()).isEqualTo("test form key");

    finishOneTaskProcess(task);
}
 
Example #3
Source File: TaskServiceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testFormKeyExpression() {
    runtimeService.startProcessInstanceByKey("testFormExpression", CollectionUtil.singletonMap("var", "abc"));

    org.flowable.task.api.Task task = taskService.createTaskQuery().singleResult();
    assertEquals("first-form.json", task.getFormKey());
    taskService.complete(task.getId());

    task = taskService.createTaskQuery().singleResult();
    assertEquals("form-abc.json", task.getFormKey());

    task.setFormKey("form-changed.json");
    taskService.saveTask(task);
    task = taskService.createTaskQuery().singleResult();
    assertEquals("form-changed.json", task.getFormKey());

    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
        HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery().taskId(task.getId()).singleResult();
        assertEquals("form-changed.json", historicTaskInstance.getFormKey());
    }
}
 
Example #4
Source File: TaskAttachmentCollectionResource.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "List attachments on a task", nickname="listTaskAttachments", tags = { "Task Attachments" })
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "Indicates the task was found and the attachments are returned."),
        @ApiResponse(code = 404, message = "Indicates the requested task was not found.")
})
@GetMapping(value = "/runtime/tasks/{taskId}/attachments", produces = "application/json")
public List<AttachmentResponse> getAttachments(@ApiParam(name = "taskId") @PathVariable String taskId, HttpServletRequest request) {
    List<AttachmentResponse> result = new ArrayList<>();
    HistoricTaskInstance task = getHistoricTaskFromRequest(taskId);

    for (Attachment attachment : taskService.getTaskAttachments(task.getId())) {
        result.add(restResponseFactory.createAttachmentResponse(attachment));
    }

    return result;
}
 
Example #5
Source File: SpringAsyncHistoryExecutorTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void testHistoryDataGenerated() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testProcess");
    List<Task> tasks = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();
    while (!tasks.isEmpty()) {
        taskService.complete(tasks.get(0).getId());
        tasks = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();
    }

    HistoryTestHelper.waitForJobExecutorToProcessAllHistoryJobs(processEngineConfiguration, managementService, 20000L, 200L, false);

    List<HistoricTaskInstance> historicTasks = historyService.createHistoricTaskInstanceQuery()
            .processInstanceId(processInstance.getId()).orderByTaskName().asc().list();

    assertThat(historicTasks)
            .extracting(HistoricTaskInstance::getName)
            .containsExactly("Task a", "Task b1", "Task b2", "Task c");
}
 
Example #6
Source File: HistoricTaskQueryEscapeClauseTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void testQueryByProcessDefinitionNameLike() {
    if (HistoryTestHelper.isHistoryLevelAtLeast(HistoryLevel.ACTIVITY, processEngineConfiguration)) {
        // processDefinitionNameLike
        List<HistoricTaskInstance> list = historyService.createHistoricTaskInstanceQuery().processDefinitionNameLike("%|%%")
                .orderByHistoricTaskInstanceStartTime().asc().list();
        // only check for existence and assume that the SQL processing has ordered the values correctly
        // see https://github.com/flowable/flowable-engine/issues/8
        assertThat(list)
                .extracting(HistoricTaskInstance::getId)
                .containsExactlyInAnyOrder(task1.getId(), task2.getId(), task3.getId(), task4.getId());

        // orQuery
        list = historyService.createHistoricTaskInstanceQuery().or().processDefinitionNameLike("%|%%").processDefinitionId("undefined")
                .orderByHistoricTaskInstanceStartTime().asc().list();
        assertThat(list)
                .extracting(HistoricTaskInstance::getId)
                .containsExactlyInAnyOrder(task1.getId(), task2.getId(), task3.getId(), task4.getId());
    }
}
 
Example #7
Source File: HistoricTaskAndVariablesQueryTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/api/task/TaskQueryTest.testProcessDefinition.bpmn20.xml" })
public void testWithoutDueDateQuery() throws Exception {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
        HistoricTaskInstance historicTask = historyService.createHistoricTaskInstanceQuery().processInstanceId(processInstance.getId()).withoutTaskDueDate().singleResult();
        assertNotNull(historicTask);
        assertNull(historicTask.getDueDate());

        // Set due-date on task
        org.flowable.task.api.Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
        Date dueDate = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss").parse("01/02/2003 01:12:13");
        task.setDueDate(dueDate);
        taskService.saveTask(task);

        assertEquals(0, historyService.createHistoricTaskInstanceQuery().processInstanceId(processInstance.getId()).withoutTaskDueDate().count());

        task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();

        // Clear due-date on task
        task.setDueDate(null);
        taskService.saveTask(task);

        assertEquals(1, historyService.createHistoricTaskInstanceQuery().processInstanceId(processInstance.getId()).withoutTaskDueDate().count());
    }
}
 
Example #8
Source File: AsyncHistoryTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void testClaimTask() {
    Task task = startOneTaskprocess();
    taskService.setAssignee(task.getId(), null);

    waitForHistoryJobExecutorToProcessAllJobs(7000L, 100L);
    HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery().singleResult();
    assertThat(historicTaskInstance.getClaimTime()).isNull();

    taskService.claim(historicTaskInstance.getId(), "johnDoe");
    waitForHistoryJobExecutorToProcessAllJobs(7000L, 100L);
    historicTaskInstance = historyService.createHistoricTaskInstanceQuery().taskId(historicTaskInstance.getId()).singleResult();
    assertThat(historicTaskInstance.getClaimTime()).isNotNull();
    assertThat(historicTaskInstance.getAssignee()).isNotNull();

    finishOneTaskProcess(task);
}
 
Example #9
Source File: HistoryServiceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml", "org/activiti/engine/test/api/runtime/oneTaskProcess2.bpmn20.xml" })
public void testHistoricTaskInstanceQueryByDeploymentIdIn() {
    org.flowable.engine.repository.Deployment deployment = repositoryService.createDeploymentQuery().singleResult();
    for (int i = 0; i < 4; i++) {
        runtimeService.startProcessInstanceByKey("oneTaskProcess", String.valueOf(i)).getId();
    }
    runtimeService.startProcessInstanceByKey("oneTaskProcess2", "1").getId();

    List<String> deploymentIds = new ArrayList<String>();
    deploymentIds.add(deployment.getId());
    HistoricTaskInstanceQuery taskInstanceQuery = historyService.createHistoricTaskInstanceQuery().deploymentIdIn(deploymentIds);
    assertEquals(5, taskInstanceQuery.count());

    List<HistoricTaskInstance> taskInstances = taskInstanceQuery.list();
    assertNotNull(taskInstances);
    assertEquals(5, taskInstances.size());

    deploymentIds.add("invalid");
    taskInstanceQuery = historyService.createHistoricTaskInstanceQuery().deploymentIdIn(deploymentIds);
    assertEquals(5, taskInstanceQuery.count());

    deploymentIds = new ArrayList<String>();
    deploymentIds.add("invalid");
    taskInstanceQuery = historyService.createHistoricTaskInstanceQuery().deploymentIdIn(deploymentIds);
    assertEquals(0, taskInstanceQuery.count());
}
 
Example #10
Source File: TaskAttachmentResource.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Get an attachment on a task", tags = { "Task Attachments" })
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "Indicates the task and attachment were found and the attachment is returned."),
        @ApiResponse(code = 404, message = "Indicates the requested task was not found or the tasks does not have a attachment with the given ID.")
})
@GetMapping(value = "/runtime/tasks/{taskId}/attachments/{attachmentId}", produces = "application/json")
public AttachmentResponse getAttachment(@ApiParam(name = "taskId") @PathVariable("taskId") String taskId, @ApiParam(name = "attachmentId") @PathVariable("attachmentId") String attachmentId, HttpServletRequest request) {

    HistoricTaskInstance task = getHistoricTaskFromRequest(taskId);

    Attachment attachment = taskService.getAttachment(attachmentId);
    if (attachment == null || !task.getId().equals(attachment.getTaskId())) {
        throw new FlowableObjectNotFoundException("Task '" + task.getId() + "' does not have an attachment with id '" + attachmentId + "'.", Comment.class);
    }

    return restResponseFactory.createAttachmentResponse(attachment);
}
 
Example #11
Source File: HistoricTaskQueryEscapeClauseTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public void testQueryByProcessDefinitionKeyLike() {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        // processDefinitionKeyLike
        List<HistoricTaskInstance> list = historyService.createHistoricTaskInstanceQuery().processDefinitionKeyLike("%|%%").list();
        assertEquals(0, list.size());

        list = historyService.createHistoricTaskInstanceQuery().processDefinitionKeyLike("%|_%").list();
        assertEquals(0, list.size());

        // orQuery
        list = historyService.createHistoricTaskInstanceQuery().or().processDefinitionKeyLike("%|%%").processDefinitionId("undefined").list();
        assertEquals(0, list.size());

        list = historyService.createHistoricTaskInstanceQuery().or().processDefinitionKeyLike("%|_%").processDefinitionId("undefined").list();
        assertEquals(0, list.size());
    }
}
 
Example #12
Source File: HistoricTaskQueryEscapeClauseTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public void testQueryByProcessDefinitionKeyLikeIgnoreCase() {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        // processDefinitionKeyLikeIgnoreCase
        List<HistoricTaskInstance> list = historyService.createHistoricTaskInstanceQuery().processDefinitionKeyLikeIgnoreCase("%|%%").list();
        assertEquals(0, list.size());

        list = historyService.createHistoricTaskInstanceQuery().processDefinitionKeyLikeIgnoreCase("%|_%").list();
        assertEquals(0, list.size());

        // orQuery
        list = historyService.createHistoricTaskInstanceQuery().or().processDefinitionKeyLikeIgnoreCase("%|%%").processDefinitionId("undefined").list();
        assertEquals(0, list.size());

        list = historyService.createHistoricTaskInstanceQuery().or().processDefinitionKeyLikeIgnoreCase("%|_%").processDefinitionId("undefined").list();
        assertEquals(0, list.size());
    }
}
 
Example #13
Source File: AsyncHistoryTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetTaskPriority() {
    Task task = startOneTaskprocess();
    assertThat(task.getPriority()).isEqualTo(Task.DEFAULT_PRIORITY);

    waitForHistoryJobExecutorToProcessAllJobs(7000L, 100L);
    HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery().singleResult();
    assertThat(historicTaskInstance.getPriority()).isEqualTo(Task.DEFAULT_PRIORITY);

    taskService.setPriority(task.getId(), 1);

    waitForHistoryJobExecutorToProcessAllJobs(7000L, 100L);
    historicTaskInstance = historyService.createHistoricTaskInstanceQuery().singleResult();
    assertThat(historicTaskInstance.getPriority()).isEqualTo(1);

    finishOneTaskProcess(task);
}
 
Example #14
Source File: HistoricTaskQueryEscapeClauseTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public void testQueryByTaskNameLike() {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        // taskNameLike
        List<HistoricTaskInstance> list = historyService.createHistoricTaskInstanceQuery().taskNameLike("%|%%").orderByHistoricTaskInstanceStartTime().asc().list();
        assertEquals(2, list.size());
        assertEquals(task1.getId(), list.get(0).getId());
        assertEquals(task3.getId(), list.get(1).getId());

        list = historyService.createHistoricTaskInstanceQuery().taskNameLike("%|_%").orderByHistoricTaskInstanceStartTime().asc().list();
        assertEquals(2, list.size());
        assertEquals(task2.getId(), list.get(0).getId());
        assertEquals(task4.getId(), list.get(1).getId());

        // orQuery
        list = historyService.createHistoricTaskInstanceQuery().or().taskNameLike("%|%%").processDefinitionId("undefined").orderByHistoricTaskInstanceStartTime().asc().list();
        assertEquals(2, list.size());
        assertEquals(task1.getId(), list.get(0).getId());
        assertEquals(task3.getId(), list.get(1).getId());

        list = historyService.createHistoricTaskInstanceQuery().or().taskNameLike("%|_%").processDefinitionId("undefined").orderByHistoricTaskInstanceStartTime().asc().list();
        assertEquals(2, list.size());
        assertEquals(task2.getId(), list.get(0).getId());
        assertEquals(task4.getId(), list.get(1).getId());
    }
}
 
Example #15
Source File: HistoryServiceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = { "org/flowable/engine/test/api/oneTaskProcess.bpmn20.xml", "org/flowable/engine/test/api/runtime/oneTaskProcess2.bpmn20.xml" })
public void testHistoricTaskInstanceQueryByDeploymentId() {
    org.flowable.engine.repository.Deployment deployment = repositoryService.createDeploymentQuery().singleResult();
    for (int i = 0; i < 4; i++) {
        runtimeService.startProcessInstanceByKey("oneTaskProcess", String.valueOf(i));
    }
    runtimeService.startProcessInstanceByKey("oneTaskProcess2", "1");

    HistoryTestHelper.waitForJobExecutorToProcessAllHistoryJobs(processEngineConfiguration, managementService, 7000, 200);

    HistoricTaskInstanceQuery taskInstanceQuery = historyService.createHistoricTaskInstanceQuery().deploymentId(deployment.getId());
    assertThat(taskInstanceQuery.count()).isEqualTo(5);

    List<HistoricTaskInstance> taskInstances = taskInstanceQuery.list();
    assertThat(taskInstances).isNotNull();
    assertThat(taskInstances).hasSize(5);

    taskInstanceQuery = historyService.createHistoricTaskInstanceQuery().deploymentId("invalid");
    assertThat(taskInstanceQuery.count()).isZero();
}
 
Example #16
Source File: HistoricTaskQueryEscapeClauseTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public void testQueryByTaskDescriptionLike() {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        // taskDescriptionLike
        List<HistoricTaskInstance> list = historyService.createHistoricTaskInstanceQuery().taskDescriptionLike("%|%%").orderByHistoricTaskInstanceStartTime().asc().list();
        assertEquals(2, list.size());
        assertEquals(task1.getId(), list.get(0).getId());
        assertEquals(task3.getId(), list.get(1).getId());

        list = historyService.createHistoricTaskInstanceQuery().taskDescriptionLike("%|_%").orderByHistoricTaskInstanceStartTime().asc().list();
        assertEquals(2, list.size());
        assertEquals(task2.getId(), list.get(0).getId());
        assertEquals(task4.getId(), list.get(1).getId());

        // orQuery
        list = historyService.createHistoricTaskInstanceQuery().or().taskDescriptionLike("%|%%").processDefinitionId("undefined").orderByHistoricTaskInstanceStartTime().asc().list();
        assertEquals(2, list.size());
        assertEquals(task1.getId(), list.get(0).getId());
        assertEquals(task3.getId(), list.get(1).getId());

        list = historyService.createHistoricTaskInstanceQuery().or().taskDescriptionLike("%|_%").processDefinitionId("undefined").orderByHistoricTaskInstanceStartTime().asc().list();
        assertEquals(2, list.size());
        assertEquals(task2.getId(), list.get(0).getId());
        assertEquals(task4.getId(), list.get(1).getId());
    }
}
 
Example #17
Source File: HistoricTaskQueryEscapeClauseTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public void testQueryByTaskOwnerLike() {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        // taskOwnerLike
        List<HistoricTaskInstance> list = historyService.createHistoricTaskInstanceQuery().taskOwnerLike("%|%%").orderByHistoricTaskInstanceStartTime().asc().list();
        assertEquals(2, list.size());
        assertEquals(task1.getId(), list.get(0).getId());
        assertEquals(task3.getId(), list.get(1).getId());

        list = historyService.createHistoricTaskInstanceQuery().taskOwnerLike("%|_%").orderByHistoricTaskInstanceStartTime().asc().list();
        assertEquals(2, list.size());
        assertEquals(task2.getId(), list.get(0).getId());
        assertEquals(task4.getId(), list.get(1).getId());

        // orQuery
        list = historyService.createHistoricTaskInstanceQuery().or().taskOwnerLike("%|%%").processDefinitionId("undefined").orderByHistoricTaskInstanceStartTime().asc().list();
        assertEquals(2, list.size());
        assertEquals(task1.getId(), list.get(0).getId());
        assertEquals(task3.getId(), list.get(1).getId());

        list = historyService.createHistoricTaskInstanceQuery().or().taskOwnerLike("%|_%").processDefinitionId("undefined").orderByHistoricTaskInstanceStartTime().asc().list();
        assertEquals(2, list.size());
        assertEquals(task2.getId(), list.get(0).getId());
        assertEquals(task4.getId(), list.get(1).getId());
    }
}
 
Example #18
Source File: HistoricTaskQueryEscapeClauseTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public void testQueryByTaskOwnerLikeIgnoreCase() {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        // taskOwnerLikeIgnoreCase
        List<HistoricTaskInstance> list = historyService.createHistoricTaskInstanceQuery().taskOwnerLikeIgnoreCase("%|%%").orderByHistoricTaskInstanceStartTime().asc().list();
        assertEquals(2, list.size());
        assertEquals(task1.getId(), list.get(0).getId());
        assertEquals(task3.getId(), list.get(1).getId());

        list = historyService.createHistoricTaskInstanceQuery().taskOwnerLikeIgnoreCase("%|_%").orderByHistoricTaskInstanceStartTime().asc().list();
        assertEquals(2, list.size());
        assertEquals(task2.getId(), list.get(0).getId());
        assertEquals(task4.getId(), list.get(1).getId());

        // orQuery
        list = historyService.createHistoricTaskInstanceQuery().or().taskOwnerLikeIgnoreCase("%|%%").processDefinitionId("undefined").orderByHistoricTaskInstanceStartTime().asc().list();
        assertEquals(2, list.size());
        assertEquals(task1.getId(), list.get(0).getId());
        assertEquals(task3.getId(), list.get(1).getId());

        list = historyService.createHistoricTaskInstanceQuery().or().taskOwnerLikeIgnoreCase("%|_%").processDefinitionId("undefined").orderByHistoricTaskInstanceStartTime().asc().list();
        assertEquals(2, list.size());
        assertEquals(task2.getId(), list.get(0).getId());
        assertEquals(task4.getId(), list.get(1).getId());
    }
}
 
Example #19
Source File: AsyncHistoryTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetTaskDueDate() {
    Task task = startOneTaskprocess();
    assertThat(task.getDueDate()).isNull();

    waitForHistoryJobExecutorToProcessAllJobs(7000L, 100L);
    HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery().singleResult();
    assertThat(historicTaskInstance.getDueDate()).isNull();

    taskService.setDueDate(task.getId(), new Date());

    waitForHistoryJobExecutorToProcessAllJobs(7000L, 100L);
    historicTaskInstance = historyService.createHistoricTaskInstanceQuery().singleResult();
    assertThat(historicTaskInstance.getDueDate()).isNotNull();

    taskService.setDueDate(task.getId(), null);
    waitForHistoryJobExecutorToProcessAllJobs(7000L, 100L);
    historicTaskInstance = historyService.createHistoricTaskInstanceQuery().taskId(historicTaskInstance.getId()).singleResult();
    assertThat(historicTaskInstance.getDueDate()).isNull();

    finishOneTaskProcess(task);
}
 
Example #20
Source File: HistoricTaskQueryEscapeClauseTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public void testQueryByTenantIdLike() {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        // tenantIdLike
        List<HistoricTaskInstance> list = historyService.createHistoricTaskInstanceQuery().taskTenantIdLike("%|%%").orderByHistoricTaskInstanceStartTime().asc().list();
        assertEquals(2, list.size());
        assertEquals(task1.getId(), list.get(0).getId());
        assertEquals(task2.getId(), list.get(1).getId());

        list = historyService.createHistoricTaskInstanceQuery().taskTenantIdLike("%|_%").orderByHistoricTaskInstanceStartTime().asc().list();
        assertEquals(2, list.size());
        assertEquals(task3.getId(), list.get(0).getId());
        assertEquals(task4.getId(), list.get(1).getId());

        // orQuery
        list = historyService.createHistoricTaskInstanceQuery().or().taskTenantIdLike("%|%%").processDefinitionId("undefined").orderByHistoricTaskInstanceStartTime().asc().list();
        assertEquals(2, list.size());
        assertEquals(task1.getId(), list.get(0).getId());
        assertEquals(task2.getId(), list.get(1).getId());

        list = historyService.createHistoricTaskInstanceQuery().or().taskTenantIdLike("%|_%").processDefinitionId("undefined").orderByHistoricTaskInstanceStartTime().asc().list();
        assertEquals(2, list.size());
        assertEquals(task3.getId(), list.get(0).getId());
        assertEquals(task4.getId(), list.get(1).getId());
    }
}
 
Example #21
Source File: FlowableUserRequestHandler.java    From syncope with Apache License 2.0 6 votes vote down vote up
protected UserRequestForm getForm(final HistoricTaskInstance task) {
    List<HistoricFormPropertyEntity> props = engine.getHistoryService().
            createHistoricDetailQuery().taskId(task.getId()).list().stream().
            filter(HistoricFormPropertyEntity.class::isInstance).
            map(HistoricFormPropertyEntity.class::cast).
            collect(Collectors.toList());

    UserRequestForm formTO = getHistoricFormTO(
            task.getProcessInstanceId(), task.getId(), task.getFormKey(), props);
    formTO.setCreateTime(task.getCreateTime());
    formTO.setDueDate(task.getDueDate());
    formTO.setExecutionId(task.getExecutionId());
    formTO.setFormKey(task.getFormKey());
    formTO.setAssignee(task.getAssignee());

    HistoricActivityInstance historicActivityInstance = engine.getHistoryService().
            createHistoricActivityInstanceQuery().
            executionId(task.getExecutionId()).activityType("userTask").activityName(task.getName()).singleResult();

    if (historicActivityInstance != null) {
        formTO.setCreateTime(historicActivityInstance.getStartTime());
        formTO.setDueDate(historicActivityInstance.getEndTime());
    }

    return formTO;
}
 
Example #22
Source File: HistoricTaskQueryResource.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected List<TaskRepresentation> convertTaskInfoList(List<HistoricTaskInstance> tasks) {
    List<TaskRepresentation> result = new ArrayList<>();
    if (CollectionUtils.isNotEmpty(tasks)) {
        TaskRepresentation representation = null;
        for (HistoricTaskInstance task : tasks) {
            representation = new TaskRepresentation(task);

            CachedUser cachedUser = userCache.getUser(task.getAssignee());
            if (cachedUser != null && cachedUser.getUser() != null) {
                representation.setAssignee(new UserRepresentation(cachedUser.getUser()));
            }

            result.add(representation);
        }
    }
    return result;
}
 
Example #23
Source File: TaskAndVariablesQueryTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void testQueryTaskDefinitionId() {
    Task taskWithDefinitionId = createTaskWithDefinitionId("testTaskId");
    try {
        this.taskService.saveTask(taskWithDefinitionId);

        Task updatedTask = taskService.createTaskQuery().taskDefinitionId("testTaskDefinitionId").singleResult();
        assertThat(updatedTask.getName()).isEqualTo("taskWithDefinitionId");
        assertThat(updatedTask.getTaskDefinitionId()).isEqualTo("testTaskDefinitionId");

        if (HistoryTestHelper.isHistoryLevelAtLeast(HistoryLevel.ACTIVITY, processEngineConfiguration)) {
            HistoricTaskInstance updatedHistoricTask = historyService.createHistoricTaskInstanceQuery().taskDefinitionId("testTaskDefinitionId")
                    .singleResult();
            assertThat(updatedHistoricTask.getName()).isEqualTo("taskWithDefinitionId");
            assertThat(updatedHistoricTask.getTaskDefinitionId()).isEqualTo("testTaskDefinitionId");
        }
    } finally {
        this.taskService.deleteTask("testTaskId", true);
    }
}
 
Example #24
Source File: FlowableTaskService.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public List<TaskRepresentation> getSubTasks(String taskId) {
    User currentUser = SecurityUtils.getCurrentUserObject();
    HistoricTaskInstance parentTask = permissionService.validateReadPermissionOnTask(currentUser, taskId);
    
    List<Task> subTasks = this.taskService.getSubTasks(taskId);
    List<TaskRepresentation> subTasksRepresentations = new ArrayList<>(subTasks.size());
    for (Task subTask : subTasks) {
        TaskRepresentation representation = new TaskRepresentation(subTask, parentTask);
        
        fillPermissionInformation(representation, subTask, currentUser);
        populateAssignee(subTask, representation);
        representation.setInvolvedPeople(getInvolvedUsers(subTask.getId()));
        
        subTasksRepresentations.add(representation);
    }
    
    return subTasksRepresentations;
}
 
Example #25
Source File: FlowableCommentService.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public CommentRepresentation addTaskComment(CommentRepresentation commentRequest, String taskId) {

        if (StringUtils.isBlank(commentRequest.getMessage())) {
            throw new BadRequestException("Comment should not be empty");
        }

        HistoricTaskInstance task = historyService.createHistoricTaskInstanceQuery().taskId(taskId).singleResult();
        if (task == null) {
            throw new NotFoundException("No task found with id: " + taskId);
        }

        // Check read permission and message
        User currentUser = SecurityUtils.getCurrentUserObject();
        checkReadPermissionOnTask(currentUser, taskId);

        // Create comment
        Comment comment = createComment(commentRequest.getMessage(), currentUser, task.getId(), task.getProcessInstanceId());
        return new CommentRepresentation(comment);
    }
 
Example #26
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 #27
Source File: HistoricTaskInstanceIdentityLinkCollectionResource.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "List identity links of a historic task instance", nickname ="listHistoricTaskInstanceIdentityLinks", tags = { "History Task" }, notes = "")
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "Indicates request was successful and the identity links are returned", response = HistoricIdentityLinkResponse.class, responseContainer = "List"),
        @ApiResponse(code = 404, message = "Indicates the task instance could not be found.") })
@GetMapping(value = "/cmmn-history/historic-task-instances/{taskId}/identitylinks", produces = "application/json")
public List<HistoricIdentityLinkResponse> getTaskIdentityLinks(@ApiParam(name = "taskId") @PathVariable String taskId, HttpServletRequest request) {
    HistoricTaskInstance task = getHistoricTaskInstanceFromRequest(taskId);
    
    List<HistoricIdentityLink> identityLinks = historyService.getHistoricIdentityLinksForTask(task.getId());

    if (identityLinks != null) {
        return restResponseFactory.createHistoricIdentityLinkResponseList(identityLinks);
    }

    return new ArrayList<>();
}
 
Example #28
Source File: HistoricTaskInstanceResource.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Get a historic task instance form", tags = { "History Task" }, nickname = "getHistoricTaskForm")
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "Indicates request was successful and the task form is returned"),
        @ApiResponse(code = 404, message = "Indicates the requested task was not found.")
})
@GetMapping(value = "/history/historic-task-instances/{taskId}/form", produces = "application/json")
public String getTaskForm(@ApiParam(name = "taskId") @PathVariable String taskId, HttpServletRequest request) {
    HistoricTaskInstance task = getHistoricTaskInstanceFromRequest(taskId);
    if (StringUtils.isEmpty(task.getFormKey())) {
        throw new FlowableIllegalArgumentException("Task has no form defined");
    }
    
    FormInfo formInfo = taskService.getTaskFormModel(task.getId());
    if (formHandlerRestApiInterceptor != null) {
        return formHandlerRestApiInterceptor.convertHistoricTaskFormInfo(formInfo, task);
    } else {
        SimpleFormModel formModel = (SimpleFormModel) formInfo.getFormModel();
        return restResponseFactory.getFormModelString(new FormModelResponse(formInfo, formModel));
    }
}
 
Example #29
Source File: CmmnRestResponseFactory.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public List<HistoricTaskInstanceResponse> createHistoricTaskInstanceResponseList(List<HistoricTaskInstance> taskInstances) {
    RestUrlBuilder urlBuilder = createUrlBuilder();
    List<HistoricTaskInstanceResponse> responseList = new ArrayList<>(taskInstances.size());
    for (HistoricTaskInstance instance : taskInstances) {
        responseList.add(createHistoricTaskInstanceResponse(instance, urlBuilder));
    }
    return responseList;
}
 
Example #30
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);
}