Search in sources :

Example 41 with RestResponseFactory

use of org.wso2.carbon.bpmn.rest.common.RestResponseFactory in project carbon-business-process by wso2.

the class BaseExecutionService method addLocalVariables.

protected void addLocalVariables(Execution execution, int variableType, Map<String, RestVariable> variableMap, UriInfo uriInfo) {
    RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
    Map<String, Object> rawLocalvariables = runtimeService.getVariablesLocal(execution.getId());
    List<RestVariable> localVariables = new RestResponseFactory().createRestVariables(rawLocalvariables, execution.getId(), variableType, RestVariable.RestVariableScope.LOCAL, uriInfo.getBaseUri().toString());
    for (RestVariable var : localVariables) {
        variableMap.put(var.getName(), var);
    }
}
Also used : RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) RuntimeService(org.activiti.engine.RuntimeService)

Example 42 with RestResponseFactory

use of org.wso2.carbon.bpmn.rest.common.RestResponseFactory in project carbon-business-process by wso2.

the class BaseHistoricDetailService method getQueryResponse.

protected DataResponse getQueryResponse(HistoricDetailQueryRequest queryRequest, Map<String, String> allRequestParams, UriInfo uriInfo) {
    HistoryService historyService = BPMNOSGIService.getHistoryService();
    HistoricDetailQuery query = historyService.createHistoricDetailQuery();
    // Populate query based on request
    if (queryRequest.getProcessInstanceId() != null) {
        query.processInstanceId(queryRequest.getProcessInstanceId());
    }
    if (queryRequest.getExecutionId() != null) {
        query.executionId(queryRequest.getExecutionId());
    }
    if (queryRequest.getActivityInstanceId() != null) {
        query.activityInstanceId(queryRequest.getActivityInstanceId());
    }
    if (queryRequest.getTaskId() != null) {
        query.taskId(queryRequest.getTaskId());
    }
    if (queryRequest.getSelectOnlyFormProperties() != null) {
        if (queryRequest.getSelectOnlyFormProperties()) {
            query.formProperties();
        }
    }
    if (queryRequest.getSelectOnlyVariableUpdates() != null) {
        if (queryRequest.getSelectOnlyVariableUpdates()) {
            query.variableUpdates();
        }
    }
    return new HistoricDetailPaginateList(new RestResponseFactory(), uriInfo).paginateList(allRequestParams, queryRequest, query, "processInstanceId", allowedSortProperties);
}
Also used : HistoricDetailPaginateList(org.wso2.carbon.bpmn.rest.model.history.HistoricDetailPaginateList) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) HistoryService(org.activiti.engine.HistoryService) HistoricDetailQuery(org.activiti.engine.history.HistoricDetailQuery)

Example 43 with RestResponseFactory

use of org.wso2.carbon.bpmn.rest.common.RestResponseFactory in project carbon-business-process by wso2.

the class BaseRuntimeService method addVariables.

protected void addVariables(ExecutionQuery processInstanceQuery, List<QueryVariable> variables, boolean process) {
    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 && 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) {
                    if (process) {
                        processInstanceQuery.processVariableValueEquals(actualValue);
                    } else {
                        processInstanceQuery.variableValueEquals(actualValue);
                    }
                } else {
                    if (process) {
                        processInstanceQuery.processVariableValueEquals(variable.getName(), actualValue);
                    } else {
                        processInstanceQuery.variableValueEquals(variable.getName(), actualValue);
                    }
                }
                break;
            case EQUALS_IGNORE_CASE:
                if (actualValue instanceof String) {
                    if (process) {
                        processInstanceQuery.processVariableValueEqualsIgnoreCase(variable.getName(), (String) actualValue);
                    } else {
                        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:
                if (process) {
                    processInstanceQuery.processVariableValueNotEquals(variable.getName(), actualValue);
                } else {
                    processInstanceQuery.variableValueNotEquals(variable.getName(), actualValue);
                }
                break;
            case NOT_EQUALS_IGNORE_CASE:
                if (actualValue instanceof String) {
                    if (process) {
                        processInstanceQuery.processVariableValueNotEqualsIgnoreCase(variable.getName(), (String) actualValue);
                    } else {
                        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;
            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 44 with RestResponseFactory

use of org.wso2.carbon.bpmn.rest.common.RestResponseFactory in project carbon-business-process by wso2.

the class BaseRuntimeService method getVariablesToSet.

protected Map<String, Object> getVariablesToSet(ExecutionActionRequest actionRequest) {
    Map<String, Object> variablesToSet = new HashMap<String, Object>();
    for (RestVariable var : actionRequest.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;
}
Also used : RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException)

Example 45 with RestResponseFactory

use of org.wso2.carbon.bpmn.rest.common.RestResponseFactory in project carbon-business-process by wso2.

the class BaseTaskService method addTaskvariables.

protected void addTaskvariables(TaskQuery taskQuery, 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) {
                    taskQuery.taskVariableValueEquals(actualValue);
                } else {
                    taskQuery.taskVariableValueEquals(variable.getName(), actualValue);
                }
                break;
            case EQUALS_IGNORE_CASE:
                if (actualValue instanceof String) {
                    taskQuery.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:
                taskQuery.taskVariableValueNotEquals(variable.getName(), actualValue);
                break;
            case NOT_EQUALS_IGNORE_CASE:
                if (actualValue instanceof String) {
                    taskQuery.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:
                taskQuery.taskVariableValueGreaterThan(variable.getName(), actualValue);
                break;
            case GREATER_THAN_OR_EQUALS:
                taskQuery.taskVariableValueGreaterThanOrEqual(variable.getName(), actualValue);
                break;
            case LESS_THAN:
                taskQuery.taskVariableValueLessThan(variable.getName(), actualValue);
                break;
            case LESS_THAN_OR_EQUALS:
                taskQuery.taskVariableValueLessThanOrEqual(variable.getName(), actualValue);
                break;
            case LIKE:
                if (actualValue instanceof String) {
                    taskQuery.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) QueryVariable(org.wso2.carbon.bpmn.rest.engine.variable.QueryVariable)

Aggregations

RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)90 RestVariable (org.wso2.carbon.bpmn.rest.engine.variable.RestVariable)28 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)26 Path (javax.ws.rs.Path)20 Produces (javax.ws.rs.Produces)20 RuntimeService (org.activiti.engine.RuntimeService)16 BaseTaskService (org.wso2.carbon.bpmn.rest.service.base.BaseTaskService)16 GET (javax.ws.rs.GET)14 QueryVariable (org.wso2.carbon.bpmn.rest.engine.variable.QueryVariable)14 DataResponse (org.wso2.carbon.bpmn.rest.model.common.DataResponse)14 HistoryService (org.activiti.engine.HistoryService)11 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)10 HashMap (java.util.HashMap)8 Response (javax.ws.rs.core.Response)8 RepositoryService (org.activiti.engine.RepositoryService)8 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)7 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)7 RestIdentityLink (org.wso2.carbon.bpmn.rest.model.common.RestIdentityLink)7 ArrayList (java.util.ArrayList)6 JAXBContext (javax.xml.bind.JAXBContext)6