Search in sources :

Example 91 with RestResponseFactory

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

the class ProcessDefinitionService method getProcessDefinitions.

@GET
@Path("/")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getProcessDefinitions() {
    RepositoryService repositoryService = BPMNOSGIService.getRepositoryService();
    Map<String, String> allRequestParams = new HashMap<>();
    for (String property : allPropertiesList) {
        String value = uriInfo.getQueryParameters().getFirst(property);
        if (value != null) {
            allRequestParams.put(property, value);
        }
    }
    ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();
    // Populate filter-parameters
    if (allRequestParams.containsKey("category")) {
        processDefinitionQuery.processDefinitionCategory(allRequestParams.get("category"));
    }
    if (allRequestParams.containsKey("categoryLike")) {
        processDefinitionQuery.processDefinitionCategoryLike(allRequestParams.get("categoryLike"));
    }
    if (allRequestParams.containsKey("categoryNotEquals")) {
        processDefinitionQuery.processDefinitionCategoryNotEquals(allRequestParams.get("categoryNotEquals"));
    }
    if (allRequestParams.containsKey("key")) {
        processDefinitionQuery.processDefinitionKey(allRequestParams.get("key"));
    }
    if (allRequestParams.containsKey("keyLike")) {
        processDefinitionQuery.processDefinitionKeyLike(allRequestParams.get("keyLike"));
    }
    if (allRequestParams.containsKey("name")) {
        processDefinitionQuery.processDefinitionName(allRequestParams.get("name"));
    }
    if (allRequestParams.containsKey("nameLike")) {
        processDefinitionQuery.processDefinitionNameLike(allRequestParams.get("nameLike"));
    }
    if (allRequestParams.containsKey("resourceName")) {
        processDefinitionQuery.processDefinitionResourceName(allRequestParams.get("resourceName"));
    }
    if (allRequestParams.containsKey("resourceNameLike")) {
        processDefinitionQuery.processDefinitionResourceNameLike(allRequestParams.get("resourceNameLike"));
    }
    if (allRequestParams.containsKey("version")) {
        processDefinitionQuery.processDefinitionVersion(Integer.valueOf(allRequestParams.get("version")));
    }
    if (allRequestParams.containsKey("suspended")) {
        Boolean suspended = Boolean.valueOf(allRequestParams.get("suspended"));
        if (suspended != null) {
            if (suspended) {
                processDefinitionQuery.suspended();
            } else {
                processDefinitionQuery.active();
            }
        }
    }
    if (allRequestParams.containsKey("latest")) {
        Boolean latest = Boolean.valueOf(allRequestParams.get("latest"));
        if (latest != null && latest) {
            processDefinitionQuery.latestVersion();
        }
    }
    if (allRequestParams.containsKey("deploymentId")) {
        processDefinitionQuery.deploymentId(allRequestParams.get("deploymentId"));
    }
    if (allRequestParams.containsKey("startableByUser")) {
        processDefinitionQuery.startableByUser(allRequestParams.get("startableByUser"));
    }
    if (allRequestParams.containsKey("tenantId")) {
        processDefinitionQuery.processDefinitionTenantId(allRequestParams.get("tenantId"));
    }
    if (allRequestParams.containsKey("tenantIdLike")) {
        processDefinitionQuery.processDefinitionTenantIdLike(allRequestParams.get("tenantIdLike"));
    }
    DataResponse response = new ProcessDefinitionsPaginateList(new RestResponseFactory(), uriInfo).paginateList(allRequestParams, processDefinitionQuery, "name", properties);
    return Response.ok().entity(response).build();
}
Also used : RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) HashMap(java.util.HashMap) DataResponse(org.wso2.carbon.bpmn.rest.model.common.DataResponse) ProcessDefinitionQuery(org.activiti.engine.repository.ProcessDefinitionQuery) ProcessDefinitionsPaginateList(org.wso2.carbon.bpmn.rest.model.repository.ProcessDefinitionsPaginateList) RepositoryService(org.activiti.engine.RepositoryService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 92 with RestResponseFactory

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

the class ProcessDefinitionService method getIdentityLink.

@GET
@Path("/{processDefinitionId}/identitylinks/{family}/{identityId}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getIdentityLink(@PathParam("processDefinitionId") String processDefinitionId, @PathParam("family") String family, @PathParam("identityId") String identityId) {
    ProcessDefinition processDefinition = getProcessDefinitionFromRequest(processDefinitionId);
    validateIdentityLinkArguments(family, identityId);
    RepositoryService repositoryService = BPMNOSGIService.getRepositoryService();
    // Check if identitylink to get exists
    IdentityLink link = getIdentityLink(family, identityId, processDefinition.getId(), repositoryService);
    return Response.ok().entity(new RestResponseFactory().createRestIdentityLink(link, uriInfo.getBaseUri().toString())).build();
}
Also used : RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) IdentityLink(org.activiti.engine.task.IdentityLink) RepositoryService(org.activiti.engine.RepositoryService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 93 with RestResponseFactory

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

the class ProcessInstanceService method createIdentityLink.

@POST
@Path("/{processInstanceId}/identitylinks")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response createIdentityLink(@PathParam("processInstanceId") String processInstanceId, RestIdentityLink identityLink) {
    ProcessInstance processInstance = getProcessInstanceFromRequest(processInstanceId);
    if (identityLink.getGroup() != null) {
        throw new ActivitiIllegalArgumentException("Only user identity links are supported on a process instance.");
    }
    if (identityLink.getUser() == null) {
        throw new ActivitiIllegalArgumentException("The user is required.");
    }
    if (identityLink.getType() == null) {
        throw new ActivitiIllegalArgumentException("The identity link type is required.");
    }
    RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
    runtimeService.addUserIdentityLink(processInstance.getId(), identityLink.getUser(), identityLink.getType());
    RestIdentityLink restIdentityLink = new RestResponseFactory().createRestIdentityLink(identityLink.getType(), identityLink.getUser(), identityLink.getGroup(), null, null, processInstance.getId(), uriInfo.getBaseUri().toString());
    return Response.ok().status(Response.Status.CREATED).entity(restIdentityLink).build();
}
Also used : RestIdentityLink(org.wso2.carbon.bpmn.rest.model.common.RestIdentityLink) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) RuntimeService(org.activiti.engine.RuntimeService) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 94 with RestResponseFactory

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

the class ProcessInstanceService method performCorrelation.

private Response performCorrelation(ProcessInstanceCreateRequest processInstanceCreateRequest) {
    CorrelationActionRequest correlationActionRequest = new CorrelationActionRequest();
    String requestValue = processInstanceCreateRequest.getProcessDefinitionId();
    if (requestValue != null) {
        correlationActionRequest.setProcessDefinitionId(processInstanceCreateRequest.getProcessDefinitionId());
    }
    requestValue = processInstanceCreateRequest.getProcessDefinitionKey();
    if (requestValue != null) {
        correlationActionRequest.setProcessDefinitionKey(requestValue);
    }
    if (processInstanceCreateRequest.isCustomTenantSet()) {
        correlationActionRequest.setTenantId(processInstanceCreateRequest.getTenantId());
    }
    requestValue = processInstanceCreateRequest.getMessageName();
    if (requestValue != null) {
        correlationActionRequest.setMessageName(requestValue);
    }
    List<RestVariable> variables = processInstanceCreateRequest.getVariables();
    if (variables != null) {
        RestResponseFactory restResponseFactory = new RestResponseFactory();
        List<QueryVariable> correlationVariableList = new ArrayList<>();
        for (RestVariable variable : variables) {
            QueryVariable correlationVariable = new QueryVariable();
            correlationVariable.setName(variable.getName());
            correlationVariable.setOperation("equals");
            correlationVariable.setType(variable.getType());
            correlationVariable.setValue(restResponseFactory.getVariableValue(variable));
            correlationVariableList.add(correlationVariable);
        }
        correlationActionRequest.setCorrelationVariables(correlationVariableList);
    }
    variables = processInstanceCreateRequest.getAdditionalVariables();
    if (variables != null) {
        correlationActionRequest.setVariables(variables);
    }
    correlationActionRequest.setAction(CorrelationActionRequest.ACTION_MESSAGE_EVENT_RECEIVED);
    return new CorrelationProcess().getQueryResponse(correlationActionRequest, uriInfo);
}
Also used : RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) CorrelationProcess(org.wso2.carbon.bpmn.rest.common.CorrelationProcess) CorrelationActionRequest(org.wso2.carbon.bpmn.rest.model.correlation.CorrelationActionRequest) QueryVariable(org.wso2.carbon.bpmn.rest.engine.variable.QueryVariable) ArrayList(java.util.ArrayList)

Example 95 with RestResponseFactory

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

the class ProcessInstanceService method performProcessInstanceAction.

@PUT
@Path("/{processInstanceId}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response performProcessInstanceAction(@PathParam("processInstanceId") String processInstanceId, ProcessInstanceActionRequest actionRequest) {
    ProcessInstance processInstance = getProcessInstanceFromRequest(processInstanceId);
    RestResponseFactory restResponseFactory = new RestResponseFactory();
    if (ProcessInstanceActionRequest.ACTION_ACTIVATE.equals(actionRequest.getAction())) {
        return Response.ok().entity(activateProcessInstance(processInstance, uriInfo)).build();
    } else if (ProcessInstanceActionRequest.ACTION_SUSPEND.equals(actionRequest.getAction())) {
        return Response.ok().entity(suspendProcessInstance(processInstance, restResponseFactory, uriInfo)).build();
    }
    throw new ActivitiIllegalArgumentException("Invalid action: '" + actionRequest.getAction() + "'.");
}
Also used : RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

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