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());
}
}
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);
}
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());
}
}
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;
}
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");
}
}
Aggregations