Search in sources :

Example 6 with HistoricData

use of org.activiti.engine.history.HistoricData in project Activiti by Activiti.

the class ProcessInstanceLogQueryTest method testIncludeTasksandComments.

public void testIncludeTasksandComments() {
    ProcessInstanceHistoryLog log = historyService.createProcessInstanceHistoryLogQuery(processInstanceId).includeTasks().includeComments().singleResult();
    List<HistoricData> events = log.getHistoricData();
    assertEquals(5, events.size());
    for (int i = 0; i < 5; i++) {
        HistoricData event = events.get(i);
        if (i < 2) {
            // tasks are created before comments
            assertTrue(event instanceof HistoricTaskInstance);
        } else {
            assertTrue(event instanceof Comment);
        }
    }
}
Also used : Comment(org.activiti.engine.task.Comment) HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) HistoricData(org.activiti.engine.history.HistoricData) ProcessInstanceHistoryLog(org.activiti.engine.history.ProcessInstanceHistoryLog)

Example 7 with HistoricData

use of org.activiti.engine.history.HistoricData 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 8 with HistoricData

use of org.activiti.engine.history.HistoricData in project Activiti by Activiti.

the class ProcessInstanceLogQueryTest method testEverything.

public void testEverything() {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
        ProcessInstanceHistoryLog log = historyService.createProcessInstanceHistoryLogQuery(processInstanceId).includeTasks().includeActivities().includeComments().includeVariables().includeVariableUpdates().singleResult();
        List<HistoricData> events = log.getHistoricData();
        assertEquals(15, events.size());
    }
}
Also used : HistoricData(org.activiti.engine.history.HistoricData) ProcessInstanceHistoryLog(org.activiti.engine.history.ProcessInstanceHistoryLog)

Example 9 with HistoricData

use of org.activiti.engine.history.HistoricData in project Activiti by Activiti.

the class ProcessInstanceLogQueryTest method testIncludeTasks.

public void testIncludeTasks() {
    ProcessInstanceHistoryLog log = historyService.createProcessInstanceHistoryLogQuery(processInstanceId).includeTasks().singleResult();
    List<HistoricData> events = log.getHistoricData();
    assertEquals(2, events.size());
    for (HistoricData event : events) {
        assertTrue(event instanceof HistoricTaskInstance);
    }
}
Also used : HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) HistoricData(org.activiti.engine.history.HistoricData) ProcessInstanceHistoryLog(org.activiti.engine.history.ProcessInstanceHistoryLog)

Example 10 with HistoricData

use of org.activiti.engine.history.HistoricData in project Activiti by Activiti.

the class ProcessInstanceLogQueryTest method testIncludeActivities.

public void testIncludeActivities() {
    ProcessInstanceHistoryLog log = historyService.createProcessInstanceHistoryLogQuery(processInstanceId).includeActivities().singleResult();
    List<HistoricData> events = log.getHistoricData();
    assertEquals(5, events.size());
    for (HistoricData event : events) {
        assertTrue(event instanceof HistoricActivityInstance);
    }
}
Also used : HistoricData(org.activiti.engine.history.HistoricData) ProcessInstanceHistoryLog(org.activiti.engine.history.ProcessInstanceHistoryLog) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance)

Aggregations

HistoricData (org.activiti.engine.history.HistoricData)12 ProcessInstanceHistoryLog (org.activiti.engine.history.ProcessInstanceHistoryLog)11 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)4 HistoricVariableUpdate (org.activiti.engine.history.HistoricVariableUpdate)3 HashMap (java.util.HashMap)2 HistoricActivityInstance (org.activiti.engine.history.HistoricActivityInstance)2 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)2 HistoricVariableInstanceEntity (org.activiti.engine.impl.persistence.entity.HistoricVariableInstanceEntity)2 Comment (org.activiti.engine.task.Comment)2 Task (org.activiti.engine.task.Task)2 Deployment (org.activiti.engine.test.Deployment)2 HistoricDetailVariableInstanceUpdateEntity (org.activiti.engine.impl.persistence.entity.HistoricDetailVariableInstanceUpdateEntity)1 HistoricProcessInstanceEntity (org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntity)1 CacheableVariable (org.activiti.engine.impl.variable.CacheableVariable)1