Search in sources :

Example 66 with Variable

use of org.wso2.siddhi.query.api.expression.Variable in project carbon-business-process by wso2.

the class WorkflowTaskService method getVariableData.

@GET
@Path("/{taskId}/variables/{variableName}/data")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getVariableData(@PathParam("taskId") String taskId, @PathParam("variableName") String variableName) {
    String scope = uriInfo.getQueryParameters().getFirst("scope");
    Response.ResponseBuilder responseBuilder = Response.ok();
    try {
        byte[] result = null;
        RestVariable variable = getVariableFromRequest(taskId, variableName, scope, true, uriInfo.getBaseUri().toString());
        if (RestResponseFactory.BYTE_ARRAY_VARIABLE_TYPE.equals(variable.getType())) {
            result = (byte[]) variable.getValue();
            responseBuilder.type(MediaType.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 error 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)

Example 67 with Variable

use of org.wso2.siddhi.query.api.expression.Variable in project carbon-business-process by wso2.

the class WorkflowTaskService method setSimpleVariable.

protected RestVariable setSimpleVariable(RestVariable restVariable, Task task, 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;
    }
    RestResponseFactory restResponseFactory = new RestResponseFactory();
    Object actualVariableValue = restResponseFactory.getVariableValue(restVariable);
    setVariable(task, restVariable.getName(), actualVariableValue, scope, isNew);
    return restResponseFactory.createRestVariable(restVariable.getName(), actualVariableValue, scope, task.getId(), RestResponseFactory.VARIABLE_TASK, false, uriInfo.getBaseUri().toString());
}
Also used : RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory)

Example 68 with Variable

use of org.wso2.siddhi.query.api.expression.Variable in project carbon-business-process by wso2.

the class HistoricDetailService method getVariableData.

@GET
@Path("/{detailId}/data")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getVariableData(@PathParam("detailId") String detailId) {
    try {
        byte[] result = null;
        RestVariable variable = getVariableFromRequest(true, detailId);
        Response.ResponseBuilder response = Response.ok();
        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 response.entity(result).build();
    } catch (IOException ioe) {
        // Re-throw IOException
        throw new ActivitiException("Unexpected exception getting variable data", ioe);
    }
}
Also used : RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) DataResponse(org.wso2.carbon.bpmn.rest.model.common.DataResponse) Response(javax.ws.rs.core.Response) 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) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 69 with Variable

use of org.wso2.siddhi.query.api.expression.Variable in project carbon-business-process by wso2.

the class HistoricProcessInstanceService method getVariableFromRequest.

public RestVariable getVariableFromRequest(boolean includeBinary, String processInstanceId, String variableName) {
    HistoryService historyService = BPMNOSGIService.getHistoryService();
    HistoricProcessInstance processObject = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).includeProcessVariables().singleResult();
    if (processObject == null) {
        throw new ActivitiObjectNotFoundException("Historic process instance '" + processInstanceId + "' couldn't be found.", HistoricProcessInstanceEntity.class);
    }
    Object value = processObject.getProcessVariables().get(variableName);
    if (value == null) {
        throw new ActivitiObjectNotFoundException("Historic process instance '" + processInstanceId + "' variable value for " + variableName + " couldn't be found.", VariableInstanceEntity.class);
    } else {
        return new RestResponseFactory().createRestVariable(variableName, value, null, processInstanceId, RestResponseFactory.VARIABLE_HISTORY_PROCESS, includeBinary, uriInfo.getBaseUri().toString());
    }
}
Also used : RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance)

Example 70 with Variable

use of org.wso2.siddhi.query.api.expression.Variable in project carbon-business-process by wso2.

the class HistoricVariableInstanceService method getVariableFromRequest.

protected RestVariable getVariableFromRequest(boolean includeBinary, String varInstanceId) {
    HistoryService historyService = BPMNOSGIService.getHistoryService();
    HistoricVariableInstance varObject = historyService.createHistoricVariableInstanceQuery().id(varInstanceId).singleResult();
    if (varObject == null) {
        throw new ActivitiObjectNotFoundException("Historic variable instance '" + varInstanceId + "' couldn't be found.", VariableInstanceEntity.class);
    } else {
        return new RestResponseFactory().createRestVariable(varObject.getVariableName(), varObject.getValue(), null, varInstanceId, RestResponseFactory.VARIABLE_HISTORY_VARINSTANCE, includeBinary, uriInfo.getBaseUri().toString());
    }
}
Also used : RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) HistoryService(org.activiti.engine.HistoryService) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

Aggregations

RestVariable (org.wso2.carbon.bpmn.rest.engine.variable.RestVariable)37 ArrayList (java.util.ArrayList)31 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)31 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)30 Test (org.testng.annotations.Test)28 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)26 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)26 HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)26 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)23 BJSON (org.ballerinalang.model.values.BJSON)22 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)18 IOException (java.io.IOException)17 BVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)17 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)17 Variable (org.wso2.siddhi.query.api.expression.Variable)17 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)16 BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)15 DataResponse (org.wso2.carbon.bpmn.rest.model.common.DataResponse)15 Response (javax.ws.rs.core.Response)14 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)13