Skip to content
Snippets Groups Projects
Commit b1e40bf7 authored by Jonas Blatt's avatar Jonas Blatt :ant:
Browse files

#9 Add action for identical rules

(delete duplicate rules only for same output)
parent 5b4d7aa8
No related branches found
No related tags found
No related merge requests found
......@@ -95,6 +95,10 @@ public class VerificationFix {
return this;
}
public Builder withFixName(String fixName) {
return withFixName(new Name(Validate.notNull(fixName)));
}
public Builder addAction(Action action) {
value.actions.add(Validate.notNull(action));
return this;
......
......@@ -14,6 +14,10 @@ import de.unikoblenz.fgbks.core.dmn.domain.vdmn.VDmnValue;
import de.unikoblenz.fgbks.core.dmn.domain.vdmn.utils.VDmnFunctions;
import de.unikoblenz.fgbks.core.dmn.verification.result.VerificationResultEntry.VerificationClassification;
import de.unikoblenz.fgbks.core.dmn.verification.result.VerificationResultEntryElement;
import de.unikoblenz.fgbks.core.dmn.verification.result.actions.Action;
import de.unikoblenz.fgbks.core.dmn.verification.result.actions.ActionScope;
import de.unikoblenz.fgbks.core.dmn.verification.result.actions.ActionType;
import de.unikoblenz.fgbks.core.dmn.verification.result.actions.VerificationFix;
import de.unikoblenz.fgbks.core.dmn.verification.verifier.AbstractVerifier;
import de.unikoblenz.fgbks.core.dmn.verification.verifier.DmnVerifier;
import de.unikoblenz.fgbks.core.dmn.verification.verifier.types.IdenticalRuleVerification;
......@@ -48,13 +52,39 @@ public class IdenticalRuleVerifier extends AbstractVerifier {
int i,
List<VDmnRule> currentRules) {
if (i == inputs.size()) {
boolean sameConclusions = VDmnFunctions.sameConclusions(currentRules);
currentRules.forEach(
rule -> vreFactory.addElement(VerificationResultEntryElement.create(rule)));
vreFactory.addVerificationFix(SHOW_RULES);
vreFactory.addToEntry(
VerificationClassification.WARNING,
templateDecision(dmnDecisionTable.getVDmnDecision()) + "Rules %s have identical inputs.",
getRulesRowsStrings(currentRules));
// Delete action, if output is the same
if (sameConclusions) {
VerificationFix.Builder verificationFixBuilder =
VerificationFix.getBuilder().withFixName("Delete Duplicates");
Action.Builder actionBuilder =
Action.getBuilder().withActionScope(ActionScope.RULE).withActionType(ActionType.DELETE);
boolean first = true;
for (VDmnRule rule : currentRules) {
if (!first) {
verificationFixBuilder.addAction(
Action.getBuilder()
.withActionScope(ActionScope.RULE)
.withActionType(ActionType.DELETE)
.addIdValue(rule.getVDmnDecision().getDecisionId())
.addIdValue(rule.getRuleId())
.build());
}
first = false;
}
vreFactory.addVerificationFix(verificationFixBuilder.build());
}
// Show action
vreFactory
.addVerificationFix(SHOW_RULES)
.addToEntry(
VerificationClassification.WARNING,
templateDecision(dmnDecisionTable.getVDmnDecision())
+ "Rules %s have identical inputs. The output is "
+ (sameConclusions ? "the same." : "the same."),
getRulesRowsStrings(currentRules));
} else {
List<VDmnInputValue> curInVals = new ArrayList<>();
List<VDmnInputValue> sortInVals =
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment