Search in sources :

Example 21 with DataResponse

use of org.wso2.carbon.bpmn.rest.model.common.DataResponse 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 22 with DataResponse

use of org.wso2.carbon.bpmn.rest.model.common.DataResponse 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 23 with DataResponse

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

Example 24 with DataResponse

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

the class ProcessInstanceService method startInstance.

@POST
@Path("/")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response startInstance(ProcessInstanceCreateRequest processInstanceCreateRequest) {
    if (log.isDebugEnabled()) {
        log.debug("ProcessInstanceCreateRequest:" + processInstanceCreateRequest.getProcessDefinitionId());
        log.debug(" processInstanceCreateRequest.getVariables().size():" + processInstanceCreateRequest.getVariables().size());
    }
    if (processInstanceCreateRequest.getProcessDefinitionId() == null && processInstanceCreateRequest.getProcessDefinitionKey() == null && processInstanceCreateRequest.getMessage() == null) {
        throw new ActivitiIllegalArgumentException("Either processDefinitionId, processDefinitionKey or message is required.");
    }
    int paramsSet = ((processInstanceCreateRequest.getProcessDefinitionId() != null) ? 1 : 0) + ((processInstanceCreateRequest.getProcessDefinitionKey() != null) ? 1 : 0) + ((processInstanceCreateRequest.getMessage() != null) ? 1 : 0);
    if (paramsSet > 1) {
        throw new ActivitiIllegalArgumentException("Only one of processDefinitionId, processDefinitionKey or message should be set.");
    }
    if (processInstanceCreateRequest.isCustomTenantSet()) {
        // Tenant-id can only be used with either key or message
        if (processInstanceCreateRequest.getProcessDefinitionId() != null) {
            throw new ActivitiIllegalArgumentException("TenantId can only be used with either processDefinitionKey or message.");
        }
    } else {
        // if no tenantId, it must be from definitionId
        if (processInstanceCreateRequest.getProcessDefinitionId() == null) {
            throw new ActivitiIllegalArgumentException("TenantId should be specified to be used with either " + "processDefinitionKey or message.");
        }
    }
    // Have to add the validation part here
    if (!isValidUserToStartProcess(processInstanceCreateRequest)) {
        throw new RestApiBasicAuthenticationException("User doesn't have the necessary permission to start the process");
    }
    if (processInstanceCreateRequest.getSkipInstanceCreation() || processInstanceCreateRequest.getSkipInstanceCreationIfExist()) {
        ProcessInstanceQueryRequest processInstanceQueryRequest = processInstanceCreateRequest.cloneInstanceCreationRequest();
        Map<String, String> allRequestParams = allRequestParams(uriInfo);
        DataResponse dataResponse = getQueryResponse(processInstanceQueryRequest, allRequestParams, uriInfo);
        if (log.isDebugEnabled()) {
            log.debug("ProcessInstanceCreation check:" + dataResponse.getSize());
        }
        int dataResponseSize = dataResponse.getSize();
        if (dataResponseSize > 0) {
            if (processInstanceCreateRequest.getCorrelate()) {
                if (dataResponseSize != 1) {
                    String responseMessage = "Correlation matching failed as there are more than one matching instance with " + "given variables state";
                    throw new NotFoundException(Response.ok().entity(responseMessage).status(Response.Status.NOT_FOUND).build());
                }
                if (processInstanceCreateRequest.getMessageName() == null) {
                    String responseMessage = "Correlation matching failed as messageName property is not specified";
                    throw new ActivitiIllegalArgumentException(responseMessage);
                }
                return performCorrelation(processInstanceCreateRequest);
            } else {
                dataResponse.setMessage("Instance information corresponding to the request");
                return Response.ok().entity(dataResponse).build();
            }
        }
    }
    RestResponseFactory restResponseFactory = new RestResponseFactory();
    Map<String, Object> startVariables = null;
    if (processInstanceCreateRequest.getVariables() != null) {
        startVariables = new HashMap<>();
        for (RestVariable variable : processInstanceCreateRequest.getVariables()) {
            if (variable.getName() == null) {
                throw new ActivitiIllegalArgumentException("Variable name is required.");
            }
            startVariables.put(variable.getName(), restResponseFactory.getVariableValue(variable));
        }
    }
    // updated the additional variables
    if (processInstanceCreateRequest.getAdditionalVariables() != null) {
        if (startVariables == null) {
            startVariables = new HashMap<>();
        }
        for (RestVariable variable : processInstanceCreateRequest.getAdditionalVariables()) {
            if (variable.getName() == null) {
                throw new ActivitiIllegalArgumentException("Additional Variable name is required.");
            }
            startVariables.put(variable.getName(), restResponseFactory.getVariableValue(variable));
        }
    }
    RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
    IdentityService identityService = BPMNOSGIService.getIdentityService();
    PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
    String userName = carbonContext.getUsername();
    ProcessInstanceResponse processInstanceResponse;
    // Actually start the instance based on key or id
    try {
        ProcessInstance instance;
        identityService.setAuthenticatedUserId(userName);
        if (processInstanceCreateRequest.getProcessDefinitionId() != null) {
            instance = runtimeService.startProcessInstanceById(processInstanceCreateRequest.getProcessDefinitionId(), processInstanceCreateRequest.getBusinessKey(), startVariables);
        } else if (processInstanceCreateRequest.getProcessDefinitionKey() != null) {
            if (processInstanceCreateRequest.isCustomTenantSet()) {
                instance = runtimeService.startProcessInstanceByKeyAndTenantId(processInstanceCreateRequest.getProcessDefinitionKey(), processInstanceCreateRequest.getBusinessKey(), startVariables, processInstanceCreateRequest.getTenantId());
            } else {
                instance = runtimeService.startProcessInstanceByKey(processInstanceCreateRequest.getProcessDefinitionKey(), processInstanceCreateRequest.getBusinessKey(), startVariables);
            }
        } else {
            if (processInstanceCreateRequest.isCustomTenantSet()) {
                instance = runtimeService.startProcessInstanceByMessageAndTenantId(processInstanceCreateRequest.getMessage(), processInstanceCreateRequest.getBusinessKey(), startVariables, processInstanceCreateRequest.getTenantId());
            } else {
                instance = runtimeService.startProcessInstanceByMessage(processInstanceCreateRequest.getMessage(), processInstanceCreateRequest.getBusinessKey(), startVariables);
            }
        }
        HistoryService historyService = BPMNOSGIService.getHistoryService();
        if (processInstanceCreateRequest.getReturnVariables()) {
            Map<String, Object> runtimeVariableMap = null;
            List<HistoricVariableInstance> historicVariableList = null;
            if (instance.isEnded()) {
                historicVariableList = historyService.createHistoricVariableInstanceQuery().processInstanceId(instance.getId()).list();
            } else {
                runtimeVariableMap = runtimeService.getVariables(instance.getId());
            }
            processInstanceResponse = restResponseFactory.createProcessInstanceResponse(instance, true, runtimeVariableMap, historicVariableList, uriInfo.getBaseUri().toString());
        } else {
            processInstanceResponse = restResponseFactory.createProcessInstanceResponse(instance, uriInfo.getBaseUri().toString());
        }
    } catch (ActivitiObjectNotFoundException aonfe) {
        throw new ActivitiIllegalArgumentException(aonfe.getMessage(), aonfe);
    } finally {
        identityService.setAuthenticatedUserId(null);
    }
    return Response.ok().status(Response.Status.CREATED).entity(processInstanceResponse).build();
}
Also used : RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) RuntimeService(org.activiti.engine.RuntimeService) NotFoundException(javax.ws.rs.NotFoundException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) HistoryService(org.activiti.engine.HistoryService) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) ProcessInstanceQueryRequest(org.wso2.carbon.bpmn.rest.model.runtime.ProcessInstanceQueryRequest) RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) IdentityService(org.activiti.engine.IdentityService) RestApiBasicAuthenticationException(org.wso2.carbon.bpmn.rest.common.exception.RestApiBasicAuthenticationException) DataResponse(org.wso2.carbon.bpmn.rest.model.common.DataResponse) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ProcessInstanceResponse(org.wso2.carbon.bpmn.rest.model.runtime.ProcessInstanceResponse) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 25 with DataResponse

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

the class ExecutionService method getProcessInstances.

@GET
@Path("/")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getProcessInstances() {
    // Populate query based on request
    ExecutionQueryRequest queryRequest = new ExecutionQueryRequest();
    Map<String, String> allRequestParams = new HashMap<>();
    for (String property : allPropertiesList) {
        String value = uriInfo.getQueryParameters().getFirst(property);
        if (value != null) {
            allRequestParams.put(property, value);
        }
    }
    String id = uriInfo.getQueryParameters().getFirst("id");
    if (id != null) {
        queryRequest.setId(id);
    }
    String processInstanceId = uriInfo.getQueryParameters().getFirst("processInstanceId");
    if (processInstanceId != null) {
        queryRequest.setProcessInstanceId(processInstanceId);
    }
    String processInstanceBusinessKey = uriInfo.getQueryParameters().getFirst("processInstanceBusinessKey");
    if (processInstanceBusinessKey != null) {
        queryRequest.setProcessBusinessKey(processInstanceBusinessKey);
    }
    String processDefinitionKey = uriInfo.getQueryParameters().getFirst("processDefinitionKey");
    if (processDefinitionKey != null) {
        queryRequest.setProcessDefinitionKey(processDefinitionKey);
    }
    String processDefinitionId = uriInfo.getQueryParameters().getFirst("processDefinitionId");
    if (processDefinitionId != null) {
        queryRequest.setProcessDefinitionId(processDefinitionId);
    }
    String messageEventSubscriptionName = uriInfo.getQueryParameters().getFirst("messageEventSubscriptionName");
    if (messageEventSubscriptionName != null) {
        queryRequest.setMessageEventSubscriptionName(messageEventSubscriptionName);
    }
    String signalEventSubscriptionName = uriInfo.getQueryParameters().getFirst("signalEventSubscriptionName");
    if (signalEventSubscriptionName != null) {
        queryRequest.setSignalEventSubscriptionName(signalEventSubscriptionName);
    }
    String activityId = uriInfo.getQueryParameters().getFirst("activityId");
    if (activityId != null) {
        queryRequest.setActivityId(activityId);
    }
    String parentId = uriInfo.getQueryParameters().getFirst("parentId");
    if (parentId != null) {
        queryRequest.setParentId(parentId);
    }
    String tenantId = uriInfo.getQueryParameters().getFirst("tenantId");
    if (tenantId != null) {
        queryRequest.setTenantId(tenantId);
    }
    String tenantIdLike = uriInfo.getQueryParameters().getFirst("tenantIdLike");
    if (tenantIdLike != null) {
        queryRequest.setTenantIdLike(tenantIdLike);
    }
    String withoutTenantId = uriInfo.getQueryParameters().getFirst("withoutTenantId");
    if (withoutTenantId != null) {
        if (Boolean.valueOf(withoutTenantId)) {
            queryRequest.setWithoutTenantId(Boolean.TRUE);
        }
    }
    // add common parameters such as sort,order,start etc.
    // allRequestParams = Utils.prepareCommonParameters(allRequestParams, uriInfo);
    DataResponse dataResponse = getQueryResponse(queryRequest, allRequestParams, uriInfo);
    return Response.ok().entity(dataResponse).build();
}
Also used : HashMap(java.util.HashMap) DataResponse(org.wso2.carbon.bpmn.rest.model.common.DataResponse)

Aggregations

DataResponse (org.wso2.carbon.bpmn.rest.model.common.DataResponse)20 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)17 HashMap (java.util.HashMap)15 Path (javax.ws.rs.Path)14 Produces (javax.ws.rs.Produces)14 GET (javax.ws.rs.GET)8 HistoryService (org.activiti.engine.HistoryService)7 POST (javax.ws.rs.POST)6 RepositoryService (org.activiti.engine.RepositoryService)3 RuntimeService (org.activiti.engine.RuntimeService)3 List (java.util.List)2 Consumes (javax.ws.rs.Consumes)2 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)2 HistoricActivityInstanceQuery (org.activiti.engine.history.HistoricActivityInstanceQuery)2 ExecutionQuery (org.activiti.engine.runtime.ExecutionQuery)2 HistoricActivityInstancePaginateList (org.wso2.carbon.bpmn.rest.model.history.HistoricActivityInstancePaginateList)2 HistoricProcessInstancePaginateList (org.wso2.carbon.bpmn.rest.model.history.HistoricProcessInstancePaginateList)2 ArrayList (java.util.ArrayList)1 NotFoundException (javax.ws.rs.NotFoundException)1 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)1