Search in sources :

Example 6 with RestResponseFactory

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

the class ProcessInstanceService method addLocalVariables.

protected void addLocalVariables(Execution execution, int variableType, Map<String, RestVariable> variableMap) {
    RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
    Map<String, Object> rawLocalvariables = runtimeService.getVariablesLocal(execution.getId());
    List<RestVariable> localVariables = new RestResponseFactory().createRestVariables(rawLocalvariables, execution.getId(), variableType, RestVariable.RestVariableScope.LOCAL, uriInfo.getBaseUri().toString());
    for (RestVariable var : localVariables) {
        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 7 with RestResponseFactory

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

the class ProcessInstanceService method setSimpleVariable.

protected RestVariable setSimpleVariable(RestVariable restVariable, Execution execution, boolean isNew) {
    if (restVariable.getName() == null) {
        throw new ActivitiIllegalArgumentException("Variable name is required");
    }
    // Figure out scope, revert to local is omitted
    RestVariable.RestVariableScope scope = restVariable.getVariableScope();
    if (scope == null) {
        scope = RestVariable.RestVariableScope.LOCAL;
    }
    Object actualVariableValue = new RestResponseFactory().getVariableValue(restVariable);
    setVariable(execution, restVariable.getName(), actualVariableValue, scope, isNew);
    return constructRestVariable(restVariable.getName(), actualVariableValue, scope, execution.getId(), false);
}
Also used : RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException)

Example 8 with RestResponseFactory

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

the class ProcessInstanceService method getIdentityLinK.

@GET
@Path("/{processInstanceId}/identitylinks/users/{identityId}/{type}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getIdentityLinK(@PathParam("processInstanceId") String processInstanceId, @PathParam("identityId") String identityId, @PathParam("type") String type) {
    ProcessInstance processInstance = getProcessInstanceFromRequest(processInstanceId);
    validateIdentityLinkArguments(identityId, type);
    IdentityLink link = getIdentityLink(identityId, type, processInstance.getId());
    return Response.ok().entity(new RestResponseFactory().createRestIdentityLink(link, uriInfo.getBaseUri().toString())).build();
}
Also used : RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) RestIdentityLink(org.wso2.carbon.bpmn.rest.model.common.RestIdentityLink) IdentityLink(org.activiti.engine.task.IdentityLink) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 9 with RestResponseFactory

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

the class ModelService method getModels.

@GET
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
public Response getModels() {
    RepositoryService repositoryService = BPMNOSGIService.getRepositoryService();
    // 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);
        }
    }
    ModelQuery modelQuery = repositoryService.createModelQuery();
    String id = uriInfo.getQueryParameters().getFirst("id");
    if (id != null) {
        modelQuery.modelId(id);
    }
    String category = uriInfo.getQueryParameters().getFirst("category");
    if (category != null) {
        modelQuery.modelCategory(category);
    }
    String categoryLike = uriInfo.getQueryParameters().getFirst("categoryLike");
    if (categoryLike != null) {
        modelQuery.modelCategoryLike(categoryLike);
    }
    String categoryNotEquals = uriInfo.getQueryParameters().getFirst("categoryNotEquals");
    if (categoryNotEquals != null) {
        modelQuery.modelCategoryNotEquals(categoryNotEquals);
    }
    String name = uriInfo.getQueryParameters().getFirst("name");
    if (name != null) {
        modelQuery.modelName(name);
    }
    String nameLike = uriInfo.getQueryParameters().getFirst("nameLike");
    if (nameLike != null) {
        modelQuery.modelNameLike(nameLike);
    }
    String key = uriInfo.getQueryParameters().getFirst("key");
    if (key != null) {
        modelQuery.modelKey(key);
    }
    String version = uriInfo.getQueryParameters().getFirst("version");
    if (version != null) {
        modelQuery.modelVersion(Integer.valueOf(version));
    }
    String latestVersion = uriInfo.getQueryParameters().getFirst("latestVersion");
    if (latestVersion != null) {
        boolean isLatestVersion = Boolean.valueOf(latestVersion);
        if (isLatestVersion) {
            modelQuery.latestVersion();
        }
    }
    String deploymentId = uriInfo.getQueryParameters().getFirst("deploymentId");
    if (deploymentId != null) {
        modelQuery.deploymentId(deploymentId);
    }
    String deployed = uriInfo.getQueryParameters().getFirst("deployed");
    if (deployed != null) {
        boolean isDeployed = Boolean.valueOf(deployed);
        if (isDeployed) {
            modelQuery.deployed();
        } else {
            modelQuery.notDeployed();
        }
    }
    String tenantId = uriInfo.getQueryParameters().getFirst("tenantId");
    if (tenantId != null) {
        modelQuery.modelTenantId(tenantId);
    }
    String tenantIdLike = uriInfo.getQueryParameters().getFirst("tenantIdLike");
    if (tenantIdLike != null) {
        modelQuery.modelTenantIdLike(tenantIdLike);
    }
    String sWithoutTenantId = uriInfo.getQueryParameters().getFirst("withoutTenantId");
    if (sWithoutTenantId != null) {
        boolean withoutTenantId = Boolean.valueOf(sWithoutTenantId);
        if (withoutTenantId) {
            modelQuery.modelWithoutTenantId();
        }
    }
    DataResponse response = new ModelsPaginateList(new RestResponseFactory(), uriInfo).paginateList(allRequestParams, modelQuery, "id", allowedSortProperties);
    List<ModelResponse> modelResponseList = (List<ModelResponse>) response.getData();
    if (log.isDebugEnabled()) {
        log.debug("modelResponseList: " + modelResponseList.size());
    }
    return Response.ok().entity(response).build();
}
Also used : ModelsPaginateList(org.wso2.carbon.bpmn.rest.model.repository.ModelsPaginateList) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) HashMap(java.util.HashMap) DataResponse(org.wso2.carbon.bpmn.rest.model.common.DataResponse) ModelResponse(org.wso2.carbon.bpmn.rest.model.repository.ModelResponse) ModelQuery(org.activiti.engine.repository.ModelQuery) ModelsPaginateList(org.wso2.carbon.bpmn.rest.model.repository.ModelsPaginateList) ArrayList(java.util.ArrayList) List(java.util.List) RepositoryService(org.activiti.engine.RepositoryService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 10 with RestResponseFactory

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

the class WorkflowTaskService method createTaskVariable.

@POST
@Path("/{taskId}/variables")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response createTaskVariable(@PathParam("taskId") String taskId, @Context HttpServletRequest httpServletRequest) {
    Task task = getTaskFromRequest(taskId);
    List<RestVariable> inputVariables = new ArrayList<>();
    List<RestVariable> resultVariables = new ArrayList<>();
    Response.ResponseBuilder responseBuilder = Response.ok();
    try {
        if (Utils.isApplicationJsonRequest(httpServletRequest)) {
            try {
                @SuppressWarnings("unchecked") List<Object> variableObjects = (List<Object>) new ObjectMapper().readValue(httpServletRequest.getInputStream(), List.class);
                for (Object restObject : variableObjects) {
                    RestVariable restVariable = new ObjectMapper().convertValue(restObject, RestVariable.class);
                    inputVariables.add(restVariable);
                }
            } catch (IOException e) {
                throw new ActivitiIllegalArgumentException("request body could not be transformed to a RestVariable " + "instance.", e);
            }
        } else if (Utils.isApplicationXmlRequest(httpServletRequest)) {
            JAXBContext jaxbContext = null;
            try {
                jaxbContext = JAXBContext.newInstance(RestVariableCollection.class);
                Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
                RestVariableCollection restVariableCollection = (RestVariableCollection) jaxbUnmarshaller.unmarshal(getXMLReader(httpServletRequest.getInputStream()));
                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 = null;
    Map<String, Object> variablesToSet = new HashMap<>();
    RestResponseFactory restResponseFactory = new RestResponseFactory();
    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 (hasVariableOnScope(task, var.getName(), varScope)) {
            throw new BPMNConflictException("Variable '" + var.getName() + "' is already present on task '" + task.getId() + "'.");
        }
        Object actualVariableValue = restResponseFactory.getVariableValue(var);
        variablesToSet.put(var.getName(), actualVariableValue);
        resultVariables.add(restResponseFactory.createRestVariable(var.getName(), actualVariableValue, varScope, task.getId(), RestResponseFactory.VARIABLE_TASK, false, uriInfo.getBaseUri().toString()));
    }
    RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
    TaskService taskService = BPMNOSGIService.getTaskService();
    if (!variablesToSet.isEmpty()) {
        if (sharedScope == RestVariable.RestVariableScope.LOCAL) {
            taskService.setVariablesLocal(task.getId(), variablesToSet);
        } else {
            if (task.getExecutionId() != null) {
                // Explicitly set on execution, setting non-local variables on task will override local-variables if exists
                runtimeService.setVariables(task.getExecutionId(), variablesToSet);
            } else {
                // Standalone task, no global variables possible
                throw new ActivitiIllegalArgumentException("Cannot set global variables on task '" + task.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 : BPMNConflictException(org.wso2.carbon.bpmn.rest.common.exception.BPMNConflictException) JAXBContext(javax.xml.bind.JAXBContext) RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) Unmarshaller(javax.xml.bind.Unmarshaller) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) BaseTaskService(org.wso2.carbon.bpmn.rest.service.base.BaseTaskService) XMLStreamException(javax.xml.stream.XMLStreamException) BPMNForbiddenException(org.wso2.carbon.bpmn.rest.common.exception.BPMNForbiddenException) BPMNConflictException(org.wso2.carbon.bpmn.rest.common.exception.BPMNConflictException) JAXBException(javax.xml.bind.JAXBException) DataResponse(org.wso2.carbon.bpmn.rest.model.common.DataResponse) Response(javax.ws.rs.core.Response)

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