Skip to content

Commit

Permalink
Add support for Finland validation profile (#598)
Browse files Browse the repository at this point in the history
  • Loading branch information
vpaturet authored Nov 21, 2024
1 parent c0df969 commit d80eec0
Show file tree
Hide file tree
Showing 7 changed files with 274 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<entur.google.pubsub.emulator.download.skip>false</entur.google.pubsub.emulator.download.skip>
<camel.version>4.4.4</camel.version>
<entur.helpers.version>3.0</entur.helpers.version>
<netex-validator-java.version>5.0.0</netex-validator-java.version>
<netex-validator-java.version>6.0.0</netex-validator-java.version>
<netex-parser-java.version>3.1.29</netex-parser-java.version>
<commons-io.version>2.11.0</commons-io.version>
<zt-zip.version>1.17</zt-zip.version>
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/no/entur/antu/config/ValidatorConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ public NetexValidationProfile netexValidationProfile(
@Qualifier(
"swedenTimetableDataSwedenValidatorsRunner"
) NetexValidatorsRunner timetableSwedenDataValidatorsRunner,
@Qualifier(
"finlandTimetableDataValidatorsRunner"
) NetexValidatorsRunner timetableFinlandDataValidatorsRunner,
@Qualifier(
"stopPlaceDataValidatorsRunner"
) NetexValidatorsRunner stopDataValidatorsRunner,
Expand All @@ -198,6 +201,8 @@ public NetexValidationProfile netexValidationProfile(
flexMergingTimetableDataValidatorsRunner,
TIMETABLE_SWEDEN,
timetableSwedenDataValidatorsRunner,
TIMETABLE_FINLAND,
timetableFinlandDataValidatorsRunner,
STOP,
stopDataValidatorsRunner
),
Expand Down
Original file line number Diff line number Diff line change
@@ -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<XPathValidator> xPathValidators = List.of(
xPathRuleValidator,
netexIdValidator,
versionOnLocalNetexIdValidator,
versionOnRefToLocalNetexIdValidator,
referenceToValidEntityTypeValidator,
netexReferenceValidator,
netexIdUniquenessValidator
);

List<JAXBValidator> jaxbValidators = List.of(
unexpectedDistanceBetweenStopPointsValidator,
identicalStopPointsValidator,
sameQuayRefValidator,
sameStopPointsValidator,
stopPointsCountValidator,
missingPassengerStopAssignmentValidator,
nonIncreasingPassingTimeValidator,
unexpectedSpeedValidator,
unexpectedDistanceInServiceLinkValidator,
mismatchedStopPointsValidator,
mandatoryFieldsValidator,
duplicateInterchangesValidator,
invalidServiceAlterationValidator,
missingReplacementValidator,
duplicateInterchangesValidator,
unexpectedInterchangeDistanceValidator
);

List<DatasetValidator> netexTimetableDatasetValidators = List.of(
duplicateLineNameValidator,
stopPointsInVehicleJourneyValidator
);

List<NetexDataCollector> 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();
}
}
Original file line number Diff line number Diff line change
@@ -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<String> 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<ValidationRule> getCompositeFrameBaseValidationRules() {
List<ValidationRule> 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<ValidationRule> getServiceFrameBaseValidationRules() {
List<ValidationRule> serviceFrameBaseValidationRules =
super.getServiceFrameBaseValidationRules();
// remove time-consuming rule
serviceFrameBaseValidationRules.removeIf(validationRule ->
"PASSENGER_STOP_ASSIGNMENT_3".equals(validationRule.getCode())
);
return serviceFrameBaseValidationRules;
}
}
5 changes: 5 additions & 0 deletions src/main/java/no/entur/antu/validation/ValidationProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public enum ValidationProfile {
*/
TIMETABLE_SWEDEN("TimetableSweden"),

/**
* Profile for validating swedish timetable data.
*/
TIMETABLE_FINLAND("TimetableFinland"),

/**
* Profile for stop dataset.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/no/entur/antu/validation/ValidationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ private <V extends AntuNetexValidator> ValidationReport runValidation(
VALIDATION_REPORT_ID,
netexEntitiesIndex,
commonDataRepositoryMock,
stopPlaceRepositoryMock,
v -> stopPlaceRepositoryMock,
TEST_CODESPACE,
mockAsCommonFile ? TEST_COMMON_XML_FILE : TEST_LINE_XML_FILE,
Map.of()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private ValidationReport getValidationReport(
validationReportId,
netexEntitiesIndex,
commonDataRepository,
stopPlaceRepository,
v -> stopPlaceRepository,
TEST_CODESPACE,
TEST_LINE_XML_FILE,
Map.of()
Expand Down

0 comments on commit d80eec0

Please sign in to comment.