Search in sources :

Example 1 with HistoricActivityInstance

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

the class MultiInstanceTest method testEndTimeOnMiSubprocess.

@Deployment
public void testEndTimeOnMiSubprocess() {
    if (!processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
        return;
    }
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("multiInstanceSubProcessParallelTasks");
    List<Task> tasks = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();
    assertEquals(2, tasks.size());
    assertEquals("User Task 1", tasks.get(0).getName());
    assertEquals("User Task 1", tasks.get(1).getName());
    // End time should not be set for the subprocess
    List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery().activityId("subprocess1").list();
    assertEquals(2, historicActivityInstances.size());
    for (HistoricActivityInstance historicActivityInstance : historicActivityInstances) {
        assertNotNull(historicActivityInstance.getStartTime());
        assertNull(historicActivityInstance.getEndTime());
    }
    // Complete one of the user tasks. This should not trigger setting of end time of the subprocess, but due to a bug it did exactly that
    taskService.complete(tasks.get(0).getId());
    historicActivityInstances = historyService.createHistoricActivityInstanceQuery().activityId("subprocess1").list();
    assertEquals(2, historicActivityInstances.size());
    for (HistoricActivityInstance historicActivityInstance : historicActivityInstances) {
        assertNull(historicActivityInstance.getEndTime());
    }
    taskService.complete(tasks.get(1).getId());
    historicActivityInstances = historyService.createHistoricActivityInstanceQuery().activityId("subprocess1").list();
    assertEquals(2, historicActivityInstances.size());
    for (HistoricActivityInstance historicActivityInstance : historicActivityInstances) {
        assertNull(historicActivityInstance.getEndTime());
    }
    tasks = taskService.createTaskQuery().processInstanceId(processInstance.getId()).taskName("User Task 3").list();
    assertEquals(2, tasks.size());
    for (Task task : tasks) {
        taskService.complete(task.getId());
        historicActivityInstances = historyService.createHistoricActivityInstanceQuery().activityId("subprocess1").list();
        assertEquals(2, historicActivityInstances.size());
        for (HistoricActivityInstance historicActivityInstance : historicActivityInstances) {
            assertNull(historicActivityInstance.getEndTime());
        }
    }
    // Finishing the tasks should also set the end time
    tasks = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();
    assertEquals(2, tasks.size());
    for (Task task : tasks) {
        taskService.complete(task.getId());
    }
    historicActivityInstances = historyService.createHistoricActivityInstanceQuery().activityId("subprocess1").list();
    assertEquals(2, historicActivityInstances.size());
    for (HistoricActivityInstance historicActivityInstance : historicActivityInstances) {
        assertNotNull(historicActivityInstance.getEndTime());
    }
}
Also used : Task(org.activiti.engine.task.Task) DelegateTask(org.activiti.engine.delegate.DelegateTask) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance) Deployment(org.activiti.engine.test.Deployment)

Example 2 with HistoricActivityInstance

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

the class MultiInstanceTest method testSequentialUserTasksHistory.

@Deployment(resources = { "org/activiti/engine/test/bpmn/multiinstance/MultiInstanceTest.sequentialUserTasks.bpmn20.xml" })
public void testSequentialUserTasksHistory() {
    runtimeService.startProcessInstanceByKey("miSequentialUserTasks", CollectionUtil.singletonMap("nrOfLoops", 4)).getId();
    for (int i = 0; i < 4; i++) {
        taskService.complete(taskService.createTaskQuery().singleResult().getId());
    }
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        List<HistoricTaskInstance> historicTaskInstances = historyService.createHistoricTaskInstanceQuery().list();
        assertEquals(4, historicTaskInstances.size());
        for (HistoricTaskInstance ht : historicTaskInstances) {
            assertNotNull(ht.getAssignee());
            assertNotNull(ht.getStartTime());
            assertNotNull(ht.getEndTime());
        }
        List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery().activityType("userTask").list();
        assertEquals(4, historicActivityInstances.size());
        for (HistoricActivityInstance hai : historicActivityInstances) {
            assertNotNull(hai.getActivityId());
            assertNotNull(hai.getActivityName());
            assertNotNull(hai.getStartTime());
            assertNotNull(hai.getEndTime());
            assertNotNull(hai.getAssignee());
        }
    }
}
Also used : HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance) Deployment(org.activiti.engine.test.Deployment)

Example 3 with HistoricActivityInstance

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

the class MultiInstanceTest method testSequentialScriptTasksHistory.

@Deployment(resources = { "org/activiti/engine/test/bpmn/multiinstance/MultiInstanceTest.testSequentialScriptTasks.bpmn20.xml" })
public void testSequentialScriptTasksHistory() {
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("sum", 0);
    vars.put("nrOfLoops", 7);
    runtimeService.startProcessInstanceByKey("miSequentialScriptTask", vars);
    // Validate history
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        List<HistoricActivityInstance> historicInstances = historyService.createHistoricActivityInstanceQuery().activityType("scriptTask").orderByActivityId().asc().list();
        assertEquals(7, historicInstances.size());
        for (int i = 0; i < 7; i++) {
            HistoricActivityInstance hai = historicInstances.get(i);
            assertEquals("scriptTask", hai.getActivityType());
            assertNotNull(hai.getStartTime());
            assertNotNull(hai.getEndTime());
        }
    }
}
Also used : HashMap(java.util.HashMap) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance) Deployment(org.activiti.engine.test.Deployment)

Example 4 with HistoricActivityInstance

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

the class ParallelGatewayTest method testHistoryTables.

// Test to verify ACT-1755
@Deployment
public void testHistoryTables() {
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("testHistoryRecords");
    List<HistoricActivityInstance> history = historyService.createHistoricActivityInstanceQuery().processInstanceId(pi.getId()).list();
    for (HistoricActivityInstance h : history) {
        if (h.getActivityId().equals("parallelgateway2")) {
            assertNotNull(h.getEndTime());
        }
    }
}
Also used : ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance) Deployment(org.activiti.engine.test.Deployment)

Example 5 with HistoricActivityInstance

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

the class HistoricVariableInstanceTest method testVariableUpdatesLinkedToActivity.

@Deployment(resources = { "org/activiti/standalone/history/FullHistoryTest.testVariableUpdatesAreLinkedToActivity.bpmn20.xml" })
public void testVariableUpdatesLinkedToActivity() throws Exception {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
        ProcessInstance pi = runtimeService.startProcessInstanceByKey("ProcessWithSubProcess");
        Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
        Map<String, Object> variables = new HashMap<String, Object>();
        variables.put("test", "1");
        taskService.complete(task.getId(), variables);
        // now we are in the subprocess
        task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
        variables.clear();
        variables.put("test", "2");
        taskService.complete(task.getId(), variables);
        // now we are ended
        assertProcessEnded(pi.getId());
        // check history
        List<HistoricDetail> updates = historyService.createHistoricDetailQuery().variableUpdates().list();
        assertEquals(2, updates.size());
        Map<String, HistoricVariableUpdate> updatesMap = new HashMap<String, HistoricVariableUpdate>();
        HistoricVariableUpdate update = (HistoricVariableUpdate) updates.get(0);
        updatesMap.put((String) update.getValue(), update);
        update = (HistoricVariableUpdate) updates.get(1);
        updatesMap.put((String) update.getValue(), update);
        HistoricVariableUpdate update1 = updatesMap.get("1");
        HistoricVariableUpdate update2 = updatesMap.get("2");
        assertNotNull(update1.getActivityInstanceId());
        assertNotNull(update1.getExecutionId());
        HistoricActivityInstance historicActivityInstance1 = historyService.createHistoricActivityInstanceQuery().activityInstanceId(update1.getActivityInstanceId()).singleResult();
        assertEquals(historicActivityInstance1.getExecutionId(), update1.getExecutionId());
        assertEquals("usertask1", historicActivityInstance1.getActivityId());
        // TODO https://activiti.atlassian.net/browse/ACT-1083
        assertNotNull(update2.getActivityInstanceId());
        HistoricActivityInstance historicActivityInstance2 = historyService.createHistoricActivityInstanceQuery().activityInstanceId(update2.getActivityInstanceId()).singleResult();
        assertEquals("usertask2", historicActivityInstance2.getActivityId());
        /*
	     * This is OK! The variable is set on the root execution, on a execution never run through the activity, where the process instances
	     * stands when calling the set Variable. But the ActivityId of this flow node is used. So the execution id's doesn't have to be equal.
	     * 
	     * execution id: On which execution it was set
	     * activity id: in which activity was the process instance when setting the variable
	     */
        assertFalse(historicActivityInstance2.getExecutionId().equals(update2.getExecutionId()));
    }
}
Also used : HistoricVariableUpdate(org.activiti.engine.history.HistoricVariableUpdate) HistoricDetail(org.activiti.engine.history.HistoricDetail) Task(org.activiti.engine.task.Task) HashMap(java.util.HashMap) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance) Deployment(org.activiti.engine.test.Deployment)

Aggregations

HistoricActivityInstance (org.activiti.engine.history.HistoricActivityInstance)50 Deployment (org.activiti.engine.test.Deployment)30 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)25 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)19 Task (org.activiti.engine.task.Task)18 HashMap (java.util.HashMap)12 ArrayList (java.util.ArrayList)9 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)7 HistoricDetail (org.activiti.engine.history.HistoricDetail)6 DelegateTask (org.activiti.engine.delegate.DelegateTask)5 HistoricActivityInstanceQuery (org.activiti.engine.history.HistoricActivityInstanceQuery)5 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)4 HistoricVariableUpdate (org.activiti.engine.history.HistoricVariableUpdate)4 HistoricVariableInstanceQuery (org.activiti.engine.history.HistoricVariableInstanceQuery)3 PvmTransition (org.activiti.engine.impl.pvm.PvmTransition)3 Date (java.util.Date)2 AssertionFailedError (junit.framework.AssertionFailedError)2 BpmnModel (org.activiti.bpmn.model.BpmnModel)2 HistoricData (org.activiti.engine.history.HistoricData)2 HistoricActivityInstanceQueryImpl (org.activiti.engine.impl.HistoricActivityInstanceQueryImpl)2