use of org.activiti.engine.impl.AbstractQuery in project carbon-business-process by wso2.
the class CorrelationProcess method getQueryResponse.
public Response getQueryResponse(CorrelationActionRequest correlationActionRequest, UriInfo uriInfo) {
RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
ExecutionQuery query = runtimeService.createExecutionQuery();
String value = correlationActionRequest.getProcessDefinitionId();
if (value != null) {
query.processDefinitionId(value);
}
value = correlationActionRequest.getProcessDefinitionKey();
if (value != null) {
query.processDefinitionKey(value);
}
value = correlationActionRequest.getMessageName();
if (value != null) {
query.messageEventSubscriptionName(value);
}
value = correlationActionRequest.getSignalName();
if (value != null) {
query.signalEventSubscriptionName(value);
}
List<QueryVariable> queryVariableList = correlationActionRequest.getCorrelationVariables();
if (queryVariableList != null) {
List<QueryVariable> updatedQueryVariableList = new ArrayList<>();
for (QueryVariable queryVariable : queryVariableList) {
if (queryVariable.getVariableOperation() == null) {
queryVariable.setOperation("equals");
}
updatedQueryVariableList.add(queryVariable);
}
addVariables(query, updatedQueryVariableList, true);
}
value = correlationActionRequest.getTenantId();
if (value != null) {
query.executionTenantId(value);
}
QueryProperty qp = allowedSortProperties.get("processInstanceId");
((AbstractQuery) query).orderBy(qp);
query.asc();
List<Execution> executionList = query.listPage(0, 10);
int size = executionList.size();
if (size == 0) {
throw new ActivitiIllegalArgumentException("No Executions found to correlate with given information");
}
if (size > 1) {
throw new ActivitiIllegalArgumentException("More than one Executions found to correlate with given information");
}
Execution execution = executionList.get(0);
String action = correlationActionRequest.getAction();
if (CorrelationActionRequest.ACTION_SIGNAL.equals(action)) {
if (correlationActionRequest.getVariables() != null) {
runtimeService.signal(execution.getId(), getVariablesToSet(correlationActionRequest));
} else {
runtimeService.signal(execution.getId());
}
} else if (CorrelationActionRequest.ACTION_SIGNAL_EVENT_RECEIVED.equals(action)) {
if (correlationActionRequest.getSignalName() == null) {
throw new ActivitiIllegalArgumentException("Signal name is required");
}
if (correlationActionRequest.getVariables() != null) {
runtimeService.signalEventReceived(correlationActionRequest.getSignalName(), execution.getId(), getVariablesToSet(correlationActionRequest));
} else {
runtimeService.signalEventReceived(correlationActionRequest.getSignalName(), execution.getId());
}
} else if (CorrelationActionRequest.ACTION_MESSAGE_EVENT_RECEIVED.equals(action)) {
if (correlationActionRequest.getMessageName() == null) {
throw new ActivitiIllegalArgumentException("Message name is required");
}
if (correlationActionRequest.getVariables() != null) {
runtimeService.messageEventReceived(correlationActionRequest.getMessageName(), execution.getId(), getVariablesToSet(correlationActionRequest));
} else {
runtimeService.messageEventReceived(correlationActionRequest.getMessageName(), execution.getId());
}
} else {
throw new ActivitiIllegalArgumentException("Invalid action: '" + correlationActionRequest.getAction() + "'.");
}
Response.ResponseBuilder responseBuilder = Response.ok();
// Re-fetch the execution, could have changed due to action or even completed
execution = runtimeService.createExecutionQuery().executionId(execution.getId()).singleResult();
if (execution == null) {
// Execution is finished, return empty body to inform user
responseBuilder.status(Response.Status.NO_CONTENT);
return responseBuilder.build();
} else {
return responseBuilder.entity(new RestResponseFactory().createExecutionResponse(execution, uriInfo.getBaseUri().toString())).build();
}
}
use of org.activiti.engine.impl.AbstractQuery in project Activiti by Activiti.
the class AbstractPaginateList method paginateList.
/**
* uses the pagination parameters form the request and makes sure to order the result and set all pagination
* attributes for the response to render
*
* @param req The request containing the pagination parameters
* @param query The query to get the paged list from
* @param listName The name model attribute name to use for the result list
* @param model The model to put the list and the pagination attributes in
* @param defaultSort THe default sort column (the rest attribute) that later will be mapped to an internal engine name
*/
@SuppressWarnings("rawtypes")
public DataResponse paginateList(Map<String, String> requestParams, PaginateRequest paginateRequest, Query query, String defaultSort, Map<String, QueryProperty> properties) {
if (paginateRequest == null) {
paginateRequest = new PaginateRequest();
}
// In case pagination request is incomplete, fill with values found in URL if possible
if (paginateRequest.getStart() == null) {
paginateRequest.setStart(RequestUtil.getInteger(requestParams, "start", 0));
}
if (paginateRequest.getSize() == null) {
paginateRequest.setSize(RequestUtil.getInteger(requestParams, "size", 10));
}
if (paginateRequest.getOrder() == null) {
paginateRequest.setOrder(requestParams.get("order"));
}
if (paginateRequest.getSort() == null) {
paginateRequest.setSort(requestParams.get("sort"));
}
// Use defaults for paging, if not set in the PaginationRequest, nor in the URL
Integer start = paginateRequest.getStart();
if (start == null || start < 0) {
start = 0;
}
Integer size = paginateRequest.getSize();
if (size == null || size < 0) {
size = 10;
}
String sort = paginateRequest.getSort();
if (sort == null) {
sort = defaultSort;
}
String order = paginateRequest.getOrder();
if (order == null) {
order = "asc";
}
// Sort order
if (sort != null && !properties.isEmpty()) {
QueryProperty qp = properties.get(sort);
if (qp == null) {
throw new ActivitiIllegalArgumentException("Value for param 'sort' is not valid, '" + sort + "' is not a valid property");
}
((AbstractQuery) query).orderBy(qp);
if (order.equals("asc")) {
query.asc();
} else if (order.equals("desc")) {
query.desc();
} else {
throw new ActivitiIllegalArgumentException("Value for param 'order' is not valid : '" + order + "', must be 'asc' or 'desc'");
}
}
// Get result and set pagination parameters
List list = processList(query.listPage(start, size));
DataResponse response = new DataResponse();
response.setStart(start);
response.setSize(list.size());
response.setSort(sort);
response.setOrder(order);
response.setTotal(query.count());
response.setData(list);
return response;
}
use of org.activiti.engine.impl.AbstractQuery in project carbon-business-process by wso2.
the class AbstractPaginateList method paginateList.
public DataResponse paginateList(Map<String, String> requestParams, PaginateRequest paginateRequest, Query query, String defaultSort, Map<String, QueryProperty> properties) {
if (paginateRequest == null) {
paginateRequest = new PaginateRequest();
}
// In case pagination request is incomplete, fill with values found in URL if possible
if (paginateRequest.getStart() == null) {
paginateRequest.setStart(RequestUtil.getInteger(requestParams, "start", 0));
}
if (paginateRequest.getSize() == null) {
paginateRequest.setSize(RequestUtil.getInteger(requestParams, "size", 10));
}
if (paginateRequest.getOrder() == null) {
paginateRequest.setOrder(requestParams.get("order"));
}
if (paginateRequest.getSort() == null) {
paginateRequest.setSort(requestParams.get("sort"));
}
// Use defaults for paging, if not set in the PaginationRequest, nor in the URL
Integer start = paginateRequest.getStart();
if (start == null || start < 0) {
start = 0;
}
Integer size = paginateRequest.getSize();
if (size == null || size < 0) {
size = 10;
}
String sort = paginateRequest.getSort();
if (sort == null) {
// id
sort = defaultSort;
}
String order = paginateRequest.getOrder();
if (order == null) {
order = "asc";
}
// Sort order
if (sort != null && !properties.isEmpty()) {
QueryProperty qp = properties.get(sort);
if (qp == null) {
throw new ActivitiIllegalArgumentException("Value for param 'sort' is not valid, '" + sort + "' is not a valid property");
}
((AbstractQuery) query).orderBy(qp);
if (order.equals("asc")) {
query.asc();
} else if (order.equals("desc")) {
query.desc();
} else {
throw new ActivitiIllegalArgumentException("Value for param 'order' is not valid : '" + order + "', must be 'asc' or 'desc'");
}
}
// Get result and set pagination parameters
List list = processList(query.listPage(start, size));
DataResponse response = new DataResponse();
response.setStart(start);
response.setSize(list.size());
response.setSort(sort);
response.setOrder(order);
response.setTotal(query.count());
response.setData(list);
return response;
}
Aggregations