Search in sources :

Example 11 with CorrelationAwareProcessRuntime

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);
    }
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) CorrelationAwareProcessRuntime(org.kie.internal.process.CorrelationAwareProcessRuntime) CorrelationKey(org.kie.internal.process.CorrelationKey) ExecutionResults(org.kie.api.executor.ExecutionResults) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) Map(java.util.Map)

Example 12 with CorrelationAwareProcessRuntime

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);
}
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 13 with CorrelationAwareProcessRuntime

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);
}
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 14 with CorrelationAwareProcessRuntime

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);
}
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 15 with CorrelationAwareProcessRuntime

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);
}
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)15 KieSession (org.kie.api.runtime.KieSession)12 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)11 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)11 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 ExecutionResultImpl (org.drools.core.runtime.impl.ExecutionResultImpl)3 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)3 RegistryContext (org.kie.internal.command.RegistryContext)3 CorrelationKeyFactory (org.kie.internal.process.CorrelationKeyFactory)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)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