Search in sources :

Example 1 with RestResponseFactory

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

the class HistoricProcessInstanceQueryService method queryProcessInstances.

@POST
@Path("/")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response queryProcessInstances(HistoricProcessInstanceQueryRequest queryRequest) {
    Map<String, String> allRequestParams = new HashMap<>();
    for (String property : allPropertiesList) {
        String value = uriInfo.getQueryParameters().getFirst(property);
        if (value != null) {
            allRequestParams.put(property, value);
        }
    }
    HistoryService historyService = BPMNOSGIService.getHistoryService();
    org.activiti.engine.history.HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery();
    // Populate query based on request
    if (queryRequest.getProcessInstanceId() != null) {
        query.processInstanceId(queryRequest.getProcessInstanceId());
    }
    if (queryRequest.getProcessInstanceIds() != null && !queryRequest.getProcessInstanceIds().isEmpty()) {
        query.processInstanceIds(new HashSet<>(queryRequest.getProcessInstanceIds()));
    }
    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.getSuperProcessInstanceId() != null) {
        query.superProcessInstanceId(queryRequest.getSuperProcessInstanceId());
    }
    if (queryRequest.getExcludeSubprocesses() != null) {
        query.excludeSubprocesses(queryRequest.getExcludeSubprocesses());
    }
    if (queryRequest.getFinishedAfter() != null) {
        query.finishedAfter(queryRequest.getFinishedAfter());
    }
    if (queryRequest.getFinishedBefore() != null) {
        query.finishedBefore(queryRequest.getFinishedBefore());
    }
    if (queryRequest.getStartedAfter() != null) {
        query.startedAfter(queryRequest.getStartedAfter());
    }
    if (queryRequest.getStartedBefore() != null) {
        query.startedBefore(queryRequest.getStartedBefore());
    }
    if (queryRequest.getStartedBy() != null) {
        query.startedBy(queryRequest.getStartedBy());
    }
    if (queryRequest.getFinished() != null) {
        if (queryRequest.getFinished()) {
            query.finished();
        } else {
            query.unfinished();
        }
    }
    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();
    }
    DataResponse dataResponse = new HistoricProcessInstancePaginateList(new RestResponseFactory(), uriInfo).paginateList(allRequestParams, queryRequest, query, "processInstanceId", allowedSortProperties);
    return Response.ok().entity(dataResponse).build();
}
Also used : RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) DataResponse(org.wso2.carbon.bpmn.rest.model.common.DataResponse) HistoryService(org.activiti.engine.HistoryService) HistoricProcessInstancePaginateList(org.wso2.carbon.bpmn.rest.model.history.HistoricProcessInstancePaginateList) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Example 2 with RestResponseFactory

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

the class DeploymentService method getDeployments.

@GET
@Path("/")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getDeployments() {
    RepositoryService repositoryService = BPMNOSGIService.getRepositoryService();
    DeploymentQuery deploymentQuery = repositoryService.createDeploymentQuery();
    // Apply filters
    Map<String, String> allRequestParams = new HashMap<>();
    for (String property : allPropertiesList) {
        String value = uriInfo.getQueryParameters().getFirst(property);
        if (value != null) {
            allRequestParams.put(property, value);
        }
    }
    String name = uriInfo.getQueryParameters().getFirst("name");
    if (name != null) {
        deploymentQuery.deploymentName(name);
    }
    String nameLike = uriInfo.getQueryParameters().getFirst("nameLike");
    if (nameLike != null) {
        deploymentQuery.deploymentNameLike(nameLike);
    }
    String category = uriInfo.getQueryParameters().getFirst("category");
    if (category != null) {
        deploymentQuery.deploymentCategory(category);
    }
    String categoryNotEquals = uriInfo.getQueryParameters().getFirst("categoryNotEquals");
    if (categoryNotEquals != null) {
        deploymentQuery.deploymentCategoryNotEquals(categoryNotEquals);
    }
    String tenantId = uriInfo.getQueryParameters().getFirst("tenantId");
    if (tenantId != null) {
        deploymentQuery.deploymentTenantId(tenantId);
    }
    String tenantIdLike = uriInfo.getQueryParameters().getFirst("tenantIdLike");
    if (tenantIdLike != null) {
        deploymentQuery.deploymentTenantIdLike(tenantIdLike);
    }
    String sWithoutTenantId = uriInfo.getQueryParameters().getFirst("withoutTenantId");
    if (sWithoutTenantId != null) {
        Boolean withoutTenantId = Boolean.valueOf(sWithoutTenantId);
        if (withoutTenantId) {
            deploymentQuery.deploymentWithoutTenantId();
        }
    }
    DeploymentsPaginateList deploymentsPaginateList = new DeploymentsPaginateList(new RestResponseFactory(), uriInfo);
    DataResponse dataResponse = deploymentsPaginateList.paginateList(allRequestParams, deploymentQuery, "id", allowedSortProperties);
    return Response.ok().entity(dataResponse).build();
}
Also used : DeploymentQuery(org.activiti.engine.repository.DeploymentQuery) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) HashMap(java.util.HashMap) DataResponse(org.wso2.carbon.bpmn.rest.model.common.DataResponse) DeploymentsPaginateList(org.wso2.carbon.bpmn.rest.model.repository.DeploymentsPaginateList) RepositoryService(org.activiti.engine.RepositoryService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with RestResponseFactory

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

the class DeploymentService method getDeployment.

@GET
@Path("/{deploymentId}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getDeployment(@PathParam("deploymentId") String deploymentId) {
    RepositoryService repositoryService = BPMNOSGIService.getRepositoryService();
    Deployment deployment = repositoryService.createDeploymentQuery().deploymentId(deploymentId).singleResult();
    if (deployment == null) {
        throw new ActivitiObjectNotFoundException("Could not find a deployment with deploymentId '" + deploymentId + "'.", Deployment.class);
    }
    DeploymentResponse deploymentResponse = new RestResponseFactory().createDeploymentResponse(deployment, uriInfo.getBaseUri().toString());
    return Response.ok().entity(deploymentResponse).build();
}
Also used : RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) Deployment(org.activiti.engine.repository.Deployment) DeploymentResponse(org.wso2.carbon.bpmn.rest.model.repository.DeploymentResponse) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) RepositoryService(org.activiti.engine.RepositoryService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with RestResponseFactory

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

the class ProcessInstanceService method addGlobalVariables.

protected void addGlobalVariables(Execution execution, int variableType, Map<String, RestVariable> variableMap) {
    RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
    Map<String, Object> rawVariables = runtimeService.getVariables(execution.getId());
    List<RestVariable> globalVariables = new RestResponseFactory().createRestVariables(rawVariables, execution.getId(), variableType, RestVariable.RestVariableScope.GLOBAL, uriInfo.getBaseUri().toString());
    // since local variables get precedence over global ones at all times.
    for (RestVariable var : globalVariables) {
        if (!variableMap.containsKey(var.getName())) {
            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 5 with RestResponseFactory

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

the class ProcessInstanceService method createExecutionVariable.

protected Response createExecutionVariable(Execution execution, boolean override, int variableType, HttpServletRequest httpServletRequest) throws IOException, ServletException {
    boolean debugEnabled = log.isDebugEnabled();
    if (debugEnabled) {
        log.debug("httpServletRequest.getContentType():" + httpServletRequest.getContentType());
    }
    Response.ResponseBuilder responseBuilder = Response.ok();
    if (debugEnabled) {
        log.debug("Processing non binary variable");
    }
    List<RestVariable> inputVariables = new ArrayList<>();
    List<RestVariable> resultVariables = new ArrayList<>();
    try {
        if (Utils.isApplicationJsonRequest(httpServletRequest)) {
            ObjectMapper objectMapper = new ObjectMapper();
            @SuppressWarnings("unchecked") List<Object> variableObjects = (List<Object>) objectMapper.readValue(httpServletRequest.getInputStream(), List.class);
            for (Object restObject : variableObjects) {
                RestVariable restVariable = objectMapper.convertValue(restObject, RestVariable.class);
                inputVariables.add(restVariable);
            }
        } else if (Utils.isApplicationXmlRequest(httpServletRequest)) {
            JAXBContext jaxbContext;
            try {
                XMLInputFactory xif = XMLInputFactory.newInstance();
                xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
                xif.setProperty(XMLInputFactory.SUPPORT_DTD, false);
                XMLStreamReader xsr = xif.createXMLStreamReader(new StreamSource(httpServletRequest.getInputStream()));
                jaxbContext = JAXBContext.newInstance(RestVariableCollection.class);
                Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
                RestVariableCollection restVariableCollection = (RestVariableCollection) jaxbUnmarshaller.unmarshal(xsr);
                if (restVariableCollection == null) {
                    throw new ActivitiIllegalArgumentException("xml request body could not be transformed to a " + "RestVariable Collection instance.");
                }
                List<RestVariable> restVariableList = restVariableCollection.getRestVariables();
                if (restVariableList.size() == 0) {
                    throw new ActivitiIllegalArgumentException("xml request body could not identify any rest " + "variables to be updated");
                }
                for (RestVariable restVariable : restVariableList) {
                    inputVariables.add(restVariable);
                }
            } catch (JAXBException | IOException e) {
                throw new ActivitiIllegalArgumentException("xml request body could not be transformed to a " + "RestVariable instance.", e);
            }
        }
    } catch (Exception e) {
        throw new ActivitiIllegalArgumentException("Failed to serialize to a RestVariable instance", e);
    }
    if (inputVariables.size() == 0) {
        throw new ActivitiIllegalArgumentException("Request didn't contain a list of variables to create.");
    }
    RestVariable.RestVariableScope sharedScope = null;
    RestVariable.RestVariableScope varScope;
    Map<String, Object> variablesToSet = new HashMap<>();
    for (RestVariable var : inputVariables) {
        // Validate if scopes match
        varScope = var.getVariableScope();
        if (var.getName() == null) {
            throw new ActivitiIllegalArgumentException("Variable name is required");
        }
        if (varScope == null) {
            varScope = RestVariable.RestVariableScope.LOCAL;
        }
        if (sharedScope == null) {
            sharedScope = varScope;
        }
        if (varScope != sharedScope) {
            throw new ActivitiIllegalArgumentException("Only allowed to update multiple variables in the same scope.");
        }
        if (!override && hasVariableOnScope(execution, var.getName(), varScope)) {
            throw new BPMNConflictException("Variable '" + var.getName() + "' is already present on execution '" + execution.getId() + "'.");
        }
        RestResponseFactory restResponseFactory = new RestResponseFactory();
        Object actualVariableValue = restResponseFactory.getVariableValue(var);
        variablesToSet.put(var.getName(), actualVariableValue);
        resultVariables.add(restResponseFactory.createRestVariable(var.getName(), actualVariableValue, varScope, execution.getId(), variableType, false, uriInfo.getBaseUri().toString()));
    }
    if (!variablesToSet.isEmpty()) {
        RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
        if (sharedScope == RestVariable.RestVariableScope.LOCAL) {
            runtimeService.setVariablesLocal(execution.getId(), variablesToSet);
        } else {
            if (execution.getParentId() != null) {
                // Explicitly set on parent, setting non-local variables on execution itself will override local-variables if exists
                runtimeService.setVariables(execution.getParentId(), variablesToSet);
            } else {
                // Standalone task, no global variables possible
                throw new ActivitiIllegalArgumentException("Cannot set global variables on execution '" + execution.getId() + "', task is not part of process.");
            }
        }
    }
    RestVariableCollection restVariableCollection = new RestVariableCollection();
    restVariableCollection.setRestVariables(resultVariables);
    responseBuilder.entity(restVariableCollection);
    // }
    return responseBuilder.status(Response.Status.CREATED).build();
}
Also used : RestVariableCollection(org.wso2.carbon.bpmn.rest.model.runtime.RestVariableCollection) BPMNConflictException(org.wso2.carbon.bpmn.rest.common.exception.BPMNConflictException) XMLStreamReader(javax.xml.stream.XMLStreamReader) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JAXBContext(javax.xml.bind.JAXBContext) RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) List(java.util.List) ArrayList(java.util.ArrayList) Unmarshaller(javax.xml.bind.Unmarshaller) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) RuntimeService(org.activiti.engine.RuntimeService) StreamSource(javax.xml.transform.stream.StreamSource) ActivitiException(org.activiti.engine.ActivitiException) ServletException(javax.servlet.ServletException) BPMNRestException(org.wso2.carbon.bpmn.rest.common.exception.BPMNRestException) BPMNContentNotSupportedException(org.wso2.carbon.bpmn.rest.common.exception.BPMNContentNotSupportedException) XMLStreamException(javax.xml.stream.XMLStreamException) BPMNConflictException(org.wso2.carbon.bpmn.rest.common.exception.BPMNConflictException) JAXBException(javax.xml.bind.JAXBException) NotFoundException(javax.ws.rs.NotFoundException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) IOException(java.io.IOException) RestApiBasicAuthenticationException(org.wso2.carbon.bpmn.rest.common.exception.RestApiBasicAuthenticationException) DataResponse(org.wso2.carbon.bpmn.rest.model.common.DataResponse) Response(javax.ws.rs.core.Response) ProcessInstanceResponse(org.wso2.carbon.bpmn.rest.model.runtime.ProcessInstanceResponse) XMLInputFactory(javax.xml.stream.XMLInputFactory)

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