Skip to content

Commit

Permalink
Precondition before running the validation rule.
Browse files Browse the repository at this point in the history
  • Loading branch information
mansoor-sajjad committed Oct 15, 2024
1 parent 728a268 commit 5fada6a
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 17 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.3</camel.version>
<entur.helpers.version>2.32</entur.helpers.version>
<netex-validator-java.version>3.0.6</netex-validator-java.version>
<netex-validator-java.version>3.0.8</netex-validator-java.version>
<commons-io.version>2.11.0</commons-io.version>
<zt-zip.version>1.17</zt-zip.version>
<redisson.version>3.37.0</redisson.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,8 @@ public NetexValidatorsRunner timetableDataValidatorsRunner(
);

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

List<NetexDataCollector> commonDataCollectors = List.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@ public List<ServiceJourneyStop> serviceJourneyStops(
.orElse(List.of());
}

@Override
public boolean hasServiceJourneyInterchangeInfos(String validationReportId) {
List<String> serviceJourneyInterchangeInfos =
serviceJourneyInterchangeInfoCache.get(validationReportId);
return (
serviceJourneyInterchangeInfos != null &&
!serviceJourneyInterchangeInfos.isEmpty()
);
}

@Override
public List<ServiceJourneyInterchangeInfo> serviceJourneyInterchangeInfos(
String validationReportId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,28 @@ public StopPointsInVehicleJourneyValidator(

@Override
public ValidationReport validate(ValidationReport validationReport) {
netexDataRepository
.serviceJourneyInterchangeInfos(validationReport.getValidationReportId())
.stream()
.map(serviceJourneyInterchange ->
StopPointsInVehicleJourneyContext.of(
validationReport.getValidationReportId(),
netexDataRepository,
serviceJourneyInterchange
)
if (
netexDataRepository.hasServiceJourneyInterchangeInfos(
validationReport.getValidationReportId()
)
.filter(StopPointsInVehicleJourneyContext::isValid)
.map(this::validateStopPoint)
.filter(Objects::nonNull)
.forEach(validationReport::addValidationReportEntry);

) {
netexDataRepository
.serviceJourneyInterchangeInfos(
validationReport.getValidationReportId()
)
.stream()
.map(serviceJourneyInterchange ->
StopPointsInVehicleJourneyContext.of(
validationReport.getValidationReportId(),
netexDataRepository,
serviceJourneyInterchange
)
)
.filter(StopPointsInVehicleJourneyContext::isValid)
.map(this::validateStopPoint)
.filter(Objects::nonNull)
.forEach(validationReport::addValidationReportEntry);
}
return validationReport;
}

Expand Down
5 changes: 5 additions & 0 deletions src/test/java/no/entur/antu/config/TestConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public List<ServiceJourneyStop> serviceJourneyStops(
return List.of();
}

@Override
public boolean hasServiceJourneyInterchangeInfos(String s) {
return false;
}

@Override
public List<ServiceJourneyInterchangeInfo> serviceJourneyInterchangeInfos(
String validationReportId
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/no/entur/antu/validation/ValidationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ void resetMocks() {
Mockito
.when(netexDataRepositoryMock.hasQuayIds(anyString()))
.thenReturn(true);
Mockito
.when(
netexDataRepositoryMock.hasServiceJourneyInterchangeInfos(anyString())
)
.thenReturn(true);

this.stopPlaceRepositoryMock = mock(StopPlaceRepository.class);
}
Expand Down

0 comments on commit 5fada6a

Please sign in to comment.