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;
}
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 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 IntermediateEventTest method testEventSubprocessTimer.
@Test
@Timeout(10)
public void testEventSubprocessTimer() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Script Task 1", 1);
kruntime = createKogitoProcessRuntime("BPMN2-EventSubprocessTimer.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("Delay"));
countDownListener.waitTillCompleted();
eventDescriptions = processInstance.getEventDescriptions();
assertThat(eventDescriptions).hasSize(1).extracting("event").contains("workItemCompleted");
assertThat(eventDescriptions).extracting("eventType").contains("workItem");
assertThat(eventDescriptions).extracting("processInstanceId").contains(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");
}
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);
}
Aggregations