Search in sources :

Example 56 with TaskQuery

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

the class ParallelGatewayTest method testReceyclingExecutionWithCallActivity.

/**
   * https://activiti.atlassian.net/browse/ACT-1222
   */
@Deployment
public void testReceyclingExecutionWithCallActivity() {
    runtimeService.startProcessInstanceByKey("parent-process");
    // After process start we have two tasks, one from the parent and one from the sub process
    TaskQuery query = taskService.createTaskQuery().orderByTaskName().asc();
    List<Task> tasks = query.list();
    assertEquals(2, tasks.size());
    assertEquals("Another task", tasks.get(0).getName());
    assertEquals("Some Task", tasks.get(1).getName());
    // we complete the task from the parent process, the root execution is receycled, the task in the sub process is still there 
    taskService.complete(tasks.get(1).getId());
    tasks = query.list();
    assertEquals(1, tasks.size());
    assertEquals("Another task", tasks.get(0).getName());
    // we end the task in the sub process and the sub process instance end is propagated to the parent process 
    taskService.complete(tasks.get(0).getId());
    assertEquals(0, taskService.createTaskQuery().count());
// There is a QA config without history, so we cannot work with this:
//assertEquals(1, historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).finished().count());    
}
Also used : Task(org.activiti.engine.task.Task) TaskQuery(org.activiti.engine.task.TaskQuery) Deployment(org.activiti.engine.test.Deployment)

Example 57 with TaskQuery

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

the class BoundaryTimerNonInterruptingEventTest method testTimerOnEmbeddedSubprocess.

@Deployment
public /**
   * see https://activiti.atlassian.net/browse/ACT-1173
   */
void testTimerOnEmbeddedSubprocess() {
    String id = runtimeService.startProcessInstanceByKey("nonInterruptingTimerOnEmbeddedSubprocess").getId();
    TaskQuery tq = taskService.createTaskQuery().taskAssignee("kermit");
    assertEquals(1, tq.count());
    // Simulate timer
    Job timer = managementService.createJobQuery().singleResult();
    managementService.executeJob(timer.getId());
    tq = taskService.createTaskQuery().taskAssignee("kermit");
    assertEquals(2, tq.count());
    List<Task> tasks = tq.list();
    taskService.complete(tasks.get(0).getId());
    taskService.complete(tasks.get(1).getId());
    assertProcessEnded(id);
}
Also used : Task(org.activiti.engine.task.Task) TaskQuery(org.activiti.engine.task.TaskQuery) Job(org.activiti.engine.runtime.Job) Deployment(org.activiti.engine.test.Deployment)

Example 58 with TaskQuery

use of org.activiti.engine.task.TaskQuery 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)

Example 59 with TaskQuery

use of org.activiti.engine.task.TaskQuery in project midpoint by Evolveum.

the class TestActivitiQuery method test200TestQueryByTaskVariable.

/**
	 * Actually, this mechanism is not used anymore. We use identity links to store information about assignees.
	 * But keeping this test - just in case something like that would be needed later.
	 */
@Test
public void test200TestQueryByTaskVariable() throws Exception {
    final String TEST_NAME = "test200TestQueryByTaskVariable";
    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";
    final String VAR = "someVariable";
    taskService.setVariableLocal(task.getId(), VAR, "[:abc];[:def];[UserType:" + userLead1Oid + "]");
    TaskQuery tq1 = taskService.createTaskQuery().includeTaskLocalVariables().taskVariableValueLike(VAR, "%:def]%").taskName(TASK_NAME);
    assertFound(tq1, "#1");
    TaskQuery tq2 = taskService.createTaskQuery().includeTaskLocalVariables().taskVariableValueLike(VAR, "%:xyz]%");
    org.activiti.engine.task.Task task2 = tq2.singleResult();
    System.out.println("Task2 = " + task2);
    assertNull("Found task2 even if it shouldn't", task2);
    TaskQuery tq3 = taskService.createTaskQuery().includeTaskLocalVariables().taskName(TASK_NAME).or().taskVariableValueLike(VAR, "%:ghi]%").taskVariableValueLike(VAR, "%:xxx]%").taskVariableValueLike(VAR, "%:" + userLead1Oid + "]%").endOr();
    org.activiti.engine.task.Task task3 = tq3.singleResult();
    System.out.println("Task3 = " + task3);
    assertNotNull("No task3", task3);
    TaskQuery tq4 = taskService.createTaskQuery().includeTaskLocalVariables().taskName(TASK_NAME).or().taskVariableValueLike(VAR, "%:" + userLead1Oid + "]%").taskVariableValueLike(VAR, "%:xxx]%").taskAssignee(userLead1Oid).endOr();
    org.activiti.engine.task.Task task4 = tq4.singleResult();
    System.out.println("Task4 = " + task4);
    assertNotNull("No task4", task4);
    TaskQuery tq5 = taskService.createTaskQuery().includeTaskLocalVariables().taskName(TASK_NAME).or().taskVariableValueLike(VAR, "%:" + userLead1Oid + "]%").taskVariableValueLike(VAR, "%:xxx]%").taskAssignee("xxx;" + userLead1Oid).endOr();
    org.activiti.engine.task.Task task5 = tq5.singleResult();
    System.out.println("Task5 = " + task5);
    assertNotNull("No task5", task5);
    TaskQuery tq6 = taskService.createTaskQuery().includeTaskLocalVariables().taskName(TASK_NAME).or().taskVariableValueLike(VAR, "%:xxx]%").taskVariableValueLike(VAR, "%:" + userLead1Oid + "]%").taskAssignee("xxx;yyy").endOr();
    org.activiti.engine.task.Task task6 = tq6.singleResult();
    System.out.println("Task6 = " + task6);
    assertNotNull("No task6", task6);
    TaskQuery tq7 = taskService.createTaskQuery().includeTaskLocalVariables().taskName(TASK_NAME).or().taskVariableValueLike(VAR, "%:xxx]%").taskVariableValueLike(VAR, "%:yyy]%").taskAssignee("xxx;UserType:" + userLead1Oid).endOr();
    org.activiti.engine.task.Task task7 = tq7.singleResult();
    System.out.println("Task7 = " + task7);
    assertNotNull("No task7", task7);
}
Also used : TaskService(org.activiti.engine.TaskService) TaskQuery(org.activiti.engine.task.TaskQuery) Test(org.testng.annotations.Test)

Example 60 with TaskQuery

use of org.activiti.engine.task.TaskQuery in project midpoint by Evolveum.

the class WorkItemProvider method createTaskQuery.

// primitive 'query interpreter'
// returns null if no results should be returned
private TaskQuery createTaskQuery(ObjectQuery query, boolean includeVariables, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult result) throws SchemaException {
    FilterComponents components = factorOutQuery(query, F_ASSIGNEE_REF, F_CANDIDATE_REF, F_EXTERNAL_ID);
    List<ObjectFilter> remainingClauses = components.getRemainderClauses();
    if (!remainingClauses.isEmpty()) {
        throw new SchemaException("Unsupported clause(s) in search filter: " + remainingClauses);
    }
    final ItemPath WORK_ITEM_ID_PATH = new ItemPath(F_EXTERNAL_ID);
    final ItemPath ASSIGNEE_PATH = new ItemPath(F_ASSIGNEE_REF);
    final ItemPath CANDIDATE_PATH = new ItemPath(F_CANDIDATE_REF);
    final ItemPath CREATED_PATH = new ItemPath(WorkItemType.F_CREATE_TIMESTAMP);
    final Map.Entry<ItemPath, Collection<? extends PrismValue>> workItemIdFilter = components.getKnownComponent(WORK_ITEM_ID_PATH);
    final Map.Entry<ItemPath, Collection<? extends PrismValue>> assigneeFilter = components.getKnownComponent(ASSIGNEE_PATH);
    final Map.Entry<ItemPath, Collection<? extends PrismValue>> candidateRolesFilter = components.getKnownComponent(CANDIDATE_PATH);
    TaskQuery taskQuery = activitiEngine.getTaskService().createTaskQuery();
    if (workItemIdFilter != null) {
        Collection<? extends PrismValue> filterValues = workItemIdFilter.getValue();
        if (filterValues.size() > 1) {
            throw new IllegalArgumentException("In a query there must be exactly one value for workItemId: " + filterValues);
        }
        taskQuery = taskQuery.taskId(((PrismPropertyValue<String>) filterValues.iterator().next()).getValue());
    }
    if (assigneeFilter != null) {
        taskQuery = addAssigneesToQuery(taskQuery, assigneeFilter);
    }
    if (candidateRolesFilter != null) {
        // TODO what about candidate users? (currently these are not supported)
        List<String> candidateGroups = MiscDataUtil.prismRefsToStrings((Collection<PrismReferenceValue>) candidateRolesFilter.getValue());
        if (!candidateGroups.isEmpty()) {
            taskQuery = taskQuery.taskCandidateGroupIn(candidateGroups);
        } else {
            // no groups -> no result
            return null;
        }
    }
    if (query != null && query.getPaging() != null) {
        ObjectPaging paging = query.getPaging();
        if (paging.getOrderingInstructions().size() > 1) {
            throw new UnsupportedOperationException("Ordering by more than one property is not supported: " + paging.getOrderingInstructions());
        } else if (paging.getOrderingInstructions().size() == 1) {
            ItemPath orderBy = paging.getOrderBy();
            if (CREATED_PATH.equivalent(orderBy)) {
                taskQuery = taskQuery.orderByTaskCreateTime();
            } else {
                throw new UnsupportedOperationException("Ordering by " + orderBy + " is not currently supported");
            }
            switch(paging.getDirection()) {
                case DESCENDING:
                    taskQuery = taskQuery.desc();
                    break;
                case ASCENDING:
                default:
                    taskQuery = taskQuery.asc();
                    break;
            }
        }
    }
    if (includeVariables) {
        return taskQuery.includeTaskLocalVariables().includeProcessVariables();
    } else {
        return taskQuery;
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) FilterComponents(com.evolveum.midpoint.schema.util.ObjectQueryUtil.FilterComponents) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) PrismValue(com.evolveum.midpoint.prism.PrismValue) ObjectPaging(com.evolveum.midpoint.prism.query.ObjectPaging) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) TaskQuery(org.activiti.engine.task.TaskQuery) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Aggregations

TaskQuery (org.activiti.engine.task.TaskQuery)92 Task (org.activiti.engine.task.Task)32 Deployment (org.activiti.engine.test.Deployment)29 ActivitiException (org.activiti.engine.ActivitiException)19 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)19 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)12 ArrayList (java.util.ArrayList)10 SimpleDateFormat (java.text.SimpleDateFormat)8 Date (java.util.Date)7 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)6 DelegateTask (org.activiti.engine.delegate.DelegateTask)3 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)3 HistoricVariableInstanceEntity (org.activiti.engine.impl.persistence.entity.HistoricVariableInstanceEntity)3 Job (org.activiti.engine.runtime.Job)3 HashMap (java.util.HashMap)2 TaskService (org.activiti.engine.TaskService)2 Test (org.testng.annotations.Test)2 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)1 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)1 PrismValue (com.evolveum.midpoint.prism.PrismValue)1