Search in sources :

Example 21 with SessionNotFoundException

use of org.kie.internal.runtime.manager.SessionNotFoundException in project jbpm by kiegroup.

the class GlobalTimerServiceBaseTest method testHumanTaskDeadlineWithGlobalTimerService.

@Test
public void testHumanTaskDeadlineWithGlobalTimerService() throws Exception {
    environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/HumanTaskWithDeadlines.bpmn"), ResourceType.BPMN2).schedulerService(globalScheduler).get();
    manager = getManager(environment, true);
    RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession = runtime.getKieSession();
    ProcessInstance processInstance = ksession.startProcess("htdeadlinetest");
    assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
    List<TaskSummary> krisTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("krisv", "en-UK");
    assertEquals(1, krisTasks.size());
    List<TaskSummary> johnTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertEquals(0, johnTasks.size());
    List<TaskSummary> maryTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("mary", "en-UK");
    assertEquals(0, maryTasks.size());
    manager.disposeRuntimeEngine(runtime);
    // now wait for 2 seconds for first reassignment
    Thread.sleep(3000);
    runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
    krisTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("krisv", "en-UK");
    assertEquals(0, krisTasks.size());
    johnTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertEquals(1, johnTasks.size());
    maryTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("mary", "en-UK");
    assertEquals(0, maryTasks.size());
    runtime.getTaskService().start(johnTasks.get(0).getId(), "john");
    manager.disposeRuntimeEngine(runtime);
    // now wait for 2 more seconds for second reassignment
    Thread.sleep(2000);
    runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
    krisTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("krisv", "en-UK");
    assertEquals(0, krisTasks.size());
    johnTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertEquals(1, johnTasks.size());
    maryTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("mary", "en-UK");
    assertEquals(0, maryTasks.size());
    manager.disposeRuntimeEngine(runtime);
    // now wait for 1 seconds to make sure that reassignment did not happen any more since task was already started
    Thread.sleep(3000);
    runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
    krisTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("krisv", "en-UK");
    assertEquals(0, krisTasks.size());
    johnTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertEquals(0, johnTasks.size());
    maryTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("mary", "en-UK");
    assertEquals(1, maryTasks.size());
    runtime.getTaskService().start(maryTasks.get(0).getId(), "mary");
    runtime.getTaskService().complete(maryTasks.get(0).getId(), "mary", null);
    manager.disposeRuntimeEngine(runtime);
    // now wait for 2 seconds to make sure that reassignment did not happen any more since task was completed
    Thread.sleep(2000);
    try {
        runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
        ksession = runtime.getKieSession();
        processInstance = ksession.getProcessInstance(processInstance.getId());
        assertNull(processInstance);
    } catch (SessionNotFoundException e) {
    // this can be thrown for per process instance strategy as instance has already been completed
    }
    manager.disposeRuntimeEngine(runtime);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) SessionNotFoundException(org.kie.internal.runtime.manager.SessionNotFoundException) Test(org.junit.Test)

Example 22 with SessionNotFoundException

use of org.kie.internal.runtime.manager.SessionNotFoundException in project jbpm by kiegroup.

the class ProcessServiceImpl method getWorkItemByProcessInstance.

@Override
public List<WorkItem> getWorkItemByProcessInstance(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();
        List<WorkItem> workItems = new ArrayList<>();
        Collection<NodeInstanceDesc> nodes = dataService.getProcessInstanceHistoryActive(processInstanceId, null);
        for (NodeInstanceDesc node : nodes) {
            if (node.getWorkItemId() != null) {
                workItems.add(((WorkItemManager) ksession.getWorkItemManager()).getWorkItem(node.getWorkItemId()));
            }
        }
        return workItems;
    } 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) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) WorkItem(org.kie.api.runtime.process.WorkItem) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) SessionNotFoundException(org.kie.internal.runtime.manager.SessionNotFoundException)

Example 23 with SessionNotFoundException

use of org.kie.internal.runtime.manager.SessionNotFoundException in project jbpm by kiegroup.

the class ProcessServiceImpl method signalProcessInstance.

@Override
public void signalProcessInstance(String deploymentId, Long processInstanceId, String signalName, Object event) {
    DeployedUnit deployedUnit = deploymentService.getDeployedUnit(deploymentId);
    if (deployedUnit == null) {
        throw new DeploymentNotFoundException("No deployments available for " + deploymentId);
    }
    RuntimeManager manager = deployedUnit.getRuntimeManager();
    event = process(event, ((InternalRuntimeManager) manager).getEnvironment().getClassLoader());
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
    try {
        KieSession ksession = engine.getKieSession();
        ksession.signalEvent(signalName, event, 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 24 with SessionNotFoundException

use of org.kie.internal.runtime.manager.SessionNotFoundException in project jbpm by kiegroup.

the class ProcessServiceImpl method completeWorkItem.

@Override
public void completeWorkItem(String deploymentId, Long processInstanceId, Long id, Map<String, Object> results) {
    DeployedUnit deployedUnit = deploymentService.getDeployedUnit(deploymentId);
    if (deployedUnit == null) {
        throw new DeploymentNotFoundException("No deployments available for " + deploymentId);
    }
    RuntimeManager manager = deployedUnit.getRuntimeManager();
    results = process(results, ((InternalRuntimeManager) manager).getEnvironment().getClassLoader());
    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().completeWorkItem(id, results);
    } 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 25 with SessionNotFoundException

use of org.kie.internal.runtime.manager.SessionNotFoundException in project jbpm by kiegroup.

the class ProcessServiceImpl method getAvailableSignals.

@Override
public Collection<String> getAvailableSignals(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();
        ProcessInstance processInstance = ksession.getProcessInstance(processInstanceId);
        Collection<String> activeSignals = new ArrayList<>();
        if (processInstance != null) {
            ((ProcessInstanceImpl) processInstance).setProcess(ksession.getKieBase().getProcess(processInstance.getProcessId()));
            Collection<NodeInstance> activeNodes = ((WorkflowProcessInstance) processInstance).getNodeInstances();
            Collection<String> activeBoundaryNodesSignals = getActiveBoundaryNodesSignals(processInstance, activeNodes);
            activeSignals.addAll(collectActiveSignals(activeNodes));
            activeSignals.addAll(activeBoundaryNodesSignals);
        }
        return activeSignals;
    } 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) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) ProcessInstanceImpl(org.jbpm.process.instance.impl.ProcessInstanceImpl) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) ArrayList(java.util.ArrayList) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) 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) NodeInstance(org.kie.api.runtime.process.NodeInstance) EventNodeInstance(org.jbpm.workflow.instance.node.EventNodeInstance) CompositeNodeInstance(org.jbpm.workflow.instance.node.CompositeNodeInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) SessionNotFoundException(org.kie.internal.runtime.manager.SessionNotFoundException)

Aggregations

SessionNotFoundException (org.kie.internal.runtime.manager.SessionNotFoundException)28 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)27 KieSession (org.kie.api.runtime.KieSession)25 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)15 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)14 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)14 DeploymentNotFoundException (org.jbpm.services.api.DeploymentNotFoundException)13 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)13 DeployedUnit (org.jbpm.services.api.model.DeployedUnit)13 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)8 WorkflowProcessInstance (org.jbpm.workflow.instance.WorkflowProcessInstance)8 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)7 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)6 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)6 HashMap (java.util.HashMap)5 ProcessNodeLeftEvent (org.kie.api.event.process.ProcessNodeLeftEvent)5 TaskSummary (org.kie.api.task.model.TaskSummary)5 WorkItem (org.kie.api.runtime.process.WorkItem)4 Properties (java.util.Properties)3