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

#36 Add Circular DRD Verifier

parent bdcbab52
No related branches found
No related tags found
No related merge requests found
package de.unikoblenz.ps.core.dmn.verification.verifier.impl;
import de.unikoblenz.ps.base.domain.Name;
import de.unikoblenz.ps.core.dmn.domain.vdmn.*;
import de.unikoblenz.ps.core.dmn.domain.vdmn.utils.VDmnFunctions;
import de.unikoblenz.ps.core.dmn.verification.result.VerificationResultEntryElement;
import de.unikoblenz.ps.core.dmn.verification.result.actions.Action;
import de.unikoblenz.ps.core.dmn.verification.result.actions.VerificationFix;
import de.unikoblenz.ps.core.dmn.verification.verifier.AbstractVerifier;
import de.unikoblenz.ps.core.dmn.verification.verifier.DmnVerifier;
import de.unikoblenz.ps.core.dmn.verification.verifier.classification.DrdModelingLevelVerification;
import java.util.*;
import java.util.stream.Collectors;
import static de.unikoblenz.ps.base.domain.Name.NO_NAME;
import static de.unikoblenz.ps.core.dmn.domain.vdmn.utils.VDmnFunctions.*;
import static de.unikoblenz.ps.core.dmn.verification.result.VerificationResultEntry.VerificationClassification.ERROR;
import static de.unikoblenz.ps.core.dmn.verification.result.VerificationResultEntry.VerificationClassification.WARNING;
import static de.unikoblenz.ps.core.dmn.verification.result.actions.Action.ACTION_SHOW_DECISION;
import static de.unikoblenz.ps.core.dmn.verification.result.actions.Action.ACTION_SHOW_INPUT_DATA;
import static de.unikoblenz.ps.core.dmn.verification.result.actions.ActionScope.*;
import static de.unikoblenz.ps.core.dmn.verification.result.actions.ActionType.*;
import static de.unikoblenz.ps.core.dmn.verification.result.actions.VerificationFix.DEFAULT_SHOW_NAME;
import static de.unikoblenz.ps.core.dmn.verification.result.actions.VerificationFix.SHOW_INPUT_COLUMNS;
@DmnVerifier(
classification = DrdModelingLevelVerification.class,
name = "CircularDRDVerifier",
niceName = "Circular DRD",
description =
"Detecting circles in the DRD.")
public class CircularDRDVerifier extends AbstractVerifier {
@Override
protected void doVerification() {
Stack<VDmnDecision> history = new Stack<>();
Set<Set<VDmnDecision>> circles = new HashSet<>();
for (VDmnDecision decision : dmnObjectContainer.getVDmnDefinition().getVDmnDecisions()) {
history.push(decision);
dfs(history, circles);
history.pop();
}
}
private void dfs(Stack<VDmnDecision> history, Set<Set<VDmnDecision>> circles) {
for (VDmnDecision next : history.peek().getInformationProvidingDecisions()) {
if (history.firstElement().equals(next)) {
Set<VDmnDecision> circle = new HashSet<>(history);
if (!circles.contains(circle)) {
// new circle
circles.add(circle);
circle.forEach(vDmnDecision -> vreFactory.addElement(VerificationResultEntryElement.create(vDmnDecision)));
vreFactory
.addVerificationFix(
VerificationFix.getBuilder()
.withFixName(DEFAULT_SHOW_NAME)
.addAction(ACTION_SHOW_DECISION)
.build());
vreFactory.addToEntry(ERROR, "Circle in Decision nodes detected.");
}
} else {
history.push(next);
dfs(history, circles);
history.pop();
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment