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));
}
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();
}
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);
}
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);
}
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");
}
Aggregations