use of org.kie.dmn.feel.util.Pair in project kogito-runtimes by kiegroup.
the class DefaultAggregator method traceOutputFrom.
private static TraceOutputValue traceOutputFrom(EvaluateDecisionResult decisionResult, DMNModel model, Map<String, Object> context) {
DMNType type = Optional.ofNullable(model).map(m -> m.getDecisionById(decisionResult.getDecisionId())).map(DecisionNode::getResultType).orElse(null);
// cast to DMNBaseNode here is required to have access to getDependencies method
Map<String, DMNType> decisionInputTypes = Optional.ofNullable(model).map(m -> m.getDecisionById(decisionResult.getDecisionId())).filter(DMNBaseNode.class::isInstance).map(DMNBaseNode.class::cast).map(DMNBaseNode::getDependencies).map(deps -> deps.values().stream().map(DMNNode::getId).collect(Collectors.toList())).map(ids -> ids.stream().map(id -> typeAndNameOf(id, model)).filter(Objects::nonNull).collect(Collectors.toMap(Pair::getRight, Pair::getLeft))).orElseGet(HashMap::new);
Map<String, TypedValue> decisionInputs = decisionInputTypes.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> EventUtils.typedValueFrom(e.getValue(), context.get(e.getKey()))));
return new TraceOutputValue(decisionResult.getDecisionId(), decisionResult.getDecisionName(), decisionResult.getEvaluationStatus().name(), EventUtils.typedValueFrom(type, decisionResult.getResult()), decisionInputs, decisionResult.getMessages());
}
use of org.kie.dmn.feel.util.Pair in project kogito-runtimes by kiegroup.
the class DecisionTracingCollectorTest method testInterleavedEvaluations.
private void testInterleavedEvaluations(Supplier<TerminationDetector> terminationDetectorSupplier) throws IOException {
MockDefaultAggregator aggregator = new MockDefaultAggregator();
Consumer<String> payloadConsumer = mock(Consumer.class);
DecisionTracingCollector collector = new DecisionTracingCollector(aggregator, payloadConsumer, (namespace, name) -> model, terminationDetectorSupplier, configBean);
List<EvaluateEvent> evaluateAllEvents = readEvaluateEventsFromJsonResource(EVALUATE_ALL_JSON_RESOURCE);
List<EvaluateEvent> evaluateDecisionServiceEvents = readEvaluateEventsFromJsonResource(EVALUATE_DECISION_SERVICE_JSON_RESOURCE);
for (int i = 0; i < Math.max(evaluateAllEvents.size(), evaluateDecisionServiceEvents.size()); i++) {
if (i < evaluateAllEvents.size()) {
collector.addEvent(evaluateAllEvents.get(i));
}
if (i < evaluateDecisionServiceEvents.size()) {
collector.addEvent(evaluateDecisionServiceEvents.get(i));
}
}
Map<String, Pair<List<EvaluateEvent>, CloudEvent>> aggregatorCalls = aggregator.getCalls();
assertEquals(2, aggregatorCalls.size());
assertTrue(aggregatorCalls.containsKey(EVALUATE_ALL_EXECUTION_ID));
assertEquals(evaluateAllEvents.size(), aggregatorCalls.get(EVALUATE_ALL_EXECUTION_ID).getLeft().size());
assertTrue(aggregatorCalls.containsKey(EVALUATE_DECISION_SERVICE_EXECUTION_ID));
assertEquals(evaluateDecisionServiceEvents.size(), aggregatorCalls.get(EVALUATE_DECISION_SERVICE_EXECUTION_ID).getLeft().size());
ArgumentCaptor<String> payloadCaptor = ArgumentCaptor.forClass(String.class);
verify(payloadConsumer, times(2)).accept(payloadCaptor.capture());
int evaluateAllIndex = evaluateAllEvents.size() > evaluateDecisionServiceEvents.size() ? 1 : 0;
int evaluateDecisionServiceIndex = evaluateAllIndex == 1 ? 0 : 1;
List<String> payloads = payloadCaptor.getAllValues();
String expectedEvaluateAll = encodeFromCall(aggregatorCalls, EVALUATE_ALL_EXECUTION_ID);
assertEquals(expectedEvaluateAll, payloads.get(evaluateAllIndex));
String expectedEvaluateDecisionService = encodeFromCall(aggregatorCalls, EVALUATE_DECISION_SERVICE_EXECUTION_ID);
assertEquals(expectedEvaluateDecisionService, payloads.get(evaluateDecisionServiceIndex));
}
use of org.kie.dmn.feel.util.Pair in project kogito-runtimes by kiegroup.
the class EvaluateEventTypeTest method testNotManagedEvents.
@Test
void testNotManagedEvents() {
for (Method listenerMethod : LISTENER_CLASS.getMethods()) {
Optional<Map.Entry<EvaluateEventType, Pair<String, Class<?>>>> optEntry = CHECK_MAP.entrySet().stream().filter(e -> e.getValue().getLeft().equals(listenerMethod.getName())).findAny();
assertTrue(optEntry.isPresent(), () -> String.format("No EvaluateEventType for listener method \"%s\"", listenerMethod.getName()));
}
}
use of org.kie.dmn.feel.util.Pair in project kogito-runtimes by kiegroup.
the class DefaultAggregator method typeAndNameOf.
private static Pair<DMNType, String> typeAndNameOf(String nodeId, DMNModel model) {
InputDataNode input = model.getInputById(nodeId);
if (input != null) {
return new Pair<>(input.getType(), input.getName());
}
DecisionNode decision = model.getDecisionById(nodeId);
if (decision != null) {
return new Pair<>(decision.getResultType(), decision.getName());
}
return null;
}
Aggregations