Search in sources :

Example 6 with VariableInstance

use of org.activiti.engine.impl.persistence.entity.VariableInstance in project Activiti by Activiti.

the class TaskVariablesTest method testGetVariablesLocalByTaskIds.

@Deployment
public void testGetVariablesLocalByTaskIds() {
    ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("twoTaskProcess");
    ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("twoTaskProcess");
    List<Task> taskList1 = taskService.createTaskQuery().processInstanceId(processInstance1.getId()).list();
    List<Task> taskList2 = taskService.createTaskQuery().processInstanceId(processInstance2.getId()).list();
    // Task local variables
    for (Task task : taskList1) {
        if ("usertask1".equals(task.getTaskDefinitionKey())) {
            taskService.setVariableLocal(task.getId(), "taskVar1", "sayHello1");
        } else {
            taskService.setVariableLocal(task.getId(), "taskVar2", "sayHello2");
        }
        // Execution variables
        taskService.setVariable(task.getId(), "executionVar1", "helloWorld1");
    }
    // Task local variables
    for (Task task : taskList2) {
        if ("usertask1".equals(task.getTaskDefinitionKey())) {
            taskService.setVariableLocal(task.getId(), "taskVar3", "sayHello3");
        } else {
            taskService.setVariableLocal(task.getId(), "taskVar4", "sayHello4");
        }
        // Execution variables
        taskService.setVariable(task.getId(), "executionVar2", "helloWorld2");
    }
    // only 1 process
    Set<String> taskIds = new HashSet<String>();
    taskIds.add(taskList1.get(0).getId());
    taskIds.add(taskList1.get(1).getId());
    List<VariableInstance> variables = taskService.getVariableInstancesLocalByTaskIds(taskIds);
    assertEquals(2, variables.size());
    checkVariable(taskList1.get(0).getId(), "taskVar1", "sayHello1", variables);
    checkVariable(taskList1.get(1).getId(), "taskVar2", "sayHello2", variables);
    // 2 process
    taskIds = new HashSet<String>();
    taskIds.add(taskList1.get(0).getId());
    taskIds.add(taskList1.get(1).getId());
    taskIds.add(taskList2.get(0).getId());
    taskIds.add(taskList2.get(1).getId());
    variables = taskService.getVariableInstancesLocalByTaskIds(taskIds);
    assertEquals(4, variables.size());
    checkVariable(taskList1.get(0).getId(), "taskVar1", "sayHello1", variables);
    checkVariable(taskList1.get(1).getId(), "taskVar2", "sayHello2", variables);
    checkVariable(taskList2.get(0).getId(), "taskVar3", "sayHello3", variables);
    checkVariable(taskList2.get(1).getId(), "taskVar4", "sayHello4", variables);
    // mixture 2 process
    taskIds = new HashSet<String>();
    taskIds.add(taskList1.get(0).getId());
    taskIds.add(taskList2.get(1).getId());
    variables = taskService.getVariableInstancesLocalByTaskIds(taskIds);
    assertEquals(2, variables.size());
    checkVariable(taskList1.get(0).getId(), "taskVar1", "sayHello1", variables);
    checkVariable(taskList2.get(1).getId(), "taskVar4", "sayHello4", variables);
}
Also used : Task(org.activiti.engine.task.Task) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) VariableInstance(org.activiti.engine.impl.persistence.entity.VariableInstance) HashSet(java.util.HashSet) Deployment(org.activiti.engine.test.Deployment)

Example 7 with VariableInstance

use of org.activiti.engine.impl.persistence.entity.VariableInstance in project Activiti by Activiti.

the class TaskVariablesTest method checkVariable.

private void checkVariable(String taskId, String name, String value, List<VariableInstance> variables) {
    for (VariableInstance variable : variables) {
        if (taskId.equals(variable.getTaskId())) {
            assertEquals(name, variable.getName());
            assertEquals(value, variable.getValue());
            return;
        }
    }
    fail();
}
Also used : VariableInstance(org.activiti.engine.impl.persistence.entity.VariableInstance)

Example 8 with VariableInstance

use of org.activiti.engine.impl.persistence.entity.VariableInstance in project Activiti by Activiti.

the class RuntimeVariablesTest method checkVariable.

private void checkVariable(String executionId, String name, String value, List<VariableInstance> variables) {
    for (VariableInstance variable : variables) {
        if (executionId.equals(variable.getExecutionId())) {
            assertEquals(name, variable.getName());
            assertEquals(value, variable.getValue());
            return;
        }
    }
    fail();
}
Also used : VariableInstance(org.activiti.engine.impl.persistence.entity.VariableInstance)

Example 9 with VariableInstance

use of org.activiti.engine.impl.persistence.entity.VariableInstance in project Activiti by Activiti.

the class RuntimeVariablesTest method testGetVariablesByExecutionIdsForScope.

@Deployment(resources = { "org/activiti/engine/test/api/runtime/variableScope.bpmn20.xml" })
public void testGetVariablesByExecutionIdsForScope() {
    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();
    Set<String> taskIds = new HashSet<String>();
    for (Task task : tasks) {
        taskService.setVariableLocal(task.getId(), "taskVar", "taskVar");
        taskIds.add(task.getId());
    }
    List<VariableInstance> executionVariableInstances = runtimeService.getVariableInstancesByExecutionIds(executionIds);
    assertEquals(executionVariableInstances.size(), 2);
    assertEquals(executionVariableInstances.get(0).getName(), "executionVar");
    assertEquals(executionVariableInstances.get(0).getValue(), "executionVar");
    assertEquals(executionVariableInstances.get(1).getName(), "executionVar");
    assertEquals(executionVariableInstances.get(1).getValue(), "executionVar");
    executionIds = new HashSet<String>();
    executionIds.add(processInstance.getId());
    executionVariableInstances = runtimeService.getVariableInstancesByExecutionIds(executionIds);
    assertEquals(executionVariableInstances.size(), 1);
    assertEquals(executionVariableInstances.get(0).getName(), "processVar");
    assertEquals(executionVariableInstances.get(0).getValue(), "processVar");
}
Also used : Task(org.activiti.engine.task.Task) HashMap(java.util.HashMap) Execution(org.activiti.engine.runtime.Execution) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) VariableInstance(org.activiti.engine.impl.persistence.entity.VariableInstance) HashSet(java.util.HashSet) Deployment(org.activiti.engine.test.Deployment)

Example 10 with VariableInstance

use of org.activiti.engine.impl.persistence.entity.VariableInstance in project Activiti by Activiti.

the class GetTasksLocalVariablesCmd method execute.

@Override
public List<VariableInstance> execute(CommandContext commandContext) {
    if (taskIds == null) {
        throw new ActivitiIllegalArgumentException("taskIds is null");
    }
    if (taskIds.isEmpty()) {
        throw new ActivitiIllegalArgumentException("Set of taskIds is empty");
    }
    List<VariableInstance> instances = new ArrayList<VariableInstance>();
    List<VariableInstanceEntity> entities = commandContext.getVariableInstanceEntityManager().findVariableInstancesByTaskIds(taskIds);
    for (VariableInstanceEntity entity : entities) {
        entity.getValue();
        instances.add(entity);
    }
    return instances;
}
Also used : ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ArrayList(java.util.ArrayList) VariableInstanceEntity(org.activiti.engine.impl.persistence.entity.VariableInstanceEntity) VariableInstance(org.activiti.engine.impl.persistence.entity.VariableInstance)

Aggregations

VariableInstance (org.activiti.engine.impl.persistence.entity.VariableInstance)12 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)6 Deployment (org.activiti.engine.test.Deployment)6 HashSet (java.util.HashSet)5 Task (org.activiti.engine.task.Task)5 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)2 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)2 VariableInstanceEntity (org.activiti.engine.impl.persistence.entity.VariableInstanceEntity)2 Execution (org.activiti.engine.runtime.Execution)2 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)1