Search in sources :

Example 6 with HistoricProcessInstanceEntity

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().findById(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;
}
Also used : HistoricVariableUpdate(org.activiti.engine.history.HistoricVariableUpdate) HistoricData(org.activiti.engine.history.HistoricData) CacheableVariable(org.activiti.engine.impl.variable.CacheableVariable) HistoricVariableInstanceEntity(org.activiti.engine.impl.persistence.entity.HistoricVariableInstanceEntity) HistoricProcessInstanceEntity(org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntity) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance)

Example 7 with HistoricProcessInstanceEntity

use of org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntity 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));
        }
    }
}
Also used : ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) HistoricActivityInstanceEntity(org.activiti.engine.impl.persistence.entity.HistoricActivityInstanceEntity) HistoricProcessInstanceEntity(org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntity) IdGenerator(org.activiti.engine.impl.cfg.IdGenerator) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) Date(java.util.Date)

Example 8 with HistoricProcessInstanceEntity

use of org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntity in project herd by FINRAOS.

the class JobServiceGetJobsTest method testGetJobsGivenOneCompletedJobAndPassingStartAndEndTimeAssertReturnCompletedJob.

@SuppressWarnings("unchecked")
@Test
public void testGetJobsGivenOneCompletedJobAndPassingStartAndEndTimeAssertReturnCompletedJob() throws Exception {
    String namespace = "namespace";
    String jobName = "jobName";
    DateTime startTime = new DateTime(new Date(0123));
    DateTime endTime = new DateTime(new Date(3456));
    JobStatusEnum jobStatus = JobStatusEnum.COMPLETED;
    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));
    historicProcessInstanceEntity1.setEndTime(new Date(2345));
    historicProcessInstances.add(historicProcessInstanceEntity1);
    when(activitiService.getHistoricProcessInstancesByStatusAndProcessDefinitionKeys(any(), any(), any(), any())).thenReturn(historicProcessInstances);
    JobSummaries getJobsResult = jobServiceImpl.getJobs(namespace, jobName, jobStatus, startTime, endTime);
    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.COMPLETED, jobSummary.getStatus());
    assertEquals(historicProcessInstanceEntity1.getStartTime().getTime(), jobSummary.getStartTime().toGregorianCalendar().getTimeInMillis());
    assertEquals(historicProcessInstanceEntity1.getEndTime().getTime(), jobSummary.getEndTime().toGregorianCalendar().getTimeInMillis());
    assertEquals(0, jobSummary.getTotalExceptions());
    verify(activitiService).getHistoricProcessInstancesCountByStatusAndProcessDefinitionKeys(eq(JobStatusEnum.COMPLETED), any(), eq(startTime), eq(endTime));
    verify(activitiService).getHistoricProcessInstancesByStatusAndProcessDefinitionKeys(eq(JobStatusEnum.COMPLETED), any(), eq(startTime), eq(endTime));
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ArrayList(java.util.ArrayList) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) JobSummaries(org.finra.herd.model.api.xml.JobSummaries) DateTime(org.joda.time.DateTime) Date(java.util.Date) JobSummary(org.finra.herd.model.api.xml.JobSummary) JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) JobStatusEnum(org.finra.herd.model.api.xml.JobStatusEnum) Collection(java.util.Collection) HistoricProcessInstanceEntity(org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntity) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with HistoricProcessInstanceEntity

use of org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntity in project herd by FINRAOS.

the class JobServiceGetJobsTest method testGetJobsGivenMultipleHistoricProcessInstanceWithSamKeyJobAssertReturnCompletedJob.

/**
 * Tests case where multiple process instances were created, but the job definition entities were deleted at some point without removing the old historic
 * instances, then a new process instance is created with the same namespace and job name pair. When a ListJobs is called, it should not return the old
 * instance information. <p/> This case was added as a verification to the bug raised by test automation.
 */
@SuppressWarnings("unchecked")
@Test
public void testGetJobsGivenMultipleHistoricProcessInstanceWithSamKeyJobAssertReturnCompletedJob() throws Exception {
    String namespace = "namespace";
    String jobName = "jobName";
    JobStatusEnum jobStatus = JobStatusEnum.COMPLETED;
    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));
        historicProcessInstanceEntity1.setEndTime(new Date(2345));
        historicProcessInstances.add(historicProcessInstanceEntity1);
    }
    {
        HistoricProcessInstanceEntity historicProcessInstanceEntity1 = new HistoricProcessInstanceEntity();
        historicProcessInstanceEntity1.setId("historicProcessInstanceEntity2.id");
        historicProcessInstanceEntity1.setProcessDefinitionId("a.b:1:2");
        historicProcessInstanceEntity1.setStartTime(new Date(1234));
        historicProcessInstanceEntity1.setEndTime(new Date(2345));
        historicProcessInstances.add(historicProcessInstanceEntity1);
    }
    when(activitiService.getHistoricProcessInstancesByStatusAndProcessDefinitionKeys(any(), any(), any(), any())).thenReturn(historicProcessInstances);
    JobSummaries getJobsResult = jobServiceImpl.getJobs(namespace, jobName, jobStatus, NO_START_TIME, NO_END_TIME);
    List<JobSummary> jobSummaries = getJobsResult.getJobSummaries();
    assertEquals(1, jobSummaries.size());
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ArrayList(java.util.ArrayList) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) JobSummaries(org.finra.herd.model.api.xml.JobSummaries) Date(java.util.Date) JobSummary(org.finra.herd.model.api.xml.JobSummary) JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) JobStatusEnum(org.finra.herd.model.api.xml.JobStatusEnum) Collection(java.util.Collection) HistoricProcessInstanceEntity(org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntity) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with HistoricProcessInstanceEntity

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 = getHistoricProcessInstanceEntityManager().findById(processInstanceId);
        if (historicProcessInstance != null) {
            historicProcessInstance.markEnded(deleteReason);
            historicProcessInstance.setEndActivityId(activityId);
            // Fire event
            ActivitiEventDispatcher activitiEventDispatcher = getEventDispatcher();
            if (activitiEventDispatcher != null && activitiEventDispatcher.isEnabled()) {
                activitiEventDispatcher.dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.HISTORIC_PROCESS_INSTANCE_ENDED, historicProcessInstance));
            }
        }
    }
}
Also used : HistoricProcessInstanceEntity(org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntity) ActivitiEventDispatcher(org.activiti.engine.delegate.event.ActivitiEventDispatcher)

Aggregations

HistoricProcessInstanceEntity (org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntity)11 Date (java.util.Date)5 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)4 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 HashSet (java.util.HashSet)3 ActivitiEventDispatcher (org.activiti.engine.delegate.event.ActivitiEventDispatcher)3 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)3 HistoricActivityInstanceEntity (org.activiti.engine.impl.persistence.entity.HistoricActivityInstanceEntity)3 JobStatusEnum (org.finra.herd.model.api.xml.JobStatusEnum)3 JobSummaries (org.finra.herd.model.api.xml.JobSummaries)3 JobSummary (org.finra.herd.model.api.xml.JobSummary)3 JobDefinitionEntity (org.finra.herd.model.jpa.JobDefinitionEntity)3 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)3 Test (org.junit.Test)3 IdGenerator (org.activiti.engine.impl.cfg.IdGenerator)2 ProcessEngineConfigurationImpl (org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 HistoricActivityInstance (org.activiti.engine.history.HistoricActivityInstance)1