use of org.activiti.engine.history.HistoricVariableInstance in project Gatekeeper by FINRAOS.
the class AccessRequestService method getCompletedRequests.
public List<CompletedAccessRequestWrapper> getCompletedRequests() {
// We can use the variables stored on the activiti requests to build out our request history.
List<HistoricVariableInstance> taskVars = historyService.createHistoricVariableInstanceQuery().list();
Map<String, Map<String, Object>> historicData = new HashMap<>();
List<CompletedAccessRequestWrapper> results = new ArrayList<>();
taskVars.forEach(taskVar -> {
String key = taskVar.getVariableName();
Object value = taskVar.getValue();
if (historicData.containsKey(taskVar.getProcessInstanceId())) {
historicData.get(taskVar.getProcessInstanceId()).put(taskVar.getVariableName(), taskVar.getValue());
} else {
Map<String, Object> data = new HashMap<>();
data.put("created", taskVar.getCreateTime());
data.put(taskVar.getVariableName(), taskVar.getValue());
historicData.put(taskVar.getProcessInstanceId(), data);
}
if (key.equals("requestStatus")) {
historicData.get(taskVar.getProcessInstanceId()).put("updated", taskVar.getLastUpdatedTime());
}
});
for (String k : historicData.keySet()) {
Map<String, Object> varMap = historicData.get(k);
RequestStatus status = (RequestStatus) varMap.get("requestStatus") != null ? (RequestStatus) varMap.get("requestStatus") : RequestStatus.APPROVAL_PENDING;
AccessRequest request = (AccessRequest) varMap.get("accessRequest");
Date created = (Date) varMap.get("created");
Date updated = (Date) varMap.get("updated");
CompletedAccessRequestWrapper wrapper = new CompletedAccessRequestWrapper(request).setUpdated(updated).setAttempts((Integer) varMap.get("attempts")).setStatus(status);
wrapper.setCreated(created);
results.add(wrapper);
}
return (List<CompletedAccessRequestWrapper>) filterResults(results);
}
use of org.activiti.engine.history.HistoricVariableInstance 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();
assertThat(userTask.getName()).isEqualTo("userTask1");
taskService.complete(userTask.getId(), singletonMap("myVar", "test789"));
assertProcessEnded(processInstance.getId());
List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery().orderByVariableName().asc().list();
assertThat(variables).hasSize(2);
HistoricVariableInstanceEntity historicVariable = (HistoricVariableInstanceEntity) variables.get(0);
assertThat(historicVariable.getName()).isEqualTo("myVar");
assertThat(historicVariable.getTextValue()).isEqualTo("test789");
HistoricVariableInstanceEntity historicVariable1 = (HistoricVariableInstanceEntity) variables.get(1);
assertThat(historicVariable1.getName()).isEqualTo("myVar1");
assertThat(historicVariable1.getTextValue()).isEqualTo("test456");
assertThat(historyService.createHistoricActivityInstanceQuery().count()).isEqualTo(8);
assertThat(historyService.createHistoricDetailQuery().count()).isEqualTo(5);
}
}
use of org.activiti.engine.history.HistoricVariableInstance 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();
assertThat(variables).hasSize(1);
HistoricVariableInstanceEntity historicVariable = (HistoricVariableInstanceEntity) variables.get(0);
assertThat(historicVariable.getTextValue()).isEqualTo("test456");
assertThat(historyService.createHistoricActivityInstanceQuery().count()).isEqualTo(7);
assertThat(historyService.createHistoricDetailQuery().count()).isEqualTo(2);
}
}
use of org.activiti.engine.history.HistoricVariableInstance 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();
assertThat(userTask.getName()).isEqualTo("userTask1");
taskService.complete(userTask.getId(), singletonMap("myVar", "test789"));
assertProcessEnded(processInstance.getId());
List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery().list();
assertThat(variables).hasSize(1);
HistoricVariableInstanceEntity historicVariable = (HistoricVariableInstanceEntity) variables.get(0);
assertThat(historicVariable.getTextValue()).isEqualTo("test456");
assertThat(historyService.createHistoricActivityInstanceQuery().count()).isEqualTo(5);
assertThat(historyService.createHistoricDetailQuery().count()).isEqualTo(3);
}
}
use of org.activiti.engine.history.HistoricVariableInstance in project Activiti by Activiti.
the class HistoricVariableInstanceTest method testHistoricVariableQueryByExecutionIdsForScope.
@Deployment(resources = { "org/activiti/engine/test/api/runtime/variableScope.bpmn20.xml" })
public void testHistoricVariableQueryByExecutionIdsForScope() {
Map<String, Object> processVars = new HashMap<String, Object>();
processVars.put("processVar", "processVar");
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("variableScopeProcess", processVars);
Set<String> executionIds = new HashSet<String>();
List<Execution> executions = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).list();
for (Execution execution : executions) {
if (!processInstance.getId().equals(execution.getId())) {
executionIds.add(execution.getId());
runtimeService.setVariableLocal(execution.getId(), "executionVar", "executionVar");
}
}
List<Task> tasks = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();
for (Task task : tasks) {
taskService.setVariableLocal(task.getId(), "taskVar", "taskVar");
}
Set<String> processInstanceIds = new HashSet<String>();
processInstanceIds.add(processInstance.getId());
List<HistoricVariableInstance> historicVariableInstances = historyService.createHistoricVariableInstanceQuery().executionIds(processInstanceIds).list();
assertThat(1).isEqualTo(historicVariableInstances.size());
assertThat("processVar").isEqualTo(historicVariableInstances.get(0).getVariableName());
assertThat("processVar").isEqualTo(historicVariableInstances.get(0).getValue());
historicVariableInstances = historyService.createHistoricVariableInstanceQuery().executionIds(executionIds).excludeTaskVariables().list();
assertThat(2).isEqualTo(historicVariableInstances.size());
assertThat("executionVar").isEqualTo(historicVariableInstances.get(0).getVariableName());
assertThat("executionVar").isEqualTo(historicVariableInstances.get(0).getValue());
assertThat("executionVar").isEqualTo(historicVariableInstances.get(1).getVariableName());
assertThat("executionVar").isEqualTo(historicVariableInstances.get(1).getValue());
}
Aggregations