Search in sources :

Example 1 with DecisionTableRulesMatchedEvent

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;
}
Also used : DecisionTableRulesSelectedEvent(org.kie.dmn.feel.runtime.events.DecisionTableRulesSelectedEvent) DecisionTableRulesMatchedEvent(org.kie.dmn.feel.runtime.events.DecisionTableRulesMatchedEvent) FEELEvent(org.kie.dmn.api.feel.runtime.events.FEELEvent)

Example 2 with DecisionTableRulesMatchedEvent

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;
}
Also used : DecisionTableRulesSelectedEvent(org.kie.dmn.feel.runtime.events.DecisionTableRulesSelectedEvent) DecisionTableRulesMatchedEvent(org.kie.dmn.feel.runtime.events.DecisionTableRulesMatchedEvent) FEELEvent(org.kie.dmn.api.feel.runtime.events.FEELEvent)

Example 3 with DecisionTableRulesMatchedEvent

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);
}
Also used : HitPolicyViolationEvent(org.kie.dmn.feel.runtime.events.HitPolicyViolationEvent) DecisionTableImpl.checkResults(org.kie.dmn.feel.runtime.decisiontables.DecisionTableImpl.checkResults) DecisionTableRulesMatchedEvent(org.kie.dmn.feel.runtime.events.DecisionTableRulesMatchedEvent) DecisionTable(org.kie.dmn.feel.runtime.decisiontables.DecisionTable) HitPolicy(org.kie.dmn.feel.runtime.decisiontables.HitPolicy) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) Function1(org.drools.model.functions.Function1) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) TreeMap(java.util.TreeMap) FEELEvent(org.kie.dmn.api.feel.runtime.events.FEELEvent) EvaluationContext(org.kie.dmn.feel.lang.EvaluationContext) Map(java.util.Map) Collections(java.util.Collections) Indexed(org.kie.dmn.feel.runtime.decisiontables.Indexed) DecisionTableRulesMatchedEvent(org.kie.dmn.feel.runtime.events.DecisionTableRulesMatchedEvent) ArrayList(java.util.ArrayList) HitPolicyViolationEvent(org.kie.dmn.feel.runtime.events.HitPolicyViolationEvent)

Aggregations

FEELEvent (org.kie.dmn.api.feel.runtime.events.FEELEvent)3 DecisionTableRulesMatchedEvent (org.kie.dmn.feel.runtime.events.DecisionTableRulesMatchedEvent)3 DecisionTableRulesSelectedEvent (org.kie.dmn.feel.runtime.events.DecisionTableRulesSelectedEvent)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1 Stream (java.util.stream.Stream)1 Function1 (org.drools.model.functions.Function1)1 EvaluationContext (org.kie.dmn.feel.lang.EvaluationContext)1 DecisionTable (org.kie.dmn.feel.runtime.decisiontables.DecisionTable)1 DecisionTableImpl.checkResults (org.kie.dmn.feel.runtime.decisiontables.DecisionTableImpl.checkResults)1 HitPolicy (org.kie.dmn.feel.runtime.decisiontables.HitPolicy)1 Indexed (org.kie.dmn.feel.runtime.decisiontables.Indexed)1 HitPolicyViolationEvent (org.kie.dmn.feel.runtime.events.HitPolicyViolationEvent)1