Search in sources :

Example 1 with QueryVariable

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;
}
Also used : RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException)

Example 2 with QueryVariable

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();
    }
}
Also used : RuntimeService(org.activiti.engine.RuntimeService) QueryVariable(org.wso2.carbon.bpmn.rest.engine.variable.QueryVariable) ArrayList(java.util.ArrayList) CorrelationQueryProperty(org.wso2.carbon.bpmn.rest.model.common.CorrelationQueryProperty) QueryProperty(org.activiti.engine.query.QueryProperty) ExecutionQuery(org.activiti.engine.runtime.ExecutionQuery) Response(javax.ws.rs.core.Response) Execution(org.activiti.engine.runtime.Execution) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) AbstractQuery(org.activiti.engine.impl.AbstractQuery)

Example 3 with QueryVariable

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());
        }
    }
}
Also used : RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) QueryVariable(org.wso2.carbon.bpmn.rest.engine.variable.QueryVariable)

Example 4 with QueryVariable

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());
        }
    }
}
Also used : RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) QueryVariable(org.wso2.carbon.bpmn.rest.engine.variable.QueryVariable)

Example 5 with QueryVariable

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());
        }
    }
}
Also used : RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) QueryVariable(org.wso2.carbon.bpmn.rest.engine.variable.QueryVariable)

Aggregations

QueryVariable (org.wso2.carbon.bpmn.rest.engine.variable.QueryVariable)14 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)12 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)10 ArrayList (java.util.ArrayList)3 RestVariable (org.wso2.carbon.bpmn.rest.engine.variable.RestVariable)3 Response (javax.ws.rs.core.Response)1 RuntimeService (org.activiti.engine.RuntimeService)1 AbstractQuery (org.activiti.engine.impl.AbstractQuery)1 QueryProperty (org.activiti.engine.query.QueryProperty)1 Execution (org.activiti.engine.runtime.Execution)1 ExecutionQuery (org.activiti.engine.runtime.ExecutionQuery)1 CorrelationProcess (org.wso2.carbon.bpmn.rest.common.CorrelationProcess)1 CorrelationQueryProperty (org.wso2.carbon.bpmn.rest.model.common.CorrelationQueryProperty)1 CorrelationActionRequest (org.wso2.carbon.bpmn.rest.model.correlation.CorrelationActionRequest)1