use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.LOCAL in project carbon-business-process by wso2.
the class BaseRuntimeService method addGlobalVariables.
protected void addGlobalVariables(Execution execution, int variableType, Map<String, RestVariable> variableMap) {
Map<String, Object> rawVariables = runtimeService.getVariables(execution.getId());
List<RestVariable> globalVariables = new RestResponseFactory().createRestVariables(rawVariables, execution.getId(), variableType, RestVariable.RestVariableScope.GLOBAL, uriInfo.getBaseUri().toString());
// since local variables get precedence over global ones at all times.
for (RestVariable var : globalVariables) {
if (!variableMap.containsKey(var.getName())) {
variableMap.put(var.getName(), var);
}
}
}
use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.LOCAL in project carbon-business-process by wso2.
the class BaseTaskService method getVariableFromRequest.
public RestVariable getVariableFromRequest(String taskId, String variableName, String scope, boolean includeBinary, String baseUri) {
boolean variableFound = false;
Object value = null;
RestVariable.RestVariableScope variableScope = RestVariable.getScopeFromString(scope);
TaskService taskService = BPMNOSGIService.getTaskService();
RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
if (variableScope == null) {
// First, check local variables (which have precedence when no scope is supplied)
if (taskService.hasVariableLocal(taskId, variableName)) {
value = taskService.getVariableLocal(taskId, variableName);
variableScope = RestVariable.RestVariableScope.LOCAL;
variableFound = true;
} else {
// Revert to execution-variable when not present local on the task
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
if (task.getExecutionId() != null && runtimeService.hasVariable(task.getExecutionId(), variableName)) {
value = runtimeService.getVariable(task.getExecutionId(), variableName);
variableScope = RestVariable.RestVariableScope.GLOBAL;
variableFound = true;
}
}
} else if (variableScope == RestVariable.RestVariableScope.GLOBAL) {
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
if (task.getExecutionId() != null && runtimeService.hasVariable(task.getExecutionId(), variableName)) {
value = runtimeService.getVariable(task.getExecutionId(), variableName);
variableFound = true;
}
} else if (variableScope == RestVariable.RestVariableScope.LOCAL) {
if (taskService.hasVariableLocal(taskId, variableName)) {
value = taskService.getVariableLocal(taskId, variableName);
variableFound = true;
}
}
if (!variableFound) {
throw new ActivitiObjectNotFoundException("Task '" + taskId + "' doesn't have a variable with name: '" + variableName + "'.", VariableInstanceEntity.class);
} else {
return new RestResponseFactory().createRestVariable(variableName, value, variableScope, taskId, RestResponseFactory.VARIABLE_TASK, includeBinary, baseUri);
}
}
use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.LOCAL in project carbon-business-process by wso2.
the class BaseTaskService method addGlobalVariables.
protected void addGlobalVariables(Task task, Map<String, RestVariable> variableMap, String baseUri) {
if (task.getExecutionId() != null) {
RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
Map<String, Object> rawVariables = runtimeService.getVariables(task.getExecutionId());
List<RestVariable> globalVariables = new RestResponseFactory().createRestVariables(rawVariables, task.getId(), RestResponseFactory.VARIABLE_TASK, RestVariable.RestVariableScope.GLOBAL, baseUri);
// since local variables get precedence over global ones at all times.
for (RestVariable var : globalVariables) {
if (!variableMap.containsKey(var.getName())) {
variableMap.put(var.getName(), var);
}
}
}
}
use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.LOCAL in project carbon-business-process by wso2.
the class BaseExecutionService method getVariableFromRequest.
public RestVariable getVariableFromRequest(Execution execution, String variableName, String scope, boolean includeBinary, UriInfo uriInfo) {
boolean variableFound = false;
Object value = null;
if (execution == null) {
throw new ActivitiObjectNotFoundException("Could not find an execution", Execution.class);
}
RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
RestVariable.RestVariableScope variableScope = RestVariable.getScopeFromString(scope);
if (variableScope == null) {
// First, check local variables (which have precedence when no scope is supplied)
if (runtimeService.hasVariableLocal(execution.getId(), variableName)) {
value = runtimeService.getVariableLocal(execution.getId(), variableName);
variableScope = RestVariable.RestVariableScope.LOCAL;
variableFound = true;
} else {
if (execution.getParentId() != null) {
value = runtimeService.getVariable(execution.getParentId(), variableName);
variableScope = RestVariable.RestVariableScope.GLOBAL;
variableFound = true;
}
}
} else if (variableScope == RestVariable.RestVariableScope.GLOBAL) {
// Use parent to get variables
if (execution.getParentId() != null) {
value = runtimeService.getVariable(execution.getParentId(), variableName);
variableScope = RestVariable.RestVariableScope.GLOBAL;
variableFound = true;
}
} else if (variableScope == RestVariable.RestVariableScope.LOCAL) {
value = runtimeService.getVariableLocal(execution.getId(), variableName);
variableScope = RestVariable.RestVariableScope.LOCAL;
variableFound = true;
}
if (!variableFound) {
throw new ActivitiObjectNotFoundException("Execution '" + execution.getId() + "' doesn't have a variable with name: '" + variableName + "'.", VariableInstanceEntity.class);
} else {
return constructRestVariable(variableName, value, variableScope, execution.getId(), includeBinary, uriInfo);
}
}
use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.LOCAL in project carbon-business-process by wso2.
the class BaseExecutionService method setSimpleVariable.
protected RestVariable setSimpleVariable(RestVariable restVariable, Execution execution, boolean isNew, UriInfo uriInfo) {
if (restVariable.getName() == null) {
throw new ActivitiIllegalArgumentException("Variable name is required");
}
// Figure out scope, revert to local is omitted
RestVariable.RestVariableScope scope = restVariable.getVariableScope();
if (scope == null) {
scope = RestVariable.RestVariableScope.LOCAL;
}
Object actualVariableValue = new RestResponseFactory().getVariableValue(restVariable);
setVariable(execution, restVariable.getName(), actualVariableValue, scope, isNew);
return constructRestVariable(restVariable.getName(), restVariable.getValue(), scope, execution.getId(), false, uriInfo);
}
Aggregations