Skip to content

Commit

Permalink
Refactor XPath validation rules
Browse files Browse the repository at this point in the history
  • Loading branch information
vpaturet committed Dec 3, 2024
1 parent ba5bebe commit b4f6d68
Show file tree
Hide file tree
Showing 17 changed files with 368 additions and 279 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.entur.netex.validation.validator.xpath.rules;

import org.entur.netex.validation.validator.Severity;
import org.rutebanken.netex.model.BookingAccessEnumeration;

/**
Expand All @@ -17,16 +18,16 @@ public class ValidateAllowedBookingAccessProperty extends ValidateNotExist {
) +
"'";

private static final String MESSAGE = "Illegal value for BookingAccess";

public ValidateAllowedBookingAccessProperty(String context) {
super(
context +
"/BookingAccess[not(. = (" +
VALID_BOOKING_ACCESS_PROPERTIES +
"))]",
MESSAGE,
"BOOKING_1"
"BOOKING_1",
"Booking illegal BookingAccess",
"Illegal value for BookingAccess",
Severity.ERROR
);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.entur.netex.validation.validator.xpath.rules;

import org.entur.netex.validation.validator.Severity;
import org.rutebanken.netex.model.BookingMethodEnumeration;

/**
Expand All @@ -20,16 +21,16 @@ public class ValidateAllowedBookingMethodProperty extends ValidateNotExist {
) +
"'";

private static final String MESSAGE = "Illegal value for BookingMethod";

public ValidateAllowedBookingMethodProperty(String context) {
super(
context +
"/BookingMethods[tokenize(.,' ')[not(. = (" +
VALID_BOOKING_METHOD_PROPERTIES +
"))]]",
MESSAGE,
"BOOKING_2"
"BOOKING_2",
"Booking illegal BookingMethod",
"Illegal value for BookingMethod",
Severity.ERROR
);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.entur.netex.validation.validator.xpath.rules;

import org.entur.netex.validation.validator.Severity;
import org.rutebanken.netex.model.PurchaseWhenEnumeration;

/**
Expand All @@ -17,13 +18,13 @@ public class ValidateAllowedBookingWhenProperty extends ValidateNotExist {
) +
"'";

private static final String MESSAGE = "Illegal value for BookWhen";

public ValidateAllowedBookingWhenProperty(String context) {
super(
context + "/BookWhen[not(. = (" + VALID_BOOKING_WHEN_PROPERTIES + "))]",
MESSAGE,
"BOOKING_3"
"BOOKING_3",
"Booking illegal BookWhen",
"Illegal value for BookWhen",
Severity.ERROR
);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.entur.netex.validation.validator.xpath.rules;

import org.entur.netex.validation.validator.Severity;
import org.rutebanken.netex.model.PurchaseMomentEnumeration;

/**
Expand All @@ -18,16 +19,16 @@ public class ValidateAllowedBuyWhenProperty extends ValidateNotExist {
) +
"'";

private static final String MESSAGE = "Illegal value for BuyWhen";

public ValidateAllowedBuyWhenProperty(String context) {
super(
context +
"/BuyWhen[tokenize(.,' ')[not(. = (" +
VALID_BUY_WHEN_PROPERTIES +
"))]]",
MESSAGE,
"BUY_WHEN_1"
"BUY_WHEN_1",
"BuyWhen illegal value",
"Illegal value for BuyWhen",
Severity.ERROR
);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.entur.netex.validation.validator.xpath.rules;

import org.entur.netex.validation.validator.Severity;
import org.rutebanken.netex.model.FlexibleLineTypeEnumeration;

/**
Expand Down Expand Up @@ -30,8 +31,10 @@ public ValidateAllowedFlexibleLineType() {
"lines/FlexibleLine/FlexibleLineType[not(. = (" +
VALID_FLEXIBLE_LINE_TYPES +
"))]",
"FLEXIBLE_LINE_8",
"FlexibleLine illegal FlexibleLineType",
MESSAGE,
"FLEXIBLE_LINE_8"
Severity.ERROR
);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.entur.netex.validation.validator.xpath.rules;

import org.entur.netex.validation.validator.Severity;
import org.rutebanken.netex.model.FlexibleServiceEnumeration;

/**
Expand All @@ -18,16 +19,15 @@ public class ValidateAllowedFlexibleServiceType extends ValidateNotExist {
) +
"'";

public static final String MESSAGE =
"Illegal FlexibleServiceType on ServiceJourney";

public ValidateAllowedFlexibleServiceType() {
super(
"vehicleJourneys/ServiceJourney/FlexibleServiceProperties/FlexibleServiceType[not(. = (" +
VALID_FLEXIBLE_SERVICE_TYPES +
"))]",
MESSAGE,
"FLEXIBLE_LINE_9"
"FLEXIBLE_LINE_9",
"FlexibleLine illegal FlexibleServiceType",
"Illegal FlexibleServiceType on ServiceJourney",
Severity.ERROR
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,18 @@ public class ValidateAllowedTransportMode extends ValidateNotExist {
public ValidateAllowedTransportMode(
String contexPath,
String code,
String name,
String message,
Severity severity
) {
this(contexPath, code, message, severity, DEFAULT_VALID_TRANSPORT_MODES);
this(
contexPath,
code,
name,
message,
severity,
DEFAULT_VALID_TRANSPORT_MODES
);
}

/**
Expand All @@ -46,14 +54,16 @@ public ValidateAllowedTransportMode(
public ValidateAllowedTransportMode(
String contexPath,
String code,
String name,
String message,
Severity severity,
String validTransportModes
) {
super(
contexPath + "/TransportMode[not(. = (" + validTransportModes + "))]",
message,
code,
name,
message,
severity
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
public class ValidateAllowedTransportModeOnLine
extends ValidateAllowedTransportMode {

private static final String CODE = "TRANSPORT_MODE_ON_LINE";
private static final String MESSAGE = "Illegal TransportMode on Line: %s";

public ValidateAllowedTransportModeOnLine() {
super(
"lines/*[self::Line or self::FlexibleLine]",
CODE,
MESSAGE,
"Line Illegal TransportMode",
"TRANSPORT_MODE_ON_LINE",
"Illegal TransportMode on Line: %s",
Severity.ERROR
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
public class ValidateAllowedTransportModeOnServiceJourney
extends ValidateAllowedTransportMode {

private static final String CODE = "TRANSPORT_MODE_ON_SERVICE_JOURNEY";
private static final String MESSAGE =
"Illegal TransportMode on ServiceJourney: %s";

public ValidateAllowedTransportModeOnServiceJourney() {
super("vehicleJourneys/ServiceJourney", CODE, MESSAGE, Severity.WARNING);
super(
"vehicleJourneys/ServiceJourney",
"TRANSPORT_MODE_ON_SERVICE_JOURNEY",
"Service Journey Illegal TransportMode",
"Illegal TransportMode on ServiceJourney: %s",
Severity.WARNING
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,14 @@ public class ValidateAllowedTransportSubMode extends ValidateNotExist {
public ValidateAllowedTransportSubMode(
String contextPath,
String code,
String name,
String message,
Severity severity
) {
this(
contextPath,
code,
name,
message,
severity,
DEFAULT_VALID_TRANSPORT_SUBMODES
Expand All @@ -95,6 +97,7 @@ public ValidateAllowedTransportSubMode(
public ValidateAllowedTransportSubMode(
String contextPath,
String code,
String name,
String message,
Severity severity,
String validTransportSubModes
Expand All @@ -104,8 +107,9 @@ public ValidateAllowedTransportSubMode(
"/TransportSubmode[not(. = (" +
validTransportSubModes +
"))]",
message,
code,
name,
message,
severity
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
public class ValidateAllowedTransportSubModeOnLine
extends ValidateAllowedTransportSubMode {

private static final String CODE = "TRANSPORT_SUB_MODE_ON_LINE";
private static final String MESSAGE = "Illegal TransportSubMode on Line: %s";

public ValidateAllowedTransportSubModeOnLine() {
super(
"lines/*[self::Line or self::FlexibleLine]",
CODE,
MESSAGE,
"TRANSPORT_SUB_MODE_ON_LINE",
"Line Illegal TransportSubMode",
"Illegal TransportSubMode on Line: %s",
Severity.ERROR
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
public class ValidateAllowedTransportSubModeOnServiceJourney
extends ValidateAllowedTransportSubMode {

private static final String CODE = "TRANSPORT_SUB_MODE_ON_SERVICE_JOURNEY";
private static final String MESSAGE =
"Illegal TransportSubMode on ServiceJourney: %s";

public ValidateAllowedTransportSubModeOnServiceJourney() {
super("vehicleJourneys/ServiceJourney", CODE, MESSAGE, Severity.WARNING);
super(
"vehicleJourneys/ServiceJourney",
"TRANSPORT_SUB_MODE_ON_SERVICE_JOURNEY",
"Service Journey Illegal TransportSubMode",
"Illegal TransportSubMode on ServiceJourney: %s",
Severity.WARNING
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,19 @@ public class ValidateAtLeastOne implements XPathValidationRule {
private final String xpath;
private final ValidationRule rule;

public ValidateAtLeastOne(String xpath, String message, String code) {
this(xpath, message, code, Severity.UNSET);
}

public ValidateAtLeastOne(
String xpath,
String message,
String code,
String name,
String message,
Severity severity
) {
this(xpath, new ValidationRule(code, name, message, severity));
}

public ValidateAtLeastOne(String xpath, ValidationRule validationRule) {
this.xpath = xpath;
this.rule = new ValidationRule(code, message, severity);
this.rule = validationRule;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,19 @@ public class ValidateExactlyOne extends AbstractXPathValidationRule {
private final String xpath;
private final ValidationRule rule;

public ValidateExactlyOne(String xpath, String message, String code) {
this(xpath, message, code, Severity.UNSET);
}

public ValidateExactlyOne(
String xpath,
String message,
String code,
String name,
String message,
Severity severity
) {
this(xpath, new ValidationRule(code, name, message, severity));
}

public ValidateExactlyOne(String xpath, ValidationRule validationRule) {
this.xpath = xpath;
this.rule = new ValidationRule(code, message, severity);
this.rule = validationRule;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,19 @@ public class ValidateNotExist extends AbstractXPathValidationRule {
private final String xpath;
private final ValidationRule rule;

public ValidateNotExist(String xpath, String message, String code) {
this(xpath, message, code, Severity.UNSET);
}

public ValidateNotExist(
String xpath,
String message,
String code,
String name,
String message,
Severity severity
) {
this(xpath, new ValidationRule(code, name, message, severity));
}

public ValidateNotExist(String xpath, ValidationRule validationRule) {
this.xpath = xpath;
this.rule = new ValidationRule(code, message, severity);
this.rule = validationRule;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ void testDescribe() {
ValidationTree tree = new ValidationTree("Root", "/");
XPathValidationRule xPathValidationRule = new ValidateNotExist(
"//Block",
"Blocks are not present",
RULE_CODE
RULE_CODE,
"Blocks are not present"
);
tree.addValidationRule(xPathValidationRule);
Set<XPathValidationRule> rules = tree.getRules();
Expand Down

0 comments on commit b4f6d68

Please sign in to comment.