Search in sources :

Example 46 with RestVariable

use of org.wso2.carbon.bpmn.rest.engine.variable.RestVariable in project carbon-business-process by wso2.

the class ExecutionService method getVariables.

@GET
@Path("/{executionId}/variables")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getVariables(@PathParam("executionId") String executionId) {
    String scope = uriInfo.getQueryParameters().getFirst("scope");
    Execution execution = getExecutionFromRequest(executionId);
    List<RestVariable> restVariableList = processVariables(execution, scope, RestResponseFactory.VARIABLE_EXECUTION, uriInfo);
    RestVariableCollection restVariableCollection = new RestVariableCollection();
    restVariableCollection.setRestVariables(restVariableList);
    return Response.ok().entity(restVariableCollection).build();
}
Also used : RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) Execution(org.activiti.engine.runtime.Execution)

Example 47 with RestVariable

use of org.wso2.carbon.bpmn.rest.engine.variable.RestVariable in project carbon-business-process by wso2.

the class SignalService method signalEventReceived.

@POST
@Path("/")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response signalEventReceived(SignalEventReceivedRequest signalRequest) {
    RestResponseFactory restResponseFactory = new RestResponseFactory();
    RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
    if (signalRequest.getSignalName() == null) {
        throw new ActivitiIllegalArgumentException("signalName is required");
    }
    Map<String, Object> signalVariables = null;
    if (signalRequest.getVariables() != null) {
        signalVariables = new HashMap<String, Object>();
        for (RestVariable variable : signalRequest.getVariables()) {
            if (variable.getName() == null) {
                throw new ActivitiIllegalArgumentException("Variable name is required.");
            }
            signalVariables.put(variable.getName(), restResponseFactory.getVariableValue(variable));
        }
    }
    if (signalRequest.isAsync()) {
        if (signalVariables != null) {
            throw new ActivitiIllegalArgumentException("Async signals cannot take variables as payload");
        }
        if (signalRequest.isCustomTenantSet()) {
            runtimeService.signalEventReceivedAsyncWithTenantId(signalRequest.getSignalName(), signalRequest.getTenantId());
        } else {
            runtimeService.signalEventReceivedAsync(signalRequest.getSignalName());
        }
        return Response.ok().status(Response.Status.ACCEPTED).build();
    } else {
        if (signalRequest.isCustomTenantSet()) {
            runtimeService.signalEventReceivedWithTenantId(signalRequest.getSignalName(), signalVariables, signalRequest.getTenantId());
        } else {
            runtimeService.signalEventReceived(signalRequest.getSignalName(), signalVariables);
        }
        return Response.ok().status(Response.Status.NO_CONTENT).build();
    }
}
Also used : RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) RuntimeService(org.activiti.engine.RuntimeService) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 48 with RestVariable

use of org.wso2.carbon.bpmn.rest.engine.variable.RestVariable in project carbon-business-process by wso2.

the class WorkflowTaskService method completeTask.

protected void completeTask(Task task, TaskActionRequest actionRequest, TaskService taskService) {
    if (actionRequest.getVariables() != null) {
        Map<String, Object> variablesToSet = new HashMap<String, Object>();
        RestResponseFactory restResponseFactory = new RestResponseFactory();
        for (RestVariable var : actionRequest.getVariables()) {
            if (var.getName() == null) {
                throw new ActivitiIllegalArgumentException("Variable name is required");
            }
            Object actualVariableValue = restResponseFactory.getVariableValue(var);
            variablesToSet.put(var.getName(), actualVariableValue);
        }
        taskService.complete(task.getId(), variablesToSet);
    } else {
        taskService.complete(task.getId());
    }
}
Also used : RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory)

Example 49 with RestVariable

use of org.wso2.carbon.bpmn.rest.engine.variable.RestVariable in project carbon-business-process by wso2.

the class WorkflowTaskService method updateTaskVariable.

@PUT
@Path("/{taskId}/variables/{variableName}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response updateTaskVariable(@PathParam("taskId") String taskId, @PathParam("variableName") String variableName, @Context HttpServletRequest httpServletRequest) {
    Task task = getTaskFromRequest(taskId);
    RestVariable restVariable = null;
    if (Utils.isApplicationJsonRequest(httpServletRequest)) {
        try {
            restVariable = new ObjectMapper().readValue(httpServletRequest.getInputStream(), RestVariable.class);
        } catch (Exception e) {
            throw new ActivitiIllegalArgumentException("Error converting request body to RestVariable instance", e);
        }
    } else if (Utils.isApplicationXmlRequest(httpServletRequest)) {
        JAXBContext jaxbContext = null;
        try {
            jaxbContext = JAXBContext.newInstance(RestVariable.class);
            Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
            restVariable = (RestVariable) jaxbUnmarshaller.unmarshal(getXMLReader(httpServletRequest.getInputStream()));
        } catch (JAXBException | IOException e) {
            throw new ActivitiIllegalArgumentException("xml request body could not be transformed to a " + "Rest Variable instance.", e);
        }
    }
    if (restVariable == null) {
        throw new ActivitiException("Invalid body was supplied");
    }
    if (!restVariable.getName().equals(variableName)) {
        throw new ActivitiIllegalArgumentException("Variable name in the body should be equal to the name used in the requested URL.");
    }
    RestVariable result = setSimpleVariable(restVariable, task, false);
    return Response.ok().entity(result).build();
}
Also used : RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) 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)

Example 50 with RestVariable

use of org.wso2.carbon.bpmn.rest.engine.variable.RestVariable in project carbon-business-process by wso2.

the class WorkflowTaskService method updateBinaryTaskVariable.

@PUT
@Path("/{taskId}/variables/{variableName}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response updateBinaryTaskVariable(@PathParam("taskId") String taskId, @PathParam("variableName") String variableName, MultipartBody multipartBody) {
    Task task = getTaskFromRequest(taskId);
    RestVariable result = null;
    try {
        result = setBinaryVariable(multipartBody, task, false, uriInfo);
    } catch (IOException e) {
        throw new ActivitiIllegalArgumentException("Error Reading variable attachment", e);
    }
    if (result != null) {
        if (!result.getName().equals(variableName)) {
            throw new ActivitiIllegalArgumentException("Variable name in the body should be equal to the name used in the requested URL.");
        }
    }
    return Response.ok().entity(result).build();
}
Also used : RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable)

Aggregations

RestVariable (org.wso2.carbon.bpmn.rest.engine.variable.RestVariable)52 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)30 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)15 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)14 IOException (java.io.IOException)11 DataResponse (org.wso2.carbon.bpmn.rest.model.common.DataResponse)11 Response (javax.ws.rs.core.Response)10 RuntimeService (org.activiti.engine.RuntimeService)10 Execution (org.activiti.engine.runtime.Execution)10 ActivitiException (org.activiti.engine.ActivitiException)9 Path (javax.ws.rs.Path)8 JAXBContext (javax.xml.bind.JAXBContext)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 ObjectOutputStream (java.io.ObjectOutputStream)7 Produces (javax.ws.rs.Produces)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 Unmarshaller (javax.xml.bind.Unmarshaller)6 Consumes (javax.ws.rs.Consumes)5 JAXBException (javax.xml.bind.JAXBException)5 XMLStreamException (javax.xml.stream.XMLStreamException)5