Search in sources :

Example 51 with Scope

use of org.wso2.ballerinalang.compiler.semantics.model.Scope 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 52 with Scope

use of org.wso2.ballerinalang.compiler.semantics.model.Scope in project carbon-business-process by wso2.

the class ProcessInstanceService method getVariableFromRequest.

public RestVariable getVariableFromRequest(Execution execution, String variableName, String scope, boolean includeBinary) {
    boolean variableFound = false;
    Object value = null;
    if (execution == null) {
        throw new ActivitiObjectNotFoundException("Could not find an execution", Execution.class);
    }
    RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
    RestVariable.RestVariableScope variableScope = RestVariable.getScopeFromString(scope);
    if (variableScope == null) {
        // First, check local variables (which have precedence when no scope is supplied)
        if (runtimeService.hasVariableLocal(execution.getId(), variableName)) {
            value = runtimeService.getVariableLocal(execution.getId(), variableName);
            variableScope = RestVariable.RestVariableScope.LOCAL;
            variableFound = true;
        } else {
            if (execution.getParentId() != null) {
                value = runtimeService.getVariable(execution.getParentId(), variableName);
                variableScope = RestVariable.RestVariableScope.GLOBAL;
                variableFound = true;
            }
        }
    } else if (variableScope == RestVariable.RestVariableScope.GLOBAL) {
        // Use parent to get variables
        if (execution.getParentId() != null) {
            value = runtimeService.getVariable(execution.getParentId(), variableName);
            variableScope = RestVariable.RestVariableScope.GLOBAL;
            variableFound = true;
        }
    } else if (variableScope == RestVariable.RestVariableScope.LOCAL) {
        value = runtimeService.getVariableLocal(execution.getId(), variableName);
        variableScope = RestVariable.RestVariableScope.LOCAL;
        variableFound = true;
    }
    if (!variableFound) {
        throw new ActivitiObjectNotFoundException("Execution '" + execution.getId() + "' doesn't have a variable with name: '" + variableName + "'.", VariableInstanceEntity.class);
    } else {
        return constructRestVariable(variableName, value, variableScope, execution.getId(), includeBinary);
    }
}
Also used : RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) RuntimeService(org.activiti.engine.RuntimeService) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

Example 53 with Scope

use of org.wso2.ballerinalang.compiler.semantics.model.Scope in project carbon-business-process by wso2.

the class ProcessInstanceService method getVariableDataByteArray.

protected byte[] getVariableDataByteArray(Execution execution, String variableName, String scope, Response.ResponseBuilder responseBuilder) {
    try {
        byte[] result;
        RestVariable variable = getVariableFromRequest(execution, variableName, scope, true);
        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 result;
    } catch (IOException ioe) {
        throw new ActivitiException("Error getting variable " + variableName, ioe);
    }
}
Also used : 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 54 with Scope

use of org.wso2.ballerinalang.compiler.semantics.model.Scope in project carbon-business-process by wso2.

the class ProcessInstanceService method getVariable.

@GET
@Path("/{processInstanceId}/variables/{variableName}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getVariable(@PathParam("processInstanceId") String processInstanceId, @PathParam("variableName") String variableName) {
    String scope = uriInfo.getQueryParameters().getFirst("scope");
    Execution execution = getExecutionInstanceFromRequest(processInstanceId);
    RestVariable restVariable = getVariableFromRequest(execution, variableName, scope, false);
    return Response.ok().entity(restVariable).build();
}
Also used : RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) Execution(org.activiti.engine.runtime.Execution) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) GET(javax.ws.rs.GET)

Example 55 with Scope

use of org.wso2.ballerinalang.compiler.semantics.model.Scope in project carbon-business-process by wso2.

the class ExecutionService method deleteVariable.

@DELETE
@Path("/{executionId}/variables/{variableName}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response deleteVariable(@PathParam("executionId") String executionId, @PathParam("variableName") String variableName) {
    String scope = uriInfo.getQueryParameters().getFirst("scope");
    Execution execution = getExecutionFromRequest(executionId);
    // Determine scope
    RestVariable.RestVariableScope variableScope = RestVariable.RestVariableScope.LOCAL;
    if (scope != null) {
        variableScope = RestVariable.getScopeFromString(scope);
    }
    if (!hasVariableOnScope(execution, variableName, variableScope)) {
        throw new ActivitiObjectNotFoundException("Execution '" + execution.getId() + "' doesn't have a variable '" + variableName + "' in scope " + variableScope.name().toLowerCase(), VariableInstanceEntity.class);
    }
    RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
    if (variableScope == RestVariable.RestVariableScope.LOCAL) {
        runtimeService.removeVariableLocal(execution.getId(), variableName);
    } else {
        // Safe to use parentId, as the hasVariableOnScope would have stopped a global-var update on a root-execution
        runtimeService.removeVariable(execution.getParentId(), variableName);
    }
    return Response.ok().status(Response.Status.NO_CONTENT).build();
}
Also used : RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) Execution(org.activiti.engine.runtime.Execution) RuntimeService(org.activiti.engine.RuntimeService) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

Aggregations

Scope (org.wso2.carbon.apimgt.core.models.Scope)41 HashMap (java.util.HashMap)25 RestVariable (org.wso2.carbon.bpmn.rest.engine.variable.RestVariable)25 Test (org.testng.annotations.Test)23 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)19 Response (javax.ws.rs.core.Response)16 ScopeInfo (org.wso2.carbon.apimgt.core.auth.dto.ScopeInfo)15 FileInputStream (java.io.FileInputStream)14 API (org.wso2.carbon.apimgt.core.models.API)14 ArrayList (java.util.ArrayList)13 KeyManager (org.wso2.carbon.apimgt.core.api.KeyManager)13 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)13 Map (java.util.Map)12 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)12 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)12 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)12 IdentityProvider (org.wso2.carbon.apimgt.core.api.IdentityProvider)11 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)11 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)10 Scope (org.wso2.ballerinalang.compiler.semantics.model.Scope)10