Search in sources :

Example 51 with HistoricTaskInstance

use of org.activiti.engine.history.HistoricTaskInstance in project Activiti by Activiti.

the class HistoricTaskAndVariablesQueryTest method testOrQuery.

@Deployment
public void testOrQuery() {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        HistoricTaskInstance task = historyService.createHistoricTaskInstanceQuery().includeTaskLocalVariables().or().taskAssignee("gonzo").endOr().singleResult();
        Map<String, Object> variableMap = task.getTaskLocalVariables();
        assertEquals(2, variableMap.size());
        assertEquals(0, task.getProcessVariables().size());
        assertNotNull(variableMap.get("testVar"));
        assertEquals("someVariable", variableMap.get("testVar"));
        assertNotNull(variableMap.get("testVar2"));
        assertEquals(123, variableMap.get("testVar2"));
        List<HistoricTaskInstance> tasks = historyService.createHistoricTaskInstanceQuery().list();
        assertEquals(3, tasks.size());
        task = historyService.createHistoricTaskInstanceQuery().includeProcessVariables().or().taskAssignee("gonzo").taskVariableValueEquals("localVar", "nonExisting").endOr().singleResult();
        assertEquals(0, task.getProcessVariables().size());
        assertEquals(0, task.getTaskLocalVariables().size());
        Map<String, Object> startMap = new HashMap<String, Object>();
        startMap.put("processVar", true);
        runtimeService.startProcessInstanceByKey("oneTaskProcess", startMap);
        task = historyService.createHistoricTaskInstanceQuery().includeProcessVariables().or().taskAssignee("kermit").taskVariableValueEquals("localVar", "nonExisting").endOr().singleResult();
        assertEquals(1, task.getProcessVariables().size());
        assertEquals(0, task.getTaskLocalVariables().size());
        assertTrue((Boolean) task.getProcessVariables().get("processVar"));
        task = historyService.createHistoricTaskInstanceQuery().includeProcessVariables().or().taskAssignee("kermit").taskVariableValueEquals("localVar", "nonExisting").endOr().or().processDefinitionKey("oneTaskProcess").taskVariableValueEquals("localVar", "nonExisting").endOr().singleResult();
        assertNotNull(task);
        assertEquals(1, task.getProcessVariables().size());
        assertEquals(0, task.getTaskLocalVariables().size());
        assertTrue((Boolean) task.getProcessVariables().get("processVar"));
        taskService.setVariable(task.getId(), "anotherProcessVar", 123);
        taskService.setVariableLocal(task.getId(), "localVar", "test");
        task = historyService.createHistoricTaskInstanceQuery().includeTaskLocalVariables().or().taskAssignee("kermit").taskVariableValueEquals("localVar", "nonExisting").endOr().singleResult();
        assertEquals(0, task.getProcessVariables().size());
        assertEquals(1, task.getTaskLocalVariables().size());
        assertEquals("test", task.getTaskLocalVariables().get("localVar"));
        task = historyService.createHistoricTaskInstanceQuery().includeProcessVariables().or().taskAssignee("kermit").taskVariableValueEquals("localVar", "nonExisting").endOr().singleResult();
        assertEquals(2, task.getProcessVariables().size());
        assertEquals(0, task.getTaskLocalVariables().size());
        assertEquals(true, task.getProcessVariables().get("processVar"));
        assertEquals(123, task.getProcessVariables().get("anotherProcessVar"));
        task = historyService.createHistoricTaskInstanceQuery().includeTaskLocalVariables().or().taskAssignee("nonexisting").taskVariableValueLike("testVar", "someVar%").endOr().singleResult();
        assertEquals(2, task.getTaskLocalVariables().size());
        assertEquals(0, task.getProcessVariables().size());
        assertEquals("someVariable", task.getTaskLocalVariables().get("testVar"));
        assertEquals(123, task.getTaskLocalVariables().get("testVar2"));
        task = historyService.createHistoricTaskInstanceQuery().includeTaskLocalVariables().or().taskAssignee("nonexisting").taskVariableValueLikeIgnoreCase("testVar", "somevar%").endOr().singleResult();
        assertEquals(2, task.getTaskLocalVariables().size());
        assertEquals(0, task.getProcessVariables().size());
        assertEquals("someVariable", task.getTaskLocalVariables().get("testVar"));
        assertEquals(123, task.getTaskLocalVariables().get("testVar2"));
        task = historyService.createHistoricTaskInstanceQuery().includeTaskLocalVariables().or().taskAssignee("nonexisting").taskVariableValueLike("testVar", "someVar2%").endOr().singleResult();
        assertNull(task);
        tasks = historyService.createHistoricTaskInstanceQuery().includeTaskLocalVariables().or().taskInvolvedUser("kermit").taskVariableValueEquals("localVar", "nonExisting").endOr().orderByTaskCreateTime().asc().list();
        assertEquals(3, tasks.size());
        assertEquals(1, tasks.get(0).getTaskLocalVariables().size());
        assertEquals("test", tasks.get(0).getTaskLocalVariables().get("test"));
        assertEquals(0, tasks.get(0).getProcessVariables().size());
        tasks = historyService.createHistoricTaskInstanceQuery().includeProcessVariables().or().taskInvolvedUser("kermit").taskVariableValueEquals("localVar", "nonExisting").endOr().orderByTaskCreateTime().asc().list();
        assertEquals(3, tasks.size());
        assertEquals(0, tasks.get(0).getProcessVariables().size());
        assertEquals(0, tasks.get(0).getTaskLocalVariables().size());
        task = historyService.createHistoricTaskInstanceQuery().includeTaskLocalVariables().taskAssignee("kermit").or().taskVariableValueEquals("localVar", "test").taskVariableValueEquals("localVar", "nonExisting").endOr().singleResult();
        assertEquals(0, task.getProcessVariables().size());
        assertEquals(1, task.getTaskLocalVariables().size());
        assertEquals("test", task.getTaskLocalVariables().get("localVar"));
        task = historyService.createHistoricTaskInstanceQuery().includeProcessVariables().taskAssignee("kermit").or().taskVariableValueEquals("localVar", "test").taskVariableValueEquals("localVar", "nonExisting").endOr().singleResult();
        assertEquals(2, task.getProcessVariables().size());
        assertEquals(0, task.getTaskLocalVariables().size());
        assertEquals(true, task.getProcessVariables().get("processVar"));
        assertEquals(123, task.getProcessVariables().get("anotherProcessVar"));
        task = historyService.createHistoricTaskInstanceQuery().includeTaskLocalVariables().includeProcessVariables().or().taskAssignee("kermit").taskVariableValueEquals("localVar", "nonExisting").endOr().singleResult();
        assertEquals(2, task.getProcessVariables().size());
        assertEquals(1, task.getTaskLocalVariables().size());
        assertEquals("test", task.getTaskLocalVariables().get("localVar"));
        assertEquals(true, task.getProcessVariables().get("processVar"));
        assertEquals(123, task.getProcessVariables().get("anotherProcessVar"));
        task = historyService.createHistoricTaskInstanceQuery().taskAssignee("gonzo").singleResult();
        taskService.complete(task.getId());
        task = historyService.createHistoricTaskInstanceQuery().includeTaskLocalVariables().or().finished().taskVariableValueEquals("localVar", "nonExisting").endOr().singleResult();
        variableMap = task.getTaskLocalVariables();
        assertEquals(2, variableMap.size());
        assertEquals(0, task.getProcessVariables().size());
        assertNotNull(variableMap.get("testVar"));
        assertEquals("someVariable", variableMap.get("testVar"));
        assertNotNull(variableMap.get("testVar2"));
        assertEquals(123, variableMap.get("testVar2"));
    }
}
Also used : HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) HashMap(java.util.HashMap) Deployment(org.activiti.engine.test.Deployment)

Example 52 with HistoricTaskInstance

use of org.activiti.engine.history.HistoricTaskInstance in project Activiti by Activiti.

the class HistoricTaskAndVariablesQueryTest method testWithoutDueDateQuery.

@Deployment(resources = { "org/activiti/engine/test/api/task/TaskQueryTest.testProcessDefinition.bpmn20.xml" })
public void testWithoutDueDateQuery() throws Exception {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
        HistoricTaskInstance historicTask = historyService.createHistoricTaskInstanceQuery().processInstanceId(processInstance.getId()).withoutTaskDueDate().singleResult();
        assertNotNull(historicTask);
        assertNull(historicTask.getDueDate());
        // Set due-date on task
        Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
        Date dueDate = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss").parse("01/02/2003 01:12:13");
        task.setDueDate(dueDate);
        taskService.saveTask(task);
        assertEquals(0, historyService.createHistoricTaskInstanceQuery().processInstanceId(processInstance.getId()).withoutTaskDueDate().count());
        task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
        // Clear due-date on task
        task.setDueDate(null);
        taskService.saveTask(task);
        assertEquals(1, historyService.createHistoricTaskInstanceQuery().processInstanceId(processInstance.getId()).withoutTaskDueDate().count());
    }
}
Also used : Task(org.activiti.engine.task.Task) HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Deployment(org.activiti.engine.test.Deployment)

Example 53 with HistoricTaskInstance

use of org.activiti.engine.history.HistoricTaskInstance in project Activiti by Activiti.

the class HistoryServiceTest method testHistoricTaskInstanceOrQueryByDeploymentIdIn.

@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml", "org/activiti/engine/test/api/runtime/oneTaskProcess2.bpmn20.xml" })
public void testHistoricTaskInstanceOrQueryByDeploymentIdIn() {
    org.activiti.engine.repository.Deployment deployment = repositoryService.createDeploymentQuery().singleResult();
    HashSet<String> processInstanceIds = new HashSet<String>();
    for (int i = 0; i < 4; i++) {
        processInstanceIds.add(runtimeService.startProcessInstanceByKey("oneTaskProcess", i + "").getId());
    }
    processInstanceIds.add(runtimeService.startProcessInstanceByKey("oneTaskProcess2", "1").getId());
    List<String> deploymentIds = new ArrayList<String>();
    deploymentIds.add(deployment.getId());
    HistoricTaskInstanceQuery taskInstanceQuery = historyService.createHistoricTaskInstanceQuery().or().deploymentIdIn(deploymentIds).processDefinitionId("invalid").endOr();
    assertEquals(5, taskInstanceQuery.count());
    List<HistoricTaskInstance> taskInstances = taskInstanceQuery.list();
    assertNotNull(taskInstances);
    assertEquals(5, taskInstances.size());
    deploymentIds.add("invalid");
    taskInstanceQuery = historyService.createHistoricTaskInstanceQuery().or().deploymentIdIn(deploymentIds).processDefinitionId("invalid").endOr();
    assertEquals(5, taskInstanceQuery.count());
    deploymentIds = new ArrayList<String>();
    deploymentIds.add("invalid");
    taskInstanceQuery = historyService.createHistoricTaskInstanceQuery().or().deploymentIdIn(deploymentIds).processDefinitionId("invalid").endOr();
    assertEquals(0, taskInstanceQuery.count());
    taskInstanceQuery = historyService.createHistoricTaskInstanceQuery().or().taskDefinitionKey("theTask").deploymentIdIn(deploymentIds).endOr();
    assertEquals(5, taskInstanceQuery.count());
    taskInstanceQuery = historyService.createHistoricTaskInstanceQuery().taskDefinitionKey("theTask").or().deploymentIdIn(deploymentIds).endOr();
    assertEquals(0, taskInstanceQuery.count());
}
Also used : HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) ArrayList(java.util.ArrayList) HistoricTaskInstanceQuery(org.activiti.engine.history.HistoricTaskInstanceQuery) HashSet(java.util.HashSet) Deployment(org.activiti.engine.test.Deployment)

Example 54 with HistoricTaskInstance

use of org.activiti.engine.history.HistoricTaskInstance in project Activiti by Activiti.

the class HistoricTaskAndVariablesQueryTest method testQuery.

@Deployment
public void testQuery() {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        HistoricTaskInstance task = historyService.createHistoricTaskInstanceQuery().includeTaskLocalVariables().taskAssignee("gonzo").singleResult();
        Map<String, Object> variableMap = task.getTaskLocalVariables();
        assertEquals(2, variableMap.size());
        assertEquals(0, task.getProcessVariables().size());
        assertNotNull(variableMap.get("testVar"));
        assertEquals("someVariable", variableMap.get("testVar"));
        assertNotNull(variableMap.get("testVar2"));
        assertEquals(123, variableMap.get("testVar2"));
        List<HistoricTaskInstance> tasks = historyService.createHistoricTaskInstanceQuery().list();
        assertEquals(3, tasks.size());
        task = historyService.createHistoricTaskInstanceQuery().includeProcessVariables().taskAssignee("gonzo").singleResult();
        assertEquals(0, task.getProcessVariables().size());
        assertEquals(0, task.getTaskLocalVariables().size());
        Map<String, Object> startMap = new HashMap<String, Object>();
        startMap.put("processVar", true);
        runtimeService.startProcessInstanceByKey("oneTaskProcess", startMap);
        task = historyService.createHistoricTaskInstanceQuery().includeProcessVariables().taskAssignee("kermit").singleResult();
        assertEquals(1, task.getProcessVariables().size());
        assertEquals(0, task.getTaskLocalVariables().size());
        assertTrue((Boolean) task.getProcessVariables().get("processVar"));
        taskService.setVariable(task.getId(), "anotherProcessVar", 123);
        taskService.setVariableLocal(task.getId(), "localVar", "test");
        task = historyService.createHistoricTaskInstanceQuery().includeTaskLocalVariables().taskAssignee("kermit").singleResult();
        assertEquals(0, task.getProcessVariables().size());
        assertEquals(1, task.getTaskLocalVariables().size());
        assertEquals("test", task.getTaskLocalVariables().get("localVar"));
        task = historyService.createHistoricTaskInstanceQuery().includeProcessVariables().taskAssignee("kermit").singleResult();
        assertEquals(2, task.getProcessVariables().size());
        assertEquals(0, task.getTaskLocalVariables().size());
        assertEquals(true, task.getProcessVariables().get("processVar"));
        assertEquals(123, task.getProcessVariables().get("anotherProcessVar"));
        task = historyService.createHistoricTaskInstanceQuery().taskVariableValueLike("testVar", "someVaria%").singleResult();
        assertNotNull(task);
        assertEquals("gonzoTask", task.getName());
        task = historyService.createHistoricTaskInstanceQuery().taskVariableValueLikeIgnoreCase("testVar", "somevaria%").singleResult();
        assertNotNull(task);
        assertEquals("gonzoTask", task.getName());
        task = historyService.createHistoricTaskInstanceQuery().taskVariableValueLikeIgnoreCase("testVar", "somevaria2%").singleResult();
        assertNull(task);
        tasks = historyService.createHistoricTaskInstanceQuery().includeTaskLocalVariables().taskInvolvedUser("kermit").orderByTaskCreateTime().asc().list();
        assertEquals(3, tasks.size());
        assertEquals(1, tasks.get(0).getTaskLocalVariables().size());
        assertEquals("test", tasks.get(0).getTaskLocalVariables().get("test"));
        assertEquals(0, tasks.get(0).getProcessVariables().size());
        tasks = historyService.createHistoricTaskInstanceQuery().includeProcessVariables().taskInvolvedUser("kermit").orderByTaskCreateTime().asc().list();
        assertEquals(3, tasks.size());
        assertEquals(0, tasks.get(0).getProcessVariables().size());
        assertEquals(0, tasks.get(0).getTaskLocalVariables().size());
        task = historyService.createHistoricTaskInstanceQuery().includeTaskLocalVariables().taskAssignee("kermit").taskVariableValueEquals("localVar", "test").singleResult();
        assertEquals(0, task.getProcessVariables().size());
        assertEquals(1, task.getTaskLocalVariables().size());
        assertEquals("test", task.getTaskLocalVariables().get("localVar"));
        task = historyService.createHistoricTaskInstanceQuery().includeProcessVariables().taskAssignee("kermit").taskVariableValueEquals("localVar", "test").singleResult();
        assertEquals(2, task.getProcessVariables().size());
        assertEquals(0, task.getTaskLocalVariables().size());
        assertEquals(true, task.getProcessVariables().get("processVar"));
        assertEquals(123, task.getProcessVariables().get("anotherProcessVar"));
        task = historyService.createHistoricTaskInstanceQuery().includeTaskLocalVariables().includeProcessVariables().taskAssignee("kermit").singleResult();
        assertEquals(2, task.getProcessVariables().size());
        assertEquals(1, task.getTaskLocalVariables().size());
        assertEquals("test", task.getTaskLocalVariables().get("localVar"));
        assertEquals(true, task.getProcessVariables().get("processVar"));
        assertEquals(123, task.getProcessVariables().get("anotherProcessVar"));
        task = historyService.createHistoricTaskInstanceQuery().taskAssignee("gonzo").singleResult();
        taskService.complete(task.getId());
        task = (HistoricTaskInstance) historyService.createHistoricTaskInstanceQuery().includeTaskLocalVariables().finished().singleResult();
        variableMap = task.getTaskLocalVariables();
        assertEquals(2, variableMap.size());
        assertEquals(0, task.getProcessVariables().size());
        assertNotNull(variableMap.get("testVar"));
        assertEquals("someVariable", variableMap.get("testVar"));
        assertNotNull(variableMap.get("testVar2"));
        assertEquals(123, variableMap.get("testVar2"));
    }
}
Also used : HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) HashMap(java.util.HashMap) Deployment(org.activiti.engine.test.Deployment)

Example 55 with HistoricTaskInstance

use of org.activiti.engine.history.HistoricTaskInstance in project Activiti by Activiti.

the class HistoricTaskAndVariablesQueryTest method testCandidate.

@Deployment
public void testCandidate() {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
        List<HistoricTaskInstance> tasks = historyService.createHistoricTaskInstanceQuery().taskCandidateUser("kermit").list();
        assertEquals(3, tasks.size());
        tasks = historyService.createHistoricTaskInstanceQuery().taskCandidateUser("gonzo").list();
        assertEquals(0, tasks.size());
        tasks = historyService.createHistoricTaskInstanceQuery().taskCandidateUser("fozzie").list();
        assertEquals(1, tasks.size());
        tasks = historyService.createHistoricTaskInstanceQuery().taskCandidateGroup("management").list();
        assertEquals(1, tasks.size());
        List<String> groups = new ArrayList<String>();
        groups.add("management");
        groups.add("accountancy");
        tasks = historyService.createHistoricTaskInstanceQuery().taskCandidateGroupIn(groups).list();
        assertEquals(1, tasks.size());
        tasks = historyService.createHistoricTaskInstanceQuery().taskCandidateUser("kermit").taskCandidateGroupIn(groups).list();
        assertEquals(3, tasks.size());
        tasks = historyService.createHistoricTaskInstanceQuery().taskCandidateUser("gonzo").taskCandidateGroupIn(groups).list();
        assertEquals(1, tasks.size());
        Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
        taskService.complete(task.getId());
        assertEquals(0, taskService.createTaskQuery().processInstanceId(processInstance.getId()).count());
        tasks = historyService.createHistoricTaskInstanceQuery().taskCandidateUser("kermit").list();
        assertEquals(3, tasks.size());
        tasks = historyService.createHistoricTaskInstanceQuery().taskCandidateUser("gonzo").list();
        assertEquals(0, tasks.size());
        tasks = historyService.createHistoricTaskInstanceQuery().taskCandidateUser("fozzie").list();
        assertEquals(1, tasks.size());
        tasks = historyService.createHistoricTaskInstanceQuery().taskCandidateGroup("management").list();
        assertEquals(1, tasks.size());
        tasks = historyService.createHistoricTaskInstanceQuery().taskCandidateUser("kermit").taskCandidateGroup("management").list();
        assertEquals(3, tasks.size());
        tasks = historyService.createHistoricTaskInstanceQuery().taskCandidateUser("gonzo").taskCandidateGroup("management").list();
        assertEquals(1, tasks.size());
        tasks = historyService.createHistoricTaskInstanceQuery().taskCandidateUser("gonzo").taskCandidateGroup("invalid").list();
        assertEquals(0, tasks.size());
        tasks = historyService.createHistoricTaskInstanceQuery().taskCandidateGroupIn(groups).list();
        assertEquals(1, tasks.size());
    }
}
Also used : Task(org.activiti.engine.task.Task) HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) ArrayList(java.util.ArrayList) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Aggregations

HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)65 Task (org.activiti.engine.task.Task)27 Deployment (org.activiti.engine.test.Deployment)26 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)16 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)9 ArrayList (java.util.ArrayList)8 HistoricTaskInstanceQuery (org.activiti.engine.history.HistoricTaskInstanceQuery)7 Date (java.util.Date)6 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)6 HistoricActivityInstance (org.activiti.engine.history.HistoricActivityInstance)6 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 Label (com.vaadin.ui.Label)4 SimpleDateFormat (java.text.SimpleDateFormat)4 Attachment (org.activiti.engine.task.Attachment)4 Button (com.vaadin.ui.Button)3 ClickEvent (com.vaadin.ui.Button.ClickEvent)3 ClickListener (com.vaadin.ui.Button.ClickListener)3