use of org.wso2.carbon.bpmn.rest.engine.variable.RestVariable 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.carbon.bpmn.rest.engine.variable.RestVariable 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.carbon.bpmn.rest.engine.variable.RestVariable in project carbon-business-process by wso2.
the class ProcessInstanceService method resolveVariable.
private String resolveVariable(ProcessInstanceCreateRequest processInstanceCreateRequest, String resolvingName) {
int initialIndex = resolvingName.indexOf("{");
int lastIndex = resolvingName.indexOf("}");
String variableName = null;
if (initialIndex != -1 && lastIndex != -1 && initialIndex < lastIndex) {
variableName = resolvingName.substring(initialIndex + 1, lastIndex);
}
List<RestVariable> variableList = processInstanceCreateRequest.getVariables();
if (variableList != null && variableName != null) {
for (RestVariable restVariable : variableList) {
if (restVariable.getName().equals(variableName)) {
return restVariable.getValue().toString();
}
}
}
variableList = processInstanceCreateRequest.getAdditionalVariables();
if (variableList != null && variableName != null) {
for (RestVariable restVariable : variableList) {
if (restVariable.getName().equals(variableName)) {
return restVariable.getValue().toString();
}
}
}
return "";
}
use of org.wso2.carbon.bpmn.rest.engine.variable.RestVariable 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.carbon.bpmn.rest.engine.variable.RestVariable 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();
}
Aggregations