use of org.activiti.engine.TaskService in project Activiti by Activiti.
the class WorkflowConversionTest method testInitiatorOnHumanStep.
@Test
public void testInitiatorOnHumanStep() {
WorkflowDefinition workflowDefinition = new WorkflowDefinition().name("testWorkflow").description("This is a test workflow").addHumanStep("step1", "kermit").addHumanStepForWorkflowInitiator("step2");
activitiRule.getIdentityService().setAuthenticatedUserId("MrPink");
activitiRule.getRuntimeService().startProcessInstanceByKey(convertAndDeploy(workflowDefinition));
activitiRule.getIdentityService().setAuthenticatedUserId("null");
// Complete first task
TaskService taskService = activitiRule.getTaskService();
assertEquals(1, taskService.createTaskQuery().taskAssignee("kermit").count());
taskService.complete(taskService.createTaskQuery().singleResult().getId());
// Second task should be done by initiator of workflow
assertEquals(1, taskService.createTaskQuery().taskAssignee("MrPink").count());
assertEquals(0, taskService.createTaskQuery().taskAssignee("kermit").count());
}
use of org.activiti.engine.TaskService in project Activiti by Activiti.
the class WorkflowConversionTest method testThreeUserTasksInParallel.
@Test
public void testThreeUserTasksInParallel() throws Exception {
TaskService taskService = activitiRule.getTaskService();
WorkflowDefinition workflowDefinition = new WorkflowDefinition().name("testWorkflow").description("This is a test workflow").inParallel().inList().addHumanStep("first task", "kermit").endList().inList().addHumanStep("second step", "gonzo").endList().inList().addHumanStep("third task", "mispiggy").endList().endParallel().addHumanStep("Task in between", "kermit").inParallel().inList().addHumanStep("fourth task", "gonzo").endList().inList().addHumanStep("fifth step", "gonzo").endList().endParallel();
// Validate
activitiRule.getRuntimeService().startProcessInstanceByKey(convertAndDeploy(workflowDefinition));
assertEquals(1, taskService.createTaskQuery().taskAssignee("kermit").count());
assertEquals(1, taskService.createTaskQuery().taskAssignee("gonzo").count());
assertEquals(1, taskService.createTaskQuery().taskAssignee("mispiggy").count());
// Complete tasks
for (Task task : taskService.createTaskQuery().list()) {
activitiRule.getTaskService().complete(task.getId());
}
// In between task should be active
Task task = taskService.createTaskQuery().singleResult();
assertEquals("Task in between", task.getName());
taskService.complete(task.getId());
// There should be two task open now for gonzo
assertEquals(2, taskService.createTaskQuery().taskAssignee("gonzo").count());
}
use of org.activiti.engine.TaskService in project Activiti by Activiti.
the class WorkflowConversionTest method testGroupsForHumanStep.
@Test
public void testGroupsForHumanStep() {
WorkflowDefinition workflowDefinition = new WorkflowDefinition().name("testWorkflow").description("This is a test workflow").addHumanStepForGroup("step1", "management", "sales").addHumanStepForGroup("step1", "sales");
activitiRule.getRuntimeService().startProcessInstanceByKey(convertAndDeploy(workflowDefinition));
// Complete first task
TaskService taskService = activitiRule.getTaskService();
assertEquals(1, taskService.createTaskQuery().taskCandidateGroup("management").count());
assertEquals(1, taskService.createTaskQuery().taskCandidateGroup("sales").count());
assertEquals(1, taskService.createTaskQuery().taskCandidateGroupIn(Arrays.asList("management")).count());
assertEquals(1, taskService.createTaskQuery().taskCandidateGroupIn(Arrays.asList("management", "sales")).count());
taskService.complete(taskService.createTaskQuery().singleResult().getId());
// Second task is only done by sales
assertEquals(0, taskService.createTaskQuery().taskCandidateGroup("management").count());
assertEquals(1, taskService.createTaskQuery().taskCandidateGroup("sales").count());
assertEquals(0, taskService.createTaskQuery().taskCandidateGroupIn(Arrays.asList("management")).count());
assertEquals(1, taskService.createTaskQuery().taskCandidateGroupIn(Arrays.asList("sales")).count());
assertEquals(1, taskService.createTaskQuery().taskCandidateGroupIn(Arrays.asList("management", "sales")).count());
}
use of org.activiti.engine.TaskService in project midpoint by Evolveum.
the class MiscDataUtil method isAmongCandidates.
// principal != null, principal.getOid() != null, principal.getUser() != null
private boolean isAmongCandidates(MidPointPrincipal principal, String taskId) {
String currentUserOid = principal.getOid();
List<IdentityLink> identityLinks;
try {
TaskService taskService = activitiEngine.getTaskService();
identityLinks = taskService.getIdentityLinksForTask(taskId);
} catch (ActivitiException e) {
throw new SystemException("Couldn't determine user authorization, because the task candidate users and groups couldn't be retrieved: " + e.getMessage(), e);
}
for (IdentityLink identityLink : identityLinks) {
if (identityLink.getUserId() != null && identityLink.getUserId().equals(currentUserOid)) {
return true;
}
if (identityLink.getGroupId() != null) {
if (isMemberOfActivitiGroup(principal.getUser(), identityLink.getGroupId())) {
return true;
}
}
}
return false;
}
use of org.activiti.engine.TaskService in project midpoint by Evolveum.
the class TestActivitiQuery method test210TestQueryByIdentityLink.
@Test
public void test210TestQueryByIdentityLink() throws Exception {
final String TEST_NAME = "test210TestQueryByIdentityLink";
TestUtil.displayTestTile(this, TEST_NAME);
login(userAdministrator);
TaskService taskService = activitiEngine.getTaskService();
TaskQuery tq = taskService.createTaskQuery();
org.activiti.engine.task.Task task = tq.singleResult();
System.out.println("Task = " + task);
assertNotNull("No task", task);
final String TASK_NAME = "Approve assigning Role1a to jack";
List<IdentityLink> linksBefore = taskService.getIdentityLinksForTask(task.getId());
System.out.println("Identity links (before)" + linksBefore);
taskService.addUserIdentityLink(task.getId(), "123", CommonProcessVariableNames.MIDPOINT_ASSIGNEE);
taskService.addUserIdentityLink(task.getId(), "456", CommonProcessVariableNames.MIDPOINT_ASSIGNEE);
List<IdentityLink> linksAfter = taskService.getIdentityLinksForTask(task.getId());
System.out.println("Identity links (after)" + linksAfter);
TaskQuery tq1 = taskService.createTaskQuery().taskInvolvedUser("UserType:" + userLead1Oid).taskName(TASK_NAME);
assertFound(tq1, "involved user (assignee)");
assertFound(taskService.createTaskQuery().taskInvolvedUser("123").taskName(TASK_NAME), "involved user (midpoint-assignee 123)");
assertFound(taskService.createTaskQuery().taskInvolvedUser("456").taskName(TASK_NAME), "involved user (midpoint-assignee 456)");
assertNotFound(taskService.createTaskQuery().taskInvolvedUser("123xxx").taskName(TASK_NAME), "involved user (wrong user)");
assertFound(taskService.createTaskQuery().taskInvolvedUser("123;124").taskName(TASK_NAME), "involved user (123 or 124)");
assertFound(taskService.createTaskQuery().taskInvolvedUser("124;123").taskName(TASK_NAME), "involved user (124 or 123)");
assertNotFound(taskService.createTaskQuery().taskInvolvedUser("124x;123x").taskName(TASK_NAME), "involved user (124x or 123x)");
assertFound(taskService.createTaskQuery().or().taskInvolvedUser("123").taskCandidateGroup("xxxxxxx").endOr().taskName(TASK_NAME), "involved user (123 or candidate group xxxxxxx)");
assertFound(taskService.createTaskQuery().or().taskInvolvedUser("123;124").taskCandidateGroup("xxxxxxx").endOr().taskName(TASK_NAME), "involved user (123 or 124 or candidate group xxxxxxx)");
assertNotFound(taskService.createTaskQuery().or().taskInvolvedUser("123x;124x").taskCandidateGroup("xxxxxxx").endOr().taskName(TASK_NAME), "involved user (123x or 124x or candidate group xxxxxxx)");
}
Aggregations