Search in sources :

Example 81 with RuntimeService

use of org.activiti.engine.RuntimeService in project carbon-business-process by wso2.

the class BaseProcessInstanceService method suspendProcessInstance.

protected ProcessInstanceResponse suspendProcessInstance(ProcessInstance processInstance, RestResponseFactory restResponseFactory, UriInfo uriInfo) {
    if (processInstance.isSuspended()) {
        throw new BPMNConflictException("Process instance with id '" + processInstance.getId() + "' is already suspended.");
    }
    RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
    runtimeService.suspendProcessInstanceById(processInstance.getId());
    ProcessInstanceResponse response = restResponseFactory.createProcessInstanceResponse(processInstance, uriInfo.getBaseUri().toString());
    // No need to re-fetch the instance, just alter the suspended state of the result-object
    response.setSuspended(true);
    return response;
}
Also used : BPMNConflictException(org.wso2.carbon.bpmn.rest.common.exception.BPMNConflictException) RuntimeService(org.activiti.engine.RuntimeService) ProcessInstanceResponse(org.wso2.carbon.bpmn.rest.model.runtime.ProcessInstanceResponse)

Example 82 with RuntimeService

use of org.activiti.engine.RuntimeService in project carbon-business-process by wso2.

the class BaseProcessInstanceService method getProcessInstanceFromRequest.

protected ProcessInstance getProcessInstanceFromRequest(String processInstanceId) {
    RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).includeProcessVariables().singleResult();
    if (processInstance == null) {
        throw new ActivitiObjectNotFoundException(" Could not find a process instance with id " + processInstanceId + "'.", ProcessInstance.class);
    }
    return processInstance;
}
Also used : RuntimeService(org.activiti.engine.RuntimeService) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

Example 83 with RuntimeService

use of org.activiti.engine.RuntimeService in project carbon-business-process by wso2.

the class BaseExecutionService method deleteAllLocalVariables.

public void deleteAllLocalVariables(Execution execution) {
    RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
    Collection<String> currentVariables = runtimeService.getVariablesLocal(execution.getId()).keySet();
    runtimeService.removeVariablesLocal(execution.getId(), currentVariables);
}
Also used : RuntimeService(org.activiti.engine.RuntimeService)

Example 84 with RuntimeService

use of org.activiti.engine.RuntimeService in project carbon-business-process by wso2.

the class BaseExecutionService method getVariableFromRequest.

public RestVariable getVariableFromRequest(Execution execution, String variableName, String scope, boolean includeBinary, UriInfo uriInfo) {
    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, uriInfo);
    }
}
Also used : RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) RuntimeService(org.activiti.engine.RuntimeService) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

Example 85 with RuntimeService

use of org.activiti.engine.RuntimeService in project carbon-business-process by wso2.

the class BaseExecutionService method setVariable.

/*    protected RestVariable setBinaryVariable(@Context HttpServletRequest httpServletRequest,
                                             Execution execution, int responseVariableType, boolean isNew, UriInfo uriInfo) {

        byte[] byteArray = null;
        try {
            byteArray = Utils.processMultiPartFile(httpServletRequest, "file content");
        } catch (IOException e) {
            throw new ActivitiIllegalArgumentException("No file content was found in request body during multipart " +
                    "processing" +
                    ".");
        }

        if (byteArray == null) {
            throw new ActivitiIllegalArgumentException("No file content was found in request body.");

        }
        String variableScope = uriInfo.getQueryParameters().getFirst("scope");
        String variableName = uriInfo.getQueryParameters().getFirst("name");
        String variableType = uriInfo.getQueryParameters().getFirst("type");

        if (log.isDebugEnabled()) {
            log.debug("variableScope:" + variableScope + " variableName:" + variableName + " variableType:" + variableType);
        }

        try {

            // Validate input and set defaults
            if (variableName == null) {
                throw new ActivitiIllegalArgumentException("No variable name was found in request body.");
            }

            if (variableType != null) {
                if (!RestResponseFactory.BYTE_ARRAY_VARIABLE_TYPE.equals(variableType) && !RestResponseFactory.SERIALIZABLE_VARIABLE_TYPE.equals(variableType)) {
                    throw new ActivitiIllegalArgumentException("Only 'binary' and 'serializable' are supported as variable type.");
                }
            } else {
                variableType = RestResponseFactory.BYTE_ARRAY_VARIABLE_TYPE;
            }

            RestVariable.RestVariableScope scope = RestVariable.RestVariableScope.LOCAL;
            if (variableScope != null) {
                scope = RestVariable.getScopeFromString(variableScope);
            }

            if (variableType.equals(RestResponseFactory.BYTE_ARRAY_VARIABLE_TYPE)) {
                // Use raw bytes as variable value
                setVariable(execution, variableName, byteArray, scope, isNew);

            } else {
                // Try deserializing the object
                InputStream inputStream = new ByteArrayInputStream(byteArray);
                ObjectInputStream stream = new ObjectInputStream(inputStream);
                Object value = stream.readObject();
                setVariable(execution, variableName, value, scope, isNew);
                stream.close();
            }

            if (responseVariableType == RestResponseFactory.VARIABLE_PROCESS) {
                return new RestResponseFactory().createBinaryRestVariable(variableName, scope, variableType,
                        null, null, execution.getId(), uriInfo.getBaseUri().toString());
            } else {
                return new RestResponseFactory().createBinaryRestVariable(variableName, scope, variableType, null,
                        execution.getId(), null, uriInfo.getBaseUri().toString());
            }

        } catch (IOException ioe) {
            throw new ActivitiIllegalArgumentException("Could not process multipart content", ioe);
        } catch (ClassNotFoundException ioe) {
            throw new BPMNContentNotSupportedException("The provided body contains a serialized object for which the class is nog found: " + ioe
                    .getMessage());
        }

    }*/
protected void setVariable(Execution execution, String name, Object value, RestVariable.RestVariableScope scope, boolean isNew) {
    // Create can only be done on new variables. Existing variables should be updated using PUT
    boolean hasVariable = hasVariableOnScope(execution, name, scope);
    if (isNew && hasVariable) {
        throw new ActivitiException("Variable '" + name + "' is already present on execution '" + execution.getId() + "'.");
    }
    if (!isNew && !hasVariable) {
        throw new ActivitiObjectNotFoundException("Execution '" + execution.getId() + "' doesn't have a variable with name: '" + name + "'.", null);
    }
    RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
    if (scope == RestVariable.RestVariableScope.LOCAL) {
        runtimeService.setVariableLocal(execution.getId(), name, value);
    } else {
        if (execution.getParentId() != null) {
            runtimeService.setVariable(execution.getParentId(), name, value);
        } else {
            runtimeService.setVariable(execution.getId(), name, value);
        }
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) RuntimeService(org.activiti.engine.RuntimeService) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

Aggregations

RuntimeService (org.activiti.engine.RuntimeService)92 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)35 Test (org.junit.Test)25 ProcessEngine (org.activiti.engine.ProcessEngine)16 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)15 TaskService (org.activiti.engine.TaskService)14 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)14 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)13 Deployment (org.activiti.engine.test.Deployment)13 RestVariable (org.wso2.carbon.bpmn.rest.engine.variable.RestVariable)12 RepositoryService (org.activiti.engine.RepositoryService)10 HashMap (java.util.HashMap)8 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)8 Task (org.activiti.engine.task.Task)8 ArrayList (java.util.ArrayList)7 Path (javax.ws.rs.Path)7 HistoricProcessInstanceQuery (org.activiti.engine.history.HistoricProcessInstanceQuery)7 Execution (org.activiti.engine.runtime.Execution)7 Produces (javax.ws.rs.Produces)6 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)6