use of org.activiti.engine.impl.persistence.entity.VariableInstance in project Activiti by Activiti.
the class GetExecutionVariableInstancesCmd method execute.
public Map<String, VariableInstance> execute(CommandContext commandContext) {
// Verify existance of execution
if (executionId == null) {
throw new ActivitiIllegalArgumentException("executionId is null");
}
ExecutionEntity execution = commandContext.getExecutionEntityManager().findExecutionById(executionId);
if (execution == null) {
throw new ActivitiObjectNotFoundException("execution " + executionId + " doesn't exist", Execution.class);
}
Map<String, VariableInstance> variables = null;
if (variableNames == null || variableNames.isEmpty()) {
// Fetch all
if (isLocal) {
variables = execution.getVariableInstancesLocal();
} else {
variables = execution.getVariableInstances();
}
} else {
// Fetch specific collection of variables
if (isLocal) {
variables = execution.getVariableInstancesLocal(variableNames, false);
} else {
variables = execution.getVariableInstances(variableNames, false);
}
}
if (variables != null && locale != null) {
for (Entry<String, VariableInstance> entry : variables.entrySet()) {
String variableName = entry.getKey();
VariableInstance variableEntity = entry.getValue();
String localizedName = null;
String localizedDescription = null;
ObjectNode languageNode = Context.getLocalizationElementProperties(locale, variableName, execution.getProcessDefinitionId(), withLocalizationFallback);
if (languageNode != null) {
JsonNode nameNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_NAME);
if (nameNode != null) {
localizedName = nameNode.asText();
}
JsonNode descriptionNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_DESCRIPTION);
if (descriptionNode != null) {
localizedDescription = descriptionNode.asText();
}
}
variableEntity.setLocalizedName(localizedName);
variableEntity.setLocalizedDescription(localizedDescription);
}
}
return variables;
}
use of org.activiti.engine.impl.persistence.entity.VariableInstance in project Activiti by Activiti.
the class CustomVariableType method testLocalizeVariables.
@Deployment
public void testLocalizeVariables() {
// Start process instance with different types of variables
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("stringVar", "coca-cola");
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("localizeVariables", variables);
ObjectNode infoNode = dynamicBpmnService.getProcessDefinitionInfo(processInstance.getProcessDefinitionId());
dynamicBpmnService.changeLocalizationName("en-US", "stringVar", "stringVar 'en-US' Name", infoNode);
dynamicBpmnService.changeLocalizationDescription("en-US", "stringVar", "stringVar 'en-US' Description", infoNode);
dynamicBpmnService.changeLocalizationName("en-AU", "stringVar", "stringVar 'en-AU' Name", infoNode);
dynamicBpmnService.changeLocalizationDescription("en-AU", "stringVar", "stringVar 'en-AU' Description", infoNode);
dynamicBpmnService.changeLocalizationName("en", "stringVar", "stringVar 'en' Name", infoNode);
dynamicBpmnService.changeLocalizationDescription("en", "stringVar", "stringVar 'en' Description", infoNode);
dynamicBpmnService.saveProcessDefinitionInfo(processInstance.getProcessDefinitionId(), infoNode);
Map<String, VariableInstance> variableInstances = runtimeService.getVariableInstances(processInstance.getId(), "es", false);
assertEquals(1, variableInstances.size());
assertEquals("stringVar", variableInstances.get("stringVar").getName());
assertEquals("coca-cola", variableInstances.get("stringVar").getValue());
assertEquals("stringVar 'es' Name", variableInstances.get("stringVar").getLocalizedName());
assertEquals("stringVar 'es' Description", variableInstances.get("stringVar").getLocalizedDescription());
// getVariableInstances
variableInstances = runtimeService.getVariableInstances(processInstance.getId(), "en-US", false);
assertEquals(1, variableInstances.size());
assertEquals("stringVar", variableInstances.get("stringVar").getName());
assertEquals("coca-cola", variableInstances.get("stringVar").getValue());
assertEquals("stringVar 'en-US' Name", variableInstances.get("stringVar").getLocalizedName());
assertEquals("stringVar 'en-US' Description", variableInstances.get("stringVar").getLocalizedDescription());
variableInstances = runtimeService.getVariableInstances(processInstance.getId(), "en-AU", false);
assertEquals(1, variableInstances.size());
assertEquals("stringVar", variableInstances.get("stringVar").getName());
assertEquals("coca-cola", variableInstances.get("stringVar").getValue());
assertEquals("stringVar 'en-AU' Name", variableInstances.get("stringVar").getLocalizedName());
assertEquals("stringVar 'en-AU' Description", variableInstances.get("stringVar").getLocalizedDescription());
variableInstances = runtimeService.getVariableInstances(processInstance.getId(), "en-GB", true);
assertEquals(1, variableInstances.size());
assertEquals("stringVar", variableInstances.get("stringVar").getName());
assertEquals("coca-cola", variableInstances.get("stringVar").getValue());
assertEquals("stringVar 'en' Name", variableInstances.get("stringVar").getLocalizedName());
assertEquals("stringVar 'en' Description", variableInstances.get("stringVar").getLocalizedDescription());
variableInstances = runtimeService.getVariableInstances(processInstance.getId(), "en-GB", false);
assertEquals(1, variableInstances.size());
assertEquals("stringVar", variableInstances.get("stringVar").getName());
assertEquals("coca-cola", variableInstances.get("stringVar").getValue());
assertEquals(null, variableInstances.get("stringVar").getLocalizedName());
assertEquals(null, variableInstances.get("stringVar").getLocalizedDescription());
List<String> variableNames = new ArrayList<String>();
variableNames.add("stringVar");
// getVariablesInstances via names
variableInstances = runtimeService.getVariableInstances(processInstance.getId(), variableNames, "en-US", false);
assertEquals(1, variableInstances.size());
assertEquals("stringVar", variableInstances.get("stringVar").getName());
assertEquals("coca-cola", variableInstances.get("stringVar").getValue());
assertEquals("stringVar 'en-US' Name", variableInstances.get("stringVar").getLocalizedName());
assertEquals("stringVar 'en-US' Description", variableInstances.get("stringVar").getLocalizedDescription());
variableInstances = runtimeService.getVariableInstances(processInstance.getId(), variableNames, "en-AU", false);
assertEquals(1, variableInstances.size());
assertEquals("stringVar", variableInstances.get("stringVar").getName());
assertEquals("coca-cola", variableInstances.get("stringVar").getValue());
assertEquals("stringVar 'en-AU' Name", variableInstances.get("stringVar").getLocalizedName());
assertEquals("stringVar 'en-AU' Description", variableInstances.get("stringVar").getLocalizedDescription());
variableInstances = runtimeService.getVariableInstances(processInstance.getId(), variableNames, "en-GB", true);
assertEquals(1, variableInstances.size());
assertEquals("stringVar", variableInstances.get("stringVar").getName());
assertEquals("coca-cola", variableInstances.get("stringVar").getValue());
assertEquals("stringVar 'en' Name", variableInstances.get("stringVar").getLocalizedName());
assertEquals("stringVar 'en' Description", variableInstances.get("stringVar").getLocalizedDescription());
variableInstances = runtimeService.getVariableInstances(processInstance.getId(), variableNames, "en-GB", false);
assertEquals(1, variableInstances.size());
assertEquals("stringVar", variableInstances.get("stringVar").getName());
assertEquals("coca-cola", variableInstances.get("stringVar").getValue());
assertEquals(null, variableInstances.get("stringVar").getLocalizedName());
assertEquals(null, variableInstances.get("stringVar").getLocalizedDescription());
// getVariableInstancesLocal
variableInstances = runtimeService.getVariableInstancesLocal(processInstance.getId(), "en-US", false);
assertEquals(1, variableInstances.size());
assertEquals("stringVar", variableInstances.get("stringVar").getName());
assertEquals("coca-cola", variableInstances.get("stringVar").getValue());
assertEquals("stringVar 'en-US' Name", variableInstances.get("stringVar").getLocalizedName());
assertEquals("stringVar 'en-US' Description", variableInstances.get("stringVar").getLocalizedDescription());
variableInstances = runtimeService.getVariableInstancesLocal(processInstance.getId(), "en-AU", false);
assertEquals(1, variableInstances.size());
assertEquals("stringVar", variableInstances.get("stringVar").getName());
assertEquals("coca-cola", variableInstances.get("stringVar").getValue());
assertEquals("stringVar 'en-AU' Name", variableInstances.get("stringVar").getLocalizedName());
assertEquals("stringVar 'en-AU' Description", variableInstances.get("stringVar").getLocalizedDescription());
variableInstances = runtimeService.getVariableInstancesLocal(processInstance.getId(), "en-GB", true);
assertEquals(1, variableInstances.size());
assertEquals("stringVar", variableInstances.get("stringVar").getName());
assertEquals("coca-cola", variableInstances.get("stringVar").getValue());
assertEquals("stringVar 'en' Name", variableInstances.get("stringVar").getLocalizedName());
assertEquals("stringVar 'en' Description", variableInstances.get("stringVar").getLocalizedDescription());
variableInstances = runtimeService.getVariableInstancesLocal(processInstance.getId(), "en-GB", false);
assertEquals(1, variableInstances.size());
assertEquals("stringVar", variableInstances.get("stringVar").getName());
assertEquals("coca-cola", variableInstances.get("stringVar").getValue());
assertEquals(null, variableInstances.get("stringVar").getLocalizedName());
assertEquals(null, variableInstances.get("stringVar").getLocalizedDescription());
// getVariableInstancesLocal via names
variableInstances = runtimeService.getVariableInstancesLocal(processInstance.getId(), variableNames, "en-US", false);
assertEquals(1, variableInstances.size());
assertEquals("stringVar", variableInstances.get("stringVar").getName());
assertEquals("coca-cola", variableInstances.get("stringVar").getValue());
assertEquals("stringVar 'en-US' Name", variableInstances.get("stringVar").getLocalizedName());
assertEquals("stringVar 'en-US' Description", variableInstances.get("stringVar").getLocalizedDescription());
variableInstances = runtimeService.getVariableInstancesLocal(processInstance.getId(), variableNames, "en-AU", false);
assertEquals(1, variableInstances.size());
assertEquals("stringVar", variableInstances.get("stringVar").getName());
assertEquals("coca-cola", variableInstances.get("stringVar").getValue());
assertEquals("stringVar 'en-AU' Name", variableInstances.get("stringVar").getLocalizedName());
assertEquals("stringVar 'en-AU' Description", variableInstances.get("stringVar").getLocalizedDescription());
variableInstances = runtimeService.getVariableInstancesLocal(processInstance.getId(), variableNames, "en-GB", true);
assertEquals(1, variableInstances.size());
assertEquals("stringVar", variableInstances.get("stringVar").getName());
assertEquals("coca-cola", variableInstances.get("stringVar").getValue());
assertEquals("stringVar 'en' Name", variableInstances.get("stringVar").getLocalizedName());
assertEquals("stringVar 'en' Description", variableInstances.get("stringVar").getLocalizedDescription());
variableInstances = runtimeService.getVariableInstancesLocal(processInstance.getId(), variableNames, "en-GB", false);
assertEquals(1, variableInstances.size());
assertEquals("stringVar", variableInstances.get("stringVar").getName());
assertEquals("coca-cola", variableInstances.get("stringVar").getValue());
assertEquals(null, variableInstances.get("stringVar").getLocalizedName());
assertEquals(null, variableInstances.get("stringVar").getLocalizedDescription());
// getVariableInstance
VariableInstance variableInstance = runtimeService.getVariableInstance(processInstance.getId(), "stringVar", "en-GB", false);
assertNotNull(variableInstance);
assertEquals("stringVar", variableInstance.getName());
assertEquals("coca-cola", variableInstance.getValue());
assertEquals(null, variableInstance.getLocalizedName());
assertEquals(null, variableInstance.getLocalizedDescription());
variableInstance = runtimeService.getVariableInstance(processInstance.getId(), "stringVar", "en-US", false);
assertNotNull(variableInstance);
assertEquals("stringVar", variableInstance.getName());
assertEquals("coca-cola", variableInstance.getValue());
assertEquals("stringVar 'en-US' Name", variableInstance.getLocalizedName());
assertEquals("stringVar 'en-US' Description", variableInstance.getLocalizedDescription());
variableInstance = runtimeService.getVariableInstance(processInstance.getId(), "stringVar", "en-AU", false);
assertNotNull(variableInstance);
assertEquals("stringVar", variableInstance.getName());
assertEquals("coca-cola", variableInstance.getValue());
assertEquals("stringVar 'en-AU' Name", variableInstance.getLocalizedName());
assertEquals("stringVar 'en-AU' Description", variableInstance.getLocalizedDescription());
variableInstance = runtimeService.getVariableInstance(processInstance.getId(), "stringVar", "en-GB", true);
assertNotNull(variableInstance);
assertEquals("stringVar", variableInstance.getName());
assertEquals("coca-cola", variableInstance.getValue());
assertEquals("stringVar 'en' Name", variableInstance.getLocalizedName());
assertEquals("stringVar 'en' Description", variableInstance.getLocalizedDescription());
variableInstance = runtimeService.getVariableInstance(processInstance.getId(), "stringVar", "en-GB", false);
assertNotNull(variableInstance);
assertEquals("stringVar", variableInstance.getName());
assertEquals("coca-cola", variableInstance.getValue());
assertEquals(null, variableInstance.getLocalizedName());
assertEquals(null, variableInstance.getLocalizedDescription());
// getVariableInstanceLocal
variableInstance = runtimeService.getVariableInstanceLocal(processInstance.getId(), "stringVar", "en-US", false);
assertNotNull(variableInstance);
assertEquals("stringVar", variableInstance.getName());
assertEquals("coca-cola", variableInstance.getValue());
assertEquals("stringVar 'en-US' Name", variableInstance.getLocalizedName());
assertEquals("stringVar 'en-US' Description", variableInstance.getLocalizedDescription());
variableInstance = runtimeService.getVariableInstanceLocal(processInstance.getId(), "stringVar", "en-AU", false);
assertNotNull(variableInstance);
assertEquals("stringVar", variableInstance.getName());
assertEquals("coca-cola", variableInstance.getValue());
assertEquals("stringVar 'en-AU' Name", variableInstance.getLocalizedName());
assertEquals("stringVar 'en-AU' Description", variableInstance.getLocalizedDescription());
variableInstance = runtimeService.getVariableInstanceLocal(processInstance.getId(), "stringVar", "en-GB", true);
assertNotNull(variableInstance);
assertEquals("stringVar", variableInstance.getName());
assertEquals("coca-cola", variableInstance.getValue());
assertEquals("stringVar 'en' Name", variableInstance.getLocalizedName());
assertEquals("stringVar 'en' Description", variableInstance.getLocalizedDescription());
variableInstance = runtimeService.getVariableInstanceLocal(processInstance.getId(), "stringVar", "en-GB", false);
assertNotNull(variableInstance);
assertEquals("stringVar", variableInstance.getName());
assertEquals("coca-cola", variableInstance.getValue());
assertEquals(null, variableInstance.getLocalizedName());
assertEquals(null, variableInstance.getLocalizedDescription());
}
use of org.activiti.engine.impl.persistence.entity.VariableInstance in project Activiti by Activiti.
the class TaskVariablesTest method testGetVariablesLocalByTaskIdsForScope.
@Deployment(resources = { "org/activiti/engine/test/api/runtime/variableScope.bpmn20.xml" })
public void testGetVariablesLocalByTaskIdsForScope() {
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> variableInstances = taskService.getVariableInstancesLocalByTaskIds(taskIds);
assertEquals(variableInstances.size(), 2);
assertEquals(variableInstances.get(0).getName(), "taskVar");
assertEquals(variableInstances.get(0).getValue(), "taskVar");
assertEquals(variableInstances.get(1).getName(), "taskVar");
assertEquals(variableInstances.get(1).getValue(), "taskVar");
}
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();
}
Aggregations