use of org.activiti.engine.impl.persistence.entity.HistoricActivityInstanceEntity in project Activiti by Activiti.
the class DefaultHistoryManager method recordProcessInstanceStart.
/* (non-Javadoc)
* @see org.activiti.engine.impl.history.HistoryManagerInterface#recordProcessInstanceStart(org.activiti.engine.impl.persistence.entity.ExecutionEntity)
*/
@Override
public void recordProcessInstanceStart(ExecutionEntity processInstance) {
if (isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) {
HistoricProcessInstanceEntity historicProcessInstance = new HistoricProcessInstanceEntity(processInstance);
// Insert historic process-instance
getDbSqlSession().insert(historicProcessInstance);
// Fire event
ProcessEngineConfigurationImpl config = Context.getProcessEngineConfiguration();
if (config != null && config.getEventDispatcher().isEnabled()) {
config.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.HISTORIC_PROCESS_INSTANCE_CREATED, historicProcessInstance));
}
// Also record the start-event manually, as there is no "start" activity history listener for this
IdGenerator idGenerator = Context.getProcessEngineConfiguration().getIdGenerator();
String processDefinitionId = processInstance.getProcessDefinitionId();
String processInstanceId = processInstance.getProcessInstanceId();
String executionId = processInstance.getId();
HistoricActivityInstanceEntity historicActivityInstance = new HistoricActivityInstanceEntity();
historicActivityInstance.setId(idGenerator.getNextId());
historicActivityInstance.setProcessDefinitionId(processDefinitionId);
historicActivityInstance.setProcessInstanceId(processInstanceId);
historicActivityInstance.setExecutionId(executionId);
historicActivityInstance.setActivityId(processInstance.getActivityId());
historicActivityInstance.setActivityName((String) processInstance.getActivity().getProperty("name"));
historicActivityInstance.setActivityType((String) processInstance.getActivity().getProperty("type"));
Date now = Context.getProcessEngineConfiguration().getClock().getCurrentTime();
historicActivityInstance.setStartTime(now);
// Inherit tenant id (if applicable)
if (processInstance.getTenantId() != null) {
historicActivityInstance.setTenantId(processInstance.getTenantId());
}
getDbSqlSession().insert(historicActivityInstance);
// Fire event
if (config != null && config.getEventDispatcher().isEnabled()) {
config.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.HISTORIC_ACTIVITY_INSTANCE_CREATED, historicActivityInstance));
}
}
}
use of org.activiti.engine.impl.persistence.entity.HistoricActivityInstanceEntity in project Activiti by Activiti.
the class DefaultHistoryManager method recordExecutionReplacedBy.
/* (non-Javadoc)
* @see org.activiti.engine.impl.history.HistoryManagerInterface#recordExecutionReplacedBy(org.activiti.engine.impl.persistence.entity.ExecutionEntity, org.activiti.engine.impl.pvm.runtime.InterpretableExecution)
*/
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void recordExecutionReplacedBy(ExecutionEntity execution, InterpretableExecution replacedBy) {
if (isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) {
// Update the cached historic activity instances that are open
List<HistoricActivityInstanceEntity> cachedHistoricActivityInstances = getDbSqlSession().findInCache(HistoricActivityInstanceEntity.class);
for (HistoricActivityInstanceEntity cachedHistoricActivityInstance : cachedHistoricActivityInstances) {
if ((cachedHistoricActivityInstance.getEndTime() == null) && (execution.getId().equals(cachedHistoricActivityInstance.getExecutionId()))) {
cachedHistoricActivityInstance.setExecutionId(replacedBy.getId());
}
}
// Update the persisted historic activity instances that are open
List<HistoricActivityInstanceEntity> historicActivityInstances = (List) new HistoricActivityInstanceQueryImpl(Context.getCommandContext()).executionId(execution.getId()).unfinished().list();
for (HistoricActivityInstanceEntity historicActivityInstance : historicActivityInstances) {
historicActivityInstance.setExecutionId(replacedBy.getId());
}
}
}
use of org.activiti.engine.impl.persistence.entity.HistoricActivityInstanceEntity in project Activiti by Activiti.
the class DefaultHistoryManager method recordActivityStart.
// Activity related history
/* (non-Javadoc)
* @see org.activiti.engine.impl.history.HistoryManagerInterface#recordActivityStart(org.activiti.engine.impl.persistence.entity.ExecutionEntity)
*/
@Override
public void recordActivityStart(ExecutionEntity executionEntity) {
if (isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) {
if (executionEntity.getActivity() != null) {
IdGenerator idGenerator = Context.getProcessEngineConfiguration().getIdGenerator();
String processDefinitionId = executionEntity.getProcessDefinitionId();
String processInstanceId = executionEntity.getProcessInstanceId();
String executionId = executionEntity.getId();
HistoricActivityInstanceEntity historicActivityInstance = new HistoricActivityInstanceEntity();
historicActivityInstance.setId(idGenerator.getNextId());
historicActivityInstance.setProcessDefinitionId(processDefinitionId);
historicActivityInstance.setProcessInstanceId(processInstanceId);
historicActivityInstance.setExecutionId(executionId);
historicActivityInstance.setActivityId(executionEntity.getActivityId());
historicActivityInstance.setActivityName((String) executionEntity.getActivity().getProperty("name"));
historicActivityInstance.setActivityType((String) executionEntity.getActivity().getProperty("type"));
historicActivityInstance.setStartTime(Context.getProcessEngineConfiguration().getClock().getCurrentTime());
// Inherit tenant id (if applicable)
if (executionEntity.getTenantId() != null) {
historicActivityInstance.setTenantId(executionEntity.getTenantId());
}
getDbSqlSession().insert(historicActivityInstance);
// Fire event
ProcessEngineConfigurationImpl config = Context.getProcessEngineConfiguration();
if (config != null && config.getEventDispatcher().isEnabled()) {
config.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.HISTORIC_ACTIVITY_INSTANCE_CREATED, historicActivityInstance));
}
}
}
}
use of org.activiti.engine.impl.persistence.entity.HistoricActivityInstanceEntity 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.impl.persistence.entity.HistoricActivityInstanceEntity in project Activiti by Activiti.
the class DefaultHistoryManager method recordSubProcessInstanceStart.
/* (non-Javadoc)
* @see org.activiti.engine.impl.history.HistoryManagerInterface#recordSubProcessInstanceStart(org.activiti.engine.impl.persistence.entity.ExecutionEntity, org.activiti.engine.impl.persistence.entity.ExecutionEntity)
*/
@Override
public void recordSubProcessInstanceStart(ExecutionEntity parentExecution, ExecutionEntity subProcessInstance) {
if (isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) {
HistoricProcessInstanceEntity historicProcessInstance = new HistoricProcessInstanceEntity((ExecutionEntity) subProcessInstance);
ActivityImpl initialActivity = subProcessInstance.getActivity();
// Fix for ACT-1728: startActivityId not initialized with subprocess-instance
if (historicProcessInstance.getStartActivityId() == null) {
historicProcessInstance.setStartActivityId(subProcessInstance.getProcessDefinition().getInitial().getId());
initialActivity = subProcessInstance.getProcessDefinition().getInitial();
}
getDbSqlSession().insert(historicProcessInstance);
// Fire event
ProcessEngineConfigurationImpl config = Context.getProcessEngineConfiguration();
if (config != null && config.getEventDispatcher().isEnabled()) {
config.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.HISTORIC_PROCESS_INSTANCE_CREATED, historicProcessInstance));
}
HistoricActivityInstanceEntity activitiyInstance = findActivityInstance(parentExecution);
if (activitiyInstance != null) {
activitiyInstance.setCalledProcessInstanceId(subProcessInstance.getProcessInstanceId());
}
// Fix for ACT-1728: start-event not recorded for subprocesses
IdGenerator idGenerator = Context.getProcessEngineConfiguration().getIdGenerator();
// Also record the start-event manually, as there is no "start" activity history listener for this
HistoricActivityInstanceEntity historicActivityInstance = new HistoricActivityInstanceEntity();
historicActivityInstance.setId(idGenerator.getNextId());
historicActivityInstance.setProcessDefinitionId(subProcessInstance.getProcessDefinitionId());
historicActivityInstance.setProcessInstanceId(subProcessInstance.getProcessInstanceId());
historicActivityInstance.setExecutionId(subProcessInstance.getId());
historicActivityInstance.setActivityId(initialActivity.getId());
historicActivityInstance.setActivityName((String) initialActivity.getProperty("name"));
historicActivityInstance.setActivityType((String) initialActivity.getProperty("type"));
Date now = Context.getProcessEngineConfiguration().getClock().getCurrentTime();
historicActivityInstance.setStartTime(now);
getDbSqlSession().insert(historicActivityInstance);
// Fire event
if (config != null && config.getEventDispatcher().isEnabled()) {
config.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.HISTORIC_ACTIVITY_INSTANCE_CREATED, historicActivityInstance));
}
}
}
Aggregations