use of org.wso2.carbon.bpmn.rest.common.RestResponseFactory in project carbon-business-process by wso2.
the class BaseProcessInstanceService method activateProcessInstance.
protected ProcessInstanceResponse activateProcessInstance(ProcessInstance processInstance, UriInfo uriInfo) {
if (!processInstance.isSuspended()) {
throw new BPMNConflictException("Process instance with id '" + processInstance.getId() + "' is already active.");
}
RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
runtimeService.activateProcessInstanceById(processInstance.getId());
ProcessInstanceResponse response = new RestResponseFactory().createProcessInstanceResponse(processInstance, uriInfo.getBaseUri().toString());
// No need to re-fetch the instance, just alter the suspended state of the result-object
response.setSuspended(false);
return response;
}
use of org.wso2.carbon.bpmn.rest.common.RestResponseFactory in project carbon-business-process by wso2.
the class BaseHistoricActivitiInstanceService method getQueryResponse.
protected DataResponse getQueryResponse(HistoricActivityInstanceQueryRequest queryRequest, Map<String, String> allRequestParams, UriInfo uriInfo) {
HistoryService historyService = BPMNOSGIService.getHistoryService();
HistoricActivityInstanceQuery query = historyService.createHistoricActivityInstanceQuery();
// Populate query based on request
if (queryRequest.getActivityId() != null) {
query.activityId(queryRequest.getActivityId());
}
if (queryRequest.getActivityInstanceId() != null) {
query.activityInstanceId(queryRequest.getActivityInstanceId());
}
if (queryRequest.getActivityName() != null) {
query.activityName(queryRequest.getActivityName());
}
if (queryRequest.getActivityType() != null) {
query.activityType(queryRequest.getActivityType());
}
if (queryRequest.getExecutionId() != null) {
query.executionId(queryRequest.getExecutionId());
}
if (queryRequest.getFinished() != null) {
Boolean finished = queryRequest.getFinished();
if (finished) {
query.finished();
} else {
query.unfinished();
}
}
if (queryRequest.getTaskAssignee() != null) {
query.taskAssignee(queryRequest.getTaskAssignee());
}
if (queryRequest.getProcessInstanceId() != null) {
query.processInstanceId(queryRequest.getProcessInstanceId());
}
if (queryRequest.getProcessDefinitionId() != null) {
query.processDefinitionId(queryRequest.getProcessDefinitionId());
}
if (queryRequest.getTenantId() != null) {
query.activityTenantId(queryRequest.getTenantId());
}
if (queryRequest.getTenantIdLike() != null) {
query.activityTenantIdLike(queryRequest.getTenantIdLike());
}
if (Boolean.TRUE.equals(queryRequest.getWithoutTenantId())) {
query.activityWithoutTenantId();
}
return new HistoricActivityInstancePaginateList(new RestResponseFactory(), uriInfo).paginateList(allRequestParams, queryRequest, query, "startTime", allowedSortProperties);
}
use of org.wso2.carbon.bpmn.rest.common.RestResponseFactory in project carbon-business-process by wso2.
the class BaseHistoricTaskInstanceService method getQueryResponse.
protected DataResponse getQueryResponse(HistoricActivityInstanceQueryRequest queryRequest, Map<String, String> allRequestParams) {
HistoryService historyService = BPMNOSGIService.getHistoryService();
HistoricActivityInstanceQuery query = historyService.createHistoricActivityInstanceQuery();
// Populate query based on request
if (queryRequest.getActivityId() != null) {
query.activityId(queryRequest.getActivityId());
}
if (queryRequest.getActivityInstanceId() != null) {
query.activityInstanceId(queryRequest.getActivityInstanceId());
}
if (queryRequest.getActivityName() != null) {
query.activityName(queryRequest.getActivityName());
}
if (queryRequest.getActivityType() != null) {
query.activityType(queryRequest.getActivityType());
}
if (queryRequest.getExecutionId() != null) {
query.executionId(queryRequest.getExecutionId());
}
if (queryRequest.getFinished() != null) {
Boolean finished = queryRequest.getFinished();
if (finished) {
query.finished();
} else {
query.unfinished();
}
}
if (queryRequest.getTaskAssignee() != null) {
query.taskAssignee(queryRequest.getTaskAssignee());
}
if (queryRequest.getProcessInstanceId() != null) {
query.processInstanceId(queryRequest.getProcessInstanceId());
}
if (queryRequest.getProcessDefinitionId() != null) {
query.processDefinitionId(queryRequest.getProcessDefinitionId());
}
if (queryRequest.getTenantId() != null) {
query.activityTenantId(queryRequest.getTenantId());
}
if (queryRequest.getTenantIdLike() != null) {
query.activityTenantIdLike(queryRequest.getTenantIdLike());
}
if (Boolean.TRUE.equals(queryRequest.getWithoutTenantId())) {
query.activityWithoutTenantId();
}
RestResponseFactory restResponseFactory = new RestResponseFactory();
return new HistoricActivityInstancePaginateList(restResponseFactory, uriInfo).paginateList(allRequestParams, queryRequest, query, "startTime", allowedSortProperties);
}
use of org.wso2.carbon.bpmn.rest.common.RestResponseFactory in project carbon-business-process by wso2.
the class BaseHistoricTaskInstanceService method addTaskVariables.
protected void addTaskVariables(HistoricTaskInstanceQuery taskInstanceQuery, List<QueryVariable> variables) {
for (QueryVariable variable : variables) {
if (variable.getVariableOperation() == null) {
throw new ActivitiIllegalArgumentException("Variable operation is missing for variable: " + variable.getName());
}
if (variable.getValue() == null) {
throw new ActivitiIllegalArgumentException("Variable value is missing for variable: " + variable.getName());
}
boolean nameLess = variable.getName() == null;
Object actualValue = new RestResponseFactory().getVariableValue(variable);
// A value-only query is only possible using equals-operator
if (nameLess) {
throw new ActivitiIllegalArgumentException("Value-only query (without a variable-name) is not supported.");
}
switch(variable.getVariableOperation()) {
case EQUALS:
if (nameLess) {
taskInstanceQuery.taskVariableValueEquals(actualValue);
} else {
taskInstanceQuery.taskVariableValueEquals(variable.getName(), actualValue);
}
break;
case EQUALS_IGNORE_CASE:
if (actualValue instanceof String) {
taskInstanceQuery.taskVariableValueEqualsIgnoreCase(variable.getName(), (String) actualValue);
} else {
throw new ActivitiIllegalArgumentException("Only string variable values are supported when ignoring casing, but was: " + actualValue.getClass().getName());
}
break;
case NOT_EQUALS:
taskInstanceQuery.taskVariableValueNotEquals(variable.getName(), actualValue);
break;
case NOT_EQUALS_IGNORE_CASE:
if (actualValue instanceof String) {
taskInstanceQuery.taskVariableValueNotEqualsIgnoreCase(variable.getName(), (String) actualValue);
} else {
throw new ActivitiIllegalArgumentException("Only string variable values are supported when ignoring casing, but was: " + actualValue.getClass().getName());
}
break;
case GREATER_THAN:
taskInstanceQuery.taskVariableValueGreaterThan(variable.getName(), actualValue);
break;
case GREATER_THAN_OR_EQUALS:
taskInstanceQuery.taskVariableValueGreaterThanOrEqual(variable.getName(), actualValue);
break;
case LESS_THAN:
taskInstanceQuery.taskVariableValueLessThan(variable.getName(), actualValue);
break;
case LESS_THAN_OR_EQUALS:
taskInstanceQuery.taskVariableValueLessThanOrEqual(variable.getName(), actualValue);
break;
case LIKE:
if (actualValue instanceof String) {
taskInstanceQuery.taskVariableValueLike(variable.getName(), (String) actualValue);
} else {
throw new ActivitiIllegalArgumentException("Only string variable values are supported using like, but was: " + actualValue.getClass().getName());
}
break;
default:
throw new ActivitiIllegalArgumentException("Unsupported variable query operation: " + variable.getVariableOperation());
}
}
}
use of org.wso2.carbon.bpmn.rest.common.RestResponseFactory in project carbon-business-process by wso2.
the class BaseExecutionService method createBinaryExecutionVariable.
protected RestVariable createBinaryExecutionVariable(Execution execution, int responseVariableType, UriInfo uriInfo, boolean isNew, MultipartBody multipartBody) {
boolean debugEnabled = log.isDebugEnabled();
Response.ResponseBuilder responseBuilder = Response.ok();
List<org.apache.cxf.jaxrs.ext.multipart.Attachment> attachments = multipartBody.getAllAttachments();
int attachmentSize = attachments.size();
if (attachmentSize <= 0) {
throw new ActivitiIllegalArgumentException("No Attachments found with the request body");
}
AttachmentDataHolder attachmentDataHolder = new AttachmentDataHolder();
for (int i = 0; i < attachmentSize; i++) {
org.apache.cxf.jaxrs.ext.multipart.Attachment attachment = attachments.get(i);
String contentDispositionHeaderValue = attachment.getHeader("Content-Disposition");
String contentType = attachment.getHeader("Content-Type");
if (debugEnabled) {
log.debug("Going to iterate:" + i);
log.debug("contentDisposition:" + contentDispositionHeaderValue);
}
if (contentDispositionHeaderValue != null) {
contentDispositionHeaderValue = contentDispositionHeaderValue.trim();
Map<String, String> contentDispositionHeaderValueMap = Utils.processContentDispositionHeader(contentDispositionHeaderValue);
String dispositionName = contentDispositionHeaderValueMap.get("name");
DataHandler dataHandler = attachment.getDataHandler();
OutputStream outputStream = null;
if ("name".equals(dispositionName)) {
try {
outputStream = Utils.getAttachmentStream(dataHandler.getInputStream());
} catch (IOException e) {
throw new ActivitiIllegalArgumentException("Attachment Name Reading error occured", e);
}
if (outputStream != null) {
String fileName = outputStream.toString();
attachmentDataHolder.setName(fileName);
}
} else if ("type".equals(dispositionName)) {
try {
outputStream = Utils.getAttachmentStream(dataHandler.getInputStream());
} catch (IOException e) {
throw new ActivitiIllegalArgumentException("Attachment Type Reading error occured", e);
}
if (outputStream != null) {
String typeName = outputStream.toString();
attachmentDataHolder.setType(typeName);
}
} else if ("scope".equals(dispositionName)) {
try {
outputStream = Utils.getAttachmentStream(dataHandler.getInputStream());
} catch (IOException e) {
throw new ActivitiIllegalArgumentException("Attachment Description Reading error occured", e);
}
if (outputStream != null) {
String description = outputStream.toString();
attachmentDataHolder.setScope(description);
}
}
if (contentType != null) {
if ("file".equals(dispositionName)) {
InputStream inputStream = null;
try {
inputStream = dataHandler.getInputStream();
} catch (IOException e) {
throw new ActivitiIllegalArgumentException("Error Occured During processing empty body.", e);
}
if (inputStream != null) {
attachmentDataHolder.setContentType(contentType);
byte[] attachmentArray = new byte[0];
try {
attachmentArray = IOUtils.toByteArray(inputStream);
} catch (IOException e) {
throw new ActivitiIllegalArgumentException("Processing Attachment Body Failed.", e);
}
attachmentDataHolder.setAttachmentArray(attachmentArray);
}
}
}
}
}
attachmentDataHolder.printDebug();
if (attachmentDataHolder.getName() == null) {
throw new ActivitiIllegalArgumentException("Attachment name is required.");
}
if (attachmentDataHolder.getAttachmentArray() == null) {
throw new ActivitiIllegalArgumentException("Empty attachment body was found in request body after " + "decoding the request" + ".");
}
String variableScope = attachmentDataHolder.getScope();
String variableName = attachmentDataHolder.getName();
String variableType = attachmentDataHolder.getType();
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 (RestResponseFactory.BYTE_ARRAY_VARIABLE_TYPE.equals(variableType)) {
// Use raw bytes as variable value
setVariable(execution, variableName, attachmentDataHolder.getAttachmentArray(), scope, isNew);
} else {
// Try deserializing the object
try (InputStream inputStream = new ByteArrayInputStream(attachmentDataHolder.getAttachmentArray());
ObjectInputStream stream = new ObjectInputStream(inputStream)) {
Object value = stream.readObject();
setVariable(execution, variableName, value, scope, isNew);
}
}
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());
}
}
Aggregations