Search in sources :

Example 1 with CorrelationProcess

use of org.wso2.carbon.bpmn.rest.common.CorrelationProcess 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);
}
Also used : ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) CorrelationProcess(org.wso2.carbon.bpmn.rest.common.CorrelationProcess) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 2 with CorrelationProcess

use of org.wso2.carbon.bpmn.rest.common.CorrelationProcess 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);
}
Also used : RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) CorrelationProcess(org.wso2.carbon.bpmn.rest.common.CorrelationProcess) CorrelationActionRequest(org.wso2.carbon.bpmn.rest.model.correlation.CorrelationActionRequest) QueryVariable(org.wso2.carbon.bpmn.rest.engine.variable.QueryVariable) ArrayList(java.util.ArrayList)

Aggregations

CorrelationProcess (org.wso2.carbon.bpmn.rest.common.CorrelationProcess)2 ArrayList (java.util.ArrayList)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)1 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)1 QueryVariable (org.wso2.carbon.bpmn.rest.engine.variable.QueryVariable)1 RestVariable (org.wso2.carbon.bpmn.rest.engine.variable.RestVariable)1 CorrelationActionRequest (org.wso2.carbon.bpmn.rest.model.correlation.CorrelationActionRequest)1