Search in sources :

Example 1 with CorrelationAwareProcessRuntime

use of org.kie.internal.process.CorrelationAwareProcessRuntime in project drools by kiegroup.

the class StartCorrelatedProcessCommand method execute.

public ProcessInstance execute(Context context) {
    KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
    if (data != null) {
        for (Object o : data) {
            ksession.insert(o);
        }
    }
    ProcessInstance processInstance = ((CorrelationAwareProcessRuntime) ksession).startProcess(processId, correlationKey, parameters);
    if (this.outIdentifier != null) {
        ((RegistryContext) context).lookup(ExecutionResultImpl.class).setResult(this.outIdentifier, processInstance.getId());
    }
    return processInstance;
}
Also used : CorrelationAwareProcessRuntime(org.kie.internal.process.CorrelationAwareProcessRuntime) ExecutionResultImpl(org.drools.core.runtime.impl.ExecutionResultImpl) KieSession(org.kie.api.runtime.KieSession) RegistryContext(org.drools.core.command.impl.RegistryContext) ProcessInstance(org.kie.api.runtime.process.ProcessInstance)

Example 2 with CorrelationAwareProcessRuntime

use of org.kie.internal.process.CorrelationAwareProcessRuntime 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)

Example 3 with CorrelationAwareProcessRuntime

use of org.kie.internal.process.CorrelationAwareProcessRuntime in project jbpm by kiegroup.

the class PerProcessInstanceRuntimeManagerTest method testCreationOfSessionWithPersistenceByCorrelationKey.

@Test
public void testCreationOfSessionWithPersistenceByCorrelationKey() {
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-UserTask.bpmn2"), ResourceType.BPMN2).get();
    CorrelationKeyFactory keyFactory = KieInternalServices.Factory.get().newCorrelationKeyFactory();
    manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
    assertNotNull(manager);
    // ksession for process instance #1
    // since there is no process instance yet we need to get new session
    CorrelationKey key = keyFactory.newCorrelationKey("first");
    RuntimeEngine runtime = manager.getRuntimeEngine(CorrelationKeyContext.get());
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    long ksession1Id = ksession.getIdentifier();
    assertTrue(ksession1Id == 2);
    // ksession for process instance #2
    // since there is no process instance yet we need to get new session
    CorrelationKey key2 = keyFactory.newCorrelationKey("second");
    RuntimeEngine runtime2 = manager.getRuntimeEngine(CorrelationKeyContext.get());
    KieSession ksession2 = runtime2.getKieSession();
    assertNotNull(ksession2);
    long ksession2Id = ksession2.getIdentifier();
    assertTrue(ksession2Id == 3);
    ProcessInstance pi1 = ((CorrelationAwareProcessRuntime) ksession).startProcess("UserTask", key, null);
    ProcessInstance pi2 = ((CorrelationAwareProcessRuntime) ksession2).startProcess("UserTask", key2, null);
    // both processes started
    assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
    assertEquals(ProcessInstance.STATE_ACTIVE, pi2.getState());
    runtime = manager.getRuntimeEngine(CorrelationKeyContext.get(key));
    ksession = runtime.getKieSession();
    assertEquals(ksession1Id, ksession.getIdentifier());
    ksession.getWorkItemManager().completeWorkItem(1, null);
    // since process is completed now session should not be there any more
    try {
        manager.getRuntimeEngine(CorrelationKeyContext.get(key)).getKieSession();
        fail("Session for this (" + pi1.getId() + ") process instance is no more accessible");
    } catch (RuntimeException e) {
    }
    runtime2 = manager.getRuntimeEngine(CorrelationKeyContext.get(key2));
    ksession2 = runtime2.getKieSession();
    assertEquals(ksession2Id, ksession2.getIdentifier());
    ksession2.getWorkItemManager().completeWorkItem(2, null);
    // since process is completed now session should not be there any more
    try {
        manager.getRuntimeEngine(CorrelationKeyContext.get(key2)).getKieSession();
        fail("Session for this (" + pi2.getId() + ") process instance is no more accessible");
    } catch (RuntimeException e) {
    }
    manager.close();
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) CorrelationAwareProcessRuntime(org.kie.internal.process.CorrelationAwareProcessRuntime) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) CorrelationKey(org.kie.internal.process.CorrelationKey) CorrelationKeyFactory(org.kie.internal.process.CorrelationKeyFactory) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Test(org.junit.Test)

Example 4 with CorrelationAwareProcessRuntime

use of org.kie.internal.process.CorrelationAwareProcessRuntime in project jbpm by kiegroup.

the class AbstractStartProcessWithCorrelationKeyTest method testProcessesWithSameBusinessKeyNotInParallel.

@Test
public void testProcessesWithSameBusinessKeyNotInParallel() {
    createRuntimeManager("org/jbpm/test/functional/correlation/humantask.bpmn");
    RuntimeEngine runtimeEngine = getRuntimeEngine();
    KieSession ksession = runtimeEngine.getKieSession();
    TaskService taskService = runtimeEngine.getTaskService();
    ProcessInstance processInstance = ((CorrelationAwareProcessRuntime) ksession).startProcess("com.sample.bpmn.hello", getCorrelationKey(), null);
    assertProcessInstanceActive(processInstance.getId(), ksession);
    assertNodeTriggered(processInstance.getId(), "Start", "Task 1");
    // let john execute Task 1
    List<TaskSummary> list = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    TaskSummary task = list.get(0);
    logger.info("John is executing task {}", task.getName());
    taskService.start(task.getId(), "john");
    taskService.complete(task.getId(), "john", null);
    assertNodeTriggered(processInstance.getId(), "Task 2");
    ProcessInstance processInstanceCopy = ((CorrelationAwareProcessRuntime) ksession).getProcessInstance(getCorrelationKey());
    assertNotNull(processInstanceCopy);
    assertEquals(processInstance.getId(), processInstanceCopy.getId());
    // let mary execute Task 2
    list = taskService.getTasksAssignedAsPotentialOwner("mary", "en-UK");
    task = list.get(0);
    logger.info("Mary is executing task {}", task.getName());
    taskService.start(task.getId(), "mary");
    taskService.complete(task.getId(), "mary", null);
    assertNodeTriggered(processInstance.getId(), "End");
    assertProcessInstanceNotActive(processInstance.getId(), ksession);
    processInstance = ((CorrelationAwareProcessRuntime) ksession).startProcess("com.sample.bpmn.hello", getCorrelationKey(), null);
    assertProcessInstanceActive(processInstance.getId(), ksession);
    assertNodeTriggered(processInstance.getId(), "Start", "Task 1");
    // let john execute Task 1
    list = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    task = list.get(0);
    logger.info("John is executing task {}", task.getName());
    taskService.start(task.getId(), "john");
    taskService.complete(task.getId(), "john", null);
    assertNodeTriggered(processInstance.getId(), "Task 2");
    processInstanceCopy = ((CorrelationAwareProcessRuntime) ksession).getProcessInstance(getCorrelationKey());
    assertNotNull(processInstanceCopy);
    assertEquals(processInstance.getId(), processInstanceCopy.getId());
    // let mary execute Task 2
    list = taskService.getTasksAssignedAsPotentialOwner("mary", "en-UK");
    task = list.get(0);
    logger.info("Mary is executing task {}", task.getName());
    taskService.start(task.getId(), "mary");
    taskService.complete(task.getId(), "mary", null);
    assertNodeTriggered(processInstance.getId(), "End");
    assertProcessInstanceNotActive(processInstance.getId(), ksession);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) CorrelationAwareProcessRuntime(org.kie.internal.process.CorrelationAwareProcessRuntime) TaskService(org.kie.api.task.TaskService) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 5 with CorrelationAwareProcessRuntime

use of org.kie.internal.process.CorrelationAwareProcessRuntime in project jbpm by kiegroup.

the class AbstractStartProcessWithCorrelationKeyTest method testCreateAndStartProcessWithBusinessKey.

@Test
public void testCreateAndStartProcessWithBusinessKey() {
    createRuntimeManager("org/jbpm/test/functional/correlation/humantask.bpmn");
    RuntimeEngine runtimeEngine = getRuntimeEngine();
    KieSession ksession = runtimeEngine.getKieSession();
    TaskService taskService = runtimeEngine.getTaskService();
    ProcessInstance processInstance = ((CorrelationAwareProcessRuntime) ksession).createProcessInstance("com.sample.bpmn.hello", getCorrelationKey(), null);
    ksession.startProcessInstance(processInstance.getId());
    assertProcessInstanceActive(processInstance.getId(), ksession);
    assertNodeTriggered(processInstance.getId(), "Start", "Task 1");
    // let john execute Task 1
    List<TaskSummary> list = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    TaskSummary task = list.get(0);
    logger.info("John is executing task {}", task.getName());
    taskService.start(task.getId(), "john");
    taskService.complete(task.getId(), "john", null);
    assertNodeTriggered(processInstance.getId(), "Task 2");
    ProcessInstance processInstanceCopy = ((CorrelationAwareProcessRuntime) ksession).getProcessInstance(getCorrelationKey());
    assertNotNull(processInstanceCopy);
    assertEquals(processInstance.getId(), processInstanceCopy.getId());
    // let mary execute Task 2
    list = taskService.getTasksAssignedAsPotentialOwner("mary", "en-UK");
    task = list.get(0);
    logger.info("Mary is executing task {}", task.getName());
    taskService.start(task.getId(), "mary");
    taskService.complete(task.getId(), "mary", null);
    assertNodeTriggered(processInstance.getId(), "End");
    assertProcessInstanceNotActive(processInstance.getId(), ksession);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) CorrelationAwareProcessRuntime(org.kie.internal.process.CorrelationAwareProcessRuntime) TaskService(org.kie.api.task.TaskService) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Aggregations

CorrelationAwareProcessRuntime (org.kie.internal.process.CorrelationAwareProcessRuntime)14 KieSession (org.kie.api.runtime.KieSession)11 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)11 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)10 Test (org.junit.Test)8 TaskService (org.kie.api.task.TaskService)7 TaskSummary (org.kie.api.task.model.TaskSummary)7 CorrelationKey (org.kie.internal.process.CorrelationKey)4 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)3 CorrelationKeyFactory (org.kie.internal.process.CorrelationKeyFactory)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 RegistryContext (org.drools.core.command.impl.RegistryContext)2 ExecutionResultImpl (org.drools.core.runtime.impl.ExecutionResultImpl)2 ProcessInstance (org.jbpm.process.instance.ProcessInstance)2 ProcessInstanceImpl (org.jbpm.process.instance.impl.ProcessInstanceImpl)2 WorkflowProcessInstanceImpl (org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl)2 Process (org.kie.api.definition.process.Process)2 HashMap (java.util.HashMap)1 Matcher (java.util.regex.Matcher)1