use of org.kie.dmn.feel.runtime.events.DecisionTableRulesMatchedEvent in project drools by kiegroup.
the class DMNDTExpressionEvaluator method processEvents.
private EventResults processEvents(List<FEELEvent> events, DMNRuntimeEventManager eventManager, DMNResultImpl result) {
EventResults r = new EventResults();
for (FEELEvent e : events) {
if (e instanceof DecisionTableRulesMatchedEvent) {
r.matchedRules = ((DecisionTableRulesMatchedEvent) e).getMatches();
} else if (e instanceof DecisionTableRulesSelectedEvent) {
r.fired = ((DecisionTableRulesSelectedEvent) e).getFired();
} else if (e.getSeverity() == FEELEvent.Severity.ERROR) {
MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, ((DMNBaseNode) node).getSource(), result, null, e, Msg.FEEL_ERROR, e.getMessage());
r.hasErrors = true;
} else if (e.getSeverity() == FEELEvent.Severity.WARN) {
MsgUtil.reportMessage(logger, DMNMessage.Severity.WARN, ((DMNBaseNode) node).getSource(), result, null, e, Msg.FEEL_WARN, e.getMessage());
}
}
events.clear();
return r;
}
use of org.kie.dmn.feel.runtime.events.DecisionTableRulesMatchedEvent in project drools by kiegroup.
the class DMNDTExpressionEvaluator method processEvents.
public static EventResults processEvents(List<FEELEvent> events, DMNRuntimeEventManager eventManager, DMNResultImpl result, DMNNode node) {
EventResults r = new EventResults();
for (FEELEvent e : events) {
if (e instanceof DecisionTableRulesMatchedEvent) {
r.matchedRules = ((DecisionTableRulesMatchedEvent) e).getMatches();
} else if (e instanceof DecisionTableRulesSelectedEvent) {
r.fired = ((DecisionTableRulesSelectedEvent) e).getFired();
} else if (e.getSeverity() == FEELEvent.Severity.ERROR) {
MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, ((DMNBaseNode) node).getSource(), result, null, e, Msg.FEEL_ERROR, e.getMessage());
r.hasErrors = true;
} else if (e.getSeverity() == FEELEvent.Severity.WARN) {
MsgUtil.reportMessage(logger, DMNMessage.Severity.WARN, ((DMNBaseNode) node).getSource(), result, null, e, Msg.FEEL_WARN, e.getMessage());
}
}
events.clear();
return r;
}
use of org.kie.dmn.feel.runtime.events.DecisionTableRulesMatchedEvent in project drools by kiegroup.
the class Results method applyHitPolicy.
public Object applyHitPolicy(EvaluationContext evaluationContext, HitPolicy hitPolicy, DecisionTable decisionTable) {
if (items.hasNoIndexes()) {
// }
if (hitPolicy.getDefaultValue() != null) {
return hitPolicy.getDefaultValue();
}
events.add(new HitPolicyViolationEvent(FEELEvent.Severity.WARN, String.format("No rule matched for decision table '%s' and no default values were defined. Setting result to null.", decisionTable.getName()), decisionTable.getName(), Collections.emptyList()));
}
List<? extends Indexed> matchIndexes = items.matches();
evaluationContext.notifyEvt(() -> {
List<Integer> matchedIndexes = matchIndexes.stream().map(dr -> dr.getIndex() + 1).collect(Collectors.toList());
return new DecisionTableRulesMatchedEvent(FEELEvent.Severity.INFO, String.format("Rules matched for decision table '%s': %s", decisionTable.getName(), matchIndexes), decisionTable.getName(), decisionTable.getName(), matchedIndexes);
});
List<Object> resultObjects = items.evaluateResults(evaluationContext);
Map<Integer, String> errorMessages = checkResults(decisionTable.getOutputs(), evaluationContext, matchIndexes, resultObjects);
if (!errorMessages.isEmpty()) {
List<Integer> offending = new ArrayList<>(errorMessages.keySet());
events.add(new HitPolicyViolationEvent(FEELEvent.Severity.ERROR, String.format("Errors found evaluating decision table '%s': \n%s", decisionTable.getName(), String.join("\n", errorMessages.values())), decisionTable.getName(), offending));
return null;
}
return hitPolicy.getDti().dti(evaluationContext, decisionTable, matchIndexes, resultObjects);
}
Aggregations