Search in sources :

Example 6 with DeployedUnit

use of org.jbpm.services.api.model.DeployedUnit in project jbpm by kiegroup.

the class ProcessServiceImpl method getProcessInstanceVariable.

@Override
public Object getProcessInstanceVariable(String deploymentId, Long processInstanceId, String variableName) {
    DeployedUnit deployedUnit = deploymentService.getDeployedUnit(deploymentId);
    if (deployedUnit == null) {
        throw new DeploymentNotFoundException("No deployments available for " + deploymentId);
    }
    RuntimeManager manager = deployedUnit.getRuntimeManager();
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
    try {
        KieSession ksession = engine.getKieSession();
        return ksession.execute(new ExecutableCommand<Object>() {

            private static final long serialVersionUID = -2693525229757876896L;

            @Override
            public Object execute(org.kie.api.runtime.Context context) {
                KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
                WorkflowProcessInstance pi = (WorkflowProcessInstance) ksession.getProcessInstance(processInstanceId, true);
                if (pi == null) {
                    throw new ProcessInstanceNotFoundException("Process instance with id " + processInstanceId + " was not found");
                }
                Object variable = pi.getVariable(variableName);
                if (variable instanceof LazyLoaded<?>) {
                    ((LazyLoaded<?>) variable).load();
                }
                return variable;
            }
        });
    } catch (SessionNotFoundException e) {
        throw new ProcessInstanceNotFoundException("Process instance with id " + processInstanceId + " was not found", e);
    } finally {
        disposeRuntimeEngine(manager, engine);
    }
}
Also used : DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) KieSession(org.kie.api.runtime.KieSession) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) SessionNotFoundException(org.kie.internal.runtime.manager.SessionNotFoundException)

Example 7 with DeployedUnit

use of org.jbpm.services.api.model.DeployedUnit in project jbpm by kiegroup.

the class ProcessServiceImpl method abortWorkItem.

@Override
public void abortWorkItem(String deploymentId, Long processInstanceId, Long id) {
    DeployedUnit deployedUnit = deploymentService.getDeployedUnit(deploymentId);
    if (deployedUnit == null) {
        throw new DeploymentNotFoundException("No deployments available for " + deploymentId);
    }
    RuntimeManager manager = deployedUnit.getRuntimeManager();
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
    try {
        KieSession ksession = engine.getKieSession();
        WorkItem workItem = ((WorkItemManager) ksession.getWorkItemManager()).getWorkItem(id);
        if (workItem == null) {
            throw new WorkItemNotFoundException("Work item with id " + id + " was not found");
        }
        ksession.getWorkItemManager().abortWorkItem(id);
    } catch (SessionNotFoundException e) {
        throw new ProcessInstanceNotFoundException("Process instance with id " + processInstanceId + " was not found", e);
    } finally {
        disposeRuntimeEngine(manager, engine);
    }
}
Also used : DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) WorkItemNotFoundException(org.jbpm.services.api.WorkItemNotFoundException) KieSession(org.kie.api.runtime.KieSession) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) WorkItem(org.kie.api.runtime.process.WorkItem) WorkItemManager(org.drools.core.process.instance.WorkItemManager) SessionNotFoundException(org.kie.internal.runtime.manager.SessionNotFoundException)

Example 8 with DeployedUnit

use of org.jbpm.services.api.model.DeployedUnit in project jbpm by kiegroup.

the class ProcessServiceImpl method getProcessInstance.

@Override
public ProcessInstance getProcessInstance(String deploymentId, Long processInstanceId) {
    DeployedUnit deployedUnit = deploymentService.getDeployedUnit(deploymentId);
    if (deployedUnit == null) {
        throw new DeploymentNotFoundException("No deployments available for " + deploymentId);
    }
    RuntimeManager manager = deployedUnit.getRuntimeManager();
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
    try {
        KieSession ksession = engine.getKieSession();
        return ksession.getProcessInstance(processInstanceId);
    } catch (SessionNotFoundException e) {
        throw new ProcessInstanceNotFoundException("Process instance with id " + processInstanceId + " was not found", e);
    } finally {
        disposeRuntimeEngine(manager, engine);
    }
}
Also used : DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) KieSession(org.kie.api.runtime.KieSession) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) SessionNotFoundException(org.kie.internal.runtime.manager.SessionNotFoundException)

Example 9 with DeployedUnit

use of org.jbpm.services.api.model.DeployedUnit in project jbpm by kiegroup.

the class ProcessServiceImpl method getWorkItem.

@Override
public WorkItem getWorkItem(String deploymentId, Long processInstanceId, Long id) {
    DeployedUnit deployedUnit = deploymentService.getDeployedUnit(deploymentId);
    if (deployedUnit == null) {
        throw new DeploymentNotFoundException("No deployments available for " + deploymentId);
    }
    RuntimeManager manager = deployedUnit.getRuntimeManager();
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
    try {
        KieSession ksession = engine.getKieSession();
        WorkItem workItem = ((WorkItemManager) ksession.getWorkItemManager()).getWorkItem(id);
        if (workItem == null) {
            throw new WorkItemNotFoundException("Work item with id " + id + " was not found");
        }
        return workItem;
    } catch (SessionNotFoundException e) {
        throw new ProcessInstanceNotFoundException("Process instance with id " + processInstanceId + " was not found", e);
    } finally {
        disposeRuntimeEngine(manager, engine);
    }
}
Also used : DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) WorkItemNotFoundException(org.jbpm.services.api.WorkItemNotFoundException) KieSession(org.kie.api.runtime.KieSession) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) WorkItem(org.kie.api.runtime.process.WorkItem) WorkItemManager(org.drools.core.process.instance.WorkItemManager) SessionNotFoundException(org.kie.internal.runtime.manager.SessionNotFoundException)

Example 10 with DeployedUnit

use of org.jbpm.services.api.model.DeployedUnit in project jbpm by kiegroup.

the class ProcessServiceImpl method getProcessInstance.

@Override
public ProcessInstance getProcessInstance(String deploymentId, CorrelationKey key) {
    DeployedUnit deployedUnit = deploymentService.getDeployedUnit(deploymentId);
    if (deployedUnit == null) {
        throw new DeploymentNotFoundException("No deployments available for " + deploymentId);
    }
    RuntimeManager manager = deployedUnit.getRuntimeManager();
    RuntimeEngine engine = manager.getRuntimeEngine(CorrelationKeyContext.get(key));
    KieSession ksession = engine.getKieSession();
    try {
        return ((CorrelationAwareProcessRuntime) ksession).getProcessInstance(key);
    } finally {
        disposeRuntimeEngine(manager, engine);
    }
}
Also used : DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) CorrelationAwareProcessRuntime(org.kie.internal.process.CorrelationAwareProcessRuntime) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) KieSession(org.kie.api.runtime.KieSession)

Aggregations

DeployedUnit (org.jbpm.services.api.model.DeployedUnit)69 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)42 Test (org.junit.Test)41 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)38 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)37 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)32 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)30 DeploymentUnit (org.jbpm.services.api.model.DeploymentUnit)28 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)20 ProcessDefinition (org.jbpm.services.api.model.ProcessDefinition)19 QueryContext (org.kie.api.runtime.query.QueryContext)19 DeploymentNotFoundException (org.jbpm.services.api.DeploymentNotFoundException)18 KieSession (org.kie.api.runtime.KieSession)17 HashMap (java.util.HashMap)16 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)13 SessionNotFoundException (org.kie.internal.runtime.manager.SessionNotFoundException)13 DeploymentDescriptor (org.kie.internal.runtime.conf.DeploymentDescriptor)10 ArrayList (java.util.ArrayList)8 CoundDownDeploymentListener (org.jbpm.kie.services.test.objects.CoundDownDeploymentListener)8 File (java.io.File)7