use of org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntity 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.HistoricProcessInstanceEntity in project Activiti by Activiti.
the class DefaultHistoryManager method updateProcessBusinessKeyInHistory.
/* (non-Javadoc)
* @see org.activiti.engine.impl.history.HistoryManagerInterface#updateProcessBusinessKeyInHistory(org.activiti.engine.impl.persistence.entity.ExecutionEntity)
*/
@Override
public void updateProcessBusinessKeyInHistory(ExecutionEntity processInstance) {
if (isHistoryEnabled()) {
if (log.isDebugEnabled()) {
log.debug("updateProcessBusinessKeyInHistory : {}", processInstance.getId());
}
if (processInstance != null) {
HistoricProcessInstanceEntity historicProcessInstance = getDbSqlSession().selectById(HistoricProcessInstanceEntity.class, processInstance.getId());
if (historicProcessInstance != null) {
historicProcessInstance.setBusinessKey(processInstance.getProcessBusinessKey());
getDbSqlSession().update(historicProcessInstance);
}
}
}
}
use of org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntity in project Activiti by Activiti.
the class ProcessInstanceHistoryLogQueryImpl method execute.
@Override
public ProcessInstanceHistoryLog execute(CommandContext commandContext) {
// Fetch historic process instance
HistoricProcessInstanceEntity historicProcessInstance = commandContext.getHistoricProcessInstanceEntityManager().findHistoricProcessInstance(processInstanceId);
if (historicProcessInstance == null) {
return null;
}
// Create a log using this historic process instance
ProcessInstanceHistoryLogImpl processInstanceHistoryLog = new ProcessInstanceHistoryLogImpl(historicProcessInstance);
// Tasks
if (includeTasks) {
List<? extends HistoricData> tasks = commandContext.getHistoricTaskInstanceEntityManager().findHistoricTaskInstancesByQueryCriteria(new HistoricTaskInstanceQueryImpl(commandExecutor).processInstanceId(processInstanceId));
processInstanceHistoryLog.addHistoricData(tasks);
}
// Activities
if (includeActivities) {
List<HistoricActivityInstance> activities = commandContext.getHistoricActivityInstanceEntityManager().findHistoricActivityInstancesByQueryCriteria(new HistoricActivityInstanceQueryImpl(commandExecutor).processInstanceId(processInstanceId), null);
processInstanceHistoryLog.addHistoricData(activities);
}
// Variables
if (includeVariables) {
List<HistoricVariableInstance> variables = commandContext.getHistoricVariableInstanceEntityManager().findHistoricVariableInstancesByQueryCriteria(new HistoricVariableInstanceQueryImpl(commandExecutor).processInstanceId(processInstanceId), null);
// Make sure all variables values are fetched (similar to the HistoricVariableInstance query)
for (HistoricVariableInstance historicVariableInstance : variables) {
historicVariableInstance.getValue();
// make sure JPA entities are cached for later retrieval
HistoricVariableInstanceEntity variableEntity = (HistoricVariableInstanceEntity) historicVariableInstance;
if (JPAEntityVariableType.TYPE_NAME.equals(variableEntity.getVariableType().getTypeName()) || JPAEntityListVariableType.TYPE_NAME.equals(variableEntity.getVariableType().getTypeName())) {
((CacheableVariable) variableEntity.getVariableType()).setForceCacheable(true);
}
}
processInstanceHistoryLog.addHistoricData(variables);
}
// Comment
if (includeComments) {
List<? extends HistoricData> comments = commandContext.getCommentEntityManager().findCommentsByProcessInstanceId(processInstanceId);
processInstanceHistoryLog.addHistoricData(comments);
}
// Details: variables
if (includeVariableUpdates) {
List<? extends HistoricData> variableUpdates = commandContext.getHistoricDetailEntityManager().findHistoricDetailsByQueryCriteria(new HistoricDetailQueryImpl(commandExecutor).variableUpdates(), null);
// Make sure all variables values are fetched (similar to the HistoricVariableInstance query)
for (HistoricData historicData : variableUpdates) {
HistoricVariableUpdate variableUpdate = (HistoricVariableUpdate) historicData;
variableUpdate.getValue();
}
processInstanceHistoryLog.addHistoricData(variableUpdates);
}
// Details: form properties
if (includeFormProperties) {
List<? extends HistoricData> formProperties = commandContext.getHistoricDetailEntityManager().findHistoricDetailsByQueryCriteria(new HistoricDetailQueryImpl(commandExecutor).formProperties(), null);
processInstanceHistoryLog.addHistoricData(formProperties);
}
// All events collected. Sort them by date.
processInstanceHistoryLog.orderHistoricData();
return processInstanceHistoryLog;
}
use of org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntity in project herd by FINRAOS.
the class JobServiceGetJobsTest method testGetJobsGivenOneRunningJobAssertReturnCompletedJob.
@SuppressWarnings("unchecked")
@Test
public void testGetJobsGivenOneRunningJobAssertReturnCompletedJob() throws Exception {
String namespace = "namespace";
String jobName = "jobName";
JobStatusEnum jobStatus = JobStatusEnum.RUNNING;
long expectedNumberOfExceptions = 1234l;
Set<String> authorizedNamespaces = new HashSet<>(Arrays.asList(namespace));
when(namespaceSecurityHelper.getAuthorizedNamespaces(any())).thenReturn(authorizedNamespaces);
NamespaceEntity namespaceEntity = new NamespaceEntity();
namespaceEntity.setCode(namespace);
when(namespaceDao.getNamespaceByCd(any())).thenReturn(namespaceEntity);
List<JobDefinitionEntity> jobDefinitionEntities = new ArrayList<>();
JobDefinitionEntity jobDefinitionEntity1 = new JobDefinitionEntity();
jobDefinitionEntity1.setActivitiId(namespace + "." + jobName + ":1" + ":1");
jobDefinitionEntities.add(jobDefinitionEntity1);
when(jobDefinitionDao.getJobDefinitionsByFilter(any(Collection.class), any())).thenReturn(jobDefinitionEntities);
ProcessDefinition processDefinition = mock(ProcessDefinition.class);
when(processDefinition.getId()).thenReturn("a.b:1:1");
when(processDefinition.getKey()).thenReturn("a.b");
when(activitiService.getProcessDefinitionsByIds(any())).thenReturn(asList(processDefinition));
when(activitiService.getHistoricProcessInstancesCountByStatusAndProcessDefinitionKeys(any(), any(), any(), any())).thenReturn(1l);
List<HistoricProcessInstance> historicProcessInstances = new ArrayList<>();
HistoricProcessInstanceEntity historicProcessInstanceEntity1 = new HistoricProcessInstanceEntity();
historicProcessInstanceEntity1.setId("historicProcessInstanceEntity1.id");
historicProcessInstanceEntity1.setProcessDefinitionId("a.b:1:1");
historicProcessInstanceEntity1.setStartTime(new Date(1234));
historicProcessInstances.add(historicProcessInstanceEntity1);
when(activitiService.getHistoricProcessInstancesByStatusAndProcessDefinitionKeys(any(), any(), any(), any())).thenReturn(historicProcessInstances);
when(activitiService.getJobsWithExceptionCountByProcessInstanceId(any())).thenReturn(expectedNumberOfExceptions);
JobSummaries getJobsResult = jobServiceImpl.getJobs(namespace, jobName, jobStatus, NO_START_TIME, NO_END_TIME);
List<JobSummary> jobSummaries = getJobsResult.getJobSummaries();
assertEquals(1, jobSummaries.size());
JobSummary jobSummary = jobSummaries.get(0);
assertEquals(historicProcessInstanceEntity1.getId(), jobSummary.getId());
assertEquals("a", jobSummary.getNamespace());
assertEquals("b", jobSummary.getJobName());
assertEquals(JobStatusEnum.RUNNING, jobSummary.getStatus());
assertEquals(historicProcessInstanceEntity1.getStartTime().getTime(), jobSummary.getStartTime().toGregorianCalendar().getTimeInMillis());
assertNull(jobSummary.getEndTime());
assertEquals(expectedNumberOfExceptions, jobSummary.getTotalExceptions());
verify(activitiService).getJobsWithExceptionCountByProcessInstanceId(historicProcessInstanceEntity1.getId());
verify(activitiService).getHistoricProcessInstancesCountByStatusAndProcessDefinitionKeys(eq(JobStatusEnum.RUNNING), any(), any(), any());
verify(activitiService).getHistoricProcessInstancesByStatusAndProcessDefinitionKeys(eq(JobStatusEnum.RUNNING), any(), any(), any());
}
use of org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntity in project Activiti by Activiti.
the class DefaultHistoryManager method recordProcessInstanceEnd.
// Process related history
/* (non-Javadoc)
* @see org.activiti.engine.impl.history.HistoryManagerInterface#recordProcessInstanceEnd(java.lang.String, java.lang.String, java.lang.String)
*/
@Override
public void recordProcessInstanceEnd(String processInstanceId, String deleteReason, String activityId) {
if (isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) {
HistoricProcessInstanceEntity historicProcessInstance = getHistoricProcessInstanceManager().findHistoricProcessInstance(processInstanceId);
if (historicProcessInstance != null) {
historicProcessInstance.markEnded(deleteReason);
historicProcessInstance.setEndActivityId(activityId);
// Fire event
ProcessEngineConfigurationImpl config = Context.getProcessEngineConfiguration();
if (config != null && config.getEventDispatcher().isEnabled()) {
config.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.HISTORIC_PROCESS_INSTANCE_ENDED, historicProcessInstance));
}
}
}
}
Aggregations