Search in sources :

Example 56 with ProcessInstanceNotFoundException

use of org.jbpm.services.api.ProcessInstanceNotFoundException in project jbpm by kiegroup.

the class ProcessServiceImpl method setProcessVariables.

@Override
public void setProcessVariables(String deploymentId, Long processInstanceId, Map<String, Object> variables) {
    DeployedUnit deployedUnit = deploymentService.getDeployedUnit(deploymentId);
    if (deployedUnit == null) {
        throw new DeploymentNotFoundException("No deployments available for " + deploymentId);
    }
    RuntimeManager manager = deployedUnit.getRuntimeManager();
    variables = process(variables, ((InternalRuntimeManager) manager).getEnvironment().getClassLoader());
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
    try {
        KieSession ksession = engine.getKieSession();
        ProcessInstance pi = ksession.getProcessInstance(processInstanceId);
        if (pi == null) {
            throw new ProcessInstanceNotFoundException("Process instance with id " + processInstanceId + " was not found");
        }
        ksession.execute(new SetProcessInstanceVariablesCommand(processInstanceId, variables));
    } 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) SetProcessInstanceVariablesCommand(org.drools.core.command.runtime.process.SetProcessInstanceVariablesCommand) KieSession(org.kie.api.runtime.KieSession) RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) SessionNotFoundException(org.kie.internal.runtime.manager.SessionNotFoundException)

Aggregations

ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)56 KieSession (org.kie.api.runtime.KieSession)21 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)21 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)16 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)16 DeploymentNotFoundException (org.jbpm.services.api.DeploymentNotFoundException)13 DeployedUnit (org.jbpm.services.api.model.DeployedUnit)13 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)13 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)13 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)13 SessionNotFoundException (org.kie.internal.runtime.manager.SessionNotFoundException)13 DeploymentUnit (org.jbpm.services.api.model.DeploymentUnit)10 After (org.junit.After)10 RegistryContext (org.drools.core.command.impl.RegistryContext)8 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)7 RuleFlowProcessInstance (org.jbpm.ruleflow.instance.RuleFlowProcessInstance)7 Test (org.junit.Test)7 HashMap (java.util.HashMap)4 WorkItem (org.kie.api.runtime.process.WorkItem)4 ArrayList (java.util.ArrayList)3