-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Finland validation profile (#598)
- Loading branch information
Showing
7 changed files
with
274 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
182 changes: 182 additions & 0 deletions
182
src/main/java/no/entur/antu/finland/config/TimetableDataFinlandValidatorConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
.../java/no/entur/antu/finland/validator/EnturTimetableDataFinlandValidationTreeFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters