Search in sources :

Example 26 with RestResponseFactory

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

the class IdentityService method getUsers.

/**
 * Get all the users that match the filters given by query parameters of the request.
 * @return DataResponse
 */
@GET
@Path("/users")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public DataResponse getUsers() {
    UserQuery query = identityService.createUserQuery();
    Map<String, String> allRequestParams = new HashMap<>();
    String id = uriInfo.getQueryParameters().getFirst("id");
    if (id != null) {
        query.userId(id);
        allRequestParams.put("id", id);
    }
    String firstName = uriInfo.getQueryParameters().getFirst("firstName");
    if (firstName != null) {
        query.userFirstName(firstName);
        allRequestParams.put("firstName", firstName);
    }
    String lastName = uriInfo.getQueryParameters().getFirst("lastName");
    if (lastName != null) {
        query.userLastName(lastName);
        allRequestParams.put("lastName", lastName);
    }
    String email = uriInfo.getQueryParameters().getFirst("email");
    if (email != null) {
        query.userEmail(email);
        allRequestParams.put("email", email);
    }
    String firstNameLike = uriInfo.getQueryParameters().getFirst("firstNameLike");
    if (firstNameLike != null) {
        query.userFirstNameLike(firstNameLike);
        allRequestParams.put("firstNameLike", firstNameLike);
    }
    String lastNameLike = uriInfo.getQueryParameters().getFirst("lastNameLike");
    if (lastNameLike != null) {
        query.userLastNameLike(lastNameLike);
        allRequestParams.put("lastNameLike", lastNameLike);
    }
    String emailLike = uriInfo.getQueryParameters().getFirst("emailLike");
    if (emailLike != null) {
        query.userEmailLike(emailLike);
        allRequestParams.put("emailLike", emailLike);
    }
    String memberOfGroup = uriInfo.getQueryParameters().getFirst("memberOfGroup");
    if (memberOfGroup != null) {
        query.memberOfGroup(memberOfGroup);
        allRequestParams.put("memberOfGroup", memberOfGroup);
    }
    String potentialStarter = uriInfo.getQueryParameters().getFirst("potentialStarter");
    if (potentialStarter != null) {
        query.potentialStarter(potentialStarter);
        allRequestParams.put("potentialStarter", potentialStarter);
    }
    allRequestParams = Utils.prepareCommonParameters(allRequestParams, uriInfo);
    return new UserPaginateList(new RestResponseFactory(), uriInfo).paginateList(allRequestParams, query, "id", userProperties);
}
Also used : RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) HashMap(java.util.HashMap) UserQuery(org.activiti.engine.identity.UserQuery) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 27 with RestResponseFactory

use of org.wso2.carbon.bpmn.rest.common.RestResponseFactory 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 28 with RestResponseFactory

use of org.wso2.carbon.bpmn.rest.common.RestResponseFactory 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 29 with RestResponseFactory

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

the class BaseProcessInstanceService method getQueryResponse.

protected DataResponse getQueryResponse(ProcessInstanceQueryRequest queryRequest, Map<String, String> requestParams, UriInfo uriInfo) {
    RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
    ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery();
    // Populate query based on request
    if (queryRequest.getProcessInstanceId() != null) {
        query.processInstanceId(queryRequest.getProcessInstanceId());
    }
    if (queryRequest.getProcessDefinitionKey() != null) {
        query.processDefinitionKey(queryRequest.getProcessDefinitionKey());
    }
    if (queryRequest.getProcessDefinitionId() != null) {
        query.processDefinitionId(queryRequest.getProcessDefinitionId());
    }
    if (queryRequest.getProcessBusinessKey() != null) {
        query.processInstanceBusinessKey(queryRequest.getProcessBusinessKey());
    }
    if (queryRequest.getInvolvedUser() != null) {
        query.involvedUser(queryRequest.getInvolvedUser());
    }
    if (queryRequest.getSuspended() != null) {
        if (queryRequest.getSuspended()) {
            query.suspended();
        } else {
            query.active();
        }
    }
    if (queryRequest.getSubProcessInstanceId() != null) {
        query.subProcessInstanceId(queryRequest.getSubProcessInstanceId());
    }
    if (queryRequest.getSuperProcessInstanceId() != null) {
        query.superProcessInstanceId(queryRequest.getSuperProcessInstanceId());
    }
    if (queryRequest.getExcludeSubprocesses() != null) {
        query.excludeSubprocesses(queryRequest.getExcludeSubprocesses());
    }
    if (queryRequest.getIncludeProcessVariables() != null) {
        if (queryRequest.getIncludeProcessVariables()) {
            query.includeProcessVariables();
        }
    }
    if (queryRequest.getVariables() != null) {
        addVariables(query, queryRequest.getVariables());
    }
    if (queryRequest.getTenantId() != null) {
        query.processInstanceTenantId(queryRequest.getTenantId());
    }
    if (queryRequest.getTenantIdLike() != null) {
        query.processInstanceTenantIdLike(queryRequest.getTenantIdLike());
    }
    if (Boolean.TRUE.equals(queryRequest.getWithoutTenantId())) {
        query.processInstanceWithoutTenantId();
    }
    return new ProcessInstancePaginateList(new RestResponseFactory(), uriInfo).paginateList(requestParams, queryRequest, query, "id", allowedSortProperties);
}
Also used : ProcessInstanceQuery(org.activiti.engine.runtime.ProcessInstanceQuery) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) RuntimeService(org.activiti.engine.RuntimeService) ProcessInstancePaginateList(org.wso2.carbon.bpmn.rest.model.runtime.ProcessInstancePaginateList)

Example 30 with RestResponseFactory

use of org.wso2.carbon.bpmn.rest.common.RestResponseFactory 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)

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