Search in sources :

Example 21 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 22 with HistoricActivityInstance

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

the class DefaultHistoryManager method findActivityInstance.

/*
   * (non-Javadoc)
   * 
   * @see
   * org.activiti.engine.impl.history.HistoryManagerInterface#findActivityInstance
   * (org.activiti.engine.impl.persistence.entity.ExecutionEntity)
   */
protected HistoricActivityInstanceEntity findActivityInstance(ExecutionEntity execution, String activityId, boolean checkPersistentStore) {
    String executionId = execution.getId();
    // search for the historic activity instance in the dbsqlsession cache
    List<HistoricActivityInstanceEntity> cachedHistoricActivityInstances = getDbSqlSession().findInCache(HistoricActivityInstanceEntity.class);
    for (HistoricActivityInstanceEntity cachedHistoricActivityInstance : cachedHistoricActivityInstances) {
        if (executionId.equals(cachedHistoricActivityInstance.getExecutionId()) && activityId != null && (activityId.equals(cachedHistoricActivityInstance.getActivityId())) && (cachedHistoricActivityInstance.getEndTime() == null)) {
            return cachedHistoricActivityInstance;
        }
    }
    List<HistoricActivityInstance> historicActivityInstances = null;
    if (checkPersistentStore) {
        historicActivityInstances = new HistoricActivityInstanceQueryImpl(Context.getCommandContext()).executionId(executionId).activityId(activityId).unfinished().listPage(0, 1);
    }
    if (historicActivityInstances != null && !historicActivityInstances.isEmpty()) {
        return (HistoricActivityInstanceEntity) historicActivityInstances.get(0);
    }
    if (execution.getParentId() != null) {
        return findActivityInstance((ExecutionEntity) execution.getParent(), activityId, checkPersistentStore);
    }
    return null;
}
Also used : HistoricActivityInstanceEntity(org.activiti.engine.impl.persistence.entity.HistoricActivityInstanceEntity) HistoricActivityInstanceQueryImpl(org.activiti.engine.impl.HistoricActivityInstanceQueryImpl) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance)

Example 23 with HistoricActivityInstance

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

the class TerminateEndEventActivityBehavior method endAllHistoricActivities.

protected void endAllHistoricActivities(String processInstanceId) {
    if (!Context.getProcessEngineConfiguration().getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        return;
    }
    Map<String, HistoricActivityInstanceEntity> historicActivityInstancMap = new HashMap<String, HistoricActivityInstanceEntity>();
    List<HistoricActivityInstance> historicActivityInstances = new HistoricActivityInstanceQueryImpl(Context.getCommandContext()).processInstanceId(processInstanceId).unfinished().list();
    for (HistoricActivityInstance historicActivityInstance : historicActivityInstances) {
        historicActivityInstancMap.put(historicActivityInstance.getId(), (HistoricActivityInstanceEntity) historicActivityInstance);
    }
    // Cached version overwites entity
    List<HistoricActivityInstanceEntity> cachedHistoricActivityInstances = Context.getCommandContext().getDbSqlSession().findInCache(HistoricActivityInstanceEntity.class);
    for (HistoricActivityInstanceEntity cachedHistoricActivityInstance : cachedHistoricActivityInstances) {
        if (processInstanceId.equals(cachedHistoricActivityInstance.getProcessInstanceId()) && (cachedHistoricActivityInstance.getEndTime() == null)) {
            historicActivityInstancMap.put(cachedHistoricActivityInstance.getId(), cachedHistoricActivityInstance);
        }
    }
    for (HistoricActivityInstanceEntity historicActivityInstance : historicActivityInstancMap.values()) {
        historicActivityInstance.markEnded(null);
        // Fire event
        ProcessEngineConfigurationImpl config = Context.getProcessEngineConfiguration();
        if (config != null && config.getEventDispatcher().isEnabled()) {
            config.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.HISTORIC_ACTIVITY_INSTANCE_ENDED, historicActivityInstance));
        }
    }
}
Also used : HistoricActivityInstanceEntity(org.activiti.engine.impl.persistence.entity.HistoricActivityInstanceEntity) HashMap(java.util.HashMap) HistoricActivityInstanceQueryImpl(org.activiti.engine.impl.HistoricActivityInstanceQueryImpl) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance)

Example 24 with HistoricActivityInstance

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

the class AbstractActivitiTestCase method assertProcessEnded.

public void assertProcessEnded(final String processInstanceId) {
    ProcessInstance processInstance = processEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
    if (processInstance != null) {
        throw new AssertionFailedError("Expected finished process instance '" + processInstanceId + "' but it was still in the db");
    }
    // Verify historical data if end times are correctly set
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
        // process instance
        HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
        assertEquals(processInstanceId, historicProcessInstance.getId());
        assertNotNull("Historic process instance has no start time", historicProcessInstance.getStartTime());
        assertNotNull("Historic process instance has no end time", historicProcessInstance.getEndTime());
        // tasks
        List<HistoricTaskInstance> historicTaskInstances = historyService.createHistoricTaskInstanceQuery().processInstanceId(processInstanceId).list();
        if (historicTaskInstances != null && historicTaskInstances.size() > 0) {
            for (HistoricTaskInstance historicTaskInstance : historicTaskInstances) {
                assertEquals(processInstanceId, historicTaskInstance.getProcessInstanceId());
                assertNotNull("Historic task " + historicTaskInstance.getTaskDefinitionKey() + " has no start time", historicTaskInstance.getStartTime());
                assertNotNull("Historic task " + historicTaskInstance.getTaskDefinitionKey() + " has no end time", historicTaskInstance.getEndTime());
            }
        }
        // activities
        List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstanceId).list();
        if (historicActivityInstances != null && historicActivityInstances.size() > 0) {
            for (HistoricActivityInstance historicActivityInstance : historicActivityInstances) {
                assertEquals(processInstanceId, historicActivityInstance.getProcessInstanceId());
                assertNotNull("Historic activity instance " + historicActivityInstance.getActivityId() + " has no start time", historicActivityInstance.getStartTime());
                assertNotNull("Historic activity instance " + historicActivityInstance.getActivityId() + " has no end time", historicActivityInstance.getEndTime());
            }
        }
    }
}
Also used : HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) AssertionFailedError(junit.framework.AssertionFailedError) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance)

Example 25 with HistoricActivityInstance

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

the class CallActivityTest method testInheritVariablesSubprocess.

public void testInheritVariablesSubprocess() throws Exception {
    BpmnModel mainBpmnModel = loadBPMNModel(INHERIT_VARIABLES_MAIN_PROCESS_RESOURCE);
    BpmnModel childBpmnModel = loadBPMNModel(INHERIT_VARIABLES_CHILD_PROCESS_RESOURCE);
    processEngine.getRepositoryService().createDeployment().name("mainProcessDeployment").addBpmnModel("mainProcess.bpmn20.xml", mainBpmnModel).deploy();
    processEngine.getRepositoryService().createDeployment().name("childProcessDeployment").addBpmnModel("childProcess.bpmn20.xml", childBpmnModel).deploy();
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("var1", "String test value");
    variables.put("var2", true);
    variables.put("var3", 12345);
    variables.put("var4", 67890);
    ProcessInstance mainProcessInstance = runtimeService.startProcessInstanceByKey("mainProcess", variables);
    HistoricActivityInstanceQuery activityInstanceQuery = historyService.createHistoricActivityInstanceQuery();
    activityInstanceQuery.processInstanceId(mainProcessInstance.getId());
    activityInstanceQuery.activityId("childProcessCall");
    HistoricActivityInstance activityInstance = activityInstanceQuery.singleResult();
    String calledInstanceId = activityInstance.getCalledProcessInstanceId();
    HistoricVariableInstanceQuery variableInstanceQuery = historyService.createHistoricVariableInstanceQuery();
    List<HistoricVariableInstance> variableInstances = variableInstanceQuery.processInstanceId(calledInstanceId).list();
    assertEquals(4, variableInstances.size());
    for (HistoricVariableInstance variable : variableInstances) {
        assertEquals(variables.get(variable.getVariableName()), variable.getValue());
    }
}
Also used : HistoricActivityInstanceQuery(org.activiti.engine.history.HistoricActivityInstanceQuery) HashMap(java.util.HashMap) HistoricVariableInstanceQuery(org.activiti.engine.history.HistoricVariableInstanceQuery) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) BpmnModel(org.activiti.bpmn.model.BpmnModel) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance)

Aggregations

HistoricActivityInstance (org.activiti.engine.history.HistoricActivityInstance)44 Deployment (org.activiti.engine.test.Deployment)30 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)24 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)18 Task (org.activiti.engine.task.Task)17 HashMap (java.util.HashMap)11 HistoricDetail (org.activiti.engine.history.HistoricDetail)6 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)6 DelegateTask (org.activiti.engine.delegate.DelegateTask)5 ArrayList (java.util.ArrayList)4 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)4 HistoricVariableUpdate (org.activiti.engine.history.HistoricVariableUpdate)4 HistoricActivityInstanceQuery (org.activiti.engine.history.HistoricActivityInstanceQuery)3 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