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

Add syntax check for values (creation of Boundary was a success)

parent 7dfbaece
No related branches found
No related tags found
No related merge requests found
Showing
with 140 additions and 30 deletions
......@@ -31,14 +31,12 @@ public class BooleanBoundary extends AbstractGrowingBoundary<Boolean> {
if (text.trim().isEmpty()) {
lowerBound = getMinValue();
upperBound = getMaxValue();
}
if (TRUE_STRING.equals(text.toLowerCase())) {
} else if (TRUE_STRING.equals(text.toLowerCase())) {
lowerBound = upperBound = getMaxValue();
}
if (FALSE_STRING.equals(text.toLowerCase())) {
} else if (FALSE_STRING.equals(text.toLowerCase())) {
lowerBound = upperBound = getMinValue();
} else {
throw new BoundaryParseException("Boolean value cloud not be parsed. " + text);
throw new BoundaryParseException("Boolean value cloud not be parsed: " + text);
}
}
}
......@@ -96,7 +96,7 @@ public class DateBoundary extends AbstractGrowingBoundary<LocalDateTime> {
throw new IllegalArgumentException();
}
} catch (Exception e) {
throw new BoundaryParseException("Date value " + text + " couldn't be parsed.");
throw new BoundaryParseException("Date value " + this.getText() + " couldn't be parsed.");
}
}
}
......@@ -62,7 +62,8 @@ public class DoubleBoundary extends AbstractGrowingBoundary<Double> {
}
} catch (Exception e) {
throw new BoundaryParseException(
String.format("Parsing boundary failed: %s. Exception: %s", text, e.getMessage()));
String.format(
"Parsing Double boundary failed: %s. Exception: %s", this.getText(), e.getMessage()));
}
}
}
......@@ -62,7 +62,9 @@ public class IntegerBoundary extends AbstractGrowingBoundary<Integer> {
}
} catch (Exception e) {
throw new BoundaryParseException(
String.format("Parsing boundary failed: %s. Exception: %s", text, e.getMessage()));
String.format(
"Parsing Integer boundary failed: %s. Exception: %s",
this.getText(), e.getMessage()));
}
simplifyBound();
}
......
package de.unikoblenz.fgbks.base.utils.boundary.impl;
import de.unikoblenz.fgbks.base.utils.boundary.Boundary;
import de.unikoblenz.fgbks.base.utils.boundary.checker.BoundaryCheckType;
import de.unikoblenz.fgbks.core.dmn.domain.vdmn.VTypeRef;
public class InvalidBoundary implements Boundary {
private static InvalidBoundary instance = new InvalidBoundary();
private InvalidBoundary() {}
public static InvalidBoundary getInstance() {
return instance;
}
@Override
public VTypeRef getTypeRef() {
return null;
}
@Override
public String getText() {
return "null";
}
@Override
public boolean checkWith(BoundaryCheckType checkType, Boundary other) {
return false;
}
@Override
public int compareTo(Boundary o) {
return 0;
}
}
......@@ -62,7 +62,8 @@ public class LongBoundary extends AbstractGrowingBoundary<Long> {
}
} catch (Exception e) {
throw new BoundaryParseException(
String.format("Parsing boundary failed: %s. Exception: %s", text, e.getMessage()));
String.format(
"Parsing Long boundary failed: %s. Exception: %s", this.getText(), e.getMessage()));
}
simplifyBound();
}
......
......@@ -2,6 +2,7 @@ package de.unikoblenz.fgbks.base.utils.boundary.impl;
import de.unikoblenz.fgbks.base.utils.boundary.AbstractBoundary;
import de.unikoblenz.fgbks.base.utils.boundary.Boundary;
import de.unikoblenz.fgbks.base.utils.boundary.BoundaryParseException;
import de.unikoblenz.fgbks.base.utils.boundary.checker.BoundaryCheck;
import de.unikoblenz.fgbks.base.utils.boundary.checker.BoundaryCheckType;
import java.util.Arrays;
......@@ -28,19 +29,26 @@ public class StringBoundary extends AbstractBoundary<String> {
@Override
protected void parse(String text) {
matchNoneOfValues = false;
matchAny = Validate.notNull(text).isEmpty();
if (!matchAny) {
matchNoneOfValues = text.toLowerCase().startsWith("not");
text = text.replace('(', '\0').replace(')', '\0').trim();
if (matchNoneOfValues) {
text = text.replaceFirst("not", "").trim();
}
values = text.split(",");
valuesHashes = new int[values.length];
for (int i = 0; i < values.length; i++) {
values[i] = values[i].replace('"', '\0').trim();
valuesHashes[i] = Objects.hashCode(values[i]);
matchAny = false;
try {
matchAny = Validate.notNull(text).isEmpty();
if (matchAny) {
values = new String[0];
} else {
matchNoneOfValues = text.toLowerCase().startsWith("not");
text = text.replace('(', '\0').replace(')', '\0').trim();
if (matchNoneOfValues) {
text = text.replaceFirst("not", "").trim();
}
values = text.split(",");
valuesHashes = new int[values.length];
for (int i = 0; i < values.length; i++) {
values[i] = values[i].replace('"', '\0').trim();
valuesHashes[i] = Objects.hashCode(values[i]);
}
}
} catch (Exception e) {
throw new BoundaryParseException("String value is not valid: " + this.getText());
}
}
......@@ -51,7 +59,7 @@ public class StringBoundary extends AbstractBoundary<String> {
@Override
protected HashMap<BoundaryCheckType, BoundaryCheck> getChecker() {
return null;
return new HashMap<>();
}
@Override
......
......@@ -5,6 +5,7 @@ import de.unikoblenz.fgbks.base.utils.boundary.impl.BooleanBoundary;
import de.unikoblenz.fgbks.base.utils.boundary.impl.DateBoundary;
import de.unikoblenz.fgbks.base.utils.boundary.impl.DoubleBoundary;
import de.unikoblenz.fgbks.base.utils.boundary.impl.IntegerBoundary;
import de.unikoblenz.fgbks.base.utils.boundary.impl.InvalidBoundary;
import de.unikoblenz.fgbks.base.utils.boundary.impl.LongBoundary;
import de.unikoblenz.fgbks.base.utils.boundary.impl.StringBoundary;
import java.time.LocalDateTime;
......@@ -52,9 +53,8 @@ public enum VTypeRef {
try {
return Optional.of(boundaryClass.getDeclaredConstructor(String.class).newInstance(text));
} catch (Exception ignored) {
// nothing
return Optional.of(InvalidBoundary.getInstance());
}
return Optional.empty();
}
VTypeRef(String name, Class<?> javaClass, Class<? extends Boundary> boundaryClass) {
......
package de.unikoblenz.fgbks.core.dmn.verification.verifier.impl;
import de.unikoblenz.fgbks.base.utils.boundary.impl.InvalidBoundary;
import de.unikoblenz.fgbks.core.dmn.domain.vdmn.VDmnInputValue;
import de.unikoblenz.fgbks.core.dmn.domain.vdmn.VTypeRef;
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.verifier.AbstractVerifier;
import de.unikoblenz.fgbks.core.dmn.verification.verifier.DmnVerifier;
import de.unikoblenz.fgbks.core.dmn.verification.verifier.config.DefaultConfiguration;
import de.unikoblenz.fgbks.core.dmn.verification.verifier.types.InputValueSyntaxVerification;
@DmnVerifier(
verifierType = InputValueSyntaxVerification.class,
verifierConfig = DefaultConfiguration.class)
public class InputValueSyntaxVerifier extends AbstractVerifier {
@Override
protected void doVerification() {
dmnObjectContainer.getvDmnDefinition().getDmnDecisions().stream()
.flatMap(
d ->
d.getDmnDecisionTable().getRules().stream()
.flatMap(r -> r.getDmnInputValues().stream()))
.forEach(v -> check(v));
}
private void check(VDmnInputValue inputValue) {
// no Date, because of extra DateVerifier
if (inputValue.getDmnColumn().getTypeRef() != VTypeRef.DATE
&& inputValue.getBoundary() instanceof InvalidBoundary) {
vref.addElement(VerificationResultEntryElement.create(inputValue));
vref.addToEntry(
VerificationClassification.FATAL_ERROR,
"Input value is not valid: " + inputValue.getText());
System.out.println(inputValue.getText() + " IS INVALID SYNTAX");
}
}
}
......@@ -2,16 +2,17 @@ package de.unikoblenz.fgbks.core.dmn.verification.verifier.types;
import de.unikoblenz.fgbks.base.domain.Description;
import de.unikoblenz.fgbks.base.domain.Name;
import javax.validation.constraints.NotNull;
public class EmptyOutputVerification extends AbstractVerificationType {
@Override
public VerificationTypeClassification getClassification() {
public @NotNull VerificationTypeClassification getClassification() {
return VerificationTypeClassification.SYNTAX_LEVEL_VERIFICATION;
}
@Override
public Name getName() {
public @NotNull Name getName() {
return new Name("Empty output check");
}
......
package de.unikoblenz.fgbks.core.dmn.verification.verifier.types;
import static de.unikoblenz.fgbks.core.dmn.verification.verifier.types.VerificationTypeClassification.*;
import static de.unikoblenz.fgbks.core.dmn.verification.verifier.types.VerificationTypeClassification.DECISION_LOGIC_LEVEL_VERIFICATION;
import de.unikoblenz.fgbks.base.domain.Description;
import de.unikoblenz.fgbks.base.domain.Name;
import javax.validation.constraints.NotNull;
public class IdenticalBusinessRuleVerification extends AbstractVerificationType {
@Override
public VerificationTypeClassification getClassification() {
public @NotNull VerificationTypeClassification getClassification() {
return DECISION_LOGIC_LEVEL_VERIFICATION;
}
@Override
public Name getName() {
public @NotNull Name getName() {
return new Name(this.getClass().getSimpleName());
}
@Override
public Description getDescription() {
public @NotNull Description getDescription() {
return new Description("test");
}
}
package de.unikoblenz.fgbks.core.dmn.verification.verifier.types;
import de.unikoblenz.fgbks.base.domain.Description;
import de.unikoblenz.fgbks.base.domain.Name;
import javax.validation.constraints.NotNull;
public class InputValueSyntaxVerification extends AbstractVerificationType {
@Override
public @NotNull VerificationTypeClassification getClassification() {
return VerificationTypeClassification.SYNTAX_LEVEL_VERIFICATION;
}
@Override
public @NotNull Name getName() {
return new Name(this.getClass().getSimpleName());
}
@Override
public @NotNull Description getDescription() {
return new Description("Check values for syntactical correctness.");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment