use of org.kie.internal.process.CorrelationAwareProcessRuntime in project jbpm by kiegroup.
the class AsyncStartProcessCommand method execute.
@SuppressWarnings("unchecked")
@Override
public ExecutionResults execute(CommandContext ctx) throws Exception {
String deploymentId = getDeploymentId(ctx);
String processId = (String) getData("ProcessId", ctx);
String correlationKey = (String) getData("CorrelationKey", ctx);
Map<String, Object> variables = (Map<String, Object>) getData("Variables", ctx);
if (deploymentId == null || processId == null) {
throw new IllegalArgumentException("Deployment id and process id is required");
}
RuntimeManager runtimeManager = RuntimeManagerRegistry.get().getManager(deploymentId);
if (runtimeManager == null) {
throw new IllegalArgumentException("No runtime manager found for deployment id " + deploymentId);
}
RuntimeEngine engine = runtimeManager.getRuntimeEngine(ProcessInstanceIdContext.get());
try {
if (correlationKey == null || correlationKey.isEmpty()) {
engine.getKieSession().startProcess(processId, variables);
} else {
String[] correlationKeyProperties = correlationKey.split(",");
CorrelationKey ck = correlationKeyFactory.newCorrelationKey(Arrays.asList(correlationKeyProperties));
((CorrelationAwareProcessRuntime) engine.getKieSession()).startProcess(processId, ck, variables);
}
return new ExecutionResults();
} finally {
runtimeManager.disposeRuntimeEngine(engine);
}
}
use of org.kie.internal.process.CorrelationAwareProcessRuntime in project jbpm by kiegroup.
the class AbstractStartProcessWithCorrelationKeyTest method testProcessWithMultiValuedBusinessKey.
@Test
public void testProcessWithMultiValuedBusinessKey() {
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", getMultiValuedCorrelationKey(), 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(getMultiValuedCorrelationKey());
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 testProcessWithInvalidBusinessKey.
@Test
public void testProcessWithInvalidBusinessKey() {
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", getMultiValuedCorrelationKey(), 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");
// now check if when using invalid correlation it won't be found
ProcessInstance processInstanceNotFound = ((CorrelationAwareProcessRuntime) ksession).getProcessInstance(getCorrelationKey());
assertNull(processInstanceNotFound);
ProcessInstance processInstanceCopy = ((CorrelationAwareProcessRuntime) ksession).getProcessInstance(getMultiValuedCorrelationKey());
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 testProcessWithBusinessKeyFailOnDuplicatedBusinessKey.
@Test
public void testProcessWithBusinessKeyFailOnDuplicatedBusinessKey() {
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");
try {
((CorrelationAwareProcessRuntime) ksession).startProcess("com.sample.bpmn.hello", getCorrelationKey(), null);
fail("Cannot have duplicated business key running at the same time");
} catch (Exception e) {
}
// 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);
}
use of org.kie.internal.process.CorrelationAwareProcessRuntime in project jbpm by kiegroup.
the class AbstractStartProcessWithCorrelationKeyTest method testProcessesWithSameBusinessKeyInParallel.
@Test
public void testProcessesWithSameBusinessKeyInParallel() {
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", getMultiValuedCorrelationKey("first", "second"), 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(getMultiValuedCorrelationKey("first", "second"));
assertNotNull(processInstanceCopy);
assertEquals(processInstance.getId(), processInstanceCopy.getId());
ProcessInstance processInstance2 = ((CorrelationAwareProcessRuntime) ksession).startProcess("com.sample.bpmn.hello", getMultiValuedCorrelationKey("third", "fourth"), null);
assertProcessInstanceActive(processInstance2.getId(), ksession);
assertNodeTriggered(processInstance2.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(processInstance2.getId(), "Task 2");
ProcessInstance processInstanceCopy2 = ((CorrelationAwareProcessRuntime) ksession).getProcessInstance(getMultiValuedCorrelationKey("third", "fourth"));
assertNotNull(processInstanceCopy2);
assertEquals(processInstance2.getId(), processInstanceCopy2.getId());
// let mary execute Task 2 on process instance 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(processInstance2.getId(), "End");
assertProcessInstanceNotActive(processInstance2.getId(), ksession);
// let mary execute Task 2 on process instance 1
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