Skip to content

Commit

Permalink
Update rules documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
vpaturet committed Jan 2, 2025
1 parent 085f590 commit 8348ce0
Show file tree
Hide file tree
Showing 13 changed files with 337 additions and 593 deletions.
283 changes: 146 additions & 137 deletions README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import java.io.InputStream;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.entur.netex.validation.exception.NetexValidationException;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;
Expand Down Expand Up @@ -48,9 +48,7 @@ private Map<String, ValidationRuleConfig> loadConfigurationFile(
.getResourceAsStream(configurationFile);

if (inputStream == null) {
throw new NetexValidationException(
"Validation rules configuration file not found: " + configurationFile
);
return new HashMap<>();
}

Yaml yaml = new Yaml(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,30 @@ public ValidationReportEntry createValidationReportEntry(
validationIssue.dataLocation()
);
}

@Override
public ValidationReportEntry templateValidationReportEntry(
ValidationRule validationRule
) {
ValidationRuleConfig validationRuleConfig = validationConfigLoader
.getValidationRuleConfigs()
.get(validationRule.code());
if (validationRuleConfig == null) {
return ValidationReportEntryFactory.super.templateValidationReportEntry(
validationRule
);
}

String message = validationRuleConfig.getMessage() != null
? validationRuleConfig.getMessage()
: validationRule.message();
String name = validationRuleConfig.getName() != null
? validationRuleConfig.getName()
: validationRule.name();
Severity severity = validationRuleConfig.getSeverity() != null
? validationRuleConfig.getSeverity()
: validationRule.severity();

return new ValidationReportEntry(message, name, severity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -482,12 +482,34 @@ > List<ValidationReportEntry> runValidator(
}
}

public Set<String> getRuleDescriptions() {
public Map<String, String> getRuleDescriptionByCode() {
return Stream
.concat(xPathValidators.stream(), jaxbValidators.stream())
.map(NetexValidator::getRules)
.flatMap(Collection::stream)
.map(ValidationRule::name)
.collect(Collectors.toSet());
.collect(
Collectors.toMap(
ValidationRule::code,
validationRule ->
validationReportEntryFactory
.templateValidationReportEntry(validationRule)
.getName(),
(a, b) -> {
throw new IllegalStateException(
"Duplicate validation rule: " + a + ", " + b
);
},
TreeMap::new
)
);
}

/**
*
* @deprecated use {@link #getRuleDescriptionByCode()}
*/
@Deprecated
public Set<String> getRuleDescriptions() {
return new LinkedHashSet<>(getRuleDescriptionByCode().values());
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
package org.entur.netex.validation.validator;

/**
* Create validation entries based on the rule execution result (code and message) and the configuration file (name and severity)
* Factory for validation report entries.
* Concrete implementation may override the default configuration provided by the validation rule.
*/
public interface ValidationReportEntryFactory {
/**
* Create a validation report entry for a validation issue.
* Concrete implementations may override the default configuration provided by the validation rule.
*/
ValidationReportEntry createValidationReportEntry(
ValidationIssue validationIssue
);

/**
* Create a template validation report entry for a validation rule, for documentation purpose.
* The data location is empty and the message placeholders are not resolved.
* Concrete implementations may override the default configuration provided by the validation rule.
*/
default ValidationReportEntry templateValidationReportEntry(
ValidationRule validationRule
) {
return new ValidationReportEntry(
validationRule.message(),
validationRule.name(),
validationRule.severity()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class NetexIdUniquenessValidator implements XPathValidator {
static final ValidationRule RULE_DUPLICATE_ID_ACROSS_COMMON_FILES =
new ValidationRule(
"NETEX_ID_10",
" Duplicate NeTEx ID across common files",
"Duplicate NeTEx ID across common files",
"Duplicate element identifiers across common files",
Severity.WARNING
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
public class VersionOnLocalNetexIdValidator implements XPathValidator {

static final ValidationRule RULE = new ValidationRule(
public static final ValidationRule RULE = new ValidationRule(
"NETEX_ID_8",
"NeTEx ID missing version on elements",
"Missing version attribute on elements with id attribute",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public class ValidateAllowedTransportModeOnLine
public ValidateAllowedTransportModeOnLine() {
super(
"lines/*[self::Line or self::FlexibleLine]",
"Line Illegal TransportMode",
"TRANSPORT_MODE_ON_LINE",
"Line Illegal TransportMode",
"Illegal TransportMode on Line: %s",
Severity.ERROR
);
Expand Down
Loading

0 comments on commit 8348ce0

Please sign in to comment.