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