Search in sources :

Example 26 with HistoricVariableInstance

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

the class HistoricVariableInstanceEscapeClauseTest method testQueryLikeByQueryVariableValue.

@Test
public void testQueryLikeByQueryVariableValue() {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        HistoricVariableInstance historicVariable = historyService.createHistoricVariableInstanceQuery().variableValueLike("var%", "%\\%%").singleResult();
        assertThat(historicVariable).isNotNull();
        assertThat(historicVariable.getProcessInstanceId()).isEqualTo(processInstance1.getId());
        historicVariable = historyService.createHistoricVariableInstanceQuery().variableValueLike("var_", "%\\_%").singleResult();
        assertThat(historicVariable).isNotNull();
        assertThat(historicVariable.getProcessInstanceId()).isEqualTo(processInstance2.getId());
    }
}
Also used : HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) Test(org.junit.Test)

Example 27 with HistoricVariableInstance

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

the class FullHistoryTest method testHistoricVariableInstanceQuery.

@Deployment(resources = "org/activiti/standalone/history/FullHistoryTest.testVariableUpdates.bpmn20.xml")
public void testHistoricVariableInstanceQuery() {
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("process", "one");
    runtimeService.startProcessInstanceByKey("receiveTask", variables);
    runtimeService.trigger(runtimeService.createExecutionQuery().activityId("waitState").singleResult().getId());
    assertThat(historyService.createHistoricVariableInstanceQuery().variableName("process").count()).isEqualTo(1);
    assertThat(historyService.createHistoricVariableInstanceQuery().variableValueEquals("process", "one").count()).isEqualTo(1);
    Map<String, Object> variables2 = new HashMap<String, Object>();
    variables2.put("process", "two");
    ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("receiveTask", variables2);
    runtimeService.trigger(runtimeService.createExecutionQuery().activityId("waitState").singleResult().getId());
    assertThat(historyService.createHistoricVariableInstanceQuery().variableName("process").count()).isEqualTo(2);
    assertThat(historyService.createHistoricVariableInstanceQuery().variableValueEquals("process", "one").count()).isEqualTo(1);
    assertThat(historyService.createHistoricVariableInstanceQuery().variableValueEquals("process", "two").count()).isEqualTo(1);
    HistoricVariableInstance historicProcessVariable = historyService.createHistoricVariableInstanceQuery().variableValueEquals("process", "one").singleResult();
    assertThat(historicProcessVariable.getVariableName()).isEqualTo("process");
    assertThat(historicProcessVariable.getValue()).isEqualTo("one");
    Map<String, Object> variables3 = new HashMap<String, Object>();
    variables3.put("long", 1000l);
    variables3.put("double", 25.43d);
    ProcessInstance processInstance3 = runtimeService.startProcessInstanceByKey("receiveTask", variables3);
    runtimeService.trigger(runtimeService.createExecutionQuery().activityId("waitState").singleResult().getId());
    assertThat(historyService.createHistoricVariableInstanceQuery().variableName("long").count()).isEqualTo(1);
    assertThat(historyService.createHistoricVariableInstanceQuery().variableValueEquals("long", 1000l).count()).isEqualTo(1);
    assertThat(historyService.createHistoricVariableInstanceQuery().variableName("double").count()).isEqualTo(1);
    assertThat(historyService.createHistoricVariableInstanceQuery().variableValueEquals("double", 25.43d).count()).isEqualTo(1);
}
Also used : HashMap(java.util.HashMap) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) Deployment(org.activiti.engine.test.Deployment)

Example 28 with HistoricVariableInstance

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

the class StandaloneTaskTest method testHistoricVariableOkOnUpdate.

public void testHistoricVariableOkOnUpdate() {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
        // 1. create a task
        Task task = taskService.newTask();
        task.setName("test execution");
        task.setOwner("josOwner");
        task.setAssignee("JosAssignee");
        taskService.saveTask(task);
        // 2. set task variables
        Map<String, Object> taskVariables = new HashMap<String, Object>();
        taskVariables.put("finishedAmount", 0);
        taskService.setVariables(task.getId(), taskVariables);
        // 3. complete this task with a new variable
        Map<String, Object> finishVariables = new HashMap<String, Object>();
        finishVariables.put("finishedAmount", 40);
        taskService.complete(task.getId(), finishVariables);
        // 4. get completed variable
        List<HistoricVariableInstance> hisVarList = historyService.createHistoricVariableInstanceQuery().taskId(task.getId()).list();
        assertThat(hisVarList).hasSize(1);
        assertThat(hisVarList.get(0).getValue()).isEqualTo(40);
        // Cleanup
        historyService.deleteHistoricTaskInstance(task.getId());
    }
}
Also used : Task(org.activiti.engine.task.Task) HashMap(java.util.HashMap) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance)

Example 29 with HistoricVariableInstance

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

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

the class ScriptExecutionListenerTest method testScriptExecutionListener.

@Deployment(resources = { "org/activiti/examples/bpmn/executionlistener/ScriptExecutionListenerTest.bpmn20.xml" })
public void testScriptExecutionListener() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("scriptExecutionListenerProcess");
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        List<HistoricVariableInstance> historicVariables = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getId()).list();
        Map<String, Object> varMap = new HashMap<String, Object>();
        for (HistoricVariableInstance historicVariableInstance : historicVariables) {
            varMap.put(historicVariableInstance.getVariableName(), historicVariableInstance.getValue());
        }
        assertThat(varMap.containsKey("foo")).isTrue();
        assertThat(varMap.get("foo")).isEqualTo("FOO");
        assertThat(varMap.containsKey("var1")).isTrue();
        assertThat(varMap.get("var1")).isEqualTo("test");
        assertThat(varMap.containsKey("bar")).isFalse();
        assertThat(varMap.containsKey("myVar")).isTrue();
        assertThat(varMap.get("myVar")).isEqualTo("BAR");
    }
}
Also used : HashMap(java.util.HashMap) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) Deployment(org.activiti.engine.test.Deployment)

Aggregations

HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)56 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)28 Deployment (org.activiti.engine.test.Deployment)25 HashMap (java.util.HashMap)20 Task (org.activiti.engine.task.Task)18 HistoricVariableInstanceEntity (org.activiti.engine.impl.persistence.entity.HistoricVariableInstanceEntity)8 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)5 Test (org.junit.Test)5 HistoricData (org.activiti.engine.history.HistoricData)4 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)4 HistoricVariableUpdate (org.activiti.engine.history.HistoricVariableUpdate)4 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 BpmnModel (org.activiti.bpmn.model.BpmnModel)3 HistoryService (org.activiti.engine.HistoryService)3 HistoricActivityInstance (org.activiti.engine.history.HistoricActivityInstance)3 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)3 HistoricVariableInstanceQuery (org.activiti.engine.history.HistoricVariableInstanceQuery)3 ProcessInstanceHistoryLog (org.activiti.engine.history.ProcessInstanceHistoryLog)3