Search in sources :

Example 21 with TaskQuery

use of org.activiti.engine.task.TaskQuery in project Activiti by Activiti.

the class TaskAdminRuntimeImpl method tasks.

@Override
public Page<Task> tasks(Pageable pageable, GetTasksPayload getTasksPayload) {
    TaskQuery taskQuery = taskService.createTaskQuery();
    if (getTasksPayload.getProcessInstanceId() != null) {
        taskQuery = taskQuery.processInstanceId(getTasksPayload.getProcessInstanceId());
    }
    if (getTasksPayload.getParentTaskId() != null) {
        taskQuery = taskQuery.taskParentTaskId(getTasksPayload.getParentTaskId());
    }
    List<Task> tasks = taskConverter.from(taskQuery.listPage(pageable.getStartIndex(), pageable.getMaxItems()));
    return new PageImpl<>(tasks, Math.toIntExact(taskQuery.count()));
}
Also used : PageImpl(org.activiti.runtime.api.query.impl.PageImpl) Task(org.activiti.api.task.model.Task) TaskQuery(org.activiti.engine.task.TaskQuery)

Example 22 with TaskQuery

use of org.activiti.engine.task.TaskQuery in project Activiti by Activiti.

the class TaskRuntimeImpl method tasks.

@Override
public Page<Task> tasks(Pageable pageable, GetTasksPayload getTasksPayload) {
    TaskQuery taskQuery = taskService.createTaskQuery();
    if (getTasksPayload == null) {
        getTasksPayload = TaskPayloadBuilder.tasks().build();
    }
    String authenticatedUserId = securityManager.getAuthenticatedUserId();
    if (authenticatedUserId != null && !authenticatedUserId.isEmpty()) {
        List<String> userGroups = securityManager.getAuthenticatedUserGroups();
        getTasksPayload.setAssigneeId(authenticatedUserId);
        getTasksPayload.setGroups(userGroups);
    } else {
        throw new IllegalStateException("You need an authenticated user to perform a task query");
    }
    taskQuery = taskQuery.or().taskCandidateOrAssigned(getTasksPayload.getAssigneeId(), getTasksPayload.getGroups()).taskOwner(authenticatedUserId).endOr();
    if (getTasksPayload.getProcessInstanceId() != null) {
        taskQuery = taskQuery.processInstanceId(getTasksPayload.getProcessInstanceId());
    }
    if (getTasksPayload.getParentTaskId() != null) {
        taskQuery = taskQuery.taskParentTaskId(getTasksPayload.getParentTaskId());
    }
    List<Task> tasks = taskConverter.from(taskQuery.listPage(pageable.getStartIndex(), pageable.getMaxItems()));
    return new PageImpl<>(tasks, Math.toIntExact(taskQuery.count()));
}
Also used : PageImpl(org.activiti.runtime.api.query.impl.PageImpl) Task(org.activiti.api.task.model.Task) TaskQuery(org.activiti.engine.task.TaskQuery)

Example 23 with TaskQuery

use of org.activiti.engine.task.TaskQuery in project Activiti by Activiti.

the class SubProcessTest method testTwoSubProcessInParallelWithinSubProcess.

@Deployment
public void testTwoSubProcessInParallelWithinSubProcess() {
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("twoSubProcessInParallelWithinSubProcess");
    TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(pi.getId()).orderByTaskName().asc();
    List<Task> tasks = taskQuery.list();
    // After process start, both tasks in the subprocesses should be active
    Task taskA = tasks.get(0);
    Task taskB = tasks.get(1);
    assertThat(taskA.getName()).isEqualTo("Task in subprocess A");
    assertThat(taskB.getName()).isEqualTo("Task in subprocess B");
    // Completing both tasks should active the tasks outside the subprocesses
    taskService.complete(taskA.getId());
    taskService.complete(taskB.getId());
    Task taskAfterSubProcess = taskQuery.singleResult();
    assertThat(taskAfterSubProcess.getName()).isEqualTo("Task after subprocess");
    // Completing this task should end the process
    taskService.complete(taskAfterSubProcess.getId());
    assertProcessEnded(pi.getId());
}
Also used : Task(org.activiti.engine.task.Task) TaskQuery(org.activiti.engine.task.TaskQuery) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 24 with TaskQuery

use of org.activiti.engine.task.TaskQuery in project Activiti by Activiti.

the class SubProcessTest method IGNORE_testSimpleSubProcessWithConcurrentTimer.

/**
 * A test case that has a timer attached to the subprocess, where 2 concurrent paths are defined when the timer fires.
 */
@Deployment
public void IGNORE_testSimpleSubProcessWithConcurrentTimer() {
    // After staring the process, the task in the subprocess should be active
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("simpleSubProcessWithConcurrentTimer");
    TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(pi.getId()).orderByTaskName().asc();
    Task subProcessTask = taskQuery.singleResult();
    assertThat(subProcessTask.getName()).isEqualTo("Task in subprocess");
    // When the timer is fired (after 2 hours), two concurrent paths should be created
    Job job = managementService.createJobQuery().singleResult();
    managementService.executeJob(job.getId());
    List<Task> tasksAfterTimer = taskQuery.list();
    assertThat(tasksAfterTimer).hasSize(2);
    Task taskAfterTimer1 = tasksAfterTimer.get(0);
    Task taskAfterTimer2 = tasksAfterTimer.get(1);
    assertThat(taskAfterTimer1.getName()).isEqualTo("Task after timer 1");
    assertThat(taskAfterTimer2.getName()).isEqualTo("Task after timer 2");
    // Completing the two tasks should end the process instance
    taskService.complete(taskAfterTimer1.getId());
    taskService.complete(taskAfterTimer2.getId());
    assertProcessEnded(pi.getId());
}
Also used : Task(org.activiti.engine.task.Task) TaskQuery(org.activiti.engine.task.TaskQuery) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Job(org.activiti.engine.runtime.Job) Deployment(org.activiti.engine.test.Deployment)

Example 25 with TaskQuery

use of org.activiti.engine.task.TaskQuery in project Activiti by Activiti.

the class TaskAssignmentExtensionsTest method testCandidateGroupsExtension.

@Deployment
public void testCandidateGroupsExtension() {
    runtimeService.startProcessInstanceByKey("candidateGroupsExtension");
    // Bugfix check: potentially the query could return 2 tasks since
    // kermit is a member of the two candidate groups
    List<Task> tasks = taskService.createTaskQuery().taskCandidateUser(KERMIT, KERMITSGROUPS).list();
    assertThat(tasks).hasSize(1);
    assertThat(tasks.get(0).getName()).isEqualTo("make profit");
    tasks = taskService.createTaskQuery().taskCandidateUser(FOZZIE, FOZZIESGROUPS).list();
    assertThat(tasks).hasSize(1);
    assertThat(tasks.get(0).getName()).isEqualTo("make profit");
    // Test the task query find-by-candidate-group operation
    TaskQuery query = taskService.createTaskQuery();
    assertThat(query.taskCandidateGroup("management").count()).isEqualTo(1);
    assertThat(query.taskCandidateGroup("accountancy").count()).isEqualTo(1);
}
Also used : Task(org.activiti.engine.task.Task) TaskQuery(org.activiti.engine.task.TaskQuery) Deployment(org.activiti.engine.test.Deployment)

Aggregations

TaskQuery (org.activiti.engine.task.TaskQuery)120 Task (org.activiti.engine.task.Task)47 Deployment (org.activiti.engine.test.Deployment)30 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)21 ActivitiException (org.activiti.engine.ActivitiException)20 ArrayList (java.util.ArrayList)18 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)12 SimpleDateFormat (java.text.SimpleDateFormat)8 Date (java.util.Date)8 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)7 HashMap (java.util.HashMap)6 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)4 Test (org.junit.jupiter.api.Test)4 Map (java.util.Map)3 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)3 HistoricVariableInstanceEntity (org.activiti.engine.impl.persistence.entity.HistoricVariableInstanceEntity)3 Job (org.activiti.engine.runtime.Job)3 IdentityLink (org.activiti.engine.task.IdentityLink)3 HashSet (java.util.HashSet)2 List (java.util.List)2