Search in sources :

Example 11 with EventDescription

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

the class WorkItemNodeInstance method getEventDescriptions.

@Override
public Set<EventDescription<?>> getEventDescriptions() {
    List<NamedDataType> inputs = new ArrayList<>();
    for (ParameterDefinition paramDef : getWorkItemNode().getWork().getParameterDefinitions()) {
        inputs.add(new NamedDataType(paramDef.getName(), paramDef.getType()));
    }
    List<NamedDataType> outputs = new ArrayList<>();
    VariableScope variableScope = (VariableScope) getProcessInstance().getContextContainer().getDefaultContext(VARIABLE_SCOPE);
    getWorkItemNode().getOutAssociations().forEach(da -> da.getSources().forEach(s -> outputs.add(new NamedDataType(s.getLabel(), variableScope.findVariable(da.getTarget().getLabel()).getType()))));
    GroupedNamedDataType dataTypes = new GroupedNamedDataType();
    dataTypes.add("Input", inputs);
    dataTypes.add("Output", outputs);
    // return just the main completion type of an event
    return Collections.singleton(new IOEventDescription("workItemCompleted", getNodeDefinitionId(), getNodeName(), "workItem", getWorkItemId(), getProcessInstance().getStringId(), dataTypes));
}
Also used : Arrays(java.util.Arrays) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) NamedDataType(org.kie.kogito.process.NamedDataType) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) GroupedNamedDataType(org.kie.kogito.process.GroupedNamedDataType) STATE_COMPLETED(org.kie.kogito.internal.process.runtime.KogitoProcessInstance.STATE_COMPLETED) ProcessInstance(org.jbpm.process.instance.ProcessInstance) Context(org.jbpm.process.core.Context) ContextInstance(org.jbpm.process.instance.ContextInstance) Map(java.util.Map) WorkItemExecutionException(org.kie.kogito.process.workitem.WorkItemExecutionException) KogitoWorkItemNodeInstance(org.kie.kogito.internal.process.runtime.KogitoWorkItemNodeInstance) ABORTED(org.kie.api.runtime.process.WorkItem.ABORTED) Collection(java.util.Collection) Set(java.util.Set) VARIABLE_SCOPE(org.jbpm.process.core.context.variable.VariableScope.VARIABLE_SCOPE) KogitoProcessContextImpl(org.jbpm.process.instance.KogitoProcessContextImpl) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) VariableScope(org.jbpm.process.core.context.variable.VariableScope) List(java.util.List) ContextContainer(org.jbpm.process.core.ContextContainer) Node(org.jbpm.workflow.core.Node) KieRuntime(org.kie.api.runtime.KieRuntime) Model(org.kie.kogito.Model) ExceptionScopeInstance(org.jbpm.process.instance.context.exception.ExceptionScopeInstance) Entry(java.util.Map.Entry) Work(org.jbpm.process.core.Work) ParameterDefinition(org.jbpm.process.core.ParameterDefinition) InternalKogitoWorkItem(org.kie.kogito.process.workitems.InternalKogitoWorkItem) ExceptionScope(org.jbpm.process.core.context.exception.ExceptionScope) WorkflowRuntimeException(org.jbpm.workflow.instance.WorkflowRuntimeException) AbstractProcessInstance(org.kie.kogito.process.impl.AbstractProcessInstance) ProcessWorkItemHandlerException(org.kie.api.runtime.process.ProcessWorkItemHandlerException) HashMap(java.util.HashMap) KogitoProcessRuntime(org.kie.kogito.internal.process.runtime.KogitoProcessRuntime) Function(java.util.function.Function) ArrayList(java.util.ArrayList) EventListener(org.kie.api.runtime.process.EventListener) NodeIoHelper(org.jbpm.workflow.core.impl.NodeIoHelper) DataAssociation(org.jbpm.workflow.core.impl.DataAssociation) ContextInstanceFactoryRegistry(org.jbpm.process.instance.impl.ContextInstanceFactoryRegistry) ContextInstanceContainer(org.jbpm.process.instance.ContextInstanceContainer) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) Logger(org.slf4j.Logger) STATE_ABORTED(org.kie.kogito.internal.process.runtime.KogitoProcessInstance.STATE_ABORTED) EnvironmentName(org.kie.api.runtime.EnvironmentName) VariableScopeInstance(org.jbpm.process.instance.context.variable.VariableScopeInstance) IOEventDescription(org.kie.kogito.process.IOEventDescription) COMPLETED(org.kie.api.runtime.process.WorkItem.COMPLETED) KogitoWorkItemImpl(org.kie.kogito.process.workitems.impl.KogitoWorkItemImpl) InternalProcessRuntime(org.jbpm.process.instance.InternalProcessRuntime) WorkItemHandlerNotFoundException(org.drools.core.WorkItemHandlerNotFoundException) ContextInstanceFactory(org.jbpm.process.instance.impl.ContextInstanceFactory) EventDescription(org.kie.kogito.process.EventDescription) InternalKogitoWorkItemManager(org.kie.kogito.process.workitems.InternalKogitoWorkItemManager) Processes(org.kie.kogito.process.Processes) Collections(java.util.Collections) NamedDataType(org.kie.kogito.process.NamedDataType) GroupedNamedDataType(org.kie.kogito.process.GroupedNamedDataType) GroupedNamedDataType(org.kie.kogito.process.GroupedNamedDataType) ArrayList(java.util.ArrayList) IOEventDescription(org.kie.kogito.process.IOEventDescription) VariableScope(org.jbpm.process.core.context.variable.VariableScope) ParameterDefinition(org.jbpm.process.core.ParameterDefinition)

Example 12 with EventDescription

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

the class SignalEventIT method testBoundarySignalEventWithData.

@Test
public void testBoundarySignalEventWithData() throws Exception {
    Map<TYPE, List<String>> resourcesTypeMap = new HashMap<>();
    resourcesTypeMap.put(TYPE.PROCESS, Collections.singletonList("signalevent/BoundarySignalEventOnTask.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("BoundarySignalOnTask");
    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(2).extracting("event").contains("MySignal", "workItemCompleted");
    assertThat(eventDescriptions).extracting("eventType").contains("signal", "workItem");
    assertThat(eventDescriptions).extracting("dataType").hasAtLeastOneElementOfType(GroupedNamedDataType.class);
    assertThat(eventDescriptions).extracting("processInstanceId").contains(processInstance.id());
    processInstance.send(Sig.of("MySignal", "test"));
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    Model result = (Model) processInstance.variables();
    assertThat(result.toMap()).hasSize(1).containsKey("x");
    assertThat(result.toMap().get("x")).isEqualTo("test");
    assertThat(p.instances().size()).isZero();
}
Also used : HashMap(java.util.HashMap) Model(org.kie.kogito.Model) List(java.util.List) Processes(org.kie.kogito.process.Processes) Application(org.kie.kogito.Application) EventDescription(org.kie.kogito.process.EventDescription) Test(org.junit.jupiter.api.Test)

Example 13 with EventDescription

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

the class IntermediateEventTest method testTimerBoundaryEventDuration.

@Test
@Timeout(10)
public void testTimerBoundaryEventDuration() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("TimerEvent", 1);
    kruntime = createKogitoProcessRuntime("BPMN2-TimerBoundaryEventDuration.bpmn2");
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("MyTask", new DoNothingWorkItemHandler());
    kruntime.getProcessEventManager().addEventListener(countDownListener);
    KogitoProcessInstance processInstance = kruntime.startProcess("TimerBoundaryEvent");
    assertProcessInstanceActive(processInstance);
    Set<EventDescription<?>> eventDescriptions = processInstance.getEventDescriptions();
    assertThat(eventDescriptions).hasSize(2).extracting("event").contains("workItemCompleted", "timerTriggered");
    assertThat(eventDescriptions).extracting("eventType").contains("workItem", "timer");
    assertThat(eventDescriptions).extracting("processInstanceId").contains(processInstance.getStringId());
    assertThat(eventDescriptions).filteredOn("eventType", "timer").hasSize(1).extracting("properties", Map.class).anyMatch(m -> m.containsKey("TimerID") && m.containsKey("Period"));
    countDownListener.waitTillCompleted();
    assertProcessInstanceFinished(processInstance, kruntime);
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.util.NodeLeftCountDownProcessEventListener) 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) Timeout(org.junit.jupiter.api.Timeout)

Example 14 with EventDescription

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

the class IntermediateEventTest method testEventBasedSplit2.

@Test
@Timeout(10)
public void testEventBasedSplit2() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 2);
    kruntime = createKogitoProcessRuntime("BPMN2-EventBasedSplit2.bpmn2");
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Email1", new SystemOutWorkItemHandler());
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Email2", new SystemOutWorkItemHandler());
    kruntime.getProcessEventManager().addEventListener(countDownListener);
    // Yes
    KogitoProcessInstance processInstance = kruntime.startProcess("com.sample.test");
    assertProcessInstanceActive(processInstance);
    Set<EventDescription<?>> eventDescriptions = processInstance.getEventDescriptions();
    assertThat(eventDescriptions).hasSize(2).extracting("event").contains("Yes", "timerTriggered");
    assertThat(eventDescriptions).extracting("eventType").contains("signal", "timer");
    assertThat(eventDescriptions).filteredOn(i -> i.getDataType() != null).extracting("dataType").hasOnlyElementsOfType(NamedDataType.class).extracting("dataType").hasOnlyElementsOfType(StringDataType.class);
    assertThat(eventDescriptions).extracting("processInstanceId").contains(processInstance.getStringId());
    assertThat(eventDescriptions).filteredOn("eventType", "timer").hasSize(1).extracting("properties", Map.class).anyMatch(m -> m.containsKey("TimerID") && m.containsKey("Delay"));
    kruntime.getProcessEventManager().addEventListener(countDownListener);
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Email1", new SystemOutWorkItemHandler());
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Email2", new SystemOutWorkItemHandler());
    kruntime.signalEvent("Yes", "YesValue", processInstance.getStringId());
    assertProcessInstanceFinished(processInstance, kruntime);
    kruntime.getProcessEventManager().addEventListener(countDownListener);
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Email1", new SystemOutWorkItemHandler());
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Email2", new SystemOutWorkItemHandler());
    kruntime.getProcessEventManager().addEventListener(countDownListener);
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Email1", new SystemOutWorkItemHandler());
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Email2", new SystemOutWorkItemHandler());
    // Timer
    processInstance = kruntime.startProcess("com.sample.test");
    assertProcessInstanceActive(processInstance);
    countDownListener.waitTillCompleted();
    kruntime.getProcessEventManager().addEventListener(countDownListener);
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Email1", new SystemOutWorkItemHandler());
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Email2", new SystemOutWorkItemHandler());
    assertProcessInstanceFinished(processInstance, kruntime);
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.util.NodeLeftCountDownProcessEventListener) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) EventDescription(org.kie.kogito.process.EventDescription) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 15 with EventDescription

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

the class IntermediateEventTest method testEventSubprocessTimerCycle.

@Test
@Timeout(10)
@RequirePersistence
public void testEventSubprocessTimerCycle() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Script Task 1", 4);
    kruntime = createKogitoProcessRuntime("BPMN2-EventSubprocessTimerCycle.bpmn2");
    kruntime.getProcessEventManager().addEventListener(countDownListener);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    KogitoProcessInstance processInstance = kruntime.startProcess("BPMN2-EventSubprocessTimer");
    assertProcessInstanceActive(processInstance);
    Set<EventDescription<?>> eventDescriptions = processInstance.getEventDescriptions();
    assertThat(eventDescriptions).hasSize(2).extracting("event").contains("workItemCompleted", "timerTriggered");
    assertThat(eventDescriptions).extracting("eventType").contains("workItem", "timer");
    assertThat(eventDescriptions).extracting("processInstanceId").contains(processInstance.getStringId());
    assertThat(eventDescriptions).filteredOn("eventType", "timer").hasSize(1).extracting("properties", Map.class).anyMatch(m -> m.containsKey("TimerID") && m.containsKey("Period"));
    countDownListener.waitTillCompleted();
    KogitoWorkItem workItem = workItemHandler.getWorkItem();
    assertThat(workItem).isNotNull();
    kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null);
    assertProcessInstanceFinished(processInstance, kruntime);
    assertNodeTriggered(processInstance.getStringId(), "start", "User Task 1", "end", "start-sub", "Script Task 1", "end-sub");
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) NodeLeftCountDownProcessEventListener(org.jbpm.test.util.NodeLeftCountDownProcessEventListener) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) InternalKogitoWorkItem(org.kie.kogito.process.workitems.InternalKogitoWorkItem) EventDescription(org.kie.kogito.process.EventDescription) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout) RequirePersistence(org.jbpm.bpmn2.test.RequirePersistence)

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