Search in sources :

Example 61 with RuntimeService

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

the class ProcessInstanceService method deleteVariable.

@DELETE
@Path("/{processInstanceId}/variables/{variableName}")
public Response deleteVariable(@PathParam("processInstanceId") String processInstanceId, @PathParam("variableName") String variableName) {
    String scope = uriInfo.getQueryParameters().getFirst("scope");
    Execution execution = getExecutionInstanceFromRequest(processInstanceId);
    // 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) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 62 with RuntimeService

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

the class ProcessInstanceService method setVariable.

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
    if (log.isDebugEnabled()) {
        log.debug("Going to invoke has variable from set binary variable");
    }
    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)

Example 63 with RuntimeService

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

the class ProcessInstanceService method deleteIdentityLink.

@DELETE
@Path("/{processInstanceId}/identitylinks/users/{identityId}/{type}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response deleteIdentityLink(@PathParam("processInstanceId") String processInstanceId, @PathParam("identityId") String identityId, @PathParam("type") String type) {
    ProcessInstance processInstance = getProcessInstanceFromRequest(processInstanceId);
    validateIdentityLinkArguments(identityId, type);
    getIdentityLink(identityId, type, processInstance.getId());
    RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
    runtimeService.deleteUserIdentityLink(processInstance.getId(), identityId, type);
    return Response.ok().status(Response.Status.NO_CONTENT).build();
}
Also used : RuntimeService(org.activiti.engine.RuntimeService) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces)

Example 64 with RuntimeService

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

the class ProcessInstanceService method createIdentityLink.

@POST
@Path("/{processInstanceId}/identitylinks")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response createIdentityLink(@PathParam("processInstanceId") String processInstanceId, RestIdentityLink identityLink) {
    ProcessInstance processInstance = getProcessInstanceFromRequest(processInstanceId);
    if (identityLink.getGroup() != null) {
        throw new ActivitiIllegalArgumentException("Only user identity links are supported on a process instance.");
    }
    if (identityLink.getUser() == null) {
        throw new ActivitiIllegalArgumentException("The user is required.");
    }
    if (identityLink.getType() == null) {
        throw new ActivitiIllegalArgumentException("The identity link type is required.");
    }
    RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
    runtimeService.addUserIdentityLink(processInstance.getId(), identityLink.getUser(), identityLink.getType());
    RestIdentityLink restIdentityLink = new RestResponseFactory().createRestIdentityLink(identityLink.getType(), identityLink.getUser(), identityLink.getGroup(), null, null, processInstance.getId(), uriInfo.getBaseUri().toString());
    return Response.ok().status(Response.Status.CREATED).entity(restIdentityLink).build();
}
Also used : RestIdentityLink(org.wso2.carbon.bpmn.rest.model.common.RestIdentityLink) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) RuntimeService(org.activiti.engine.RuntimeService) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 65 with RuntimeService

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

the class ProcessInstanceService method deleteProcessInstance.

@DELETE
@Path("/{processInstanceId}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response deleteProcessInstance(@PathParam("processInstanceId") String processInstanceId) {
    RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
    String deleteReason = uriInfo.getQueryParameters().getFirst("deleteReason");
    if (deleteReason == null) {
        deleteReason = "";
    }
    ProcessInstance processInstance = getProcessInstanceFromRequest(processInstanceId);
    runtimeService.deleteProcessInstance(processInstance.getId(), deleteReason);
    return Response.ok().status(Response.Status.NO_CONTENT).build();
}
Also used : RuntimeService(org.activiti.engine.RuntimeService) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces)

Aggregations

RuntimeService (org.activiti.engine.RuntimeService)77 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)32 ProcessEngine (org.activiti.engine.ProcessEngine)16 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)15 Test (org.junit.Test)14 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)14 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)13 RestVariable (org.wso2.carbon.bpmn.rest.engine.variable.RestVariable)12 RepositoryService (org.activiti.engine.RepositoryService)10 TaskService (org.activiti.engine.TaskService)10 HashMap (java.util.HashMap)8 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)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 Task (org.activiti.engine.task.Task)6 BPMNInstance (org.wso2.carbon.bpmn.core.mgt.model.BPMNInstance)6 ActivitiException (org.activiti.engine.ActivitiException)5