use of org.wso2.ballerinalang.compiler.semantics.model.Scope in project carbon-business-process by wso2.
the class ProcessInstanceService method setSimpleVariable.
protected RestVariable setSimpleVariable(RestVariable restVariable, Execution execution, boolean isNew) {
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(), actualVariableValue, scope, execution.getId(), false);
}
use of org.wso2.ballerinalang.compiler.semantics.model.Scope in project carbon-business-process by wso2.
the class ProcessInstanceService method getVariableFromRequest.
public RestVariable getVariableFromRequest(Execution execution, String variableName, String scope, boolean includeBinary) {
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);
}
}
use of org.wso2.ballerinalang.compiler.semantics.model.Scope in project carbon-business-process by wso2.
the class ProcessInstanceService method getVariableDataByteArray.
protected byte[] getVariableDataByteArray(Execution execution, String variableName, String scope, Response.ResponseBuilder responseBuilder) {
try {
byte[] result;
RestVariable variable = getVariableFromRequest(execution, variableName, scope, true);
if (RestResponseFactory.BYTE_ARRAY_VARIABLE_TYPE.equals(variable.getType())) {
result = (byte[]) variable.getValue();
responseBuilder.type(MediaType.APPLICATION_OCTET_STREAM);
} else if (RestResponseFactory.SERIALIZABLE_VARIABLE_TYPE.equals(variable.getType())) {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream outputStream = new ObjectOutputStream(buffer);
outputStream.writeObject(variable.getValue());
outputStream.close();
result = buffer.toByteArray();
responseBuilder.type("application/x-java-serialized-object");
} else {
throw new ActivitiObjectNotFoundException("The variable does not have a binary data stream.", null);
}
return result;
} catch (IOException ioe) {
throw new ActivitiException("Error getting variable " + variableName, ioe);
}
}
use of org.wso2.ballerinalang.compiler.semantics.model.Scope in project carbon-business-process by wso2.
the class ProcessInstanceService method getVariable.
@GET
@Path("/{processInstanceId}/variables/{variableName}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getVariable(@PathParam("processInstanceId") String processInstanceId, @PathParam("variableName") String variableName) {
String scope = uriInfo.getQueryParameters().getFirst("scope");
Execution execution = getExecutionInstanceFromRequest(processInstanceId);
RestVariable restVariable = getVariableFromRequest(execution, variableName, scope, false);
return Response.ok().entity(restVariable).build();
}
use of org.wso2.ballerinalang.compiler.semantics.model.Scope in project carbon-business-process by wso2.
the class ExecutionService method deleteVariable.
@DELETE
@Path("/{executionId}/variables/{variableName}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response deleteVariable(@PathParam("executionId") String executionId, @PathParam("variableName") String variableName) {
String scope = uriInfo.getQueryParameters().getFirst("scope");
Execution execution = getExecutionFromRequest(executionId);
// Determine scope
RestVariable.RestVariableScope variableScope = RestVariable.RestVariableScope.LOCAL;
if (scope != null) {
variableScope = RestVariable.getScopeFromString(scope);
}
if (!hasVariableOnScope(execution, variableName, variableScope)) {
throw new ActivitiObjectNotFoundException("Execution '" + execution.getId() + "' doesn't have a variable '" + variableName + "' in scope " + variableScope.name().toLowerCase(), VariableInstanceEntity.class);
}
RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
if (variableScope == RestVariable.RestVariableScope.LOCAL) {
runtimeService.removeVariableLocal(execution.getId(), variableName);
} else {
// Safe to use parentId, as the hasVariableOnScope would have stopped a global-var update on a root-execution
runtimeService.removeVariable(execution.getParentId(), variableName);
}
return Response.ok().status(Response.Status.NO_CONTENT).build();
}
Aggregations