Search in sources :

Example 26 with RestVariable

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

the class HistoricProcessInstanceService method getVariableData.

@GET
@Path("/{processInstanceId}/variables/{variableName}/data")
public Response getVariableData(@PathParam("processInstanceId") String processInstanceId, @PathParam("variableName") String variableName) {
    try {
        Response.ResponseBuilder responseBuilder = Response.ok();
        byte[] result = null;
        RestVariable variable = getVariableFromRequest(true, processInstanceId, variableName);
        if (RestResponseFactory.BYTE_ARRAY_VARIABLE_TYPE.equals(variable.getType())) {
            result = (byte[]) variable.getValue();
            responseBuilder.type("application/octet-stream");
        } else if (RestResponseFactory.SERIALIZABLE_VARIABLE_TYPE.equals(variable.getType())) {
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            ObjectOutputStream outputStream = new ObjectOutputStream(buffer);
            outputStream.writeObject(variable.getValue());
            outputStream.close();
            result = buffer.toByteArray();
            responseBuilder.type("application/x-java-serialized-object");
        } else {
            throw new ActivitiObjectNotFoundException("The variable does not have a binary data stream.", null);
        }
        return responseBuilder.entity(result).build();
    } catch (IOException ioe) {
        // Re-throw IOException
        throw new ActivitiException("Unexpected exception getting variable data", ioe);
    }
}
Also used : HistoricProcessInstanceResponse(org.wso2.carbon.bpmn.rest.model.history.HistoricProcessInstanceResponse) CommentResponse(org.wso2.carbon.bpmn.rest.model.runtime.CommentResponse) HistoricIdentityLinkResponse(org.wso2.carbon.bpmn.rest.model.history.HistoricIdentityLinkResponse) DataResponse(org.wso2.carbon.bpmn.rest.model.common.DataResponse) Response(javax.ws.rs.core.Response) RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream)

Example 27 with RestVariable

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

the class HistoricTaskInstanceService method getVariableFromRequest.

protected RestVariable getVariableFromRequest(boolean includeBinary, String taskId, String variableName, String scope) {
    HistoryService historyService = BPMNOSGIService.getHistoryService();
    RestVariable.RestVariableScope variableScope = RestVariable.getScopeFromString(scope);
    HistoricTaskInstanceQuery taskQuery = historyService.createHistoricTaskInstanceQuery().taskId(taskId);
    if (variableScope != null) {
        if (variableScope == RestVariable.RestVariableScope.GLOBAL) {
            taskQuery.includeProcessVariables();
        } else {
            taskQuery.includeTaskLocalVariables();
        }
    } else {
        taskQuery.includeTaskLocalVariables().includeProcessVariables();
    }
    HistoricTaskInstance taskObject = taskQuery.singleResult();
    if (taskObject == null) {
        throw new ActivitiObjectNotFoundException("Historic task instance '" + taskId + "' couldn't be found.", HistoricTaskInstanceEntity.class);
    }
    Object value = null;
    if (variableScope != null) {
        if (variableScope == RestVariable.RestVariableScope.GLOBAL) {
            value = taskObject.getProcessVariables().get(variableName);
        } else {
            value = taskObject.getTaskLocalVariables().get(variableName);
        }
    } else {
        // look for local task restVariables first
        if (taskObject.getTaskLocalVariables().containsKey(variableName)) {
            value = taskObject.getTaskLocalVariables().get(variableName);
        } else {
            value = taskObject.getProcessVariables().get(variableName);
        }
    }
    if (value == null) {
        throw new ActivitiObjectNotFoundException("Historic task instance '" + taskId + "' variable value for " + variableName + " couldn't be found.", VariableInstanceEntity.class);
    } else {
        return new RestResponseFactory().createRestVariable(variableName, value, null, taskId, RestResponseFactory.VARIABLE_HISTORY_TASK, includeBinary, uriInfo.getBaseUri().toString());
    }
}
Also used : RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) HistoryService(org.activiti.engine.HistoryService) HistoricTaskInstanceQuery(org.activiti.engine.history.HistoricTaskInstanceQuery) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

Example 28 with RestVariable

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

the class HistoricTaskInstanceService method getVariableData.

@GET
@Path("/{taskId}/variables/{variableName}/data")
public byte[] getVariableData(@PathParam("taskId") String taskId, @PathParam("variableName") String variableName) {
    String scope = uriInfo.getQueryParameters().getFirst("scope");
    Response.ResponseBuilder response = Response.ok();
    try {
        byte[] result = null;
        RestVariable variable = getVariableFromRequest(true, taskId, variableName, scope);
        if (RestResponseFactory.BYTE_ARRAY_VARIABLE_TYPE.equals(variable.getType())) {
            result = (byte[]) variable.getValue();
            response.type("application/octet-stream");
        } else if (RestResponseFactory.SERIALIZABLE_VARIABLE_TYPE.equals(variable.getType())) {
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            ObjectOutputStream outputStream = new ObjectOutputStream(buffer);
            outputStream.writeObject(variable.getValue());
            outputStream.close();
            result = buffer.toByteArray();
            response.type("application/x-java-serialized-object");
        } else {
            throw new ActivitiObjectNotFoundException("The variable does not have a binary data stream.", null);
        }
        return result;
    } catch (IOException ioe) {
        // Re-throw IOException
        throw new ActivitiException("Unexpected exception getting variable data", ioe);
    }
}
Also used : HistoricIdentityLinkResponse(org.wso2.carbon.bpmn.rest.model.history.HistoricIdentityLinkResponse) DataResponse(org.wso2.carbon.bpmn.rest.model.common.DataResponse) Response(javax.ws.rs.core.Response) HistoricTaskInstanceResponse(org.wso2.carbon.bpmn.rest.model.runtime.HistoricTaskInstanceResponse) RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) ActivitiException(org.activiti.engine.ActivitiException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

Example 29 with RestVariable

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

the class HistoricVariableInstanceService method getVariableData.

/**
 * Get variable data for a given variable instance by Id.
 * @param varInstanceId
 * @return
 */
@GET
@Path("/{varInstanceId}/data")
public byte[] getVariableData(@PathParam("varInstanceId") String varInstanceId) {
    Response.ResponseBuilder response = Response.ok();
    try {
        byte[] result = null;
        RestVariable variable = getVariableFromRequest(true, varInstanceId);
        if (RestResponseFactory.BYTE_ARRAY_VARIABLE_TYPE.equals(variable.getType())) {
            result = (byte[]) variable.getValue();
            response.type("application/octet-stream");
        } else if (RestResponseFactory.SERIALIZABLE_VARIABLE_TYPE.equals(variable.getType())) {
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            ObjectOutputStream outputStream = new ObjectOutputStream(buffer);
            outputStream.writeObject(variable.getValue());
            outputStream.close();
            result = buffer.toByteArray();
            response.type("application/x-java-serialized-object");
        } else {
            throw new ActivitiObjectNotFoundException("The variable does not have a binary data stream.", null);
        }
        return result;
    } catch (IOException ioe) {
        // Re-throw IOException
        throw new ActivitiException("Unexpected exception getting variable data", ioe);
    }
}
Also used : DataResponse(org.wso2.carbon.bpmn.rest.model.common.DataResponse) Response(javax.ws.rs.core.Response) RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) ActivitiException(org.activiti.engine.ActivitiException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 30 with RestVariable

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

the class BaseRuntimeService method addGlobalVariables.

protected void addGlobalVariables(Execution execution, int variableType, Map<String, RestVariable> variableMap) {
    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)

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