Search in sources :

Example 16 with HistoricVariableInstance

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);
}
Also used : CompletedAccessRequestWrapper(org.finra.gatekeeper.controllers.wrappers.CompletedAccessRequestWrapper) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance)

Example 17 with HistoricVariableInstance

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);
    }
}
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 18 with HistoricVariableInstance

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);
    }
}
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 19 with HistoricVariableInstance

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);
    }
}
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 20 with HistoricVariableInstance

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());
}
Also used : Task(org.activiti.engine.task.Task) HashMap(java.util.HashMap) Execution(org.activiti.engine.runtime.Execution) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) HashSet(java.util.HashSet) 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