Search in sources :

Example 6 with TaskService

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());
}
Also used : TaskService(org.activiti.engine.TaskService) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) Test(org.junit.Test)

Example 7 with TaskService

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());
}
Also used : Task(org.activiti.engine.task.Task) TaskService(org.activiti.engine.TaskService) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) Test(org.junit.Test)

Example 8 with TaskService

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());
}
Also used : TaskService(org.activiti.engine.TaskService) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) Test(org.junit.Test)

Example 9 with TaskService

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;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) TaskService(org.activiti.engine.TaskService) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) IdentityLink(org.activiti.engine.task.IdentityLink)

Example 10 with TaskService

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)");
}
Also used : TaskService(org.activiti.engine.TaskService) TaskQuery(org.activiti.engine.task.TaskQuery) IdentityLink(org.activiti.engine.task.IdentityLink) Test(org.testng.annotations.Test)

Aggregations

TaskService (org.activiti.engine.TaskService)38 Task (org.activiti.engine.task.Task)25 Test (org.junit.Test)15 RuntimeService (org.activiti.engine.RuntimeService)10 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)10 ProcessEngine (org.activiti.engine.ProcessEngine)6 WorkflowDefinition (org.activiti.workflow.simple.definition.WorkflowDefinition)6 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)5 HashMap (java.util.HashMap)5 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)4 StandaloneProcessEngineConfiguration (org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration)4 ObjectTypeUtil.toShortString (com.evolveum.midpoint.schema.util.ObjectTypeUtil.toShortString)3 MidPointPrincipal (com.evolveum.midpoint.security.api.MidPointPrincipal)3 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)3 ArrayList (java.util.ArrayList)3 RepositoryService (org.activiti.engine.RepositoryService)3 Task (com.evolveum.midpoint.task.api.Task)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 SystemException (com.evolveum.midpoint.util.exception.SystemException)2 ExternalResource (com.vaadin.terminal.ExternalResource)2