use of org.kie.dmn.feel.runtime.decisiontables.Indexed 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