Search in sources :

Example 6 with EventDescription

use of org.kie.kogito.process.EventDescription in project kogito-runtimes by kiegroup.

the class IntermediateEventTest method testSignalBoundaryEventInterrupting.

@Test
public void testSignalBoundaryEventInterrupting() throws Exception {
    kruntime = createKogitoProcessRuntime("BPMN2-SignalBoundaryEventInterrupting.bpmn2");
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("MyTask", new DoNothingWorkItemHandler());
    KogitoProcessInstance processInstance = kruntime.startProcess("SignalBoundaryEvent");
    assertProcessInstanceActive(processInstance);
    Set<EventDescription<?>> eventDescriptions = processInstance.getEventDescriptions();
    assertThat(eventDescriptions).hasSize(2).extracting("event").contains("MyMessage", "workItemCompleted");
    assertThat(eventDescriptions).extracting("eventType").contains("signal", "workItem");
    assertThat(eventDescriptions).extracting("processInstanceId").contains(processInstance.getStringId());
    assertThat(eventDescriptions).filteredOn("eventType", "signal").hasSize(1).extracting("properties", Map.class).anyMatch(m -> m.containsKey("AttachedToID") && m.containsKey("AttachedToName"));
    kruntime.signalEvent("MyMessage", null);
    assertProcessInstanceFinished(processInstance, kruntime);
}
Also used : KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) DoNothingWorkItemHandler(org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler) EventDescription(org.kie.kogito.process.EventDescription) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 7 with EventDescription

use of org.kie.kogito.process.EventDescription in project kogito-runtimes by kiegroup.

the class IntermediateEventTest method testSignalBoundaryEvent.

/*
     * TESTS!
     */
@Test
public void testSignalBoundaryEvent() throws Exception {
    kruntime = createKogitoProcessRuntime("BPMN2-BoundarySignalEventOnTaskbpmn2.bpmn", "BPMN2-IntermediateThrowEventSignal.bpmn2");
    TestWorkItemHandler handler = new TestWorkItemHandler();
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", handler);
    KogitoProcessInstance processInstance = kruntime.startProcess("BoundarySignalOnTask");
    Set<EventDescription<?>> eventDescriptions = processInstance.getEventDescriptions();
    assertThat(eventDescriptions).hasSize(2).extracting("event").contains("MySignal");
    assertThat(eventDescriptions).extracting("eventType").contains("signal");
    assertThat(eventDescriptions).extracting("processInstanceId").contains(processInstance.getStringId());
    assertThat(eventDescriptions).filteredOn("eventType", "signal").hasSize(1).extracting("properties", Map.class).anyMatch(m -> m.containsKey("AttachedToID") && m.containsKey("AttachedToName"));
    KogitoProcessInstance processInstance2 = kruntime.startProcess("SignalIntermediateEvent");
    assertProcessInstanceFinished(processInstance2, kruntime);
    assertProcessInstanceFinished(processInstance, kruntime);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) EventDescription(org.kie.kogito.process.EventDescription) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 8 with EventDescription

use of org.kie.kogito.process.EventDescription 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 9 with EventDescription

use of org.kie.kogito.process.EventDescription in project kogito-runtimes by kiegroup.

the class SignalEventIT method testIntermediateSignalEventWithData.

@Test
public void testIntermediateSignalEventWithData() throws Exception {
    Map<TYPE, List<String>> resourcesTypeMap = new HashMap<>();
    resourcesTypeMap.put(TYPE.PROCESS, Collections.singletonList("signalevent/IntermediateCatchEventSignal.bpmn2"));
    resourcesTypeMap.put(TYPE.RULES, Collections.singletonList("ruletask/BusinessRuleTask.drl"));
    Application app = generateCode(resourcesTypeMap);
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.get(Processes.class).processById("IntermediateCatchEventSignal");
    Model m = p.createModel();
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    Set<EventDescription<?>> eventDescriptions = processInstance.events();
    assertThat(eventDescriptions).hasSize(1).extracting("event").contains("workItemCompleted");
    assertThat(eventDescriptions).extracting("eventType").contains("workItem");
    assertThat(eventDescriptions).extracting("processInstanceId").contains(processInstance.id());
    List<WorkItem> workItems = processInstance.workItems();
    assertThat(workItems).hasSize(1);
    processInstance.completeWorkItem(workItems.get(0).getId(), null);
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    eventDescriptions = processInstance.events();
    assertThat(eventDescriptions).hasSize(1).extracting("event").contains("MyMessage");
    assertThat(eventDescriptions).extracting("eventType").contains("signal");
    assertThat(eventDescriptions).extracting("processInstanceId").contains(processInstance.id());
    processInstance.send(Sig.of("MyMessage", "test"));
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    Model result = (Model) processInstance.variables();
    assertThat(result.toMap()).hasSize(2).containsKey("x");
    assertThat(result.toMap().get("x")).isEqualTo("test");
    assertThat(p.instances().size()).isZero();
}
Also used : HashMap(java.util.HashMap) Processes(org.kie.kogito.process.Processes) WorkItem(org.kie.kogito.process.WorkItem) Model(org.kie.kogito.Model) List(java.util.List) Application(org.kie.kogito.Application) EventDescription(org.kie.kogito.process.EventDescription) Test(org.junit.jupiter.api.Test)

Example 10 with EventDescription

use of org.kie.kogito.process.EventDescription in project kogito-runtimes by kiegroup.

the class WorkflowProcessInstanceImpl method getEventDescriptions.

@Override
public Set<EventDescription<?>> getEventDescriptions() {
    if (getState() == KogitoProcessInstance.STATE_COMPLETED || getState() == KogitoProcessInstance.STATE_ABORTED) {
        return Collections.emptySet();
    }
    VariableScope variableScope = (VariableScope) ((ContextContainer) getProcess()).getDefaultContext(VariableScope.VARIABLE_SCOPE);
    Set<EventDescription<?>> eventDesciptions = new LinkedHashSet<>();
    List<KogitoEventListener> activeListeners = eventListeners.values().stream().flatMap(List::stream).collect(Collectors.toList());
    activeListeners.addAll(externalEventListeners.values().stream().flatMap(List::stream).collect(Collectors.toList()));
    activeListeners.forEach(el -> eventDesciptions.addAll(el.getEventDescriptions()));
    ((org.jbpm.workflow.core.WorkflowProcess) getProcess()).getNodesRecursively().stream().filter(n -> n instanceof EventNodeInterface).forEach(n -> {
        NamedDataType dataType = null;
        if (((EventNodeInterface) n).getVariableName() != null) {
            Variable eventVar = variableScope.findVariable(((EventNodeInterface) n).getVariableName());
            if (eventVar != null) {
                dataType = new NamedDataType(eventVar.getName(), eventVar.getType());
            }
        }
        if (n instanceof BoundaryEventNode) {
            BoundaryEventNode boundaryEventNode = (BoundaryEventNode) n;
            StateBasedNodeInstance attachedToNodeInstance = (StateBasedNodeInstance) getNodeInstances(true).stream().filter(ni -> ni.getNode().getMetaData().get(UNIQUE_ID).equals(boundaryEventNode.getAttachedToNodeId())).findFirst().orElse(null);
            if (attachedToNodeInstance != null) {
                Map<String, String> properties = new HashMap<>();
                properties.put("AttachedToID", attachedToNodeInstance.getNodeDefinitionId());
                properties.put("AttachedToName", attachedToNodeInstance.getNodeName());
                String eventType = EVENT_TYPE_SIGNAL;
                String eventName = boundaryEventNode.getType();
                Map<String, String> timerProperties = attachedToNodeInstance.extractTimerEventInformation();
                if (timerProperties != null) {
                    properties.putAll(timerProperties);
                    eventType = "timer";
                    eventName = "timerTriggered";
                }
                eventDesciptions.add(new BaseEventDescription(eventName, (String) n.getMetaData().get(UNIQUE_ID), n.getName(), eventType, null, getStringId(), dataType, properties));
            }
        } else if (n instanceof EventSubProcessNode) {
            EventSubProcessNode eventSubProcessNode = (EventSubProcessNode) n;
            org.kie.api.definition.process.Node startNode = eventSubProcessNode.findStartNode();
            Map<Timer, DroolsAction> timers = eventSubProcessNode.getTimers();
            if (timers != null && !timers.isEmpty()) {
                getNodeInstances(eventSubProcessNode.getId()).forEach(ni -> {
                    Map<String, String> timerProperties = ((StateBasedNodeInstance) ni).extractTimerEventInformation();
                    if (timerProperties != null) {
                        eventDesciptions.add(new BaseEventDescription("timerTriggered", (String) startNode.getMetaData().get("UniqueId"), startNode.getName(), "timer", ni.getStringId(), getStringId(), null, timerProperties));
                    }
                });
            } else {
                for (String eventName : eventSubProcessNode.getEvents()) {
                    eventDesciptions.add(new BaseEventDescription(eventName, (String) startNode.getMetaData().get("UniqueId"), startNode.getName(), "signal", null, getStringId(), dataType));
                }
            }
        } else if (n instanceof EventNode) {
            NamedDataType finalDataType = dataType;
            getNodeInstances(n.getId()).forEach(ni -> eventDesciptions.add(new BaseEventDescription(((EventNode) n).getType(), (String) n.getMetaData().get(UNIQUE_ID), n.getName(), (String) n.getMetaData().getOrDefault(EVENT_TYPE, EVENT_TYPE_SIGNAL), ni.getStringId(), getStringId(), finalDataType)));
        } else if (n instanceof StateNode) {
            getNodeInstances(n.getId()).forEach(ni -> eventDesciptions.add(new BaseEventDescription((String) n.getMetaData().get(CONDITION), (String) n.getMetaData().get(UNIQUE_ID), n.getName(), (String) n.getMetaData().getOrDefault(EVENT_TYPE, EVENT_TYPE_SIGNAL), ni.getStringId(), getStringId(), null)));
        }
    });
    return eventDesciptions;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Milestone(org.kie.kogito.process.flexible.Milestone) ProcessInstanceJobDescription(org.kie.kogito.jobs.ProcessInstanceJobDescription) Date(java.util.Date) EventNodeInstanceInterface(org.jbpm.workflow.instance.node.EventNodeInstanceInterface) EventBasedNodeInstanceInterface(org.jbpm.workflow.instance.node.EventBasedNodeInstanceInterface) LoggerFactory(org.slf4j.LoggerFactory) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) DynamicNode(org.jbpm.workflow.core.node.DynamicNode) StartNode(org.jbpm.workflow.core.node.StartNode) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) PatternConstants(org.jbpm.util.PatternConstants) NamedDataType(org.kie.kogito.process.NamedDataType) NodeImpl(org.jbpm.workflow.core.impl.NodeImpl) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) EventSubProcessNodeInstance(org.jbpm.workflow.instance.node.EventSubProcessNodeInstance) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) KogitoNodeInstanceContainer(org.kie.kogito.internal.process.runtime.KogitoNodeInstanceContainer) StateNode(org.jbpm.workflow.core.node.StateNode) Matcher(java.util.regex.Matcher) EventNodeInterface(org.jbpm.workflow.core.node.EventNodeInterface) ContextInstance(org.jbpm.process.instance.ContextInstance) CORRELATION_KEY(org.jbpm.ruleflow.core.Metadata.CORRELATION_KEY) Map(java.util.Map) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) UUID(java.util.UUID) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) DurationExpirationTime(org.kie.kogito.jobs.DurationExpirationTime) VariableScope(org.jbpm.process.core.context.variable.VariableScope) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) IS_FOR_COMPENSATION(org.jbpm.ruleflow.core.Metadata.IS_FOR_COMPENSATION) List(java.util.List) Stream(java.util.stream.Stream) ContextContainer(org.jbpm.process.core.ContextContainer) ProcessInstance(org.kie.kogito.process.ProcessInstance) Node(org.jbpm.workflow.core.Node) COMPENSATION(org.jbpm.ruleflow.core.Metadata.COMPENSATION) BusinessCalendar(org.jbpm.process.core.timer.BusinessCalendar) MilestoneNode(org.jbpm.workflow.core.node.MilestoneNode) ACTIVE(org.kie.kogito.process.flexible.ItemDescription.Status.ACTIVE) Optional(java.util.Optional) COMPLETED(org.kie.kogito.process.flexible.ItemDescription.Status.COMPLETED) NodeContainer(org.kie.api.definition.process.NodeContainer) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) StateBasedNodeInstance(org.jbpm.workflow.instance.node.StateBasedNodeInstance) DateTimeUtils(org.jbpm.process.core.timer.DateTimeUtils) EndNodeInstance(org.jbpm.workflow.instance.node.EndNodeInstance) AdHocFragment(org.kie.kogito.process.flexible.AdHocFragment) HashMap(java.util.HashMap) Function(java.util.function.Function) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) ArrayList(java.util.ArrayList) Timer(org.jbpm.process.core.timer.Timer) NodeInstance(org.jbpm.workflow.instance.NodeInstance) FaultNodeInstance(org.jbpm.workflow.instance.node.FaultNodeInstance) CUSTOM_SLA_DUE_DATE(org.jbpm.ruleflow.core.Metadata.CUSTOM_SLA_DUE_DATE) CONDITION(org.jbpm.ruleflow.core.Metadata.CONDITION) EventNodeInstance(org.jbpm.workflow.instance.node.EventNodeInstance) CompositeNodeInstance(org.jbpm.workflow.instance.node.CompositeNodeInstance) DroolsAction(org.jbpm.workflow.core.DroolsAction) LinkedHashSet(java.util.LinkedHashSet) MVELEvaluator(org.drools.mvel.util.MVELEvaluator) Variable(org.jbpm.process.core.context.variable.Variable) AVAILABLE(org.kie.kogito.process.flexible.ItemDescription.Status.AVAILABLE) UNIQUE_ID(org.jbpm.ruleflow.core.Metadata.UNIQUE_ID) InternalKnowledgeRuntime(org.drools.core.common.InternalKnowledgeRuntime) Logger(org.slf4j.Logger) CorrelationKey(org.kie.internal.process.CorrelationKey) Metadata(org.jbpm.ruleflow.core.Metadata) VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) EventNode(org.jbpm.workflow.core.node.EventNode) BaseEventDescription(org.kie.kogito.process.BaseEventDescription) VariableScopeInstance(org.jbpm.process.instance.context.variable.VariableScopeInstance) AgendaFilter(org.kie.api.runtime.rule.AgendaFilter) ProcessInstanceImpl(org.jbpm.process.instance.impl.ProcessInstanceImpl) EVENT_TYPE_SIGNAL(org.jbpm.ruleflow.core.Metadata.EVENT_TYPE_SIGNAL) TimerInstance(org.kie.kogito.timer.TimerInstance) InternalProcessRuntime(org.jbpm.process.instance.InternalProcessRuntime) TimerJobId(org.kie.kogito.jobs.TimerJobId) KogitoEventListener(org.kie.kogito.internal.process.event.KogitoEventListener) ItemDescription(org.kie.kogito.process.flexible.ItemDescription) EventDescription(org.kie.kogito.process.EventDescription) KogitoWorkflowProcess(org.kie.kogito.internal.process.runtime.KogitoWorkflowProcess) Collections(java.util.Collections) EVENT_TYPE(org.jbpm.ruleflow.core.Metadata.EVENT_TYPE) EMPTY_EVENT_LISTENER(org.jbpm.workflow.instance.impl.DummyEventListener.EMPTY_EVENT_LISTENER) Variable(org.jbpm.process.core.context.variable.Variable) HashMap(java.util.HashMap) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) DynamicNode(org.jbpm.workflow.core.node.DynamicNode) StartNode(org.jbpm.workflow.core.node.StartNode) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) StateNode(org.jbpm.workflow.core.node.StateNode) Node(org.jbpm.workflow.core.Node) MilestoneNode(org.jbpm.workflow.core.node.MilestoneNode) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) EventNode(org.jbpm.workflow.core.node.EventNode) StateNode(org.jbpm.workflow.core.node.StateNode) KogitoEventListener(org.kie.kogito.internal.process.event.KogitoEventListener) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EventNode(org.jbpm.workflow.core.node.EventNode) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) StateBasedNodeInstance(org.jbpm.workflow.instance.node.StateBasedNodeInstance) EventNodeInterface(org.jbpm.workflow.core.node.EventNodeInterface) BaseEventDescription(org.kie.kogito.process.BaseEventDescription) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) NamedDataType(org.kie.kogito.process.NamedDataType) BaseEventDescription(org.kie.kogito.process.BaseEventDescription) EventDescription(org.kie.kogito.process.EventDescription) Map(java.util.Map) HashMap(java.util.HashMap) VariableScope(org.jbpm.process.core.context.variable.VariableScope)

Aggregations

EventDescription (org.kie.kogito.process.EventDescription)17 Test (org.junit.jupiter.api.Test)14 KogitoProcessInstance (org.kie.kogito.internal.process.runtime.KogitoProcessInstance)14 HashMap (java.util.HashMap)12 Map (java.util.Map)10 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)7 InternalKogitoWorkItem (org.kie.kogito.process.workitems.InternalKogitoWorkItem)6 ArrayList (java.util.ArrayList)5 KogitoWorkItem (org.kie.kogito.internal.process.runtime.KogitoWorkItem)5 List (java.util.List)4 SystemOutWorkItemHandler (org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler)3 NodeLeftCountDownProcessEventListener (org.jbpm.test.util.NodeLeftCountDownProcessEventListener)3 Timeout (org.junit.jupiter.api.Timeout)3 Model (org.kie.kogito.Model)3 Processes (org.kie.kogito.process.Processes)3 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Date (java.util.Date)2 Set (java.util.Set)2 Function (java.util.function.Function)2