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