Search in sources :

Example 61 with RestResponseFactory

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

the class BaseTaskService method getTasksFromQueryRequest.

protected DataResponse getTasksFromQueryRequest(TaskQueryRequest request, UriInfo uriInfo, Map<String, String> requestParams) {
    if (requestParams == null) {
        requestParams = new HashMap<>();
        for (String property : allPropertiesList) {
            String value = uriInfo.getQueryParameters().getFirst(property);
            if (value != null) {
                requestParams.put(property, value);
            }
        }
    }
    TaskService taskService = BPMNOSGIService.getTaskService();
    TaskQuery taskQuery = taskService.createTaskQuery();
    if (request.getName() != null) {
        taskQuery.taskName(request.getName());
    }
    if (request.getNameLike() != null) {
        taskQuery.taskNameLike(request.getNameLike());
    }
    if (request.getDescription() != null) {
        taskQuery.taskDescription(request.getDescription());
    }
    if (request.getDescriptionLike() != null) {
        taskQuery.taskDescriptionLike(request.getDescriptionLike());
    }
    if (request.getPriority() != null) {
        taskQuery.taskPriority(request.getPriority());
    }
    if (request.getMinimumPriority() != null) {
        taskQuery.taskMinPriority(request.getMinimumPriority());
    }
    if (request.getMaximumPriority() != null) {
        taskQuery.taskMaxPriority(request.getMaximumPriority());
    }
    if (request.getAssignee() != null) {
        taskQuery.taskAssignee(request.getAssignee());
    }
    if (request.getAssigneeLike() != null) {
        taskQuery.taskAssigneeLike(request.getAssigneeLike());
    }
    if (request.getOwner() != null) {
        taskQuery.taskOwner(request.getOwner());
    }
    if (request.getOwnerLike() != null) {
        taskQuery.taskOwnerLike(request.getOwnerLike());
    }
    if (request.getUnassigned() != null) {
        taskQuery.taskUnassigned();
    }
    if (request.getDelegationState() != null) {
        DelegationState state = getDelegationState(request.getDelegationState());
        if (state != null) {
            taskQuery.taskDelegationState(state);
        }
    }
    if (request.getCandidateUser() != null) {
        taskQuery.taskCandidateUser(request.getCandidateUser());
    }
    if (request.getInvolvedUser() != null) {
        taskQuery.taskInvolvedUser(request.getInvolvedUser());
    }
    if (request.getCandidateGroup() != null) {
        taskQuery.taskCandidateGroup(request.getCandidateGroup());
    }
    if (request.getCandidateGroupIn() != null) {
        taskQuery.taskCandidateGroupIn(request.getCandidateGroupIn());
    }
    if (request.getProcessInstanceId() != null) {
        taskQuery.processInstanceId(request.getProcessInstanceId());
    }
    if (request.getProcessInstanceBusinessKey() != null) {
        taskQuery.processInstanceBusinessKey(request.getProcessInstanceBusinessKey());
    }
    if (request.getExecutionId() != null) {
        taskQuery.executionId(request.getExecutionId());
    }
    if (request.getCreatedOn() != null) {
        taskQuery.taskCreatedOn(request.getCreatedOn());
    }
    if (request.getCreatedBefore() != null) {
        taskQuery.taskCreatedBefore(request.getCreatedBefore());
    }
    if (request.getCreatedAfter() != null) {
        taskQuery.taskCreatedAfter(request.getCreatedAfter());
    }
    if (request.getExcludeSubTasks() != null) {
        if (request.getExcludeSubTasks()) {
            taskQuery.excludeSubtasks();
        }
    }
    if (request.getTaskDefinitionKey() != null) {
        taskQuery.taskDefinitionKey(request.getTaskDefinitionKey());
    }
    if (request.getTaskDefinitionKeyLike() != null) {
        taskQuery.taskDefinitionKeyLike(request.getTaskDefinitionKeyLike());
    }
    if (request.getDueDate() != null) {
        taskQuery.taskDueDate(request.getDueDate());
    }
    if (request.getDueBefore() != null) {
        taskQuery.taskDueBefore(request.getDueBefore());
    }
    if (request.getDueAfter() != null) {
        taskQuery.taskDueAfter(request.getDueAfter());
    }
    if (request.getWithoutDueDate() != null && request.getWithoutDueDate()) {
        taskQuery.withoutTaskDueDate();
    }
    if (request.getActive() != null) {
        if (request.getActive().booleanValue()) {
            taskQuery.active();
        } else {
            taskQuery.suspended();
        }
    }
    if (request.getIncludeTaskLocalVariables() != null) {
        if (request.getIncludeTaskLocalVariables()) {
            taskQuery.includeTaskLocalVariables();
        }
    }
    if (request.getIncludeProcessVariables() != null) {
        if (request.getIncludeProcessVariables()) {
            taskQuery.includeProcessVariables();
        }
    }
    if (request.getProcessInstanceBusinessKeyLike() != null) {
        taskQuery.processInstanceBusinessKeyLike(request.getProcessInstanceBusinessKeyLike());
    }
    if (request.getProcessDefinitionKey() != null) {
        taskQuery.processDefinitionKey(request.getProcessDefinitionKey());
    }
    if (request.getProcessDefinitionKeyLike() != null) {
        taskQuery.processDefinitionKeyLike(request.getProcessDefinitionKeyLike());
    }
    if (request.getProcessDefinitionName() != null) {
        taskQuery.processDefinitionName(request.getProcessDefinitionName());
    }
    if (request.getProcessDefinitionNameLike() != null) {
        taskQuery.processDefinitionNameLike(request.getProcessDefinitionNameLike());
    }
    if (request.getTaskVariables() != null) {
        addTaskvariables(taskQuery, request.getTaskVariables());
    }
    if (request.getProcessInstanceVariables() != null) {
        addProcessvariables(taskQuery, request.getProcessInstanceVariables());
    }
    if (request.getTenantId() != null) {
        taskQuery.taskTenantId(request.getTenantId());
    }
    if (request.getTenantIdLike() != null) {
        taskQuery.taskTenantIdLike(request.getTenantIdLike());
    }
    if (Boolean.TRUE.equals(request.getWithoutTenantId())) {
        taskQuery.taskWithoutTenantId();
    }
    if (request.getCandidateOrAssigned() != null) {
        taskQuery.taskCandidateOrAssigned(request.getCandidateOrAssigned());
    }
    DataResponse dataResponse = new TaskPaginateList(new RestResponseFactory(), uriInfo).paginateList(requestParams, request, taskQuery, "id", properties);
    return dataResponse;
// return Response.ok().entity(dataResponse).build();
}
Also used : DelegationState(org.activiti.engine.task.DelegationState) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) DataResponse(org.wso2.carbon.bpmn.rest.model.common.DataResponse) TaskQuery(org.activiti.engine.task.TaskQuery) TaskPaginateList(org.wso2.carbon.bpmn.rest.model.runtime.TaskPaginateList)

Example 62 with RestResponseFactory

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

the class BaseHistoricVariableInstanceService method getQueryResponse.

protected DataResponse getQueryResponse(HistoricVariableInstanceQueryRequest queryRequest, Map<String, String> allRequestParams) {
    HistoryService historyService = BPMNOSGIService.getHistoryService();
    HistoricVariableInstanceQuery query = historyService.createHistoricVariableInstanceQuery();
    // Populate query based on request
    if (queryRequest.getExcludeTaskVariables() != null) {
        if (queryRequest.getExcludeTaskVariables()) {
            query.excludeTaskVariables();
        }
    }
    if (queryRequest.getTaskId() != null) {
        query.taskId(queryRequest.getTaskId());
    }
    if (queryRequest.getExecutionId() != null) {
        query.executionId(queryRequest.getExecutionId());
    }
    if (queryRequest.getProcessInstanceId() != null) {
        query.processInstanceId(queryRequest.getProcessInstanceId());
    }
    if (queryRequest.getVariableName() != null) {
        query.variableName(queryRequest.getVariableName());
    }
    if (queryRequest.getVariableNameLike() != null) {
        query.variableNameLike(queryRequest.getVariableNameLike());
    }
    if (queryRequest.getVariables() != null) {
        addVariables(query, queryRequest.getVariables());
    }
    return new HistoricVariableInstancePaginateList(new RestResponseFactory(), uriInfo).paginateList(allRequestParams, query, "variableName", allowedSortProperties);
}
Also used : RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) HistoricVariableInstanceQuery(org.activiti.engine.history.HistoricVariableInstanceQuery) HistoryService(org.activiti.engine.HistoryService) HistoricVariableInstancePaginateList(org.wso2.carbon.bpmn.rest.model.history.HistoricVariableInstancePaginateList)

Example 63 with RestResponseFactory

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

the class BaseProcessInstanceService method suspendProcessInstance.

protected ProcessInstanceResponse suspendProcessInstance(ProcessInstance processInstance, RestResponseFactory restResponseFactory, UriInfo uriInfo) {
    if (processInstance.isSuspended()) {
        throw new BPMNConflictException("Process instance with id '" + processInstance.getId() + "' is already suspended.");
    }
    RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
    runtimeService.suspendProcessInstanceById(processInstance.getId());
    ProcessInstanceResponse response = restResponseFactory.createProcessInstanceResponse(processInstance, uriInfo.getBaseUri().toString());
    // No need to re-fetch the instance, just alter the suspended state of the result-object
    response.setSuspended(true);
    return response;
}
Also used : BPMNConflictException(org.wso2.carbon.bpmn.rest.common.exception.BPMNConflictException) RuntimeService(org.activiti.engine.RuntimeService) ProcessInstanceResponse(org.wso2.carbon.bpmn.rest.model.runtime.ProcessInstanceResponse)

Example 64 with RestResponseFactory

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

the class BaseHistoricTaskInstanceService method addProcessVariables.

protected void addProcessVariables(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:
                taskInstanceQuery.processVariableValueEquals(variable.getName(), actualValue);
                break;
            case EQUALS_IGNORE_CASE:
                if (actualValue instanceof String) {
                    taskInstanceQuery.processVariableValueEqualsIgnoreCase(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.processVariableValueNotEquals(variable.getName(), actualValue);
                break;
            case NOT_EQUALS_IGNORE_CASE:
                if (actualValue instanceof String) {
                    taskInstanceQuery.processVariableValueNotEqualsIgnoreCase(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.processVariableValueGreaterThan(variable.getName(), actualValue);
                break;
            case GREATER_THAN_OR_EQUALS:
                taskInstanceQuery.processVariableValueGreaterThanOrEqual(variable.getName(), actualValue);
                break;
            case LESS_THAN:
                taskInstanceQuery.processVariableValueLessThan(variable.getName(), actualValue);
                break;
            case LESS_THAN_OR_EQUALS:
                taskInstanceQuery.processVariableValueLessThanOrEqual(variable.getName(), actualValue);
                break;
            case LIKE:
                if (actualValue instanceof String) {
                    taskInstanceQuery.processVariableValueLike(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)

Example 65 with RestResponseFactory

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

the class BaseHistoricTaskInstanceService method getQueryResponse.

protected DataResponse getQueryResponse(HistoricTaskInstanceQueryRequest queryRequest, Map<String, String> allRequestParams, String serverRootUrl) {
    HistoryService historyService = BPMNOSGIService.getHistoryService();
    HistoricTaskInstanceQuery query = historyService.createHistoricTaskInstanceQuery();
    // Populate query based on request
    if (queryRequest.getTaskId() != null) {
        query.taskId(queryRequest.getTaskId());
    }
    if (queryRequest.getProcessInstanceId() != null) {
        query.processInstanceId(queryRequest.getProcessInstanceId());
    }
    if (queryRequest.getProcessBusinessKey() != null) {
        query.processInstanceBusinessKey(queryRequest.getProcessBusinessKey());
    }
    if (queryRequest.getProcessBusinessKeyLike() != null) {
        query.processInstanceBusinessKeyLike(queryRequest.getProcessBusinessKeyLike());
    }
    if (queryRequest.getProcessDefinitionKey() != null) {
        query.processDefinitionKey(queryRequest.getProcessDefinitionKey());
    }
    if (queryRequest.getProcessDefinitionKeyLike() != null) {
        query.processDefinitionKeyLike(queryRequest.getProcessDefinitionKeyLike());
    }
    if (queryRequest.getProcessDefinitionId() != null) {
        query.processDefinitionId(queryRequest.getProcessDefinitionId());
    }
    if (queryRequest.getProcessDefinitionName() != null) {
        query.processDefinitionName(queryRequest.getProcessDefinitionName());
    }
    if (queryRequest.getProcessDefinitionNameLike() != null) {
        query.processDefinitionNameLike(queryRequest.getProcessDefinitionNameLike());
    }
    if (queryRequest.getExecutionId() != null) {
        query.executionId(queryRequest.getExecutionId());
    }
    if (queryRequest.getTaskName() != null) {
        query.taskName(queryRequest.getTaskName());
    }
    if (queryRequest.getTaskNameLike() != null) {
        query.taskNameLike(queryRequest.getTaskNameLike());
    }
    if (queryRequest.getTaskDescription() != null) {
        query.taskDescription(queryRequest.getTaskDescription());
    }
    if (queryRequest.getTaskDescriptionLike() != null) {
        query.taskDescriptionLike(queryRequest.getTaskDescriptionLike());
    }
    if (queryRequest.getTaskDefinitionKey() != null) {
        query.taskDefinitionKey(queryRequest.getTaskDefinitionKey());
    }
    if (queryRequest.getTaskDefinitionKeyLike() != null) {
        query.taskDefinitionKeyLike(queryRequest.getTaskDefinitionKeyLike());
    }
    if (queryRequest.getTaskDeleteReason() != null) {
        query.taskDeleteReason(queryRequest.getTaskDeleteReason());
    }
    if (queryRequest.getTaskDeleteReasonLike() != null) {
        query.taskDeleteReasonLike(queryRequest.getTaskDeleteReasonLike());
    }
    if (queryRequest.getTaskAssignee() != null) {
        query.taskAssignee(queryRequest.getTaskAssignee());
    }
    if (queryRequest.getTaskAssigneeLike() != null) {
        query.taskAssigneeLike(queryRequest.getTaskAssigneeLike());
    }
    if (queryRequest.getTaskOwner() != null) {
        query.taskOwner(queryRequest.getTaskOwner());
    }
    if (queryRequest.getTaskOwnerLike() != null) {
        query.taskOwnerLike(queryRequest.getTaskOwnerLike());
    }
    if (queryRequest.getTaskInvolvedUser() != null) {
        query.taskInvolvedUser(queryRequest.getTaskInvolvedUser());
    }
    if (queryRequest.getTaskPriority() != null) {
        query.taskPriority(queryRequest.getTaskPriority());
    }
    if (queryRequest.getTaskMinPriority() != null) {
        query.taskMinPriority(queryRequest.getTaskMinPriority());
    }
    if (queryRequest.getTaskMaxPriority() != null) {
        query.taskMaxPriority(queryRequest.getTaskMaxPriority());
    }
    if (queryRequest.getTaskPriority() != null) {
        query.taskPriority(queryRequest.getTaskPriority());
    }
    if (queryRequest.getFinished() != null) {
        if (queryRequest.getFinished()) {
            query.finished();
        } else {
            query.unfinished();
        }
    }
    if (queryRequest.getProcessFinished() != null) {
        if (queryRequest.getProcessFinished()) {
            query.processFinished();
        } else {
            query.processUnfinished();
        }
    }
    if (queryRequest.getParentTaskId() != null) {
        query.taskParentTaskId(queryRequest.getParentTaskId());
    }
    if (queryRequest.getDueDate() != null) {
        query.taskDueDate(queryRequest.getDueDate());
    }
    if (queryRequest.getDueDateAfter() != null) {
        query.taskDueAfter(queryRequest.getDueDateAfter());
    }
    if (queryRequest.getDueDateBefore() != null) {
        query.taskDueBefore(queryRequest.getDueDateBefore());
    }
    if (queryRequest.getWithoutDueDate() != null && queryRequest.getWithoutDueDate()) {
        query.withoutTaskDueDate();
    }
    if (queryRequest.getTaskCreatedOn() != null) {
        query.taskCreatedOn(queryRequest.getTaskCreatedOn());
    }
    if (queryRequest.getTaskCreatedBefore() != null) {
        query.taskCreatedBefore(queryRequest.getTaskCreatedBefore());
    }
    if (queryRequest.getTaskCreatedAfter() != null) {
        query.taskCreatedAfter(queryRequest.getTaskCreatedAfter());
    }
    if (queryRequest.getTaskCreatedOn() != null) {
        query.taskCreatedOn(queryRequest.getTaskCreatedOn());
    }
    if (queryRequest.getTaskCreatedBefore() != null) {
        query.taskCreatedBefore(queryRequest.getTaskCreatedBefore());
    }
    if (queryRequest.getTaskCreatedAfter() != null) {
        query.taskCreatedAfter(queryRequest.getTaskCreatedAfter());
    }
    if (queryRequest.getTaskCompletedOn() != null) {
        query.taskCompletedOn(queryRequest.getTaskCompletedOn());
    }
    if (queryRequest.getTaskCompletedBefore() != null) {
        query.taskCompletedBefore(queryRequest.getTaskCompletedBefore());
    }
    if (queryRequest.getTaskCompletedAfter() != null) {
        query.taskCompletedAfter(queryRequest.getTaskCompletedAfter());
    }
    if (queryRequest.getIncludeTaskLocalVariables() != null) {
        if (queryRequest.getIncludeTaskLocalVariables()) {
            query.includeTaskLocalVariables();
        }
    }
    if (queryRequest.getIncludeProcessVariables() != null) {
        if (queryRequest.getIncludeProcessVariables()) {
            query.includeProcessVariables();
        }
    }
    if (queryRequest.getTaskVariables() != null) {
        addTaskVariables(query, queryRequest.getTaskVariables());
    }
    if (queryRequest.getProcessVariables() != null) {
        addProcessVariables(query, queryRequest.getProcessVariables());
    }
    if (queryRequest.getTenantId() != null) {
        query.taskTenantId(queryRequest.getTenantId());
    }
    if (queryRequest.getTenantIdLike() != null) {
        query.taskTenantIdLike(queryRequest.getTenantIdLike());
    }
    if (Boolean.TRUE.equals(queryRequest.getWithoutTenantId())) {
        query.taskWithoutTenantId();
    }
    if (queryRequest.getTaskCandidateGroup() != null) {
        query.taskCandidateGroup(queryRequest.getTaskCandidateGroup());
    }
    RestResponseFactory restResponseFactory = new RestResponseFactory();
    return new HistoricTaskInstancePaginateList(restResponseFactory, uriInfo, serverRootUrl).paginateList(allRequestParams, queryRequest, query, "taskInstanceId", allowedSortProperties);
}
Also used : RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) HistoricTaskInstancePaginateList(org.wso2.carbon.bpmn.rest.model.history.HistoricTaskInstancePaginateList) HistoryService(org.activiti.engine.HistoryService) HistoricTaskInstanceQuery(org.activiti.engine.history.HistoricTaskInstanceQuery)

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