use of org.wso2.carbon.bpmn.rest.model.correlation.CorrelationActionRequest 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.model.correlation.CorrelationActionRequest in project carbon-business-process by wso2.
the class BaseExecutionService method getVariablesToSet.
protected Map<String, Object> getVariablesToSet(CorrelationActionRequest correlationActionRequest) {
Map<String, Object> variablesToSet = new HashMap<String, Object>();
for (RestVariable var : correlationActionRequest.getVariables()) {
if (var.getName() == null) {
throw new ActivitiIllegalArgumentException("Variable name is required");
}
Object actualVariableValue = new RestResponseFactory().getVariableValue(var);
variablesToSet.put(var.getName(), actualVariableValue);
}
return variablesToSet;
}
use of org.wso2.carbon.bpmn.rest.model.correlation.CorrelationActionRequest in project carbon-business-process by wso2.
the class CorrelationService method recieveMessage.
@POST
@Path("/")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response recieveMessage(CorrelationActionRequest correlationActionRequest) {
if (correlationActionRequest.getProcessDefinitionId() == null && correlationActionRequest.getProcessDefinitionKey() == null && (correlationActionRequest.getMessageName() == null && correlationActionRequest.getSignalName() == null)) {
throw new ActivitiIllegalArgumentException("Either processDefinitionId, processDefinitionKey, signal or " + "message is required.");
}
int paramsSet = ((correlationActionRequest.getProcessDefinitionId() != null) ? 1 : 0) + ((correlationActionRequest.getProcessDefinitionKey() != null) ? 1 : 0);
if (paramsSet > 1) {
throw new ActivitiIllegalArgumentException("Only one of processDefinitionId or processDefinitionKey should be set.");
}
paramsSet = ((correlationActionRequest.getMessageName() != null) ? 1 : 0) + ((correlationActionRequest.getSignalName() != null) ? 1 : 0);
if (paramsSet > 1) {
throw new ActivitiIllegalArgumentException("Only one of message name or signal should be " + "set.");
}
CorrelationProcess correlationProcess = new CorrelationProcess();
return correlationProcess.getQueryResponse(correlationActionRequest, uriInfo);
}
use of org.wso2.carbon.bpmn.rest.model.correlation.CorrelationActionRequest in project carbon-business-process by wso2.
the class CorrelationProcess method getVariablesToSet.
protected Map<String, Object> getVariablesToSet(CorrelationActionRequest correlationActionRequest) {
Map<String, Object> variablesToSet = new HashMap<String, Object>();
for (RestVariable var : correlationActionRequest.getVariables()) {
if (var.getName() == null) {
throw new ActivitiIllegalArgumentException("Variable name is required");
}
Object actualVariableValue = new RestResponseFactory().getVariableValue(var);
variablesToSet.put(var.getName(), actualVariableValue);
}
return variablesToSet;
}
use of org.wso2.carbon.bpmn.rest.model.correlation.CorrelationActionRequest in project carbon-business-process by wso2.
the class ProcessInstanceService method performCorrelation.
private Response performCorrelation(ProcessInstanceCreateRequest processInstanceCreateRequest) {
CorrelationActionRequest correlationActionRequest = new CorrelationActionRequest();
String requestValue = processInstanceCreateRequest.getProcessDefinitionId();
if (requestValue != null) {
correlationActionRequest.setProcessDefinitionId(processInstanceCreateRequest.getProcessDefinitionId());
}
requestValue = processInstanceCreateRequest.getProcessDefinitionKey();
if (requestValue != null) {
correlationActionRequest.setProcessDefinitionKey(requestValue);
}
if (processInstanceCreateRequest.isCustomTenantSet()) {
correlationActionRequest.setTenantId(processInstanceCreateRequest.getTenantId());
}
requestValue = processInstanceCreateRequest.getMessageName();
if (requestValue != null) {
correlationActionRequest.setMessageName(requestValue);
}
List<RestVariable> variables = processInstanceCreateRequest.getVariables();
if (variables != null) {
RestResponseFactory restResponseFactory = new RestResponseFactory();
List<QueryVariable> correlationVariableList = new ArrayList<>();
for (RestVariable variable : variables) {
QueryVariable correlationVariable = new QueryVariable();
correlationVariable.setName(variable.getName());
correlationVariable.setOperation("equals");
correlationVariable.setType(variable.getType());
correlationVariable.setValue(restResponseFactory.getVariableValue(variable));
correlationVariableList.add(correlationVariable);
}
correlationActionRequest.setCorrelationVariables(correlationVariableList);
}
variables = processInstanceCreateRequest.getAdditionalVariables();
if (variables != null) {
correlationActionRequest.setVariables(variables);
}
correlationActionRequest.setAction(CorrelationActionRequest.ACTION_MESSAGE_EVENT_RECEIVED);
return new CorrelationProcess().getQueryResponse(correlationActionRequest, uriInfo);
}
Aggregations