Skip to content

Commit

Permalink
Refactor JAXBValidationContext (#594)
Browse files Browse the repository at this point in the history
  • Loading branch information
vpaturet authored Nov 18, 2024
1 parent 16bed51 commit 86ce1b3
Show file tree
Hide file tree
Showing 53 changed files with 848 additions and 1,169 deletions.
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
<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>4.1.2</netex-validator-java.version>
<netex-validator-java.version>4.2.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>
<redisson.version>3.39.0</redisson.version>
Expand Down Expand Up @@ -64,6 +65,11 @@
<artifactId>netex-validator-java</artifactId>
<version>${netex-validator-java.version}</version>
</dependency>
<dependency>
<groupId>org.entur</groupId>
<artifactId>netex-parser-java</artifactId>
<version>${netex-parser-java.version}</version>
</dependency>
<dependency>
<groupId>org.entur.ror.helpers</groupId>
<artifactId>entur-google-pubsub</artifactId>
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/no/entur/antu/netexdata/NetexDataResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import java.util.Objects;
import java.util.stream.Collectors;
import no.entur.antu.exception.AntuException;
import no.entur.antu.validation.AntuNetexData;
import org.entur.netex.NetexParser;
import org.entur.netex.index.api.NetexEntitiesIndex;
import org.entur.netex.validation.validator.jaxb.JAXBValidationContext;
import org.entur.netex.validation.validator.model.FromToScheduledStopPointId;
import org.entur.netex.validation.validator.model.ServiceLinkId;
import org.rutebanken.netex.model.PassengerStopAssignment;
Expand Down Expand Up @@ -63,8 +63,10 @@ public Map<String, String> getQuayIdsPerScheduledStopPoints() {
}

public Map<String, String> getFromToScheduledStopPointIdPerServiceLinkId() {
return AntuNetexData
.serviceLinks(getCommonDataIndex())
return getCommonDataIndex()
.getServiceLinkIndex()
.getAll()
.stream()
.collect(
Collectors.toMap(
serviceLink -> ServiceLinkId.of(serviceLink).toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import no.entur.antu.validation.AntuNetexData;
import org.entur.netex.validation.validator.jaxb.JAXBValidationContext;
import org.entur.netex.validation.validator.jaxb.NetexDataCollector;
import org.entur.netex.validation.validator.jaxb.support.FlexibleLineUtils;
import org.entur.netex.validation.validator.model.SimpleLine;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
Expand All @@ -27,15 +27,9 @@ public LineInfoCollector(
protected void collectDataFromLineFile(
JAXBValidationContext validationContext
) {
AntuNetexData antuNetexData = new AntuNetexData(
validationContext.getValidationReportId(),
validationContext.getNetexEntitiesIndex(),
validationContext.getNetexDataRepository(),
validationContext.getStopPlaceRepository()
);
addLineName(
antuNetexData.validationReportId(),
antuNetexData.lineInfo(validationContext.getFileName())
validationContext.getValidationReportId(),
lineInfo(validationContext)
);
}

Expand Down Expand Up @@ -65,4 +59,25 @@ public void addLineName(String validationReportId, SimpleLine lineInfo) {
}
}
}

private SimpleLine lineInfo(JAXBValidationContext validationContext) {
return validationContext
.getNetexEntitiesIndex()
.getLineIndex()
.getAll()
.stream()
.findFirst()
.map(line -> SimpleLine.of(line, validationContext.getFileName()))
.orElse(
validationContext
.getNetexEntitiesIndex()
.getFlexibleLineIndex()
.getAll()
.stream()
.filter(FlexibleLineUtils::isFixedFlexibleLine)
.findFirst()
.map(line -> SimpleLine.of(line, validationContext.getFileName()))
.orElse(null)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
import no.entur.antu.validation.AntuNetexData;
import org.entur.netex.validation.validator.jaxb.JAXBValidationContext;
import org.entur.netex.validation.validator.jaxb.NetexDataCollector;
import org.entur.netex.validation.validator.model.ServiceJourneyInterchangeInfo;
Expand All @@ -31,18 +30,12 @@ public ServiceJourneyInterchangeInfoCollector(
protected void collectDataFromLineFile(
JAXBValidationContext validationContext
) {
AntuNetexData antuNetexData = new AntuNetexData(
validationContext.getValidationReportId(),
validationContext.getNetexEntitiesIndex(),
validationContext.getNetexDataRepository(),
validationContext.getStopPlaceRepository()
);

addData(
validationContext.getFileName(),
antuNetexData.validationReportId(),
antuNetexData
validationContext.getValidationReportId(),
validationContext
.serviceJourneyInterchanges()
.stream()
.map(serviceJourneyInterchange ->
ServiceJourneyInterchangeInfo.of(
validationContext.getFileName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import no.entur.antu.validation.AntuNetexData;
import no.entur.antu.validation.validator.support.NetexUtils;
import org.entur.netex.validation.validator.jaxb.JAXBValidationContext;
import org.entur.netex.validation.validator.jaxb.NetexDataCollector;
import org.entur.netex.validation.validator.model.ScheduledStopPointId;
Expand Down Expand Up @@ -33,33 +33,28 @@ public ServiceJourneyStopsCollector(
protected void collectDataFromLineFile(
JAXBValidationContext validationContext
) {
AntuNetexData antuNetexData = new AntuNetexData(
validationContext.getValidationReportId(),
validationContext.getNetexEntitiesIndex(),
validationContext.getNetexDataRepository(),
validationContext.getStopPlaceRepository()
);

// TODO: Do I need to check that? Is it possible that some line files
// dont have interchanges in it, but other have references to
// service journeys in them?
// if (antuNetexData.serviceJourneyInterchanges().findAny().isPresent()) {}
// if (validationContext.serviceJourneyInterchanges().findAny().isPresent()) {}

Map<String, List<String>> serviceJourneyStops = antuNetexData
.validServiceJourneys()
Map<String, List<String>> serviceJourneyStops = validationContext
.serviceJourneys()
.stream()
.map(serviceJourney -> {
Map<String, ScheduledStopPointId> scheduledStopPointIdMap =
AntuNetexData.scheduledStopPointIdByStopPointId(
antuNetexData.journeyPattern(serviceJourney)
NetexUtils.scheduledStopPointIdByStopPointId(
validationContext.journeyPattern(serviceJourney)
);
return Map.entry(
serviceJourney.getId(),
antuNetexData
validationContext
.timetabledPassingTimes(serviceJourney)
.stream()
.map(passingTime ->
ServiceJourneyStop.of(
scheduledStopPointIdMap.get(
AntuNetexData.stopPointRef(passingTime)
NetexUtils.stopPointRef(passingTime)
),
passingTime
)
Expand Down
25 changes: 13 additions & 12 deletions src/main/java/no/entur/antu/stoptime/SortStopTimesUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import no.entur.antu.validation.AntuNetexData;
import no.entur.antu.validation.validator.support.NetexUtils;
import org.entur.netex.index.api.NetexEntitiesIndex;
import org.entur.netex.validation.validator.jaxb.JAXBValidationContext;
import org.entur.netex.validation.validator.model.ScheduledStopPointId;
import org.rutebanken.netex.model.EntityStructure;
import org.rutebanken.netex.model.JourneyPattern;
Expand Down Expand Up @@ -38,9 +39,9 @@ private SortStopTimesUtil() {}
*/
public static List<StopTime> getSortedStopTimes(
ServiceJourney serviceJourney,
AntuNetexData antuNetexData
JAXBValidationContext validationContext
) {
JourneyPattern journeyPattern = antuNetexData.journeyPattern(
JourneyPattern journeyPattern = validationContext.journeyPattern(
serviceJourney
);

Expand All @@ -57,28 +58,27 @@ public static List<StopTime> getSortedStopTimes(
);

Map<String, ScheduledStopPointId> scheduledStopPointIdByStopPointId =
AntuNetexData.scheduledStopPointIdByStopPointId(journeyPattern);
NetexUtils.scheduledStopPointIdByStopPointId(journeyPattern);

return antuNetexData
return validationContext
.timetabledPassingTimes(serviceJourney)
.stream()
.filter(SortStopTimesUtil::hasStopPointInJourneyPatternRef)
.sorted(
comparing(timetabledPassingTime ->
stopPointIdToOrder.get(
AntuNetexData.stopPointRef(timetabledPassingTime)
)
stopPointIdToOrder.get(NetexUtils.stopPointRef(timetabledPassingTime))
)
)
.map(timetabledPassingTime ->
StopTime.of(
scheduledStopPointIdByStopPointId.get(
AntuNetexData.stopPointRef(timetabledPassingTime)
NetexUtils.stopPointRef(timetabledPassingTime)
),
timetabledPassingTime,
hasFlexibleStopPoint(
antuNetexData.netexEntitiesIndex(),
validationContext.getNetexEntitiesIndex(),
scheduledStopPointIdByStopPointId.get(
AntuNetexData.stopPointRef(timetabledPassingTime)
NetexUtils.stopPointRef(timetabledPassingTime)
)
)
)
Expand All @@ -99,8 +99,9 @@ private static boolean hasStopPointInJourneyPatternRef(
private static Map<String, Integer> getStopPointIdsOrder(
JourneyPattern journeyPattern
) {
return AntuNetexData
return NetexUtils
.stopPointsInJourneyPattern(journeyPattern)
.stream()
.collect(
Collectors.toMap(
EntityStructure::getId,
Expand Down
Loading

0 comments on commit 86ce1b3

Please sign in to comment.