Search in sources :

Example 51 with RestVariable

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

the class ProcessInstanceService method updateBinaryVariable.

@PUT
@Path("/{processInstanceId}/variables/{variableName}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response updateBinaryVariable(@PathParam("processInstanceId") String processInstanceId, @PathParam("variableName") String variableName, MultipartBody multipartBody) {
    Execution execution = getExecutionInstanceFromRequest(processInstanceId);
    RestVariable result;
    try {
        result = setBinaryVariable(multipartBody, execution, RestResponseFactory.VARIABLE_PROCESS, false);
    } catch (IOException | ServletException e) {
        throw new BPMNRestException("Exception occured during creating binary execution variable", e);
    }
    return Response.ok().entity(result).build();
}
Also used : RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) ServletException(javax.servlet.ServletException) Execution(org.activiti.engine.runtime.Execution) BPMNRestException(org.wso2.carbon.bpmn.rest.common.exception.BPMNRestException) IOException(java.io.IOException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 52 with RestVariable

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

the class ProcessInstanceService method updateVariable.

@PUT
@Path("/{processInstanceId}/variables/{variableName}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public RestVariable updateVariable(@PathParam("processInstanceId") String processInstanceId, @PathParam("variableName") String variableName, @Context HttpServletRequest httpServletRequest) {
    Execution execution = getExecutionInstanceFromRequest(processInstanceId);
    RestVariable restVariable = null;
    if (Utils.isApplicationJsonRequest(httpServletRequest)) {
        try {
            restVariable = new ObjectMapper().readValue(httpServletRequest.getInputStream(), RestVariable.class);
        } catch (IOException e) {
            throw new ActivitiIllegalArgumentException("request body could not be transformed to a RestVariable " + "instance.", e);
        }
    } else if (Utils.isApplicationXmlRequest(httpServletRequest)) {
        JAXBContext jaxbContext;
        try {
            XMLInputFactory xif = XMLInputFactory.newFactory();
            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(RestVariable.class);
            Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
            restVariable = (RestVariable) jaxbUnmarshaller.unmarshal(xsr);
        } catch (JAXBException | IOException | XMLStreamException e) {
            throw new ActivitiIllegalArgumentException("xml request body could not be transformed to a " + "RestVariable " + "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.");
    }
    return setSimpleVariable(restVariable, execution, false);
}
Also used : RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) ActivitiException(org.activiti.engine.ActivitiException) Execution(org.activiti.engine.runtime.Execution) XMLStreamReader(javax.xml.stream.XMLStreamReader) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) StreamSource(javax.xml.transform.stream.StreamSource) JAXBContext(javax.xml.bind.JAXBContext) IOException(java.io.IOException) Unmarshaller(javax.xml.bind.Unmarshaller) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) XMLInputFactory(javax.xml.stream.XMLInputFactory) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 53 with RestVariable

use of org.wso2.carbon.bpmn.rest.engine.variable.RestVariable 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 54 with RestVariable

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

the class ProcessInstanceService method getVariables.

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

Example 55 with RestVariable

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

the class RestResponseFactory method createRestVariable.

/*public RestVariable createRestVariable(String name, Object value, RestVariable.RestVariableScope scope,
                                           String id, int variableType, boolean includeBinaryValue, String baseUri){

        return createRestVariable(name, value, scope, id, variableType, includeBinaryValue, baseUri);
    }*/
public RestVariable createRestVariable(String name, Object value, RestVariable.RestVariableScope scope, String id, int variableType, boolean includeBinaryValue, String baseUri) {
    RestUrlBuilder urlBuilder = createUrlBuilder(baseUri);
    RestVariableConverter converter = null;
    RestVariable restVar = new RestVariable();
    restVar.setVariableScope(scope);
    restVar.setName(name);
    if (value != null) {
        // Try converting the value
        for (RestVariableConverter c : variableConverters) {
            if (c.getVariableType().isAssignableFrom(value.getClass())) {
                converter = c;
                break;
            }
        }
        if (converter != null) {
            converter.convertVariableValue(value, restVar);
            restVar.setType(converter.getRestTypeName());
        } else {
            // Revert to default conversion, which is the serializable/byte-array form
            if (value instanceof Byte[] || value instanceof byte[]) {
                restVar.setType(BYTE_ARRAY_VARIABLE_TYPE);
            } else {
                restVar.setType(SERIALIZABLE_VARIABLE_TYPE);
            }
            if (includeBinaryValue) {
                restVar.setValue(value);
            }
            if (variableType == VARIABLE_TASK) {
                restVar.setValueUrl(urlBuilder.buildUrl(RestUrls.URL_TASK_VARIABLE_DATA, id, name));
            } else if (variableType == VARIABLE_EXECUTION) {
                restVar.setValueUrl(urlBuilder.buildUrl(RestUrls.URL_EXECUTION_VARIABLE_DATA, id, name));
            } else if (variableType == VARIABLE_PROCESS) {
                restVar.setValueUrl(urlBuilder.buildUrl(RestUrls.URL_PROCESS_INSTANCE_VARIABLE_DATA, id, name));
            } else if (variableType == VARIABLE_HISTORY_TASK) {
                restVar.setValueUrl(urlBuilder.buildUrl(RestUrls.URL_HISTORIC_TASK_INSTANCE_VARIABLE_DATA, id, name));
            } else if (variableType == VARIABLE_HISTORY_PROCESS) {
                restVar.setValueUrl(urlBuilder.buildUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_VARIABLE_DATA, id, name));
            } else if (variableType == VARIABLE_HISTORY_VARINSTANCE) {
                restVar.setValueUrl(urlBuilder.buildUrl(RestUrls.URL_HISTORIC_VARIABLE_INSTANCE_DATA, id));
            } else if (variableType == VARIABLE_HISTORY_DETAIL) {
                restVar.setValueUrl(urlBuilder.buildUrl(RestUrls.URL_HISTORIC_DETAIL_VARIABLE_DATA, id));
            }
        }
    }
    return restVar;
}
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