Search in sources :

Example 1 with DMNDTAnalysisMessage

use of org.kie.dmn.validation.dtanalysis.DMNDTAnalysisMessage in project drools by kiegroup.

the class DTAnalysis method gapsAsMessages.

private Collection gapsAsMessages() {
    List<DMNDTAnalysisMessage> results = new ArrayList<>();
    if (!ddtaTable.getColIDsStringWithoutEnum().isEmpty()) {
        List<String> names = ddtaTable.getColIDsStringWithoutEnum().stream().map(id -> sourceDT.getInput().get(id - 1)).map(InputClause::getInputExpression).map(LiteralExpression::getText).collect(Collectors.toList());
        results.add(new DMNDTAnalysisMessage(this, Severity.WARN, MsgUtil.createMessage(Msg.DTANALYSIS_GAP_SKIPPED_BECAUSE_FREE_STRING, names), Msg.DTANALYSIS_GAP_SKIPPED_BECAUSE_FREE_STRING.getType()));
        return results;
    }
    for (Hyperrectangle gap : gaps) {
        results.add(new DMNDTAnalysisMessage(this, Severity.WARN, MsgUtil.createMessage(Msg.DTANALYSIS_GAP, gap.asHumanFriendly(ddtaTable)), Msg.DTANALYSIS_GAP.getType()));
    }
    return results;
}
Also used : MsgUtil(org.kie.dmn.core.util.MsgUtil) Arrays(java.util.Arrays) RangeBoundary(org.kie.dmn.feel.runtime.Range.RangeBoundary) DecisionTable(org.kie.dmn.model.api.DecisionTable) DMNMessage(org.kie.dmn.api.core.DMNMessage) InputClause(org.kie.dmn.model.api.InputClause) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LiteralExpression(org.kie.dmn.model.api.LiteralExpression) DMNDTAnalysisMessage(org.kie.dmn.validation.dtanalysis.DMNDTAnalysisMessage) Map(java.util.Map) PosNegBlock(org.kie.dmn.validation.dtanalysis.mcdc.MCDCAnalyser.PosNegBlock) DashNode(org.kie.dmn.feel.lang.ast.DashNode) Logger(org.slf4j.Logger) Collection(java.util.Collection) Set(java.util.Set) ValidatorUtil(org.kie.dmn.validation.ValidatorUtil) Collectors(java.util.stream.Collectors) Severity(org.kie.dmn.api.core.DMNMessage.Severity) HitPolicy(org.kie.dmn.model.api.HitPolicy) List(java.util.List) Msg(org.kie.dmn.core.util.Msg) Collections(java.util.Collections) DMNDTAnalysisMessage(org.kie.dmn.validation.dtanalysis.DMNDTAnalysisMessage) ArrayList(java.util.ArrayList) InputClause(org.kie.dmn.model.api.InputClause)

Example 2 with DMNDTAnalysisMessage

use of org.kie.dmn.validation.dtanalysis.DMNDTAnalysisMessage in project drools by kiegroup.

the class DTAnalysis method computeOutputInLOV.

public void computeOutputInLOV() {
    for (int ruleIdx = 0; ruleIdx < ddtaTable.getRule().size(); ruleIdx++) {
        DDTARule rule = ddtaTable.getRule().get(ruleIdx);
        for (int outputIdx = 0; outputIdx < ddtaTable.getOutputs().size(); outputIdx++) {
            Comparable<?> value = rule.getOutputEntry().get(outputIdx);
            if (value instanceof DDTAOutputEntryExpression) {
                // we can't say _statically_ if the output expression is in the output LoV; skipping
                continue;
            }
            DDTAOutputClause outputClause = ddtaTable.getOutputs().get(outputIdx);
            if (outputClause.isDiscreteDomain() && !outputClause.getDiscreteValues().contains(value)) {
                passThruMessages.add(new DMNDTAnalysisMessage(this, Severity.ERROR, MsgUtil.createMessage(Msg.DTANALYSIS_ERROR_RULE_OUTPUT_OUTSIDE_LOV, ruleIdx + 1, value, outputIdx + 1, outputClause.getDiscreteValues()), Msg.DTANALYSIS_ERROR_RULE_OUTPUT_OUTSIDE_LOV.getType()));
            }
        }
    }
}
Also used : DMNDTAnalysisMessage(org.kie.dmn.validation.dtanalysis.DMNDTAnalysisMessage)

Example 3 with DMNDTAnalysisMessage

use of org.kie.dmn.validation.dtanalysis.DMNDTAnalysisMessage in project drools by kiegroup.

the class DTAnalysis method subsumptionsAsMessages.

private Collection<? extends DMNMessage> subsumptionsAsMessages() {
    List<DMNDTAnalysisMessage> results = new ArrayList<>();
    for (Subsumption s : subsumptions) {
        List<Integer> inNaturalOrder = Arrays.asList(s.rule, s.includedRule);
        List<Integer> inReversedOrder = Arrays.asList(s.includedRule, s.rule);
        boolean subsumptionIsA1NFdup = getDuplicateRulesTuples().stream().anyMatch(tuple -> tuple.equals(inNaturalOrder) || tuple.equals(inReversedOrder));
        if (!subsumptionIsA1NFdup) {
            results.add(new DMNDTAnalysisMessage(this, Severity.WARN, MsgUtil.createMessage(Msg.DTANALYSIS_SUBSUMPTION_RULE, s.rule, s.includedRule, s.rule, s.includedRule), Msg.DTANALYSIS_SUBSUMPTION_RULE.getType(), Collections.singletonList(s.rule)));
        } else {
            LOG.debug("skipping Subsumption message because it is actually redundant to the 1st NF duplicate rule ERROR: {}", s);
        }
    }
    return results;
}
Also used : DMNDTAnalysisMessage(org.kie.dmn.validation.dtanalysis.DMNDTAnalysisMessage) ArrayList(java.util.ArrayList)

Example 4 with DMNDTAnalysisMessage

use of org.kie.dmn.validation.dtanalysis.DMNDTAnalysisMessage in project drools by kiegroup.

the class DTAnalysis method asDMNMessages.

public List<DMNMessage> asDMNMessages() {
    List<DMNMessage> results = new ArrayList<>();
    if (isError()) {
        DMNMessage m = new DMNDTAnalysisMessage(this, Severity.WARN, MsgUtil.createMessage(Msg.DTANALYSIS_ERROR_ANALYSIS_SKIPPED, nameOrIDOfTable(), error.getMessage()), Msg.DTANALYSIS_ERROR_ANALYSIS_SKIPPED.getType());
        results.add(m);
        return results;
    }
    results.addAll(passThruMessages());
    results.addAll(gapsAsMessages());
    results.addAll(overlapsAsMessages());
    results.addAll(maskedAndMisleadingRulesAsMessagesIfPriority());
    results.addAll(subsumptionsAsMessages());
    results.addAll(contractionsAsMessages());
    results.addAll(check1stNFViolationAsMessages());
    results.addAll(check2ndNFViolationAsMessages());
    // keep last.
    if (results.isEmpty()) {
        DMNMessage m = new DMNDTAnalysisMessage(this, Severity.INFO, MsgUtil.createMessage(Msg.DTANALYSIS_EMPTY, nameOrIDOfTable()), Msg.DTANALYSIS_EMPTY.getType());
        results.add(m);
        return results;
    }
    return results;
}
Also used : DMNDTAnalysisMessage(org.kie.dmn.validation.dtanalysis.DMNDTAnalysisMessage) DMNMessage(org.kie.dmn.api.core.DMNMessage) ArrayList(java.util.ArrayList)

Example 5 with DMNDTAnalysisMessage

use of org.kie.dmn.validation.dtanalysis.DMNDTAnalysisMessage in project drools by kiegroup.

the class DTAnalysis method overlapsAsMessages.

private Collection overlapsAsMessages() {
    List<DMNDTAnalysisMessage> results = new ArrayList<>();
    for (Overlap overlap : overlaps) {
        switch(sourceDT.getHitPolicy()) {
            case UNIQUE:
                results.add(new DMNDTAnalysisMessage(this, Severity.ERROR, MsgUtil.createMessage(Msg.DTANALYSIS_OVERLAP_HITPOLICY_UNIQUE, overlap.asHumanFriendly(ddtaTable)), Msg.DTANALYSIS_OVERLAP_HITPOLICY_UNIQUE.getType(), overlap.getRules()));
                break;
            case ANY:
                List<Comparable<?>> prevValue = ddtaTable.getRule().get(overlap.getRules().get(0) - 1).getOutputEntry();
                for (int i = 1; i < overlap.getRules().size(); i++) {
                    // deliberately start index 1 for 2nd overlapping rule number.
                    int curIndex = overlap.getRules().get(i) - 1;
                    List<Comparable<?>> curValue = ddtaTable.getRule().get(curIndex).getOutputEntry();
                    if (!prevValue.equals(curValue)) {
                        results.add(new DMNDTAnalysisMessage(this, Severity.ERROR, MsgUtil.createMessage(Msg.DTANALYSIS_OVERLAP_HITPOLICY_ANY, overlap.asHumanFriendly(ddtaTable)), Msg.DTANALYSIS_OVERLAP_HITPOLICY_ANY.getType(), overlap.getRules()));
                        break;
                    } else {
                        prevValue = curValue;
                    }
                }
                break;
            case PRIORITY:
            case FIRST:
            default:
                LOG.debug("In case of any other HitPolicy no overalps is reported, DROOLS-5363: {}", overlap);
                break;
        }
    }
    return results;
}
Also used : DMNDTAnalysisMessage(org.kie.dmn.validation.dtanalysis.DMNDTAnalysisMessage) ArrayList(java.util.ArrayList)

Aggregations

DMNDTAnalysisMessage (org.kie.dmn.validation.dtanalysis.DMNDTAnalysisMessage)5 ArrayList (java.util.ArrayList)4 DMNMessage (org.kie.dmn.api.core.DMNMessage)2 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Severity (org.kie.dmn.api.core.DMNMessage.Severity)1 Msg (org.kie.dmn.core.util.Msg)1 MsgUtil (org.kie.dmn.core.util.MsgUtil)1 DashNode (org.kie.dmn.feel.lang.ast.DashNode)1 RangeBoundary (org.kie.dmn.feel.runtime.Range.RangeBoundary)1 DecisionTable (org.kie.dmn.model.api.DecisionTable)1 HitPolicy (org.kie.dmn.model.api.HitPolicy)1 InputClause (org.kie.dmn.model.api.InputClause)1