Search in sources :

Example 1 with HistoricVariableInstanceEntity

use of org.activiti.engine.impl.persistence.entity.HistoricVariableInstanceEntity 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;
}
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 2 with HistoricVariableInstanceEntity

use of org.activiti.engine.impl.persistence.entity.HistoricVariableInstanceEntity in project Activiti by Activiti.

the class HistoricVariableInstanceTest method testSimple.

@Deployment
public void testSimple() {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProc");
        TaskQuery taskQuery = taskService.createTaskQuery();
        Task userTask = taskQuery.singleResult();
        assertEquals("userTask1", userTask.getName());
        taskService.complete(userTask.getId(), CollectionUtil.singletonMap("myVar", "test789"));
        assertProcessEnded(processInstance.getId());
        List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery().list();
        assertEquals(1, variables.size());
        HistoricVariableInstanceEntity historicVariable = (HistoricVariableInstanceEntity) variables.get(0);
        assertEquals("test456", historicVariable.getTextValue());
        assertEquals(5, historyService.createHistoricActivityInstanceQuery().count());
        assertEquals(3, historyService.createHistoricDetailQuery().count());
    }
}
Also used : Task(org.activiti.engine.task.Task) TaskQuery(org.activiti.engine.task.TaskQuery) HistoricVariableInstanceEntity(org.activiti.engine.impl.persistence.entity.HistoricVariableInstanceEntity) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) Deployment(org.activiti.engine.test.Deployment)

Example 3 with HistoricVariableInstanceEntity

use of org.activiti.engine.impl.persistence.entity.HistoricVariableInstanceEntity in project Activiti by Activiti.

the class HistoricVariableInstanceTest method testParallel.

@Deployment
public void testParallel() {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProc");
        TaskQuery taskQuery = taskService.createTaskQuery();
        Task userTask = taskQuery.singleResult();
        assertEquals("userTask1", userTask.getName());
        taskService.complete(userTask.getId(), CollectionUtil.singletonMap("myVar", "test789"));
        assertProcessEnded(processInstance.getId());
        List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery().orderByVariableName().asc().list();
        assertEquals(2, variables.size());
        HistoricVariableInstanceEntity historicVariable = (HistoricVariableInstanceEntity) variables.get(0);
        assertEquals("myVar", historicVariable.getName());
        assertEquals("test789", historicVariable.getTextValue());
        HistoricVariableInstanceEntity historicVariable1 = (HistoricVariableInstanceEntity) variables.get(1);
        assertEquals("myVar1", historicVariable1.getName());
        assertEquals("test456", historicVariable1.getTextValue());
        assertEquals(8, historyService.createHistoricActivityInstanceQuery().count());
        assertEquals(5, historyService.createHistoricDetailQuery().count());
    }
}
Also used : Task(org.activiti.engine.task.Task) TaskQuery(org.activiti.engine.task.TaskQuery) HistoricVariableInstanceEntity(org.activiti.engine.impl.persistence.entity.HistoricVariableInstanceEntity) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) Deployment(org.activiti.engine.test.Deployment)

Example 4 with HistoricVariableInstanceEntity

use of org.activiti.engine.impl.persistence.entity.HistoricVariableInstanceEntity in project Activiti by Activiti.

the class HistoricVariableInstanceTest method testParallelNoWaitState.

@Deployment
public void testParallelNoWaitState() {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProc");
        assertProcessEnded(processInstance.getId());
        List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery().list();
        assertEquals(1, variables.size());
        HistoricVariableInstanceEntity historicVariable = (HistoricVariableInstanceEntity) variables.get(0);
        assertEquals("test456", historicVariable.getTextValue());
        assertEquals(7, historyService.createHistoricActivityInstanceQuery().count());
        assertEquals(2, historyService.createHistoricDetailQuery().count());
    }
}
Also used : HistoricVariableInstanceEntity(org.activiti.engine.impl.persistence.entity.HistoricVariableInstanceEntity) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) Deployment(org.activiti.engine.test.Deployment)

Example 5 with HistoricVariableInstanceEntity

use of org.activiti.engine.impl.persistence.entity.HistoricVariableInstanceEntity in project Activiti by Activiti.

the class HistoricVariableInstanceQueryImpl method executeList.

public List<HistoricVariableInstance> executeList(CommandContext commandContext, Page page) {
    checkQueryOk();
    ensureVariablesInitialized();
    List<HistoricVariableInstance> historicVariableInstances = commandContext.getHistoricVariableInstanceEntityManager().findHistoricVariableInstancesByQueryCriteria(this, page);
    if (excludeVariableInitialization == false) {
        for (HistoricVariableInstance historicVariableInstance : historicVariableInstances) {
            if (historicVariableInstance instanceof HistoricVariableInstanceEntity) {
                HistoricVariableInstanceEntity variableEntity = (HistoricVariableInstanceEntity) historicVariableInstance;
                if (variableEntity != null && variableEntity.getVariableType() != null) {
                    variableEntity.getValue();
                    // make sure JPA entities are cached for later retrieval
                    if (JPAEntityVariableType.TYPE_NAME.equals(variableEntity.getVariableType().getTypeName()) || JPAEntityListVariableType.TYPE_NAME.equals(variableEntity.getVariableType().getTypeName())) {
                        ((CacheableVariable) variableEntity.getVariableType()).setForceCacheable(true);
                    }
                }
            }
        }
    }
    return historicVariableInstances;
}
Also used : HistoricVariableInstanceEntity(org.activiti.engine.impl.persistence.entity.HistoricVariableInstanceEntity) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) CacheableVariable(org.activiti.engine.impl.variable.CacheableVariable)

Aggregations

HistoricVariableInstanceEntity (org.activiti.engine.impl.persistence.entity.HistoricVariableInstanceEntity)9 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)8 Deployment (org.activiti.engine.test.Deployment)7 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)6 Task (org.activiti.engine.task.Task)4 TaskQuery (org.activiti.engine.task.TaskQuery)3 HistoricData (org.activiti.engine.history.HistoricData)2 CacheableVariable (org.activiti.engine.impl.variable.CacheableVariable)2 HashMap (java.util.HashMap)1 HistoricActivityInstance (org.activiti.engine.history.HistoricActivityInstance)1 HistoricVariableUpdate (org.activiti.engine.history.HistoricVariableUpdate)1 ProcessInstanceHistoryLog (org.activiti.engine.history.ProcessInstanceHistoryLog)1 HistoricProcessInstanceEntity (org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntity)1