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());
}
}
}
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;
}
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));
}
}
}
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());
}
}
}
}
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());
}
}
Aggregations