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;
}
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);
}
}
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();
}
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);
}
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);
}
Aggregations