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;
}
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());
}
}
}
}
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());
}
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);
}
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();
}
Aggregations