use of org.wso2.carbon.bpmn.rest.engine.variable.QueryVariable in project carbon-business-process by wso2.
the class RestResponseFactory method getVariableValue.
public Object getVariableValue(QueryVariable restVariable) {
Object value;
if (restVariable.getType() != null) {
// Try locating a converter if the type has been specified
RestVariableConverter converter = null;
for (RestVariableConverter conv : variableConverters) {
if (conv.getRestTypeName().equals(restVariable.getType())) {
converter = conv;
break;
}
}
if (converter == null) {
throw new ActivitiIllegalArgumentException("Variable '" + restVariable.getName() + "' has unsupported type: '" + restVariable.getType() + "'.");
}
RestVariable temp = new RestVariable();
temp.setValue(restVariable.getValue());
temp.setType(restVariable.getType());
temp.setName(restVariable.getName());
value = converter.getVariableValue(temp);
} else {
// Revert to type determined by REST-to-Java mapping when no explicit type has been provided
value = restVariable.getValue();
}
return value;
}
use of org.wso2.carbon.bpmn.rest.engine.variable.QueryVariable 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.wso2.carbon.bpmn.rest.engine.variable.QueryVariable in project carbon-business-process by wso2.
the class BaseHistoricVariableInstanceService method addVariables.
protected void addVariables(HistoricVariableInstanceQuery variableInstanceQuery, 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:
variableInstanceQuery.variableValueEquals(variable.getName(), actualValue);
break;
default:
throw new ActivitiIllegalArgumentException("Unsupported variable query operation: " + variable.getVariableOperation());
}
}
}
use of org.wso2.carbon.bpmn.rest.engine.variable.QueryVariable in project carbon-business-process by wso2.
the class BaseProcessInstanceService method addVariables.
protected void addVariables(ProcessInstanceQuery processInstanceQuery, List<QueryVariable> variables) {
RestResponseFactory restResponseFactory = new RestResponseFactory();
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 = restResponseFactory.getVariableValue(variable);
// A value-only query is only possible using equals-operator
if (nameLess && variable.getVariableOperation() != QueryVariable.QueryVariableOperation.EQUALS) {
throw new ActivitiIllegalArgumentException("Value-only query (without a variable-name) is only supported when using 'equals' operation.");
}
switch(variable.getVariableOperation()) {
case EQUALS:
if (nameLess) {
processInstanceQuery.variableValueEquals(actualValue);
} else {
processInstanceQuery.variableValueEquals(variable.getName(), actualValue);
}
break;
case EQUALS_IGNORE_CASE:
if (actualValue instanceof String) {
processInstanceQuery.variableValueEqualsIgnoreCase(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:
processInstanceQuery.variableValueNotEquals(variable.getName(), actualValue);
break;
case NOT_EQUALS_IGNORE_CASE:
if (actualValue instanceof String) {
processInstanceQuery.variableValueNotEqualsIgnoreCase(variable.getName(), (String) actualValue);
} else {
throw new ActivitiIllegalArgumentException("Only string variable values are supported when ignoring casing, but was: " + actualValue.getClass().getName());
}
break;
case LIKE:
if (actualValue instanceof String) {
processInstanceQuery.variableValueLike(variable.getName(), (String) actualValue);
} else {
throw new ActivitiIllegalArgumentException("Only string variable values are supported for like, but was: " + actualValue.getClass().getName());
}
break;
case GREATER_THAN:
processInstanceQuery.variableValueGreaterThan(variable.getName(), actualValue);
break;
case GREATER_THAN_OR_EQUALS:
processInstanceQuery.variableValueGreaterThanOrEqual(variable.getName(), actualValue);
break;
case LESS_THAN:
processInstanceQuery.variableValueLessThan(variable.getName(), actualValue);
break;
case LESS_THAN_OR_EQUALS:
processInstanceQuery.variableValueLessThanOrEqual(variable.getName(), actualValue);
break;
default:
throw new ActivitiIllegalArgumentException("Unsupported variable query operation: " + variable.getVariableOperation());
}
}
}
use of org.wso2.carbon.bpmn.rest.engine.variable.QueryVariable 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());
}
}
}
Aggregations