use of org.activiti.engine.RuntimeService in project carbon-business-process by wso2.
the class BaseProcessInstanceService method suspendProcessInstance.
protected ProcessInstanceResponse suspendProcessInstance(ProcessInstance processInstance, RestResponseFactory restResponseFactory, UriInfo uriInfo) {
if (processInstance.isSuspended()) {
throw new BPMNConflictException("Process instance with id '" + processInstance.getId() + "' is already suspended.");
}
RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
runtimeService.suspendProcessInstanceById(processInstance.getId());
ProcessInstanceResponse response = restResponseFactory.createProcessInstanceResponse(processInstance, uriInfo.getBaseUri().toString());
// No need to re-fetch the instance, just alter the suspended state of the result-object
response.setSuspended(true);
return response;
}
use of org.activiti.engine.RuntimeService in project carbon-business-process by wso2.
the class BaseProcessInstanceService method getProcessInstanceFromRequest.
protected ProcessInstance getProcessInstanceFromRequest(String processInstanceId) {
RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).includeProcessVariables().singleResult();
if (processInstance == null) {
throw new ActivitiObjectNotFoundException(" Could not find a process instance with id " + processInstanceId + "'.", ProcessInstance.class);
}
return processInstance;
}
use of org.activiti.engine.RuntimeService in project carbon-business-process by wso2.
the class BaseExecutionService method deleteAllLocalVariables.
public void deleteAllLocalVariables(Execution execution) {
RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
Collection<String> currentVariables = runtimeService.getVariablesLocal(execution.getId()).keySet();
runtimeService.removeVariablesLocal(execution.getId(), currentVariables);
}
use of org.activiti.engine.RuntimeService 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.activiti.engine.RuntimeService in project carbon-business-process by wso2.
the class BaseExecutionService method setVariable.
/* protected RestVariable setBinaryVariable(@Context HttpServletRequest httpServletRequest,
Execution execution, int responseVariableType, boolean isNew, UriInfo uriInfo) {
byte[] byteArray = null;
try {
byteArray = Utils.processMultiPartFile(httpServletRequest, "file content");
} catch (IOException e) {
throw new ActivitiIllegalArgumentException("No file content was found in request body during multipart " +
"processing" +
".");
}
if (byteArray == null) {
throw new ActivitiIllegalArgumentException("No file content was found in request body.");
}
String variableScope = uriInfo.getQueryParameters().getFirst("scope");
String variableName = uriInfo.getQueryParameters().getFirst("name");
String variableType = uriInfo.getQueryParameters().getFirst("type");
if (log.isDebugEnabled()) {
log.debug("variableScope:" + variableScope + " variableName:" + variableName + " variableType:" + variableType);
}
try {
// Validate input and set defaults
if (variableName == null) {
throw new ActivitiIllegalArgumentException("No variable name was found in request body.");
}
if (variableType != null) {
if (!RestResponseFactory.BYTE_ARRAY_VARIABLE_TYPE.equals(variableType) && !RestResponseFactory.SERIALIZABLE_VARIABLE_TYPE.equals(variableType)) {
throw new ActivitiIllegalArgumentException("Only 'binary' and 'serializable' are supported as variable type.");
}
} else {
variableType = RestResponseFactory.BYTE_ARRAY_VARIABLE_TYPE;
}
RestVariable.RestVariableScope scope = RestVariable.RestVariableScope.LOCAL;
if (variableScope != null) {
scope = RestVariable.getScopeFromString(variableScope);
}
if (variableType.equals(RestResponseFactory.BYTE_ARRAY_VARIABLE_TYPE)) {
// Use raw bytes as variable value
setVariable(execution, variableName, byteArray, scope, isNew);
} else {
// Try deserializing the object
InputStream inputStream = new ByteArrayInputStream(byteArray);
ObjectInputStream stream = new ObjectInputStream(inputStream);
Object value = stream.readObject();
setVariable(execution, variableName, value, scope, isNew);
stream.close();
}
if (responseVariableType == RestResponseFactory.VARIABLE_PROCESS) {
return new RestResponseFactory().createBinaryRestVariable(variableName, scope, variableType,
null, null, execution.getId(), uriInfo.getBaseUri().toString());
} else {
return new RestResponseFactory().createBinaryRestVariable(variableName, scope, variableType, null,
execution.getId(), null, uriInfo.getBaseUri().toString());
}
} catch (IOException ioe) {
throw new ActivitiIllegalArgumentException("Could not process multipart content", ioe);
} catch (ClassNotFoundException ioe) {
throw new BPMNContentNotSupportedException("The provided body contains a serialized object for which the class is nog found: " + ioe
.getMessage());
}
}*/
protected void setVariable(Execution execution, String name, Object value, RestVariable.RestVariableScope scope, boolean isNew) {
// Create can only be done on new variables. Existing variables should be updated using PUT
boolean hasVariable = hasVariableOnScope(execution, name, scope);
if (isNew && hasVariable) {
throw new ActivitiException("Variable '" + name + "' is already present on execution '" + execution.getId() + "'.");
}
if (!isNew && !hasVariable) {
throw new ActivitiObjectNotFoundException("Execution '" + execution.getId() + "' doesn't have a variable with name: '" + name + "'.", null);
}
RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
if (scope == RestVariable.RestVariableScope.LOCAL) {
runtimeService.setVariableLocal(execution.getId(), name, value);
} else {
if (execution.getParentId() != null) {
runtimeService.setVariable(execution.getParentId(), name, value);
} else {
runtimeService.setVariable(execution.getId(), name, value);
}
}
}
Aggregations