Search in sources :

Example 11 with TaskQuery

use of org.activiti.engine.task.TaskQuery in project carbon-business-process by wso2.

the class UserSubstitutionUtils method validateTasksList.

/**
 * Check whether each given task is a candidate for substitution by assignee
 * @param taskList
 * @param assignee
 */
public static boolean validateTasksList(List<String> taskList, String assignee) {
    if (taskList != null) {
        TaskQuery taskQuery = BPMNServerHolder.getInstance().getEngine().getTaskService().createTaskQuery();
        for (String taskId : taskList) {
            taskQuery.taskId(taskId);
            taskQuery.taskAssignee(assignee);
            // this should return a task if valid
            List<Task> tasks = taskQuery.list();
            if (tasks == null || tasks.isEmpty()) {
                return false;
            }
        }
    }
    return true;
}
Also used : Task(org.activiti.engine.task.Task) TaskQuery(org.activiti.engine.task.TaskQuery)

Example 12 with TaskQuery

use of org.activiti.engine.task.TaskQuery in project carbon-business-process by wso2.

the class UserSubstitutionUtils method assignToTaskOwner.

private static void assignToTaskOwner(String assignee, List<String> taskList) {
    TaskService taskService = BPMNServerHolder.getInstance().getEngine().getTaskService();
    if (taskList != null) {
        for (String taskId : taskList) {
            String taskOwner = null;
            List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(taskId);
            for (IdentityLink link : identityLinks) {
                if (IdentityLinkType.OWNER.equals(link.getType())) {
                    taskOwner = link.getUserId();
                }
            }
            if (taskOwner != null) {
                // assign to task owner
                taskService.setAssignee(taskId, taskOwner);
            } else {
                taskService.addCandidateUser(taskId, assignee);
                taskService.unclaim(taskId);
            }
        }
    } else {
        // reassign all tasks
        TaskQuery taskQuery = taskService.createTaskQuery();
        taskQuery.taskAssignee(assignee);
        List<Task> list = taskQuery.list();
        for (Task task : list) {
            String taskOwner = task.getOwner();
            if (taskOwner != null) {
                // assign to task owner
                taskService.setAssignee(task.getId(), taskOwner);
            } else {
                taskService.addCandidateUser(task.getId(), assignee);
                taskService.unclaim(task.getId());
            }
        }
    }
}
Also used : Task(org.activiti.engine.task.Task) TaskQuery(org.activiti.engine.task.TaskQuery) IdentityLink(org.activiti.engine.task.IdentityLink)

Example 13 with TaskQuery

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

the class CallActivityAdvancedTest method testCallSequentialSubProcessWithExpressions.

@Deployment(resources = { "org/activiti/engine/test/bpmn/callactivity/CallActivity.testCallSequentialSubProcess.bpmn20.xml", "org/activiti/engine/test/bpmn/callactivity/CallActivity.testCallSimpleSubProcessWithExpressions.bpmn20.xml", "org/activiti/engine/test/bpmn/callactivity/simpleSubProcess.bpmn20.xml", "org/activiti/engine/test/bpmn/callactivity/simpleSubProcess2.bpmn20.xml" })
public void testCallSequentialSubProcessWithExpressions() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("callSequentialSubProcess");
    // FIRST sub process calls simpleSubProcess
    // one task in the subprocess should be active after starting the
    // process
    // instance
    TaskQuery taskQuery = taskService.createTaskQuery();
    Task taskBeforeSubProcess = taskQuery.singleResult();
    assertThat(taskBeforeSubProcess.getName()).isEqualTo("Task before subprocess");
    // Completing the task continues the process which leads to calling the
    // subprocess. The sub process we want to call is passed in as a
    // variable
    // into this task
    taskService.setVariable(taskBeforeSubProcess.getId(), "simpleSubProcessExpression", "simpleSubProcess");
    taskService.complete(taskBeforeSubProcess.getId());
    Task taskInSubProcess = taskQuery.singleResult();
    assertThat(taskInSubProcess.getName()).isEqualTo("Task in subprocess");
    // Completing the task in the subprocess, finishes the subprocess
    taskService.complete(taskInSubProcess.getId());
    Task taskAfterSubProcess = taskQuery.singleResult();
    assertThat(taskAfterSubProcess.getName()).isEqualTo("Task after subprocess");
    // Completing this task end the process instance
    taskService.complete(taskAfterSubProcess.getId());
    // SECOND sub process calls simpleSubProcess2
    // one task in the subprocess should be active after starting the
    // process
    // instance
    taskQuery = taskService.createTaskQuery();
    taskBeforeSubProcess = taskQuery.singleResult();
    assertThat(taskBeforeSubProcess.getName()).isEqualTo("Task before subprocess");
    // Completing the task continues the process which leads to calling the
    // subprocess. The sub process we want to call is passed in as a
    // variable
    // into this task
    taskService.setVariable(taskBeforeSubProcess.getId(), "simpleSubProcessExpression", "simpleSubProcess2");
    taskService.complete(taskBeforeSubProcess.getId());
    taskInSubProcess = taskQuery.singleResult();
    assertThat(taskInSubProcess.getName()).isEqualTo("Task in subprocess 2");
    // Completing the task in the subprocess, finishes the subprocess
    taskService.complete(taskInSubProcess.getId());
    taskAfterSubProcess = taskQuery.singleResult();
    assertThat(taskAfterSubProcess.getName()).isEqualTo("Task after subprocess");
    // Completing this task end the process instance
    taskService.complete(taskAfterSubProcess.getId());
    assertProcessEnded(processInstance.getId());
}
Also used : Task(org.activiti.engine.task.Task) TaskQuery(org.activiti.engine.task.TaskQuery) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 14 with TaskQuery

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

the class SubTaskQueryTest method testQueryWithPagination.

/**
 * test for task inclusion/exclusion (no other filters, no sort)
 */
public void testQueryWithPagination() throws Exception {
    // query all tasks, including subtasks
    TaskQuery query = taskService.createTaskQuery();
    assertThat(query.count()).isEqualTo(10);
    assertThat(query.listPage(0, 2)).hasSize(2);
    // query only parent tasks (exclude subtasks)
    query = taskService.createTaskQuery().excludeSubtasks();
    assertThat(query.count()).isEqualTo(3);
    assertThat(query.listPage(0, 1)).hasSize(1);
}
Also used : TaskQuery(org.activiti.engine.task.TaskQuery)

Example 15 with TaskQuery

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

the class SubTaskQueryTest method testQueryByAssigneeExcludeSubtasksPaginated.

/**
 * test for task inclusion/exclusion when additional filter is specified (like assignee), no order.
 */
public void testQueryByAssigneeExcludeSubtasksPaginated() throws Exception {
    // gonzo has 2 root tasks and 3+2 subtasks assigned
    // include subtasks
    TaskQuery query = taskService.createTaskQuery().taskAssignee("gonzo");
    assertThat(query.count()).isEqualTo(7);
    assertThat(query.listPage(0, 2)).hasSize(2);
    // exclude subtasks
    query = taskService.createTaskQuery().taskAssignee("gonzo").excludeSubtasks();
    assertThat(query.count()).isEqualTo(2);
    assertThat(query.listPage(0, 1)).hasSize(1);
    // kermit has no root tasks and no subtasks assigned
    // include subtasks
    query = taskService.createTaskQuery().taskAssignee(KERMIT);
    assertThat(query.count()).isEqualTo(0);
    assertThat(query.listPage(0, 2)).hasSize(0);
    assertThat(query.singleResult()).isNull();
    // exclude subtasks
    query = taskService.createTaskQuery().taskAssignee(KERMIT).excludeSubtasks();
    assertThat(query.count()).isEqualTo(0);
    assertThat(query.listPage(0, 2)).hasSize(0);
    assertThat(query.singleResult()).isNull();
}
Also used : TaskQuery(org.activiti.engine.task.TaskQuery)

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