From 2195d17b18fc33c60f076bf6dc3b8c22028b535a Mon Sep 17 00:00:00 2001 From: Vincent Paturet Date: Thu, 21 Nov 2024 15:25:09 +0100 Subject: [PATCH] Add support for Finland validation profile --- pom.xml | 2 +- .../no/entur/antu/config/ValidatorConfig.java | 5 + .../TimetableDataFinlandValidatorConfig.java | 182 ++++++++++++++++++ ...tableDataFinlandValidationTreeFactory.java | 79 ++++++++ .../antu/validation/ValidationProfile.java | 5 + .../entur/antu/validation/ValidationTest.java | 2 +- ...topAssignmentValidatorIntegrationTest.java | 2 +- 7 files changed, 274 insertions(+), 3 deletions(-) create mode 100644 src/main/java/no/entur/antu/finland/config/TimetableDataFinlandValidatorConfig.java create mode 100644 src/main/java/no/entur/antu/finland/validator/EnturTimetableDataFinlandValidationTreeFactory.java diff --git a/pom.xml b/pom.xml index 40c2cf1d..a53b56f0 100644 --- a/pom.xml +++ b/pom.xml @@ -27,7 +27,7 @@ false 4.4.4 3.0 - 5.0.0 + 6.0.0 3.1.29 2.11.0 1.17 diff --git a/src/main/java/no/entur/antu/config/ValidatorConfig.java b/src/main/java/no/entur/antu/config/ValidatorConfig.java index 745ebd34..01f59f60 100644 --- a/src/main/java/no/entur/antu/config/ValidatorConfig.java +++ b/src/main/java/no/entur/antu/config/ValidatorConfig.java @@ -176,6 +176,9 @@ public NetexValidationProfile netexValidationProfile( @Qualifier( "swedenTimetableDataSwedenValidatorsRunner" ) NetexValidatorsRunner timetableSwedenDataValidatorsRunner, + @Qualifier( + "finlandTimetableDataValidatorsRunner" + ) NetexValidatorsRunner timetableFinlandDataValidatorsRunner, @Qualifier( "stopPlaceDataValidatorsRunner" ) NetexValidatorsRunner stopDataValidatorsRunner, @@ -198,6 +201,8 @@ public NetexValidationProfile netexValidationProfile( flexMergingTimetableDataValidatorsRunner, TIMETABLE_SWEDEN, timetableSwedenDataValidatorsRunner, + TIMETABLE_FINLAND, + timetableFinlandDataValidatorsRunner, STOP, stopDataValidatorsRunner ), diff --git a/src/main/java/no/entur/antu/finland/config/TimetableDataFinlandValidatorConfig.java b/src/main/java/no/entur/antu/finland/config/TimetableDataFinlandValidatorConfig.java new file mode 100644 index 00000000..419d8b61 --- /dev/null +++ b/src/main/java/no/entur/antu/finland/config/TimetableDataFinlandValidatorConfig.java @@ -0,0 +1,182 @@ +/* + * Licensed under the EUPL, Version 1.2 or – as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * + * https://joinup.ec.europa.eu/software/page/eupl + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + */ + +package no.entur.antu.finland.config; + +import java.util.List; +import no.entur.antu.finland.validator.EnturTimetableDataFinlandValidationTreeFactory; +import no.entur.antu.netexdata.collectors.LineInfoCollector; +import no.entur.antu.netexdata.collectors.ServiceJourneyInterchangeInfoCollector; +import no.entur.antu.netexdata.collectors.ServiceJourneyStopsCollector; +import no.entur.antu.validation.validator.id.NetexIdValidator; +import no.entur.antu.validation.validator.interchange.distance.UnexpectedInterchangeDistanceValidator; +import no.entur.antu.validation.validator.interchange.duplicate.DuplicateInterchangesValidator; +import no.entur.antu.validation.validator.interchange.mandatoryfields.MandatoryFieldsValidator; +import no.entur.antu.validation.validator.interchange.stoppoints.StopPointsInVehicleJourneyValidator; +import no.entur.antu.validation.validator.journeypattern.stoppoint.distance.UnexpectedDistanceBetweenStopPointsValidator; +import no.entur.antu.validation.validator.journeypattern.stoppoint.identicalstoppoints.IdenticalStopPointsValidator; +import no.entur.antu.validation.validator.journeypattern.stoppoint.samequayref.SameQuayRefValidator; +import no.entur.antu.validation.validator.journeypattern.stoppoint.samestoppoints.SameStopPointsValidator; +import no.entur.antu.validation.validator.journeypattern.stoppoint.stoppointscount.StopPointsCountValidator; +import no.entur.antu.validation.validator.line.DuplicateLineNameValidator; +import no.entur.antu.validation.validator.passengerstopassignment.MissingPassengerStopAssignmentValidator; +import no.entur.antu.validation.validator.servicejourney.passingtime.NonIncreasingPassingTimeValidator; +import no.entur.antu.validation.validator.servicejourney.servicealteration.InvalidServiceAlterationValidator; +import no.entur.antu.validation.validator.servicejourney.servicealteration.MissingReplacementValidator; +import no.entur.antu.validation.validator.servicejourney.speed.UnexpectedSpeedValidator; +import no.entur.antu.validation.validator.servicelink.distance.UnexpectedDistanceInServiceLinkValidator; +import no.entur.antu.validation.validator.servicelink.stoppoints.MismatchedStopPointsValidator; +import org.entur.netex.validation.validator.DatasetValidator; +import org.entur.netex.validation.validator.NetexValidatorsRunner; +import org.entur.netex.validation.validator.ValidationReportEntryFactory; +import org.entur.netex.validation.validator.XPathValidator; +import org.entur.netex.validation.validator.id.NetexIdUniquenessValidator; +import org.entur.netex.validation.validator.id.NetexReferenceValidator; +import org.entur.netex.validation.validator.id.ReferenceToValidEntityTypeValidator; +import org.entur.netex.validation.validator.id.VersionOnLocalNetexIdValidator; +import org.entur.netex.validation.validator.id.VersionOnRefToLocalNetexIdValidator; +import org.entur.netex.validation.validator.jaxb.CommonDataRepositoryLoader; +import org.entur.netex.validation.validator.jaxb.JAXBValidator; +import org.entur.netex.validation.validator.jaxb.NetexDataCollector; +import org.entur.netex.validation.validator.jaxb.NetexDataRepository; +import org.entur.netex.validation.validator.jaxb.SiteFrameStopPlaceRepository; +import org.entur.netex.validation.validator.jaxb.StopPlaceRepository; +import org.entur.netex.validation.validator.schema.NetexSchemaValidator; +import org.entur.netex.validation.validator.xpath.ValidationTreeFactory; +import org.entur.netex.validation.validator.xpath.XPathRuleValidator; +import org.entur.netex.validation.xml.NetexXMLParser; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * Configuration for validating timetable data from Sweden. + */ +@Configuration +public class TimetableDataFinlandValidatorConfig { + + @Bean + public ValidationTreeFactory finlandTimetableDataValidationTreeFactory() { + return new EnturTimetableDataFinlandValidationTreeFactory(); + } + + @Bean + public XPathRuleValidator finlandTimetableDataXPathValidator( + @Qualifier( + "finlandTimetableDataValidationTreeFactory" + ) ValidationTreeFactory validationTreeFactory, + ValidationReportEntryFactory validationReportEntryFactory + ) { + return new XPathRuleValidator( + validationTreeFactory, + validationReportEntryFactory + ); + } + + @Bean + public NetexValidatorsRunner finlandTimetableDataValidatorsRunner( + NetexSchemaValidator netexSchemaValidator, + @Qualifier( + "finlandTimetableDataXPathValidator" + ) XPathRuleValidator xPathRuleValidator, + NetexIdValidator netexIdValidator, + VersionOnLocalNetexIdValidator versionOnLocalNetexIdValidator, + VersionOnRefToLocalNetexIdValidator versionOnRefToLocalNetexIdValidator, + ReferenceToValidEntityTypeValidator referenceToValidEntityTypeValidator, + NetexReferenceValidator netexReferenceValidator, + @Qualifier( + "netexIdUniquenessValidator" + ) NetexIdUniquenessValidator netexIdUniquenessValidator, + UnexpectedDistanceBetweenStopPointsValidator unexpectedDistanceBetweenStopPointsValidator, + IdenticalStopPointsValidator identicalStopPointsValidator, + SameQuayRefValidator sameQuayRefValidator, + SameStopPointsValidator sameStopPointsValidator, + StopPointsCountValidator stopPointsCountValidator, + MissingPassengerStopAssignmentValidator missingPassengerStopAssignmentValidator, + NonIncreasingPassingTimeValidator nonIncreasingPassingTimeValidator, + UnexpectedSpeedValidator unexpectedSpeedValidator, + UnexpectedDistanceInServiceLinkValidator unexpectedDistanceInServiceLinkValidator, + MismatchedStopPointsValidator mismatchedStopPointsValidator, + MandatoryFieldsValidator mandatoryFieldsValidator, + DuplicateInterchangesValidator duplicateInterchangesValidator, + InvalidServiceAlterationValidator invalidServiceAlterationValidator, + UnexpectedInterchangeDistanceValidator unexpectedInterchangeDistanceValidator, + StopPointsInVehicleJourneyValidator stopPointsInVehicleJourneyValidator, + DuplicateLineNameValidator duplicateLineNameValidator, + MissingReplacementValidator missingReplacementValidator, + LineInfoCollector lineInfoCollector, + ServiceJourneyStopsCollector serviceJourneyStopsCollector, + ServiceJourneyInterchangeInfoCollector serviceJourneyInterchangeInfoCollector, + CommonDataRepositoryLoader commonDataRepository, + NetexDataRepository netexDataRepository, + StopPlaceRepository stopPlaceRepository + ) { + NetexXMLParser netexXMLParser = new NetexXMLParser(); + + List xPathValidators = List.of( + xPathRuleValidator, + netexIdValidator, + versionOnLocalNetexIdValidator, + versionOnRefToLocalNetexIdValidator, + referenceToValidEntityTypeValidator, + netexReferenceValidator, + netexIdUniquenessValidator + ); + + List jaxbValidators = List.of( + unexpectedDistanceBetweenStopPointsValidator, + identicalStopPointsValidator, + sameQuayRefValidator, + sameStopPointsValidator, + stopPointsCountValidator, + missingPassengerStopAssignmentValidator, + nonIncreasingPassingTimeValidator, + unexpectedSpeedValidator, + unexpectedDistanceInServiceLinkValidator, + mismatchedStopPointsValidator, + mandatoryFieldsValidator, + duplicateInterchangesValidator, + invalidServiceAlterationValidator, + missingReplacementValidator, + duplicateInterchangesValidator, + unexpectedInterchangeDistanceValidator + ); + + List netexTimetableDatasetValidators = List.of( + duplicateLineNameValidator, + stopPointsInVehicleJourneyValidator + ); + + List commonDataCollectors = List.of( + lineInfoCollector, + serviceJourneyInterchangeInfoCollector, + serviceJourneyStopsCollector + ); + + return NetexValidatorsRunner + .of() + .withNetexXMLParser(netexXMLParser) + .withNetexSchemaValidator(netexSchemaValidator) + .withXPathValidators(xPathValidators) + .withJaxbValidators(jaxbValidators) + .withDatasetValidators(netexTimetableDatasetValidators) + .withNetexDataCollectors(commonDataCollectors) + .withCommonDataRepository(commonDataRepository) + .withNetexDataRepository(netexDataRepository) + .withStopPlaceRepository(SiteFrameStopPlaceRepository::new) + .build(); + } +} diff --git a/src/main/java/no/entur/antu/finland/validator/EnturTimetableDataFinlandValidationTreeFactory.java b/src/main/java/no/entur/antu/finland/validator/EnturTimetableDataFinlandValidationTreeFactory.java new file mode 100644 index 00000000..537fb38f --- /dev/null +++ b/src/main/java/no/entur/antu/finland/validator/EnturTimetableDataFinlandValidationTreeFactory.java @@ -0,0 +1,79 @@ +package no.entur.antu.finland.validator; + +import java.util.List; +import java.util.Set; +import no.entur.antu.organisation.OrganisationRepository; +import no.entur.antu.validation.validator.xpath.EnturTimetableDataValidationTreeFactory; +import org.entur.netex.validation.validator.xpath.ValidationRule; +import org.entur.netex.validation.validator.xpath.ValidationTree; + +/** + * XPath validation tree for timetable data from Finland. + * Validation rules are adapted to match finnish content. + */ +public class EnturTimetableDataFinlandValidationTreeFactory + extends EnturTimetableDataValidationTreeFactory { + + public EnturTimetableDataFinlandValidationTreeFactory() { + super( + new OrganisationRepository() { + @Override + public void refreshCache() {} + + @Override + public boolean isEmpty() { + return false; + } + + @Override + public Set getWhitelistedAuthorityIds(String codespace) { + return Set.of(); + } + } + ); + } + + @Override + protected ValidationTree getSingleFramesValidationTreeForCommonFile() { + ValidationTree validationTree = + super.getSingleFramesValidationTreeForCommonFile(); + // remove check on SiteFrame, they are part of Swedish datasets + validationTree.removeValidationRule("SITE_FRAME_IN_COMMON_FILE"); + return validationTree; + } + + @Override + protected List getCompositeFrameBaseValidationRules() { + List compositeFrameBaseValidationRules = + super.getCompositeFrameBaseValidationRules(); + // remove check on NSR codespace + compositeFrameBaseValidationRules.removeIf(validationRule -> + validationRule.getCode().equals("NSR_CODESPACE") + ); + // allow SiteFrame + compositeFrameBaseValidationRules.removeIf(validationRule -> + validationRule.getCode().equals("COMPOSITE_SITE_FRAME_IN_COMMON_FILE") + ); + return compositeFrameBaseValidationRules; + } + + @Override + protected ValidationTree getResourceFrameValidationTree(String path) { + ValidationTree resourceFrameValidationTree = + super.getResourceFrameValidationTree(path); + // remove validation against the Norwegian organisation registry + resourceFrameValidationTree.removeValidationRule("AUTHORITY_ID"); + return resourceFrameValidationTree; + } + + @Override + protected List getServiceFrameBaseValidationRules() { + List serviceFrameBaseValidationRules = + super.getServiceFrameBaseValidationRules(); + // remove time-consuming rule + serviceFrameBaseValidationRules.removeIf(validationRule -> + "PASSENGER_STOP_ASSIGNMENT_3".equals(validationRule.getCode()) + ); + return serviceFrameBaseValidationRules; + } +} diff --git a/src/main/java/no/entur/antu/validation/ValidationProfile.java b/src/main/java/no/entur/antu/validation/ValidationProfile.java index 31a8982a..92fd502e 100644 --- a/src/main/java/no/entur/antu/validation/ValidationProfile.java +++ b/src/main/java/no/entur/antu/validation/ValidationProfile.java @@ -34,6 +34,11 @@ public enum ValidationProfile { */ TIMETABLE_SWEDEN("TimetableSweden"), + /** + * Profile for validating swedish timetable data. + */ + TIMETABLE_FINLAND("TimetableFinland"), + /** * Profile for stop dataset. */ diff --git a/src/test/java/no/entur/antu/validation/ValidationTest.java b/src/test/java/no/entur/antu/validation/ValidationTest.java index 8eb91383..6c413bf4 100644 --- a/src/test/java/no/entur/antu/validation/ValidationTest.java +++ b/src/test/java/no/entur/antu/validation/ValidationTest.java @@ -202,7 +202,7 @@ private ValidationReport runValidation( VALIDATION_REPORT_ID, netexEntitiesIndex, commonDataRepositoryMock, - stopPlaceRepositoryMock, + v -> stopPlaceRepositoryMock, TEST_CODESPACE, mockAsCommonFile ? TEST_COMMON_XML_FILE : TEST_LINE_XML_FILE, Map.of() diff --git a/src/test/java/no/entur/antu/validation/validator/passengerstopassignemnt/MissingPassengerStopAssignmentValidatorIntegrationTest.java b/src/test/java/no/entur/antu/validation/validator/passengerstopassignemnt/MissingPassengerStopAssignmentValidatorIntegrationTest.java index 03d56805..5dcdb982 100644 --- a/src/test/java/no/entur/antu/validation/validator/passengerstopassignemnt/MissingPassengerStopAssignmentValidatorIntegrationTest.java +++ b/src/test/java/no/entur/antu/validation/validator/passengerstopassignemnt/MissingPassengerStopAssignmentValidatorIntegrationTest.java @@ -113,7 +113,7 @@ private ValidationReport getValidationReport( validationReportId, netexEntitiesIndex, commonDataRepository, - stopPlaceRepository, + v -> stopPlaceRepository, TEST_CODESPACE, TEST_LINE_XML_FILE, Map.of()