Search in sources :

Example 6 with KogitoProcessEventListener

use of org.kie.kogito.internal.process.event.KogitoProcessEventListener in project kogito-runtimes by kiegroup.

the class SLAComplianceTest method testSLAonProcessViolatedNoTracking.

@Test
public void testSLAonProcessViolatedNoTracking() throws Exception {
    CountDownLatch latch = new CountDownLatch(1);
    final KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() {

        @Override
        public void afterSLAViolated(SLAViolatedEvent event) {
            latch.countDown();
        }
    };
    kruntime = createKogitoProcessRuntime("BPMN2-UserTaskWithSLA.bpmn2");
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    kruntime.getProcessEventManager().addEventListener(listener);
    kruntime.getKieRuntime().getEnvironment().set("SLATimerMode", "false");
    KogitoProcessInstance processInstance = kruntime.startProcess("UserTask");
    assertEquals(KogitoProcessInstance.STATE_ACTIVE, processInstance.getState());
    KogitoWorkItem workItem = workItemHandler.getWorkItem();
    assertNotNull(workItem);
    assertEquals("john", workItem.getParameter("ActorId"));
    boolean slaViolated = latch.await(5, TimeUnit.SECONDS);
    assertFalse(slaViolated, "SLA should not violated by timer");
    processInstance = kruntime.getProcessInstance(processInstance.getStringId());
    assertEquals(KogitoProcessInstance.STATE_ACTIVE, processInstance.getState());
    int slaCompliance = getSLAComplianceForProcessInstance(processInstance);
    assertEquals(KogitoProcessInstance.SLA_PENDING, slaCompliance);
    kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null);
    assertProcessInstanceFinished(processInstance, kruntime);
    slaCompliance = getSLAComplianceForProcessInstance(processInstance);
    assertEquals(KogitoProcessInstance.SLA_VIOLATED, slaCompliance);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) KogitoProcessEventListener(org.kie.kogito.internal.process.event.KogitoProcessEventListener) SLAViolatedEvent(org.kie.api.event.process.SLAViolatedEvent) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Example 7 with KogitoProcessEventListener

use of org.kie.kogito.internal.process.event.KogitoProcessEventListener in project kogito-runtimes by kiegroup.

the class ErrorEventTest method testEventSubprocessErrorWithOutErrorCode.

@Test
public void testEventSubprocessErrorWithOutErrorCode() throws Exception {
    kruntime = createKogitoProcessRuntime("subprocess/EventSubprocessErrorHandlingWithOutErrorCode.bpmn2");
    final List<String> executednodes = new ArrayList<>();
    KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() {

        @Override
        public void afterNodeLeft(ProcessNodeLeftEvent event) {
            if (event.getNodeInstance().getNodeName().equals("Script2")) {
                executednodes.add(((KogitoNodeInstance) event.getNodeInstance()).getStringId());
            }
        }
    };
    kruntime.getProcessEventManager().addEventListener(listener);
    KogitoProcessInstance processInstance = kruntime.startProcess("order-fulfillment-bpm.ccc");
    assertProcessInstanceFinished(processInstance, kruntime);
    assertNodeTriggered(processInstance.getStringId(), "start", "Script1", "starterror", "Script2", "end2", "eventsubprocess");
    assertProcessVarValue(processInstance, "CapturedException", "java.lang.RuntimeException: XXX");
    assertEquals(1, executednodes.size());
}
Also used : KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) ArrayList(java.util.ArrayList) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) KogitoProcessEventListener(org.kie.kogito.internal.process.event.KogitoProcessEventListener) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) Test(org.junit.jupiter.api.Test)

Example 8 with KogitoProcessEventListener

use of org.kie.kogito.internal.process.event.KogitoProcessEventListener in project kogito-runtimes by kiegroup.

the class IntermediateEventTest method runTestEventSubprocessSignal.

public void runTestEventSubprocessSignal(String processFile, String[] completedNodes) throws Exception {
    kruntime = createKogitoProcessRuntime(processFile);
    final List<String> executednodes = new ArrayList<>();
    KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() {

        @Override
        public void afterNodeLeft(ProcessNodeLeftEvent event) {
            if (event.getNodeInstance().getNodeName().equals("sub-script")) {
                executednodes.add(((KogitoNodeInstance) event.getNodeInstance()).getStringId());
            }
        }
    };
    kruntime.getProcessEventManager().addEventListener(listener);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    KogitoProcessInstance processInstance = kruntime.startProcess("BPMN2-EventSubprocessSignal");
    assertProcessInstanceActive(processInstance);
    kruntime.getProcessEventManager().addEventListener(listener);
    Set<EventDescription<?>> eventDescriptions = processInstance.getEventDescriptions();
    assertThat(eventDescriptions).hasSize(2).extracting("event").contains("MySignal", "workItemCompleted");
    assertThat(eventDescriptions).extracting("eventType").contains("signal", "workItem");
    assertThat(eventDescriptions).extracting("processInstanceId").contains(processInstance.getStringId());
    kruntime.signalEvent("MySignal", null, processInstance.getStringId());
    assertProcessInstanceActive(processInstance);
    kruntime.signalEvent("MySignal", null);
    assertProcessInstanceActive(processInstance);
    kruntime.signalEvent("MySignal", null);
    assertProcessInstanceActive(processInstance);
    kruntime.signalEvent("MySignal", null);
    assertProcessInstanceActive(processInstance);
    KogitoWorkItem workItem = workItemHandler.getWorkItem();
    assertThat(workItem).isNotNull();
    kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null);
    assertProcessInstanceFinished(processInstance, kruntime);
    assertNodeTriggered(processInstance.getStringId(), completedNodes);
    assertThat(executednodes.size()).isEqualTo(4);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) ArrayList(java.util.ArrayList) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) KogitoProcessEventListener(org.kie.kogito.internal.process.event.KogitoProcessEventListener) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) InternalKogitoWorkItem(org.kie.kogito.process.workitems.InternalKogitoWorkItem) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) EventDescription(org.kie.kogito.process.EventDescription)

Example 9 with KogitoProcessEventListener

use of org.kie.kogito.internal.process.event.KogitoProcessEventListener in project kogito-runtimes by kiegroup.

the class IntermediateEventTest method testEventSubprocessMessage.

@Test
public void testEventSubprocessMessage() throws Exception {
    kruntime = createKogitoProcessRuntime("BPMN2-EventSubprocessMessage.bpmn2");
    final List<String> executednodes = new ArrayList<>();
    KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() {

        @Override
        public void afterNodeLeft(ProcessNodeLeftEvent event) {
            if (event.getNodeInstance().getNodeName().equals("Script Task 1")) {
                executednodes.add(((KogitoNodeInstance) event.getNodeInstance()).getStringId());
            }
        }
    };
    kruntime.getProcessEventManager().addEventListener(listener);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    KogitoProcessInstance processInstance = kruntime.startProcess("BPMN2-EventSubprocessMessage");
    assertProcessInstanceActive(processInstance);
    Set<EventDescription<?>> eventDescriptions = processInstance.getEventDescriptions();
    assertThat(eventDescriptions).hasSize(2).extracting("event").contains("Message-HelloMessage", "workItemCompleted");
    assertThat(eventDescriptions).extracting("eventType").contains("signal", "workItem");
    assertThat(eventDescriptions).extracting("processInstanceId").contains(processInstance.getStringId());
    kruntime.getProcessEventManager().addEventListener(listener);
    kruntime.signalEvent("Message-HelloMessage", null, processInstance.getStringId());
    kruntime.signalEvent("Message-HelloMessage", null);
    kruntime.signalEvent("Message-HelloMessage", null);
    kruntime.signalEvent("Message-HelloMessage", null);
    kruntime.getProcessInstance(processInstance.getStringId());
    kruntime.getProcessInstance(processInstance.getStringId());
    kruntime.getProcessInstance(processInstance.getStringId());
    kruntime.getProcessInstance(processInstance.getStringId());
    KogitoWorkItem workItem = workItemHandler.getWorkItem();
    assertThat(workItem).isNotNull();
    kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null);
    assertProcessInstanceFinished(processInstance, kruntime);
    assertNodeTriggered(processInstance.getStringId(), "start", "User Task 1", "end", "Sub Process 1", "start-sub", "Script Task 1", "end-sub");
    assertThat(executednodes.size()).isEqualTo(4);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) ArrayList(java.util.ArrayList) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) KogitoProcessEventListener(org.kie.kogito.internal.process.event.KogitoProcessEventListener) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) InternalKogitoWorkItem(org.kie.kogito.process.workitems.InternalKogitoWorkItem) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) EventDescription(org.kie.kogito.process.EventDescription) Test(org.junit.jupiter.api.Test)

Example 10 with KogitoProcessEventListener

use of org.kie.kogito.internal.process.event.KogitoProcessEventListener in project kogito-runtimes by kiegroup.

the class KogitoProcessEventSupportImpl method fireTaskNotification.

private void fireTaskNotification(KogitoProcessInstance instance, HumanTaskWorkItem workItem, Map<String, Object> notification, DeadlineType type, KieRuntime kruntime) {
    final HumanTaskDeadlineEvent event = new HumanTaskDeadlineEventImpl(instance, workItem, notification, type, kruntime);
    unitOfWorkManager.currentUnitOfWork().intercept(WorkUnit.create(event, e -> notifyAllListeners(event, KogitoProcessEventListener::onHumanTaskDeadline)));
}
Also used : ProcessStartedEventImpl(org.drools.core.event.ProcessStartedEventImpl) ProcessCompletedEvent(org.kie.api.event.process.ProcessCompletedEvent) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) WorkUnit(org.kie.kogito.uow.WorkUnit) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) AbstractEventSupport(org.drools.core.event.AbstractEventSupport) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DeadlineType(org.kie.kogito.internal.process.event.HumanTaskDeadlineEvent.DeadlineType) KogitoProcessEventListener(org.kie.kogito.internal.process.event.KogitoProcessEventListener) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) Map(java.util.Map) UnitOfWorkManager(org.kie.kogito.uow.UnitOfWorkManager) SLAViolatedEventImpl(org.drools.core.event.SLAViolatedEventImpl) SignalEvent(org.kie.api.event.process.SignalEvent) ProcessVariableChangedEvent(org.kie.api.event.process.ProcessVariableChangedEvent) SignalEventImpl(org.drools.core.event.SignalEventImpl) ProcessCompletedEventImpl(org.drools.core.event.ProcessCompletedEventImpl) MessageEvent(org.kie.api.event.process.MessageEvent) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) MessageEventImpl(org.drools.core.event.MessageEventImpl) List(java.util.List) ProcessNodeTriggeredEvent(org.kie.api.event.process.ProcessNodeTriggeredEvent) Transition(org.kie.kogito.process.workitem.Transition) KieRuntime(org.kie.api.runtime.KieRuntime) KogitoProcessEventSupport(org.kie.kogito.internal.process.event.KogitoProcessEventSupport) HumanTaskDeadlineEvent(org.kie.kogito.internal.process.event.HumanTaskDeadlineEvent) SLAViolatedEvent(org.kie.api.event.process.SLAViolatedEvent) HumanTaskWorkItem(org.kie.kogito.process.workitem.HumanTaskWorkItem) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) ProcessWorkItemTransitionEvent(org.kie.kogito.internal.process.event.ProcessWorkItemTransitionEvent) HumanTaskDeadlineEvent(org.kie.kogito.internal.process.event.HumanTaskDeadlineEvent) KogitoProcessEventListener(org.kie.kogito.internal.process.event.KogitoProcessEventListener)

Aggregations

KogitoProcessEventListener (org.kie.kogito.internal.process.event.KogitoProcessEventListener)23 Test (org.junit.jupiter.api.Test)21 KogitoProcessInstance (org.kie.kogito.internal.process.runtime.KogitoProcessInstance)21 DefaultKogitoProcessEventListener (org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener)20 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)14 KogitoWorkItem (org.kie.kogito.internal.process.runtime.KogitoWorkItem)14 ProcessNodeLeftEvent (org.kie.api.event.process.ProcessNodeLeftEvent)13 ArrayList (java.util.ArrayList)11 SLAViolatedEvent (org.kie.api.event.process.SLAViolatedEvent)9 CountDownLatch (java.util.concurrent.CountDownLatch)8 KogitoNodeInstance (org.kie.kogito.internal.process.runtime.KogitoNodeInstance)5 KogitoWorkflowProcessInstance (org.kie.kogito.internal.process.runtime.KogitoWorkflowProcessInstance)4 InternalKogitoWorkItem (org.kie.kogito.process.workitems.InternalKogitoWorkItem)4 SignalEvent (org.kie.api.event.process.SignalEvent)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 SystemOutWorkItemHandler (org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler)2 Application (org.kie.kogito.Application)2 EventDescription (org.kie.kogito.process.EventDescription)2 ProcessConfig (org.kie.kogito.process.ProcessConfig)2