diff --git a/pom.xml b/pom.xml index 8cf62387..2348150b 100644 --- a/pom.xml +++ b/pom.xml @@ -74,6 +74,9 @@ 8.4.3 1.21.0 5.0.0.4389 + 2.1.0 + 0.22 + write 0.8.12 @@ -285,6 +288,22 @@ false + + com.hubspot.maven.plugins + prettier-maven-plugin + ${prettier-maven-plugin.version} + + ${prettier-java.version} + + + + validate + + ${plugin.prettier.goal} + + + + @@ -305,6 +324,14 @@ sonar-maven-plugin ${sonar-maven-plugin.version} + + com.hubspot.maven.plugins + prettier-maven-plugin + ${prettier-maven-plugin.version} + + true + + @@ -386,5 +413,12 @@ + + prettierCheck + + + check + + \ No newline at end of file diff --git a/src/main/java/org/entur/netex/NetexParser.java b/src/main/java/org/entur/netex/NetexParser.java index e2767e6f..71a177f0 100644 --- a/src/main/java/org/entur/netex/NetexParser.java +++ b/src/main/java/org/entur/netex/NetexParser.java @@ -1,92 +1,96 @@ package org.entur.netex; -import org.entur.netex.index.api.NetexEntitiesIndex; -import org.entur.netex.index.impl.NetexEntitiesIndexImpl; -import org.entur.netex.loader.NetexXmlParser; -import org.entur.netex.loader.parser.NetexDocumentParser; -import org.rutebanken.netex.model.PublicationDeliveryStructure; - import jakarta.xml.bind.JAXBException; import java.io.IOException; import java.io.InputStream; import java.util.Enumeration; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; +import org.entur.netex.index.api.NetexEntitiesIndex; +import org.entur.netex.index.impl.NetexEntitiesIndexImpl; +import org.entur.netex.loader.NetexXmlParser; +import org.entur.netex.loader.parser.NetexDocumentParser; +import org.rutebanken.netex.model.PublicationDeliveryStructure; /** * Main entry point to the library. Used to parse a NeTEx publication * delivery into a queryable index. */ public class NetexParser { - private final NetexXmlParser xmlParser = new NetexXmlParser(); - /** - * Parse a NeTEx publication delivery from one or more files in - * a zip archive - * - * @param pathToZip Path to zip file - * @return A queryable index of NeTEx entities - */ - public NetexEntitiesIndex parse(String pathToZip) throws IOException { - NetexEntitiesIndex index = new NetexEntitiesIndexImpl(); - return parse(pathToZip, index); - } + private final NetexXmlParser xmlParser = new NetexXmlParser(); - /** - * Parse a NeTEx publication delivery from one or more files in - * a zip archive into an existing index. - * - * Existing entities with same id will be overwritten. - * - * @param pathToZip Path to zip file - * @param index An instance of NetexEntitiesIndex - * @return The mutated index - */ - public NetexEntitiesIndex parse(String pathToZip, NetexEntitiesIndex index) throws IOException { - try(ZipFile zipFile = new ZipFile(pathToZip)) { - Enumeration entries = zipFile.entries(); - while(entries.hasMoreElements()){ - ZipEntry entry = entries.nextElement(); - InputStream stream = zipFile.getInputStream(entry); - load(index, stream); - } - return index; - } - } + /** + * Parse a NeTEx publication delivery from one or more files in + * a zip archive + * + * @param pathToZip Path to zip file + * @return A queryable index of NeTEx entities + */ + public NetexEntitiesIndex parse(String pathToZip) throws IOException { + NetexEntitiesIndex index = new NetexEntitiesIndexImpl(); + return parse(pathToZip, index); + } - /** - * Parse an input stream of a single NeTEx public delivery - * - * @param inputStream - * @return A queryable index of NeTEx entities - */ - public NetexEntitiesIndex parse(InputStream inputStream) { - NetexEntitiesIndex index = new NetexEntitiesIndexImpl(); - load(index, inputStream); - return index; + /** + * Parse a NeTEx publication delivery from one or more files in + * a zip archive into an existing index. + * + * Existing entities with same id will be overwritten. + * + * @param pathToZip Path to zip file + * @param index An instance of NetexEntitiesIndex + * @return The mutated index + */ + public NetexEntitiesIndex parse(String pathToZip, NetexEntitiesIndex index) + throws IOException { + try (ZipFile zipFile = new ZipFile(pathToZip)) { + Enumeration entries = zipFile.entries(); + while (entries.hasMoreElements()) { + ZipEntry entry = entries.nextElement(); + InputStream stream = zipFile.getInputStream(entry); + load(index, stream); + } + return index; } + } - /** - * Parse an input stream of a single NeTEx publication delivery - * into an existing index - * - * Existing entities with same id will be overwritten. - * - * @param inputStream An InputStream - * @param index An instance of NetexEntitiesIndex - * @return The mutated index - */ - public NetexEntitiesIndex parse(InputStream inputStream, NetexEntitiesIndex index) { - load(index, inputStream); - return index; - } + /** + * Parse an input stream of a single NeTEx public delivery + * + * @param inputStream + * @return A queryable index of NeTEx entities + */ + public NetexEntitiesIndex parse(InputStream inputStream) { + NetexEntitiesIndex index = new NetexEntitiesIndexImpl(); + load(index, inputStream); + return index; + } + + /** + * Parse an input stream of a single NeTEx publication delivery + * into an existing index + * + * Existing entities with same id will be overwritten. + * + * @param inputStream An InputStream + * @param index An instance of NetexEntitiesIndex + * @return The mutated index + */ + public NetexEntitiesIndex parse( + InputStream inputStream, + NetexEntitiesIndex index + ) { + load(index, inputStream); + return index; + } - private void load(NetexEntitiesIndex index, InputStream inputStream) { - try { - PublicationDeliveryStructure doc = xmlParser.parseXmlDoc(inputStream); - NetexDocumentParser.parseAndPopulateIndex(index, doc); - } catch (JAXBException e) { - throw new RuntimeException(e.getMessage(), e); - } + private void load(NetexEntitiesIndex index, InputStream inputStream) { + try { + PublicationDeliveryStructure doc = xmlParser.parseXmlDoc(inputStream); + NetexDocumentParser.parseAndPopulateIndex(index, doc); + } catch (JAXBException e) { + throw new RuntimeException(e.getMessage(), e); } + } } diff --git a/src/main/java/org/entur/netex/index/api/NetexEntitiesIndex.java b/src/main/java/org/entur/netex/index/api/NetexEntitiesIndex.java index ae74d68e..d72b1331 100644 --- a/src/main/java/org/entur/netex/index/api/NetexEntitiesIndex.java +++ b/src/main/java/org/entur/netex/index/api/NetexEntitiesIndex.java @@ -1,5 +1,6 @@ package org.entur.netex.index.api; +import com.google.common.collect.Multimap; import java.time.LocalDateTime; import java.util.Collection; import java.util.Map; @@ -45,272 +46,266 @@ import org.rutebanken.netex.model.TopographicPlace; import org.rutebanken.netex.model.VehicleScheduleFrame; -import com.google.common.collect.Multimap; - /** * Entrypoint to the NeTEx entities index */ public interface NetexEntitiesIndex { - - /** - * Get an entity index of GroupOfLines - * @return - */ - NetexEntityIndex getGroupOfLinesIndex(); - - /** - * Get an entity index of Network - * @return - */ - NetexEntityIndex getNetworkIndex(); - - /** - * Get a map of Network id by GroupOfLine id - * @return - */ - Map getNetworkIdByGroupOfLineIdIndex(); - - /** - * Get an entity index of Authority - * @return - */ - NetexEntityIndex getAuthorityIndex(); - - /** - * Get an entity index of DayType - * @return - */ - NetexEntityIndex getDayTypeIndex(); - - /** - * Get a Multimap of DayTypeAssignment by DayType id - * @return - */ - Multimap getDayTypeAssignmentsByDayTypeIdIndex(); - - - /** - * Get a Multimap of PassengerStopAssignment by StopPoint ref - * * @return - */ - Multimap getPassengerStopAssignmentsByStopPointRefIndex(); - - /** - * Get an entity index of DatedServiceJourney - * @return - */ - NetexEntityIndex getDatedServiceJourneyIndex(); - - /** - * Get an entity index of DeadRun - * @return - */ - NetexEntityIndex getDeadRunIndex(); - - - /** - * Get a Multimap of DatedServiceJourney by ServiceJourney id - * @return - */ - Multimap getDatedServiceJourneyByServiceJourneyRefIndex(); - - - /** - * Get an entity index of DestinationDisplay - * @return - */ - NetexEntityIndex getDestinationDisplayIndex(); - - /** - * Get an entity index of FlexibleStopPlace - * @return - */ - NetexEntityIndex getFlexibleStopPlaceIndex(); - - /** - * Get an entity index of GroupOfStopPlaces - * @return - */ - NetexEntityIndex getGroupOfStopPlacesIndex(); - - /** - * Get an entity index of JourneyPattern - * @return - */ - NetexEntityIndex getJourneyPatternIndex(); - - /** - * Get an entity index of FlexibleLine - * @return - */ - NetexEntityIndex getFlexibleLineIndex(); - - /** - * Get an entity index of Line - * @return - */ - NetexEntityIndex getLineIndex(); - - /** - * Get an entity index of Notice - * @return - */ - NetexEntityIndex getNoticeIndex(); - - /** - * Get an entity index of NoticeAssignment - * @return - */ - NetexEntityIndex getNoticeAssignmentIndex(); - - /** - * Get an entity index of OperatingDay - * @return - */ - NetexEntityIndex getOperatingDayIndex(); - - /** - * Get an entity index of OperatingPeriod - * @return - */ - NetexEntityIndex getOperatingPeriodIndex(); - - /** - * Get an entity index of Operator - * @return - */ - NetexEntityIndex getOperatorIndex(); - - /** - * Get an entity index of Branding - * @return - */ - NetexEntityIndex getBrandingIndex(); - - /** - * Get a versioned entity index of Quay - * @return - */ - VersionedNetexEntityIndex getQuayIndex(); - - /** - * Get a map of Quay id by StopPoint ref - * @return - */ - Map getQuayIdByStopPointRefIndex(); - - /** - * Get a map of StopPlace id by StopPoint ref - * @return - */ - Map getStopPlaceIdByStopPointRefIndex(); - - /** - * Get a map of StopPlace id by Quay id - * @return - */ - Map getStopPlaceIdByQuayIdIndex(); - - /** - * Get a map of FlexibleStopPlace id by StopPoint ref - * @return - */ - Map getFlexibleStopPlaceIdByStopPointRefIndex(); - - /** - * Get an entity index of Route - * @return - */ - NetexEntityIndex getRouteIndex(); - - /** - * Get an entity index of ServiceJourney - * @return - */ - NetexEntityIndex getServiceJourneyIndex(); - - /** - * Get an entity index of ServiceJourneyInterchange - * @return - */ - NetexEntityIndex getServiceJourneyInterchangeIndex(); - - /** - * Get a map of ServiceJourneyInterchange by feeder or consumer ServiceJourney - * @return - */ - Multimap getServiceJourneyInterchangeByServiceJourneyRefIndex(); - - /** - * Get an entity index of ServiceLink - * @return - */ - NetexEntityIndex getServiceLinkIndex(); - - /** - * Get a versioned entity index of StopPlace - * @return - */ - VersionedNetexEntityIndex getStopPlaceIndex(); - - /** - * Get an entity index of TariffZone - * @return - */ - VersionedNetexEntityIndex getTariffZoneIndex(); - - /** - * Get an entity index of TopographicPlace - * @return - */ - VersionedNetexEntityIndex getTopographicPlaceIndex(); - - /** - * Get an entity index of Parking - * @return - */ - VersionedNetexEntityIndex getParkingIndex(); - - /** - * Get an entity index of ScheduledStopPoint - * @return - */ - VersionedNetexEntityIndex getScheduledStopPointIndex(); - - /** - * Get an entity index of RoutePoint - * @return - */ - NetexEntityIndex getRoutePointIndex(); - - /** - * Get an entity index of Block - * @return - */ - NetexEntityIndex getBlockIndex(); - - /** - * Get a Multimap of parkings by ParentSite ref - * @return - */ - Multimap getParkingsByParentSiteRefIndex(); - - /** - * Get an entity index of FareZone - * @return - */ - VersionedNetexEntityIndex getFareZoneIndex(); - - VersionedNetexEntityIndex getGroupOfTariffZonesIndex(); - - Collection getCompositeFrames(); - Collection getResourceFrames(); - Collection getSiteFrames(); - Collection getServiceFrames(); - Collection getServiceCalendarFrames(); - Collection getVehicleScheduleFrames(); - Collection getTimetableFrames(); - - LocalDateTime getPublicationTimestamp(); - void setPublicationTimestamp(LocalDateTime publicationTimestamp); + /** + * Get an entity index of GroupOfLines + * @return + */ + NetexEntityIndex getGroupOfLinesIndex(); + + /** + * Get an entity index of Network + * @return + */ + NetexEntityIndex getNetworkIndex(); + + /** + * Get a map of Network id by GroupOfLine id + * @return + */ + Map getNetworkIdByGroupOfLineIdIndex(); + + /** + * Get an entity index of Authority + * @return + */ + NetexEntityIndex getAuthorityIndex(); + + /** + * Get an entity index of DayType + * @return + */ + NetexEntityIndex getDayTypeIndex(); + + /** + * Get a Multimap of DayTypeAssignment by DayType id + * @return + */ + Multimap getDayTypeAssignmentsByDayTypeIdIndex(); + + /** + * Get a Multimap of PassengerStopAssignment by StopPoint ref + * * @return + */ + Multimap getPassengerStopAssignmentsByStopPointRefIndex(); + + /** + * Get an entity index of DatedServiceJourney + * @return + */ + NetexEntityIndex getDatedServiceJourneyIndex(); + + /** + * Get an entity index of DeadRun + * @return + */ + NetexEntityIndex getDeadRunIndex(); + + /** + * Get a Multimap of DatedServiceJourney by ServiceJourney id + * @return + */ + Multimap getDatedServiceJourneyByServiceJourneyRefIndex(); + + /** + * Get an entity index of DestinationDisplay + * @return + */ + NetexEntityIndex getDestinationDisplayIndex(); + + /** + * Get an entity index of FlexibleStopPlace + * @return + */ + NetexEntityIndex getFlexibleStopPlaceIndex(); + + /** + * Get an entity index of GroupOfStopPlaces + * @return + */ + NetexEntityIndex getGroupOfStopPlacesIndex(); + + /** + * Get an entity index of JourneyPattern + * @return + */ + NetexEntityIndex getJourneyPatternIndex(); + + /** + * Get an entity index of FlexibleLine + * @return + */ + NetexEntityIndex getFlexibleLineIndex(); + + /** + * Get an entity index of Line + * @return + */ + NetexEntityIndex getLineIndex(); + + /** + * Get an entity index of Notice + * @return + */ + NetexEntityIndex getNoticeIndex(); + + /** + * Get an entity index of NoticeAssignment + * @return + */ + NetexEntityIndex getNoticeAssignmentIndex(); + + /** + * Get an entity index of OperatingDay + * @return + */ + NetexEntityIndex getOperatingDayIndex(); + + /** + * Get an entity index of OperatingPeriod + * @return + */ + NetexEntityIndex getOperatingPeriodIndex(); + + /** + * Get an entity index of Operator + * @return + */ + NetexEntityIndex getOperatorIndex(); + + /** + * Get an entity index of Branding + * @return + */ + NetexEntityIndex getBrandingIndex(); + + /** + * Get a versioned entity index of Quay + * @return + */ + VersionedNetexEntityIndex getQuayIndex(); + + /** + * Get a map of Quay id by StopPoint ref + * @return + */ + Map getQuayIdByStopPointRefIndex(); + + /** + * Get a map of StopPlace id by StopPoint ref + * @return + */ + Map getStopPlaceIdByStopPointRefIndex(); + + /** + * Get a map of StopPlace id by Quay id + * @return + */ + Map getStopPlaceIdByQuayIdIndex(); + + /** + * Get a map of FlexibleStopPlace id by StopPoint ref + * @return + */ + Map getFlexibleStopPlaceIdByStopPointRefIndex(); + + /** + * Get an entity index of Route + * @return + */ + NetexEntityIndex getRouteIndex(); + + /** + * Get an entity index of ServiceJourney + * @return + */ + NetexEntityIndex getServiceJourneyIndex(); + + /** + * Get an entity index of ServiceJourneyInterchange + * @return + */ + NetexEntityIndex getServiceJourneyInterchangeIndex(); + + /** + * Get a map of ServiceJourneyInterchange by feeder or consumer ServiceJourney + * @return + */ + Multimap getServiceJourneyInterchangeByServiceJourneyRefIndex(); + + /** + * Get an entity index of ServiceLink + * @return + */ + NetexEntityIndex getServiceLinkIndex(); + + /** + * Get a versioned entity index of StopPlace + * @return + */ + VersionedNetexEntityIndex getStopPlaceIndex(); + + /** + * Get an entity index of TariffZone + * @return + */ + VersionedNetexEntityIndex getTariffZoneIndex(); + + /** + * Get an entity index of TopographicPlace + * @return + */ + VersionedNetexEntityIndex getTopographicPlaceIndex(); + + /** + * Get an entity index of Parking + * @return + */ + VersionedNetexEntityIndex getParkingIndex(); + + /** + * Get an entity index of ScheduledStopPoint + * @return + */ + VersionedNetexEntityIndex getScheduledStopPointIndex(); + + /** + * Get an entity index of RoutePoint + * @return + */ + NetexEntityIndex getRoutePointIndex(); + + /** + * Get an entity index of Block + * @return + */ + NetexEntityIndex getBlockIndex(); + + /** + * Get a Multimap of parkings by ParentSite ref + * @return + */ + Multimap getParkingsByParentSiteRefIndex(); + + /** + * Get an entity index of FareZone + * @return + */ + VersionedNetexEntityIndex getFareZoneIndex(); + + VersionedNetexEntityIndex getGroupOfTariffZonesIndex(); + + Collection getCompositeFrames(); + Collection getResourceFrames(); + Collection getSiteFrames(); + Collection getServiceFrames(); + Collection getServiceCalendarFrames(); + Collection getVehicleScheduleFrames(); + Collection getTimetableFrames(); + + LocalDateTime getPublicationTimestamp(); + void setPublicationTimestamp(LocalDateTime publicationTimestamp); } diff --git a/src/main/java/org/entur/netex/index/api/NetexEntityIndex.java b/src/main/java/org/entur/netex/index/api/NetexEntityIndex.java index 5993d4cd..c81a9baa 100644 --- a/src/main/java/org/entur/netex/index/api/NetexEntityIndex.java +++ b/src/main/java/org/entur/netex/index/api/NetexEntityIndex.java @@ -1,48 +1,47 @@ package org.entur.netex.index.api; -import org.rutebanken.netex.model.EntityStructure; - import java.util.Collection; +import org.rutebanken.netex.model.EntityStructure; /** * A simple index of NeTEx entities of a specific type * @param */ public interface NetexEntityIndex { - /** - * Get an entity by its id - * - * @param id - * @return The entity - */ - V get(String id); + /** + * Get an entity by its id + * + * @param id + * @return The entity + */ + V get(String id); - /** - * Get all entities in the index - * - * @return A collection of the entity type - */ - Collection getAll(); + /** + * Get all entities in the index + * + * @return A collection of the entity type + */ + Collection getAll(); - /** - * Put an entity into the collection - * If the entity already exists in the index, all versions - * will be replaced. - * @param entity - */ - void put(String id, V entity); + /** + * Put an entity into the collection + * If the entity already exists in the index, all versions + * will be replaced. + * @param entity + */ + void put(String id, V entity); - /** - * Put all entities into the collection - * If an entity already exists in the index, all versions - * will be replaced. - * @param entities - */ - void putAll(Collection entities); + /** + * Put all entities into the collection + * If an entity already exists in the index, all versions + * will be replaced. + * @param entities + */ + void putAll(Collection entities); - /** - * Remove an entity from the index given its id - * @param id - */ - void remove(String id); + /** + * Remove an entity from the index given its id + * @param id + */ + void remove(String id); } diff --git a/src/main/java/org/entur/netex/index/api/VersionedNetexEntityIndex.java b/src/main/java/org/entur/netex/index/api/VersionedNetexEntityIndex.java index 78d6acec..41b3e1c7 100644 --- a/src/main/java/org/entur/netex/index/api/VersionedNetexEntityIndex.java +++ b/src/main/java/org/entur/netex/index/api/VersionedNetexEntityIndex.java @@ -1,71 +1,68 @@ package org.entur.netex.index.api; -import org.rutebanken.netex.model.EntityStructure; - import java.util.Collection; import java.util.Map; +import org.rutebanken.netex.model.EntityStructure; /** * An index of versioned NeTEx entities * @param */ public interface VersionedNetexEntityIndex { + /** + * Return the element with the latest version with the given {@code id}. Returns + * {@code null} if no element is found. + */ + V getLatestVersion(String id); - /** - * Return the element with the latest version with the given {@code id}. Returns - * {@code null} if no element is found. - */ - V getLatestVersion(String id); - - /** - * Return the element with the given {@code id} and {@code version}. Returns - * {@code null} if no element is found - * @param id - * @param version - * @return - */ - V getVersion(String id, String version); - + /** + * Return the element with the given {@code id} and {@code version}. Returns + * {@code null} if no element is found + * @param id + * @param version + * @return + */ + V getVersion(String id, String version); - /** - * Return the latest version of all entities - * @return - */ - Collection getLatestVersions(); + /** + * Return the latest version of all entities + * @return + */ + Collection getLatestVersions(); - /** - * Lookup all versions of element with the given {@code id}. - * - * @return an empty collection if no elements are found. - */ - Collection getAllVersions(String id); + /** + * Lookup all versions of element with the given {@code id}. + * + * @return an empty collection if no elements are found. + */ + Collection getAllVersions(String id); - /** - * Get all versions of all entities - * @return - */ - Map> getAllVersions(); + /** + * Get all versions of all entities + * @return + */ + Map> getAllVersions(); - /** - * Put all versions of an entity into the index. - * If the entity already exists in the index, all versions - * will be replaced. - * - * @param id - * @param entities - */ - void put(String id, Collection entities); + /** + * Put all versions of an entity into the index. + * If the entity already exists in the index, all versions + * will be replaced. + * + * @param id + * @param entities + */ + void put(String id, Collection entities); - /** - * Put all entities into the collection - * If an entity already exists in the index, all versions - * will be replaced. - * @param entities - */ - void putAll(Collection entities); + /** + * Put all entities into the collection + * If an entity already exists in the index, all versions + * will be replaced. + * @param entities + */ + void putAll(Collection entities); - /** - * Remove all versions of an entity from the index given its id - */ - void remove(String id); + /** + * Remove all versions of an entity from the index given its id + */ + void remove(String id); } diff --git a/src/main/java/org/entur/netex/index/impl/NetexEntitiesIndexImpl.java b/src/main/java/org/entur/netex/index/impl/NetexEntitiesIndexImpl.java index 395acaae..95ea42a9 100644 --- a/src/main/java/org/entur/netex/index/impl/NetexEntitiesIndexImpl.java +++ b/src/main/java/org/entur/netex/index/impl/NetexEntitiesIndexImpl.java @@ -1,5 +1,8 @@ package org.entur.netex.index.impl; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Multimap; +import com.google.common.collect.Multimaps; import java.time.LocalDateTime; import java.util.Collection; import java.util.HashSet; @@ -50,382 +53,383 @@ import org.rutebanken.netex.model.TopographicPlace; import org.rutebanken.netex.model.VehicleScheduleFrame; -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Multimap; -import com.google.common.collect.Multimaps; - /** * */ public class NetexEntitiesIndexImpl implements NetexEntitiesIndex { - // Indexes to entities - public final NetexEntityIndex authoritiesById; - public final NetexEntityIndex datedServiceJourneys; - public final Multimap datedServiceJourneyByServiceJourneyRefIndex; - private final NetexEntityIndex deadRuns; - public final NetexEntityIndex dayTypeById; - public final Multimap dayTypeAssignmentByDayTypeId; - public final Multimap passengerStopAssignmentByStopPointRef; - public final NetexEntityIndex destinationDisplayById; - public final NetexEntityIndex flexibleStopPlaceById; - public final NetexEntityIndex groupOfLinesById; - public final NetexEntityIndex groupOfStopPlacesById; - public final NetexEntityIndex journeyPatternsById; - public final NetexEntityIndex flexibleLineByid; - public final NetexEntityIndex lineById; - public final NetexEntityIndex networkById; - public final NetexEntityIndex noticeById; - public final NetexEntityIndex noticeAssignmentById; - public final NetexEntityIndex operatingDayById; - public final NetexEntityIndex operatingPeriodById; - public final NetexEntityIndex operatorsById; - public final NetexEntityIndex brandingsById; - public final VersionedNetexEntityIndex quayById; - public final Map flexibleStopPlaceByStopPointRef; - public final Map quayIdByStopPointRef; - public final Map stopPlaceIdByStopPointRef; - public final Map stopPlaceIdByQuayId; - public final NetexEntityIndex routeById; - public final NetexEntityIndex serviceJourneyById; - public final NetexEntityIndex serviceJourneyInterchangeById; - public final Multimap serviceJourneyInterchangeByServiceJourneyRef; - public final NetexEntityIndex serviceLinkById; - public final VersionedNetexEntityIndex stopPlaceById; - public final VersionedNetexEntityIndex tariffZonesById; - public final VersionedNetexEntityIndex topographicPlaceById; - public final VersionedNetexEntityIndex parkingById; - public final VersionedNetexEntityIndex scheduledStopPointById; - public final NetexEntityIndex routePointById; - public final NetexEntityIndex blockById; - public final VersionedNetexEntityIndex fareZoneById; - public final VersionedNetexEntityIndex groupOfTariffZonesById; - public final Multimap parkingsByParentSiteRef; - - // Relations between entities - The Netex XML sometimes rely on the - // nested structure of the XML document, rater than explicit references. - // Since we throw away the document we need to keep track of these. - - public final Map networkIdByGroupOfLineId; - - // NeTEx Frames - public final Collection compositeFrames; - public final Collection resourceFrames; - public final Collection siteFrames; - public final Collection serviceFrames; - public final Collection serviceCalendarFrames; - public final Collection vehicleScheduleFrames; - public final Collection timetableFrames; - - private LocalDateTime publicationTimestamp; - - /** - * Create a root node. - */ - public NetexEntitiesIndexImpl() { - this.authoritiesById = new NetexEntityMapByIdImpl<>(); - this.dayTypeById = new NetexEntityMapByIdImpl<>(); - this.dayTypeAssignmentByDayTypeId = Multimaps.synchronizedListMultimap(ArrayListMultimap.create()); - this.passengerStopAssignmentByStopPointRef = Multimaps.synchronizedListMultimap(ArrayListMultimap.create()); - this.datedServiceJourneys = new NetexEntityMapByIdImpl<>(); - this.datedServiceJourneyByServiceJourneyRefIndex = Multimaps.synchronizedListMultimap(ArrayListMultimap.create()); - this.deadRuns = new NetexEntityMapByIdImpl<>(); - this.destinationDisplayById = new NetexEntityMapByIdImpl<>(); - this.flexibleStopPlaceById = new NetexEntityMapByIdImpl<>(); - this.groupOfLinesById = new NetexEntityMapByIdImpl<>(); - this.groupOfStopPlacesById = new NetexEntityMapByIdImpl<>(); - this.journeyPatternsById = new NetexEntityMapByIdImpl<>(); - this.flexibleLineByid = new NetexEntityMapByIdImpl<>(); - this.lineById = new NetexEntityMapByIdImpl<>(); - this.networkById = new NetexEntityMapByIdImpl<>(); - this.networkIdByGroupOfLineId = new ConcurrentHashMap<>(); - this.noticeById = new NetexEntityMapByIdImpl<>(); - this.noticeAssignmentById = new NetexEntityMapByIdImpl<>(); - this.operatingDayById = new NetexEntityMapByIdImpl<>(); - this.operatingPeriodById = new NetexEntityMapByIdImpl<>(); - this.operatorsById = new NetexEntityMapByIdImpl<>(); - this.brandingsById = new NetexEntityMapByIdImpl<>(); - this.quayById = new VersionedNetexEntityIndexImpl<>(); - this.flexibleStopPlaceByStopPointRef = new ConcurrentHashMap<>(); - this.quayIdByStopPointRef = new ConcurrentHashMap<>(); - this.stopPlaceIdByStopPointRef = new ConcurrentHashMap<>(); - this.stopPlaceIdByQuayId = new ConcurrentHashMap<>(); - this.routeById = new NetexEntityMapByIdImpl<>(); - this.serviceJourneyById = new NetexEntityMapByIdImpl<>(); - this.serviceJourneyInterchangeById = new NetexEntityMapByIdImpl<>(); - this.serviceJourneyInterchangeByServiceJourneyRef = Multimaps.synchronizedListMultimap(ArrayListMultimap.create()); - this.serviceLinkById = new NetexEntityMapByIdImpl<>(); - this.stopPlaceById = new VersionedNetexEntityIndexImpl<>(); - this.tariffZonesById = new VersionedNetexEntityIndexImpl<>(); - this.topographicPlaceById = new VersionedNetexEntityIndexImpl<>(); - this.parkingById = new VersionedNetexEntityIndexImpl<>(); - this.scheduledStopPointById = new VersionedNetexEntityIndexImpl<>(); - this.routePointById = new NetexEntityMapByIdImpl<>(); - this.blockById = new NetexEntityMapByIdImpl<>(); - this.fareZoneById = new VersionedNetexEntityIndexImpl<>(); - this.groupOfTariffZonesById = new VersionedNetexEntityIndexImpl<>(); - this.compositeFrames = new HashSet<>(); - this.siteFrames = new HashSet<>(); - this.resourceFrames = new HashSet<>(); - this.serviceFrames = new HashSet<>(); - this.serviceCalendarFrames = new HashSet<>(); - this.vehicleScheduleFrames = new HashSet<>(); - this.timetableFrames = new HashSet<>(); - this.parkingsByParentSiteRef = Multimaps.synchronizedListMultimap(ArrayListMultimap.create()); - } - - @Override - public NetexEntityIndex getGroupOfLinesIndex() { - return groupOfLinesById; - } - - @Override - public NetexEntityIndex getNetworkIndex() { - return networkById; - } - - @Override - public Map getNetworkIdByGroupOfLineIdIndex() { - return networkIdByGroupOfLineId; - } - - @Override - public NetexEntityIndex getAuthorityIndex() { - return authoritiesById; - } - - @Override - public NetexEntityIndex getDayTypeIndex() { - return dayTypeById; - } - - @Override - public Multimap getDayTypeAssignmentsByDayTypeIdIndex() { - return dayTypeAssignmentByDayTypeId; - } - - @Override - public Multimap getPassengerStopAssignmentsByStopPointRefIndex() { - return passengerStopAssignmentByStopPointRef; - } - - @Override - public NetexEntityIndex getDatedServiceJourneyIndex() { - return datedServiceJourneys; - } - - @Override - public NetexEntityIndex getDeadRunIndex() { - return deadRuns; - } - - @Override - public Multimap getDatedServiceJourneyByServiceJourneyRefIndex() { - return datedServiceJourneyByServiceJourneyRefIndex; - } - - @Override - public NetexEntityIndex getDestinationDisplayIndex() { - return destinationDisplayById; - } - - @Override - public NetexEntityIndex getFlexibleStopPlaceIndex() { - return flexibleStopPlaceById; - } - - @Override - public NetexEntityIndex getGroupOfStopPlacesIndex() { - return groupOfStopPlacesById; - } - - @Override - public NetexEntityIndex getJourneyPatternIndex() { - return journeyPatternsById; - } - - @Override - public NetexEntityIndex getFlexibleLineIndex() { - return flexibleLineByid; - } - - @Override - public NetexEntityIndex getLineIndex() { - return lineById; - } - - @Override - public NetexEntityIndex getNoticeIndex() { - return noticeById; - } - - @Override - public NetexEntityIndex getNoticeAssignmentIndex() { - return noticeAssignmentById; - } - - @Override - public NetexEntityIndex getOperatingDayIndex() { - return operatingDayById; - } - - @Override - public NetexEntityIndex getOperatingPeriodIndex() { - return operatingPeriodById; - } - - @Override - public NetexEntityIndex getOperatorIndex() { - return operatorsById; - } - - @Override - public NetexEntityIndex getBrandingIndex() { - return brandingsById; - } - - @Override - public VersionedNetexEntityIndex getQuayIndex() { - return quayById; - } - - @Override - public Map getFlexibleStopPlaceIdByStopPointRefIndex() { - return flexibleStopPlaceByStopPointRef; - } - - @Override - public Map getQuayIdByStopPointRefIndex() { - return quayIdByStopPointRef; - } - - @Override - public Map getStopPlaceIdByStopPointRefIndex() { - return stopPlaceIdByStopPointRef; - } - - @Override - public Map getStopPlaceIdByQuayIdIndex() { - return stopPlaceIdByQuayId; - } - - @Override - public NetexEntityIndex getRouteIndex() { - return routeById; - } - - @Override - public NetexEntityIndex getServiceJourneyIndex() { - return serviceJourneyById; - } - - @Override - public NetexEntityIndex getServiceJourneyInterchangeIndex() { - return serviceJourneyInterchangeById; - } - - @Override - public Multimap getServiceJourneyInterchangeByServiceJourneyRefIndex() { - return serviceJourneyInterchangeByServiceJourneyRef; - } - - @Override - public NetexEntityIndex getServiceLinkIndex() { - return serviceLinkById; - } - - @Override - public VersionedNetexEntityIndex getStopPlaceIndex() { - return stopPlaceById; - } - - @Override - public VersionedNetexEntityIndex getTariffZoneIndex() { - return tariffZonesById; - } - - @Override - public VersionedNetexEntityIndex getTopographicPlaceIndex() { - return topographicPlaceById; - } - - @Override - public VersionedNetexEntityIndex getParkingIndex() { - return parkingById; - } - - @Override - public VersionedNetexEntityIndex getScheduledStopPointIndex() { - return scheduledStopPointById; - } - - @Override - public NetexEntityIndex getRoutePointIndex() { - return routePointById; - } - - @Override - public NetexEntityIndex getBlockIndex() { - return blockById; - } - - @Override - public VersionedNetexEntityIndex getFareZoneIndex() { - return fareZoneById; - } - - @Override - public VersionedNetexEntityIndex getGroupOfTariffZonesIndex() { - return groupOfTariffZonesById; - } - - @Override - public Collection getCompositeFrames() { - return compositeFrames; - } - - @Override - public Collection getResourceFrames() { - return resourceFrames; - } - - @Override - public Collection getSiteFrames() { - return siteFrames; - } - - @Override - public Collection getServiceFrames() { - return serviceFrames; - } - - @Override - public Collection getServiceCalendarFrames() { - return serviceCalendarFrames; - } - - @Override - public Collection getVehicleScheduleFrames() { - return vehicleScheduleFrames; - } - - @Override - public Collection getTimetableFrames() { - return timetableFrames; - } - - @Override - public LocalDateTime getPublicationTimestamp() { - return publicationTimestamp; - } - - @Override - public void setPublicationTimestamp(LocalDateTime publicationTimestamp) { - this.publicationTimestamp = publicationTimestamp; - } - - @Override - public Multimap getParkingsByParentSiteRefIndex() { - return parkingsByParentSiteRef; - } + // Indexes to entities + public final NetexEntityIndex authoritiesById; + public final NetexEntityIndex datedServiceJourneys; + public final Multimap datedServiceJourneyByServiceJourneyRefIndex; + private final NetexEntityIndex deadRuns; + public final NetexEntityIndex dayTypeById; + public final Multimap dayTypeAssignmentByDayTypeId; + public final Multimap passengerStopAssignmentByStopPointRef; + public final NetexEntityIndex destinationDisplayById; + public final NetexEntityIndex flexibleStopPlaceById; + public final NetexEntityIndex groupOfLinesById; + public final NetexEntityIndex groupOfStopPlacesById; + public final NetexEntityIndex journeyPatternsById; + public final NetexEntityIndex flexibleLineByid; + public final NetexEntityIndex lineById; + public final NetexEntityIndex networkById; + public final NetexEntityIndex noticeById; + public final NetexEntityIndex noticeAssignmentById; + public final NetexEntityIndex operatingDayById; + public final NetexEntityIndex operatingPeriodById; + public final NetexEntityIndex operatorsById; + public final NetexEntityIndex brandingsById; + public final VersionedNetexEntityIndex quayById; + public final Map flexibleStopPlaceByStopPointRef; + public final Map quayIdByStopPointRef; + public final Map stopPlaceIdByStopPointRef; + public final Map stopPlaceIdByQuayId; + public final NetexEntityIndex routeById; + public final NetexEntityIndex serviceJourneyById; + public final NetexEntityIndex serviceJourneyInterchangeById; + public final Multimap serviceJourneyInterchangeByServiceJourneyRef; + public final NetexEntityIndex serviceLinkById; + public final VersionedNetexEntityIndex stopPlaceById; + public final VersionedNetexEntityIndex tariffZonesById; + public final VersionedNetexEntityIndex topographicPlaceById; + public final VersionedNetexEntityIndex parkingById; + public final VersionedNetexEntityIndex scheduledStopPointById; + public final NetexEntityIndex routePointById; + public final NetexEntityIndex blockById; + public final VersionedNetexEntityIndex fareZoneById; + public final VersionedNetexEntityIndex groupOfTariffZonesById; + public final Multimap parkingsByParentSiteRef; + + // Relations between entities - The Netex XML sometimes rely on the + // nested structure of the XML document, rater than explicit references. + // Since we throw away the document we need to keep track of these. + + public final Map networkIdByGroupOfLineId; + + // NeTEx Frames + public final Collection compositeFrames; + public final Collection resourceFrames; + public final Collection siteFrames; + public final Collection serviceFrames; + public final Collection serviceCalendarFrames; + public final Collection vehicleScheduleFrames; + public final Collection timetableFrames; + + private LocalDateTime publicationTimestamp; + + /** + * Create a root node. + */ + public NetexEntitiesIndexImpl() { + this.authoritiesById = new NetexEntityMapByIdImpl<>(); + this.dayTypeById = new NetexEntityMapByIdImpl<>(); + this.dayTypeAssignmentByDayTypeId = + Multimaps.synchronizedListMultimap(ArrayListMultimap.create()); + this.passengerStopAssignmentByStopPointRef = + Multimaps.synchronizedListMultimap(ArrayListMultimap.create()); + this.datedServiceJourneys = new NetexEntityMapByIdImpl<>(); + this.datedServiceJourneyByServiceJourneyRefIndex = + Multimaps.synchronizedListMultimap(ArrayListMultimap.create()); + this.deadRuns = new NetexEntityMapByIdImpl<>(); + this.destinationDisplayById = new NetexEntityMapByIdImpl<>(); + this.flexibleStopPlaceById = new NetexEntityMapByIdImpl<>(); + this.groupOfLinesById = new NetexEntityMapByIdImpl<>(); + this.groupOfStopPlacesById = new NetexEntityMapByIdImpl<>(); + this.journeyPatternsById = new NetexEntityMapByIdImpl<>(); + this.flexibleLineByid = new NetexEntityMapByIdImpl<>(); + this.lineById = new NetexEntityMapByIdImpl<>(); + this.networkById = new NetexEntityMapByIdImpl<>(); + this.networkIdByGroupOfLineId = new ConcurrentHashMap<>(); + this.noticeById = new NetexEntityMapByIdImpl<>(); + this.noticeAssignmentById = new NetexEntityMapByIdImpl<>(); + this.operatingDayById = new NetexEntityMapByIdImpl<>(); + this.operatingPeriodById = new NetexEntityMapByIdImpl<>(); + this.operatorsById = new NetexEntityMapByIdImpl<>(); + this.brandingsById = new NetexEntityMapByIdImpl<>(); + this.quayById = new VersionedNetexEntityIndexImpl<>(); + this.flexibleStopPlaceByStopPointRef = new ConcurrentHashMap<>(); + this.quayIdByStopPointRef = new ConcurrentHashMap<>(); + this.stopPlaceIdByStopPointRef = new ConcurrentHashMap<>(); + this.stopPlaceIdByQuayId = new ConcurrentHashMap<>(); + this.routeById = new NetexEntityMapByIdImpl<>(); + this.serviceJourneyById = new NetexEntityMapByIdImpl<>(); + this.serviceJourneyInterchangeById = new NetexEntityMapByIdImpl<>(); + this.serviceJourneyInterchangeByServiceJourneyRef = + Multimaps.synchronizedListMultimap(ArrayListMultimap.create()); + this.serviceLinkById = new NetexEntityMapByIdImpl<>(); + this.stopPlaceById = new VersionedNetexEntityIndexImpl<>(); + this.tariffZonesById = new VersionedNetexEntityIndexImpl<>(); + this.topographicPlaceById = new VersionedNetexEntityIndexImpl<>(); + this.parkingById = new VersionedNetexEntityIndexImpl<>(); + this.scheduledStopPointById = new VersionedNetexEntityIndexImpl<>(); + this.routePointById = new NetexEntityMapByIdImpl<>(); + this.blockById = new NetexEntityMapByIdImpl<>(); + this.fareZoneById = new VersionedNetexEntityIndexImpl<>(); + this.groupOfTariffZonesById = new VersionedNetexEntityIndexImpl<>(); + this.compositeFrames = new HashSet<>(); + this.siteFrames = new HashSet<>(); + this.resourceFrames = new HashSet<>(); + this.serviceFrames = new HashSet<>(); + this.serviceCalendarFrames = new HashSet<>(); + this.vehicleScheduleFrames = new HashSet<>(); + this.timetableFrames = new HashSet<>(); + this.parkingsByParentSiteRef = + Multimaps.synchronizedListMultimap(ArrayListMultimap.create()); + } + + @Override + public NetexEntityIndex getGroupOfLinesIndex() { + return groupOfLinesById; + } + + @Override + public NetexEntityIndex getNetworkIndex() { + return networkById; + } + + @Override + public Map getNetworkIdByGroupOfLineIdIndex() { + return networkIdByGroupOfLineId; + } + + @Override + public NetexEntityIndex getAuthorityIndex() { + return authoritiesById; + } + + @Override + public NetexEntityIndex getDayTypeIndex() { + return dayTypeById; + } + + @Override + public Multimap getDayTypeAssignmentsByDayTypeIdIndex() { + return dayTypeAssignmentByDayTypeId; + } + + @Override + public Multimap getPassengerStopAssignmentsByStopPointRefIndex() { + return passengerStopAssignmentByStopPointRef; + } + + @Override + public NetexEntityIndex getDatedServiceJourneyIndex() { + return datedServiceJourneys; + } + + @Override + public NetexEntityIndex getDeadRunIndex() { + return deadRuns; + } + + @Override + public Multimap getDatedServiceJourneyByServiceJourneyRefIndex() { + return datedServiceJourneyByServiceJourneyRefIndex; + } + + @Override + public NetexEntityIndex getDestinationDisplayIndex() { + return destinationDisplayById; + } + + @Override + public NetexEntityIndex getFlexibleStopPlaceIndex() { + return flexibleStopPlaceById; + } + + @Override + public NetexEntityIndex getGroupOfStopPlacesIndex() { + return groupOfStopPlacesById; + } + + @Override + public NetexEntityIndex getJourneyPatternIndex() { + return journeyPatternsById; + } + + @Override + public NetexEntityIndex getFlexibleLineIndex() { + return flexibleLineByid; + } + + @Override + public NetexEntityIndex getLineIndex() { + return lineById; + } + + @Override + public NetexEntityIndex getNoticeIndex() { + return noticeById; + } + + @Override + public NetexEntityIndex getNoticeAssignmentIndex() { + return noticeAssignmentById; + } + + @Override + public NetexEntityIndex getOperatingDayIndex() { + return operatingDayById; + } + + @Override + public NetexEntityIndex getOperatingPeriodIndex() { + return operatingPeriodById; + } + + @Override + public NetexEntityIndex getOperatorIndex() { + return operatorsById; + } + + @Override + public NetexEntityIndex getBrandingIndex() { + return brandingsById; + } + + @Override + public VersionedNetexEntityIndex getQuayIndex() { + return quayById; + } + + @Override + public Map getFlexibleStopPlaceIdByStopPointRefIndex() { + return flexibleStopPlaceByStopPointRef; + } + + @Override + public Map getQuayIdByStopPointRefIndex() { + return quayIdByStopPointRef; + } + + @Override + public Map getStopPlaceIdByStopPointRefIndex() { + return stopPlaceIdByStopPointRef; + } + + @Override + public Map getStopPlaceIdByQuayIdIndex() { + return stopPlaceIdByQuayId; + } + + @Override + public NetexEntityIndex getRouteIndex() { + return routeById; + } + + @Override + public NetexEntityIndex getServiceJourneyIndex() { + return serviceJourneyById; + } + + @Override + public NetexEntityIndex getServiceJourneyInterchangeIndex() { + return serviceJourneyInterchangeById; + } + + @Override + public Multimap getServiceJourneyInterchangeByServiceJourneyRefIndex() { + return serviceJourneyInterchangeByServiceJourneyRef; + } + + @Override + public NetexEntityIndex getServiceLinkIndex() { + return serviceLinkById; + } + + @Override + public VersionedNetexEntityIndex getStopPlaceIndex() { + return stopPlaceById; + } + + @Override + public VersionedNetexEntityIndex getTariffZoneIndex() { + return tariffZonesById; + } + + @Override + public VersionedNetexEntityIndex getTopographicPlaceIndex() { + return topographicPlaceById; + } + + @Override + public VersionedNetexEntityIndex getParkingIndex() { + return parkingById; + } + + @Override + public VersionedNetexEntityIndex getScheduledStopPointIndex() { + return scheduledStopPointById; + } + + @Override + public NetexEntityIndex getRoutePointIndex() { + return routePointById; + } + + @Override + public NetexEntityIndex getBlockIndex() { + return blockById; + } + + @Override + public VersionedNetexEntityIndex getFareZoneIndex() { + return fareZoneById; + } + + @Override + public VersionedNetexEntityIndex getGroupOfTariffZonesIndex() { + return groupOfTariffZonesById; + } + + @Override + public Collection getCompositeFrames() { + return compositeFrames; + } + + @Override + public Collection getResourceFrames() { + return resourceFrames; + } + + @Override + public Collection getSiteFrames() { + return siteFrames; + } + + @Override + public Collection getServiceFrames() { + return serviceFrames; + } + + @Override + public Collection getServiceCalendarFrames() { + return serviceCalendarFrames; + } + + @Override + public Collection getVehicleScheduleFrames() { + return vehicleScheduleFrames; + } + + @Override + public Collection getTimetableFrames() { + return timetableFrames; + } + + @Override + public LocalDateTime getPublicationTimestamp() { + return publicationTimestamp; + } + + @Override + public void setPublicationTimestamp(LocalDateTime publicationTimestamp) { + this.publicationTimestamp = publicationTimestamp; + } + + @Override + public Multimap getParkingsByParentSiteRefIndex() { + return parkingsByParentSiteRef; + } } diff --git a/src/main/java/org/entur/netex/index/impl/NetexEntityMapByIdImpl.java b/src/main/java/org/entur/netex/index/impl/NetexEntityMapByIdImpl.java index 573e30dc..4cfd219b 100644 --- a/src/main/java/org/entur/netex/index/impl/NetexEntityMapByIdImpl.java +++ b/src/main/java/org/entur/netex/index/impl/NetexEntityMapByIdImpl.java @@ -1,41 +1,42 @@ package org.entur.netex.index.impl; -import org.entur.netex.index.api.NetexEntityIndex; -import org.rutebanken.netex.model.EntityStructure; - import java.util.Collection; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.entur.netex.index.api.NetexEntityIndex; +import org.rutebanken.netex.model.EntityStructure; + +public class NetexEntityMapByIdImpl + implements NetexEntityIndex { + + private final Map map = new ConcurrentHashMap<>(); + + @Override + public V get(String id) { + return map.get(id); + } + + @Override + public Collection getAll() { + return map.values(); + } + + @Override + public void put(String id, V entity) { + map.put(id, entity); + } + + @Override + public void putAll(Collection entities) { + entities.forEach(this::add); + } + + @Override + public void remove(String id) { + map.remove(id); + } -public class NetexEntityMapByIdImpl implements NetexEntityIndex { - private final Map map = new ConcurrentHashMap<>(); - - @Override - public V get(String id) { - return map.get(id); - } - - @Override - public Collection getAll() { - return map.values(); - } - - @Override - public void put(String id, V entity) { - map.put(id, entity); - } - - @Override - public void putAll(Collection entities) { - entities.forEach(this::add); - } - - @Override - public void remove(String id) { - map.remove(id); - } - - public void add(V entity) { - map.put(entity.getId(), entity); - } + public void add(V entity) { + map.put(entity.getId(), entity); + } } diff --git a/src/main/java/org/entur/netex/index/impl/VersionedNetexEntityIndexImpl.java b/src/main/java/org/entur/netex/index/impl/VersionedNetexEntityIndexImpl.java index 44c8f820..32087a6f 100644 --- a/src/main/java/org/entur/netex/index/impl/VersionedNetexEntityIndexImpl.java +++ b/src/main/java/org/entur/netex/index/impl/VersionedNetexEntityIndexImpl.java @@ -1,73 +1,81 @@ package org.entur.netex.index.impl; +import static org.entur.netex.support.NetexVersionHelper.latestVersionedElementIn; +import static org.entur.netex.support.NetexVersionHelper.versionOfElementIn; + import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; import com.google.common.collect.Multimaps; -import org.entur.netex.index.api.VersionedNetexEntityIndex; -import org.rutebanken.netex.model.EntityInVersionStructure; -import org.rutebanken.netex.model.EntityStructure; - import java.util.Collection; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; +import org.entur.netex.index.api.VersionedNetexEntityIndex; +import org.rutebanken.netex.model.EntityInVersionStructure; +import org.rutebanken.netex.model.EntityStructure; -import static org.entur.netex.support.NetexVersionHelper.latestVersionedElementIn; -import static org.entur.netex.support.NetexVersionHelper.versionOfElementIn; +public class VersionedNetexEntityIndexImpl + implements VersionedNetexEntityIndex { -public class VersionedNetexEntityIndexImpl implements VersionedNetexEntityIndex { - private final Multimap map = Multimaps.synchronizedListMultimap(ArrayListMultimap.create()); - private final Map latestMap = new ConcurrentHashMap<>(); + private final Multimap map = Multimaps.synchronizedListMultimap( + ArrayListMultimap.create() + ); + private final Map latestMap = new ConcurrentHashMap<>(); - @Override - public V getLatestVersion(String id) { - return latestMap.get(id); - } + @Override + public V getLatestVersion(String id) { + return latestMap.get(id); + } - @Override - public V getVersion(String id, String version) { - return versionOfElementIn(map.get(id), version); - } + @Override + public V getVersion(String id, String version) { + return versionOfElementIn(map.get(id), version); + } - @Override - public Collection getLatestVersions() { - return latestMap.values(); - } + @Override + public Collection getLatestVersions() { + return latestMap.values(); + } - @Override - public Collection getAllVersions(String id) { - return map.get(id); - } + @Override + public Collection getAllVersions(String id) { + return map.get(id); + } - @Override - public Map> getAllVersions() { - synchronized (map) { - return map.asMap(); - } + @Override + public Map> getAllVersions() { + synchronized (map) { + return map.asMap(); } + } - @Override - public void put(String id, Collection entities) { - map.replaceValues(id, entities); - latestMap.put(id, latestVersionedElementIn(entities)); - } + @Override + public void put(String id, Collection entities) { + map.replaceValues(id, entities); + latestMap.put(id, latestVersionedElementIn(entities)); + } - @Override - public void putAll(Collection entities) { - Map> entityMap = entities.stream() - .collect(Collectors.groupingBy(V::getId)); + @Override + public void putAll(Collection entities) { + Map> entityMap = entities + .stream() + .collect(Collectors.groupingBy(V::getId)); - entityMap.forEach(map::replaceValues); + entityMap.forEach(map::replaceValues); - latestMap.putAll(entityMap.keySet().stream() - .map(id -> latestVersionedElementIn(map.get(id))) - .collect(Collectors.toMap(EntityStructure::getId, e -> e))); - } + latestMap.putAll( + entityMap + .keySet() + .stream() + .map(id -> latestVersionedElementIn(map.get(id))) + .collect(Collectors.toMap(EntityStructure::getId, e -> e)) + ); + } - @Override - public void remove(String id) { - map.removeAll(id); - latestMap.remove(id); - } + @Override + public void remove(String id) { + map.removeAll(id); + latestMap.remove(id); + } } diff --git a/src/main/java/org/entur/netex/loader/NetexXmlParser.java b/src/main/java/org/entur/netex/loader/NetexXmlParser.java index f7ec6e02..81ad81ec 100644 --- a/src/main/java/org/entur/netex/loader/NetexXmlParser.java +++ b/src/main/java/org/entur/netex/loader/NetexXmlParser.java @@ -1,44 +1,47 @@ package org.entur.netex.loader; -import org.rutebanken.netex.model.PublicationDeliveryStructure; - import jakarta.xml.bind.JAXBContext; import jakarta.xml.bind.JAXBElement; import jakarta.xml.bind.JAXBException; import jakarta.xml.bind.Unmarshaller; import java.io.InputStream; +import org.rutebanken.netex.model.PublicationDeliveryStructure; /** Simple wrapper to perform typesafe xml parsing and simple error handling. */ public class NetexXmlParser { - /** used to parse the XML. */ - private final Unmarshaller unmarshaller; - - public NetexXmlParser() { - this.unmarshaller = createUnmarshaller(); - } - - /** - * Parse an input stream and return the root document type for the given xml file (stream). - */ - public PublicationDeliveryStructure parseXmlDoc(InputStream stream) throws JAXBException { - - @SuppressWarnings("unchecked") - JAXBElement root = (JAXBElement) unmarshaller.unmarshal(stream); - - return root.getValue(); - } - /** factory method for unmarshaller */ - private static Unmarshaller createUnmarshaller() { - try { - return JAXBContext - .newInstance(PublicationDeliveryStructure.class) - .createUnmarshaller(); - } catch (JAXBException e) { - // This is a programming error - not expected! - // We abort early and also allow for this to happen in the constructor; - // Which in other cases would be considered bad practice. - throw new RuntimeException(e); - } + /** used to parse the XML. */ + private final Unmarshaller unmarshaller; + + public NetexXmlParser() { + this.unmarshaller = createUnmarshaller(); + } + + /** + * Parse an input stream and return the root document type for the given xml file (stream). + */ + public PublicationDeliveryStructure parseXmlDoc(InputStream stream) + throws JAXBException { + @SuppressWarnings("unchecked") + JAXBElement root = + (JAXBElement) unmarshaller.unmarshal( + stream + ); + + return root.getValue(); + } + + /** factory method for unmarshaller */ + private static Unmarshaller createUnmarshaller() { + try { + return JAXBContext + .newInstance(PublicationDeliveryStructure.class) + .createUnmarshaller(); + } catch (JAXBException e) { + // This is a programming error - not expected! + // We abort early and also allow for this to happen in the constructor; + // Which in other cases would be considered bad practice. + throw new RuntimeException(e); } + } } diff --git a/src/main/java/org/entur/netex/loader/parser/FareFrameParser.java b/src/main/java/org/entur/netex/loader/parser/FareFrameParser.java index 80e957ca..318408d3 100644 --- a/src/main/java/org/entur/netex/loader/parser/FareFrameParser.java +++ b/src/main/java/org/entur/netex/loader/parser/FareFrameParser.java @@ -1,29 +1,29 @@ package org.entur.netex.loader.parser; +import java.util.ArrayList; +import java.util.Collection; import org.entur.netex.index.api.NetexEntitiesIndex; import org.rutebanken.netex.model.FareFrame_VersionFrameStructure; import org.rutebanken.netex.model.FareZone; -import java.util.ArrayList; -import java.util.Collection; +public class FareFrameParser + extends NetexParser { -public class FareFrameParser extends NetexParser { + private final Collection fareZones = new ArrayList<>(); - private final Collection fareZones = new ArrayList<>(); - - @Override - void parse(FareFrame_VersionFrameStructure node) { - if (node.getFareZones() != null) { - parseFareZones(node.getFareZones().getFareZone()); - } + @Override + void parse(FareFrame_VersionFrameStructure node) { + if (node.getFareZones() != null) { + parseFareZones(node.getFareZones().getFareZone()); } + } - @Override - void setResultOnIndex(NetexEntitiesIndex netexIndex) { - netexIndex.getFareZoneIndex().putAll(fareZones); - } + @Override + void setResultOnIndex(NetexEntitiesIndex netexIndex) { + netexIndex.getFareZoneIndex().putAll(fareZones); + } - private void parseFareZones(Collection fareZoneList) { - fareZones.addAll(fareZoneList); - } + private void parseFareZones(Collection fareZoneList) { + fareZones.addAll(fareZoneList); + } } diff --git a/src/main/java/org/entur/netex/loader/parser/NetexDocumentParser.java b/src/main/java/org/entur/netex/loader/parser/NetexDocumentParser.java index e0bc7dd4..2d374ee2 100644 --- a/src/main/java/org/entur/netex/loader/parser/NetexDocumentParser.java +++ b/src/main/java/org/entur/netex/loader/parser/NetexDocumentParser.java @@ -1,5 +1,8 @@ package org.entur.netex.loader.parser; +import jakarta.xml.bind.JAXBElement; +import java.util.Collection; +import java.util.List; import org.entur.netex.index.api.NetexEntitiesIndex; import org.rutebanken.netex.model.Common_VersionFrameStructure; import org.rutebanken.netex.model.CompositeFrame; @@ -16,99 +19,101 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import jakarta.xml.bind.JAXBElement; -import java.util.Collection; -import java.util.List; - /** * This is the root parser for a Netex XML Document. The parser ONLY read the document and * populate the index with entities. The parser is only responsible for populating the * index, not for validating the document, nor linking of entities. */ public class NetexDocumentParser { - private static final Logger LOG = LoggerFactory.getLogger(NetexDocumentParser.class); - private final NetexEntitiesIndex netexIndex; + private static final Logger LOG = LoggerFactory.getLogger( + NetexDocumentParser.class + ); - private NetexDocumentParser(NetexEntitiesIndex netexIndex) { - this.netexIndex = netexIndex; - } + private final NetexEntitiesIndex netexIndex; - /** - * This static method create a new parser and parse the document. The result is added - * to given index for further processing. - */ - public static void parseAndPopulateIndex(NetexEntitiesIndex index, PublicationDeliveryStructure doc) { - new NetexDocumentParser(index).parse(doc); - } + private NetexDocumentParser(NetexEntitiesIndex netexIndex) { + this.netexIndex = netexIndex; + } - /** Top level parse method - parses the document. */ - private void parse(PublicationDeliveryStructure doc) { - netexIndex.setPublicationTimestamp(doc.getPublicationTimestamp()); - parseFrameList(doc.getDataObjects().getCompositeFrameOrCommonFrame()); - } + /** + * This static method create a new parser and parse the document. The result is added + * to given index for further processing. + */ + public static void parseAndPopulateIndex( + NetexEntitiesIndex index, + PublicationDeliveryStructure doc + ) { + new NetexDocumentParser(index).parse(doc); + } - private void parseFrameList(List> frames) { - for (JAXBElement frame : frames) { - parseCommonFrame(frame.getValue()); - } - } + /** Top level parse method - parses the document. */ + private void parse(PublicationDeliveryStructure doc) { + netexIndex.setPublicationTimestamp(doc.getPublicationTimestamp()); + parseFrameList(doc.getDataObjects().getCompositeFrameOrCommonFrame()); + } - private void parseCommonFrame(Common_VersionFrameStructure value) { - if(value instanceof ResourceFrame resourceFrame) { - netexIndex.getResourceFrames().add(resourceFrame); - parse((ResourceFrame) value, new ResourceFrameParser()); - } else if(value instanceof ServiceCalendarFrame serviceCalendarFrame) { - netexIndex.getServiceCalendarFrames().add(serviceCalendarFrame); - parse((ServiceCalendarFrame) value, new ServiceCalendarFrameParser()); - } else if (value instanceof VehicleScheduleFrame vehicleScheduleFrame) { - netexIndex.getVehicleScheduleFrames().add(vehicleScheduleFrame); - parse((VehicleScheduleFrame) value, new VehicleScheduleFrameParser()); - } else if (value instanceof TimetableFrame timetableFrame) { - netexIndex.getTimetableFrames().add(timetableFrame); - parse((TimetableFrame) value, new TimeTableFrameParser()); - } else if(value instanceof ServiceFrame serviceFrame) { - netexIndex.getServiceFrames().add(serviceFrame); - parse((ServiceFrame) value, new ServiceFrameParser( - netexIndex.getFlexibleStopPlaceIndex() - )); - } else if (value instanceof SiteFrame siteFrame) { - netexIndex.getSiteFrames().add(siteFrame); - parse((SiteFrame) value, new SiteFrameParser()); - } else if (value instanceof FareFrame fareFrame) { - parse(fareFrame, new FareFrameParser()); - } else if (value instanceof CompositeFrame compositeFrame) { - netexIndex.getCompositeFrames().add(compositeFrame); - // We recursively parse composite frames and content until there - // is no more nested frames - this is accepting documents witch - // are not withing the specification, but we leave this for the - // document schema validation - parseCompositeFrame(compositeFrame); - } else if ( - value instanceof GeneralFrame || - value instanceof InfrastructureFrame - ) { - NetexParser.informOnElementIntentionallySkipped(LOG, value); - } else { - NetexParser.informOnElementIntentionallySkipped(LOG, value); - } + private void parseFrameList( + List> frames + ) { + for (JAXBElement frame : frames) { + parseCommonFrame(frame.getValue()); } + } - private void parseCompositeFrame(CompositeFrame frame) { - // Declare some ugly types to prevent obstructing the reading later... - Collection> frames; - - frames = frame.getFrames().getCommonFrame(); - - for (JAXBElement it : frames) { - parseCommonFrame(it.getValue()); - } + private void parseCommonFrame(Common_VersionFrameStructure value) { + if (value instanceof ResourceFrame resourceFrame) { + netexIndex.getResourceFrames().add(resourceFrame); + parse((ResourceFrame) value, new ResourceFrameParser()); + } else if (value instanceof ServiceCalendarFrame serviceCalendarFrame) { + netexIndex.getServiceCalendarFrames().add(serviceCalendarFrame); + parse((ServiceCalendarFrame) value, new ServiceCalendarFrameParser()); + } else if (value instanceof VehicleScheduleFrame vehicleScheduleFrame) { + netexIndex.getVehicleScheduleFrames().add(vehicleScheduleFrame); + parse((VehicleScheduleFrame) value, new VehicleScheduleFrameParser()); + } else if (value instanceof TimetableFrame timetableFrame) { + netexIndex.getTimetableFrames().add(timetableFrame); + parse((TimetableFrame) value, new TimeTableFrameParser()); + } else if (value instanceof ServiceFrame serviceFrame) { + netexIndex.getServiceFrames().add(serviceFrame); + parse( + (ServiceFrame) value, + new ServiceFrameParser(netexIndex.getFlexibleStopPlaceIndex()) + ); + } else if (value instanceof SiteFrame siteFrame) { + netexIndex.getSiteFrames().add(siteFrame); + parse((SiteFrame) value, new SiteFrameParser()); + } else if (value instanceof FareFrame fareFrame) { + parse(fareFrame, new FareFrameParser()); + } else if (value instanceof CompositeFrame compositeFrame) { + netexIndex.getCompositeFrames().add(compositeFrame); + // We recursively parse composite frames and content until there + // is no more nested frames - this is accepting documents witch + // are not withing the specification, but we leave this for the + // document schema validation + parseCompositeFrame(compositeFrame); + } else if ( + value instanceof GeneralFrame || value instanceof InfrastructureFrame + ) { + NetexParser.informOnElementIntentionallySkipped(LOG, value); + } else { + NetexParser.informOnElementIntentionallySkipped(LOG, value); } + } + private void parseCompositeFrame(CompositeFrame frame) { + // Declare some ugly types to prevent obstructing the reading later... + Collection> frames; + frames = frame.getFrames().getCommonFrame(); - private void parse(T node, NetexParser parser) { - parser.parse(node); - parser.setResultOnIndex(netexIndex); + for (JAXBElement it : frames) { + parseCommonFrame(it.getValue()); } + } + + private void parse(T node, NetexParser parser) { + parser.parse(node); + parser.setResultOnIndex(netexIndex); + } } diff --git a/src/main/java/org/entur/netex/loader/parser/NetexParser.java b/src/main/java/org/entur/netex/loader/parser/NetexParser.java index 9a9a3824..00b2f801 100644 --- a/src/main/java/org/entur/netex/loader/parser/NetexParser.java +++ b/src/main/java/org/entur/netex/loader/parser/NetexParser.java @@ -1,11 +1,10 @@ package org.entur.netex.loader.parser; +import java.util.Collection; import org.entur.netex.index.api.NetexEntitiesIndex; import org.rutebanken.netex.model.VersionFrame_VersionStructure; import org.slf4j.Logger; -import java.util.Collection; - /** * An abstract parser of given type T. Enforce two steps parsing: *
    @@ -16,32 +15,38 @@ @SuppressWarnings("SameParameterValue") abstract class NetexParser { - /** Perform parsing and keep the parsed objects internally. */ - abstract void parse(T node); - - /** Add the result - the parsed objects - to the index. */ - abstract void setResultOnIndex(NetexEntitiesIndex netexIndex); - - - /* static methods for logging unhandled elements - this ensure consistent logging. */ - - static void verifyCommonUnusedPropertiesIsNotSet(Logger log, VersionFrame_VersionStructure rel) { - informOnElementIntentionallySkipped(log, rel.getTypeOfFrameRef()); - informOnElementIntentionallySkipped(log, rel.getBaselineVersionFrameRef()); - informOnElementIntentionallySkipped(log, rel.getCodespaces()); - informOnElementIntentionallySkipped(log, rel.getFrameDefaults()); - informOnElementIntentionallySkipped(log, rel.getVersions()); - informOnElementIntentionallySkipped(log, rel.getTraces()); - informOnElementIntentionallySkipped(log, rel.getContentValidityConditions()); - informOnElementIntentionallySkipped(log, rel.getKeyList()); - informOnElementIntentionallySkipped(log, rel.getExtensions()); - informOnElementIntentionallySkipped(log, rel.getBrandingRef()); - } - - static void informOnElementIntentionallySkipped(Logger log, Object rel) { - if(rel == null) return; - if(rel instanceof Collection) throw new IllegalArgumentException("Do not pass in collections to this method."); - log.info("Netex import - Element skipped: {}", rel.getClass().getName()); - } - + /** Perform parsing and keep the parsed objects internally. */ + abstract void parse(T node); + + /** Add the result - the parsed objects - to the index. */ + abstract void setResultOnIndex(NetexEntitiesIndex netexIndex); + + /* static methods for logging unhandled elements - this ensure consistent logging. */ + + static void verifyCommonUnusedPropertiesIsNotSet( + Logger log, + VersionFrame_VersionStructure rel + ) { + informOnElementIntentionallySkipped(log, rel.getTypeOfFrameRef()); + informOnElementIntentionallySkipped(log, rel.getBaselineVersionFrameRef()); + informOnElementIntentionallySkipped(log, rel.getCodespaces()); + informOnElementIntentionallySkipped(log, rel.getFrameDefaults()); + informOnElementIntentionallySkipped(log, rel.getVersions()); + informOnElementIntentionallySkipped(log, rel.getTraces()); + informOnElementIntentionallySkipped( + log, + rel.getContentValidityConditions() + ); + informOnElementIntentionallySkipped(log, rel.getKeyList()); + informOnElementIntentionallySkipped(log, rel.getExtensions()); + informOnElementIntentionallySkipped(log, rel.getBrandingRef()); + } + + static void informOnElementIntentionallySkipped(Logger log, Object rel) { + if (rel == null) return; + if (rel instanceof Collection) throw new IllegalArgumentException( + "Do not pass in collections to this method." + ); + log.info("Netex import - Element skipped: {}", rel.getClass().getName()); + } } diff --git a/src/main/java/org/entur/netex/loader/parser/NoticeParser.java b/src/main/java/org/entur/netex/loader/parser/NoticeParser.java index 20c9b92a..3b598219 100644 --- a/src/main/java/org/entur/netex/loader/parser/NoticeParser.java +++ b/src/main/java/org/entur/netex/loader/parser/NoticeParser.java @@ -1,5 +1,8 @@ package org.entur.netex.loader.parser; +import jakarta.xml.bind.JAXBElement; +import java.util.ArrayList; +import java.util.Collection; import org.entur.netex.index.api.NetexEntitiesIndex; import org.rutebanken.netex.model.DataManagedObjectStructure; import org.rutebanken.netex.model.Notice; @@ -9,57 +12,57 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import jakarta.xml.bind.JAXBElement; -import java.util.ArrayList; -import java.util.Collection; - /** * Parse a Notice and Notice Assigment, used only be the {@link ServiceFrameParser} and * {@link TimeTableFrameParser}. */ class NoticeParser { - private static final Logger LOG = LoggerFactory.getLogger(NoticeParser.class); - private final Collection notices = new ArrayList<>(); - private final Collection noticeAssignments = new ArrayList<>(); + private static final Logger LOG = LoggerFactory.getLogger(NoticeParser.class); + private final Collection notices = new ArrayList<>(); + private final Collection noticeAssignments = + new ArrayList<>(); - void parseNotices(NoticesInFrame_RelStructure notices) { - if (notices == null) return; + void parseNotices(NoticesInFrame_RelStructure notices) { + if (notices == null) return; - this.notices.addAll(notices.getNotice()); - } + this.notices.addAll(notices.getNotice()); + } - void parseNoticeAssignments(NoticeAssignmentsInFrame_RelStructure na) { - if (na == null) return; + void parseNoticeAssignments(NoticeAssignmentsInFrame_RelStructure na) { + if (na == null) return; - for (JAXBElement it : na.getNoticeAssignment_()) { - NoticeAssignment noticeAssignment = (NoticeAssignment) it.getValue(); - boolean error = false; + for (JAXBElement it : na.getNoticeAssignment_()) { + NoticeAssignment noticeAssignment = (NoticeAssignment) it.getValue(); + boolean error = false; - if(noticeAssignment.getNoticedObjectRef() == null) { - LOG.warn( - "Notice assignment is missing 'noticedObjectRef'. Id: {}", - noticeAssignment.getId() - ); - error = true; - } - if(noticeAssignment.getNoticeRef() == null && noticeAssignment.getNotice() == null) { - LOG.warn( - "Notice assignment have no 'notice' or 'noticeRef'. Id: {}", - noticeAssignment.getId() - ); - error = true; - } - if(!error) { - this.noticeAssignments.add(noticeAssignment); - } - } + if (noticeAssignment.getNoticedObjectRef() == null) { + LOG.warn( + "Notice assignment is missing 'noticedObjectRef'. Id: {}", + noticeAssignment.getId() + ); + error = true; + } + if ( + noticeAssignment.getNoticeRef() == null && + noticeAssignment.getNotice() == null + ) { + LOG.warn( + "Notice assignment have no 'notice' or 'noticeRef'. Id: {}", + noticeAssignment.getId() + ); + error = true; + } + if (!error) { + this.noticeAssignments.add(noticeAssignment); + } } + } - void setResultOnIndex(NetexEntitiesIndex index) { - // update entities - index.getNoticeIndex().putAll(notices); - index.getNoticeAssignmentIndex().putAll(noticeAssignments); - } + void setResultOnIndex(NetexEntitiesIndex index) { + // update entities + index.getNoticeIndex().putAll(notices); + index.getNoticeAssignmentIndex().putAll(noticeAssignments); + } } diff --git a/src/main/java/org/entur/netex/loader/parser/ResourceFrameParser.java b/src/main/java/org/entur/netex/loader/parser/ResourceFrameParser.java index 6c1d1bab..51686f04 100644 --- a/src/main/java/org/entur/netex/loader/parser/ResourceFrameParser.java +++ b/src/main/java/org/entur/netex/loader/parser/ResourceFrameParser.java @@ -1,5 +1,8 @@ package org.entur.netex.loader.parser; +import jakarta.xml.bind.JAXBElement; +import java.util.ArrayList; +import java.util.Collection; import org.entur.netex.index.api.NetexEntitiesIndex; import org.rutebanken.netex.model.Authority; import org.rutebanken.netex.model.Branding; @@ -11,83 +14,85 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import jakarta.xml.bind.JAXBElement; -import java.util.ArrayList; -import java.util.Collection; - -class ResourceFrameParser extends NetexParser { - private static final Logger LOG = LoggerFactory.getLogger(ResourceFrameParser.class); +class ResourceFrameParser + extends NetexParser { - private final Collection authorities = new ArrayList<>(); - private final Collection operators = new ArrayList<>(); - private final Collection brandings = new ArrayList<>(); - - @Override - void parse(ResourceFrame_VersionFrameStructure frame) { - if (frame.getOrganisations() != null) { - parseOrganisations(frame.getOrganisations()); - } - parseTypeOfValues(frame.getTypesOfValue()); + private static final Logger LOG = LoggerFactory.getLogger( + ResourceFrameParser.class + ); - // Keep list sorted alphabetically - informOnElementIntentionallySkipped(LOG, frame.getBlacklists()); - informOnElementIntentionallySkipped(LOG, frame.getControlCentres()); - informOnElementIntentionallySkipped(LOG, frame.getDataSources()); - informOnElementIntentionallySkipped(LOG, frame.getEquipments()); - informOnElementIntentionallySkipped(LOG, frame.getGroupsOfEntities()); - informOnElementIntentionallySkipped(LOG, frame.getGroupsOfOperators()); - informOnElementIntentionallySkipped(LOG, frame.getOperationalContexts()); - informOnElementIntentionallySkipped(LOG, frame.getResponsibilitySets()); - informOnElementIntentionallySkipped(LOG, frame.getSchematicMaps()); - informOnElementIntentionallySkipped(LOG, frame.getVehicles()); - informOnElementIntentionallySkipped(LOG, frame.getVehicleEquipmentProfiles()); - informOnElementIntentionallySkipped(LOG, frame.getVehicleModels()); - informOnElementIntentionallySkipped(LOG, frame.getVehicleTypes()); - informOnElementIntentionallySkipped(LOG, frame.getWhitelists()); - informOnElementIntentionallySkipped(LOG, frame.getZones()); + private final Collection authorities = new ArrayList<>(); + private final Collection operators = new ArrayList<>(); + private final Collection brandings = new ArrayList<>(); - verifyCommonUnusedPropertiesIsNotSet(LOG, frame); - } - - @Override - void setResultOnIndex(NetexEntitiesIndex netexIndex) { - netexIndex.getAuthorityIndex().putAll(authorities); - netexIndex.getOperatorIndex().putAll(operators); - netexIndex.getBrandingIndex().putAll(brandings); + @Override + void parse(ResourceFrame_VersionFrameStructure frame) { + if (frame.getOrganisations() != null) { + parseOrganisations(frame.getOrganisations()); } + parseTypeOfValues(frame.getTypesOfValue()); + // Keep list sorted alphabetically + informOnElementIntentionallySkipped(LOG, frame.getBlacklists()); + informOnElementIntentionallySkipped(LOG, frame.getControlCentres()); + informOnElementIntentionallySkipped(LOG, frame.getDataSources()); + informOnElementIntentionallySkipped(LOG, frame.getEquipments()); + informOnElementIntentionallySkipped(LOG, frame.getGroupsOfEntities()); + informOnElementIntentionallySkipped(LOG, frame.getGroupsOfOperators()); + informOnElementIntentionallySkipped(LOG, frame.getOperationalContexts()); + informOnElementIntentionallySkipped(LOG, frame.getResponsibilitySets()); + informOnElementIntentionallySkipped(LOG, frame.getSchematicMaps()); + informOnElementIntentionallySkipped(LOG, frame.getVehicles()); + informOnElementIntentionallySkipped( + LOG, + frame.getVehicleEquipmentProfiles() + ); + informOnElementIntentionallySkipped(LOG, frame.getVehicleModels()); + informOnElementIntentionallySkipped(LOG, frame.getVehicleTypes()); + informOnElementIntentionallySkipped(LOG, frame.getWhitelists()); + informOnElementIntentionallySkipped(LOG, frame.getZones()); - /* private methods */ + verifyCommonUnusedPropertiesIsNotSet(LOG, frame); + } - private void parseOrganisations(OrganisationsInFrame_RelStructure elements) { - if (elements != null) { - for (JAXBElement e : elements.getOrganisation_()) { - parseOrganisation((Organisation_VersionStructure) e.getValue()); - } - } - } + @Override + void setResultOnIndex(NetexEntitiesIndex netexIndex) { + netexIndex.getAuthorityIndex().putAll(authorities); + netexIndex.getOperatorIndex().putAll(operators); + netexIndex.getBrandingIndex().putAll(brandings); + } + /* private methods */ - private void parseOrganisation(Organisation_VersionStructure element) { - if (element instanceof Authority authority) { - authorities.add(authority); - } else if (element instanceof Operator operator) { - operators.add(operator); + private void parseOrganisations(OrganisationsInFrame_RelStructure elements) { + if (elements != null) { + for (JAXBElement e : elements.getOrganisation_()) { + parseOrganisation((Organisation_VersionStructure) e.getValue()); + } + } + } - } else { - informOnElementIntentionallySkipped(LOG, element); - } + private void parseOrganisation(Organisation_VersionStructure element) { + if (element instanceof Authority authority) { + authorities.add(authority); + } else if (element instanceof Operator operator) { + operators.add(operator); + } else { + informOnElementIntentionallySkipped(LOG, element); } + } - private void parseTypeOfValues(TypesOfValueInFrame_RelStructure typesOfValue) { - if (typesOfValue != null) { - for (JAXBElement e : typesOfValue.getValueSetOrTypeOfValue()) { - if (e.getValue() instanceof Branding) { - brandings.add((Branding) e.getValue()); - } else { - informOnElementIntentionallySkipped(LOG, e); - } - } + private void parseTypeOfValues( + TypesOfValueInFrame_RelStructure typesOfValue + ) { + if (typesOfValue != null) { + for (JAXBElement e : typesOfValue.getValueSetOrTypeOfValue()) { + if (e.getValue() instanceof Branding) { + brandings.add((Branding) e.getValue()); + } else { + informOnElementIntentionallySkipped(LOG, e); } + } } + } } diff --git a/src/main/java/org/entur/netex/loader/parser/ServiceCalendarFrameParser.java b/src/main/java/org/entur/netex/loader/parser/ServiceCalendarFrameParser.java index 4a2e19e0..571c6de9 100644 --- a/src/main/java/org/entur/netex/loader/parser/ServiceCalendarFrameParser.java +++ b/src/main/java/org/entur/netex/loader/parser/ServiceCalendarFrameParser.java @@ -2,6 +2,10 @@ import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; +import jakarta.xml.bind.JAXBElement; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; import org.entur.netex.index.api.NetexEntitiesIndex; import org.rutebanken.netex.model.DayType; import org.rutebanken.netex.model.DayTypeAssignment; @@ -19,100 +23,116 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import jakarta.xml.bind.JAXBElement; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -class ServiceCalendarFrameParser extends NetexParser { - private static final Logger LOG = LoggerFactory.getLogger(ServiceCalendarFrameParser.class); - - private final Collection dayTypes = new ArrayList<>(); - private final Collection operatingPeriods = new ArrayList<>(); - private final Collection operatingDays = new ArrayList<>(); - private final Multimap dayTypeAssignmentByDayTypeId = ArrayListMultimap.create(); - - - @Override - void parse(ServiceCalendarFrame_VersionFrameStructure frame) { - parseServiceCalendar(frame.getServiceCalendar()); - parseDayTypes(frame.getDayTypes()); - parseOperatingPeriods(frame.getOperatingPeriods()); - parseOperatingDays(frame.getOperatingDays()); - parseDayTypeAssignments(frame.getDayTypeAssignments()); - - // Keep list sorted alphabetically - - informOnElementIntentionallySkipped(LOG, frame.getTimebands()); - informOnElementIntentionallySkipped(LOG, frame.getGroupOfTimebands()); - - verifyCommonUnusedPropertiesIsNotSet(LOG, frame); +class ServiceCalendarFrameParser + extends NetexParser { + + private static final Logger LOG = LoggerFactory.getLogger( + ServiceCalendarFrameParser.class + ); + + private final Collection dayTypes = new ArrayList<>(); + private final Collection operatingPeriods = + new ArrayList<>(); + private final Collection operatingDays = new ArrayList<>(); + private final Multimap dayTypeAssignmentByDayTypeId = + ArrayListMultimap.create(); + + @Override + void parse(ServiceCalendarFrame_VersionFrameStructure frame) { + parseServiceCalendar(frame.getServiceCalendar()); + parseDayTypes(frame.getDayTypes()); + parseOperatingPeriods(frame.getOperatingPeriods()); + parseOperatingDays(frame.getOperatingDays()); + parseDayTypeAssignments(frame.getDayTypeAssignments()); + + // Keep list sorted alphabetically + + informOnElementIntentionallySkipped(LOG, frame.getTimebands()); + informOnElementIntentionallySkipped(LOG, frame.getGroupOfTimebands()); + + verifyCommonUnusedPropertiesIsNotSet(LOG, frame); + } + + @Override + void setResultOnIndex(NetexEntitiesIndex netexIndex) { + netexIndex.getDayTypeIndex().putAll(dayTypes); + netexIndex.getOperatingPeriodIndex().putAll(operatingPeriods); + netexIndex.getOperatingDayIndex().putAll(operatingDays); + netexIndex + .getDayTypeAssignmentsByDayTypeIdIndex() + .putAll(dayTypeAssignmentByDayTypeId); + } + + private void parseServiceCalendar(ServiceCalendar serviceCalendar) { + if (serviceCalendar == null) return; + + parseDayTypes(serviceCalendar.getDayTypes()); + // TODO - What about OperatingPeriods here? + parseDayTypeAssignments(serviceCalendar.getDayTypeAssignments()); + } + + //List> + private void parseDayTypes(DayTypesInFrame_RelStructure element) { + if (element == null) return; + for (JAXBElement dt : element.getDayType_()) { + parseDayType(dt); } + } - @Override - void setResultOnIndex(NetexEntitiesIndex netexIndex) { - netexIndex.getDayTypeIndex().putAll(dayTypes); - netexIndex.getOperatingPeriodIndex().putAll(operatingPeriods); - netexIndex.getOperatingDayIndex().putAll(operatingDays); - netexIndex.getDayTypeAssignmentsByDayTypeIdIndex().putAll(dayTypeAssignmentByDayTypeId); + private void parseDayTypes(DayTypes_RelStructure dayTypes) { + if (dayTypes == null) return; + for (JAXBElement dt : dayTypes.getDayTypeRefOrDayType_()) { + parseDayType(dt); } + } - private void parseServiceCalendar(ServiceCalendar serviceCalendar) { - if(serviceCalendar == null) return; - - parseDayTypes(serviceCalendar.getDayTypes()); - // TODO - What about OperatingPeriods here? - parseDayTypeAssignments(serviceCalendar.getDayTypeAssignments()); + private void parseDayType(JAXBElement dt) { + if (dt.getValue() instanceof DayType) { + dayTypes.add((DayType) dt.getValue()); } + } - //List> - private void parseDayTypes(DayTypesInFrame_RelStructure element) { - if(element == null) return; - for (JAXBElement dt : element.getDayType_()) { - parseDayType(dt); - } + private void parseOperatingPeriods( + OperatingPeriodsInFrame_RelStructure element + ) { + if (element == null) { + return; } - private void parseDayTypes(DayTypes_RelStructure dayTypes) { - if(dayTypes == null) return; - for (JAXBElement dt : dayTypes.getDayTypeRefOrDayType_()) { - parseDayType(dt); - } + for (OperatingPeriod_VersionStructure p : element.getOperatingPeriodOrUicOperatingPeriod()) { + operatingPeriods.add((OperatingPeriod) p); } + } - private void parseDayType(JAXBElement dt) { - if (dt.getValue() instanceof DayType) { - dayTypes.add((DayType) dt.getValue()); - } + private void parseOperatingDays(OperatingDaysInFrame_RelStructure element) { + if (element == null) { + return; } - - private void parseOperatingPeriods(OperatingPeriodsInFrame_RelStructure element) { - if(element == null) { return; } - - for (OperatingPeriod_VersionStructure p : element.getOperatingPeriodOrUicOperatingPeriod()) { - operatingPeriods.add((OperatingPeriod) p); - } + operatingDays.addAll(element.getOperatingDay()); + } + + private void parseDayTypeAssignments( + DayTypeAssignments_RelStructure element + ) { + if (element == null) { + return; } - - private void parseOperatingDays(OperatingDaysInFrame_RelStructure element) { - if(element == null) { return; } - operatingDays.addAll(element.getOperatingDay()); - } - - private void parseDayTypeAssignments(DayTypeAssignments_RelStructure element) { - if(element == null) { return; } - parseDayTypeAssignments(element.getDayTypeAssignment()); - } - - private void parseDayTypeAssignments(DayTypeAssignmentsInFrame_RelStructure element) { - if(element == null) { return; } - parseDayTypeAssignments(element.getDayTypeAssignment()); + parseDayTypeAssignments(element.getDayTypeAssignment()); + } + + private void parseDayTypeAssignments( + DayTypeAssignmentsInFrame_RelStructure element + ) { + if (element == null) { + return; } + parseDayTypeAssignments(element.getDayTypeAssignment()); + } - private void parseDayTypeAssignments(List elements) { - for (DayTypeAssignment it : elements) { - String ref = it.getDayTypeRef().getValue().getRef(); - dayTypeAssignmentByDayTypeId.put(ref, it); - } + private void parseDayTypeAssignments(List elements) { + for (DayTypeAssignment it : elements) { + String ref = it.getDayTypeRef().getValue().getRef(); + dayTypeAssignmentByDayTypeId.put(ref, it); } + } } diff --git a/src/main/java/org/entur/netex/loader/parser/ServiceFrameParser.java b/src/main/java/org/entur/netex/loader/parser/ServiceFrameParser.java index b624e37e..bbb5d5fb 100644 --- a/src/main/java/org/entur/netex/loader/parser/ServiceFrameParser.java +++ b/src/main/java/org/entur/netex/loader/parser/ServiceFrameParser.java @@ -2,8 +2,13 @@ import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; -import org.entur.netex.index.api.NetexEntityIndex; +import jakarta.xml.bind.JAXBElement; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; import org.entur.netex.index.api.NetexEntitiesIndex; +import org.entur.netex.index.api.NetexEntityIndex; import org.rutebanken.netex.model.DestinationDisplay; import org.rutebanken.netex.model.DestinationDisplaysInFrame_RelStructure; import org.rutebanken.netex.model.FlexibleLine; @@ -31,254 +36,302 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import jakarta.xml.bind.JAXBElement; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - class ServiceFrameParser extends NetexParser { - private static final Logger LOG = LoggerFactory.getLogger(ServiceFrameParser.class); - - private final NetexEntityIndex flexibleStopPlaceById; - - private final Collection networks = new ArrayList<>(); - - private final Collection groupOfLines = new ArrayList<>(); - - private final Collection routes = new ArrayList<>(); - - private final Collection flexibleLines = new ArrayList<>(); - - private final Collection lines = new ArrayList<>(); - - private final Map networkIdByGroupOfLineId = new HashMap<>(); - - private final Collection journeyPatterns = new ArrayList<>(); - - private final Collection destinationDisplays = new ArrayList<>(); - - private final Map quayIdByStopPointRef = new HashMap<>(); - - private final Map stopPlaceIdByStopPointRef = new HashMap<>(); - - private final Map flexibleStopPlaceByStopPointRef = new HashMap<>(); - - private final Collection serviceLinks = new ArrayList<>(); - - private final Collection scheduledStopPoints = new ArrayList<>(); - - private final Collection routePoints = new ArrayList<>(); - - private final Multimap passengerStopAssignmentByStopPointRef = ArrayListMultimap.create(); - - private final NoticeParser noticeParser = new NoticeParser(); - - ServiceFrameParser(NetexEntityIndex flexibleStopPlaceById) { - this.flexibleStopPlaceById = flexibleStopPlaceById; - } - - @Override - void parse(Service_VersionFrameStructure frame) { - parseStopAssignments(frame.getStopAssignments()); - parseRoutes(frame.getRoutes()); - parseNetwork(frame.getNetwork()); - parseAdditionalNetworks(frame.getAdditionalNetworks()); - noticeParser.parseNotices(frame.getNotices()); - noticeParser.parseNoticeAssignments(frame.getNoticeAssignments()); - parseLines(frame.getLines()); - parseJourneyPatterns(frame.getJourneyPatterns()); - parseDestinationDisplays(frame.getDestinationDisplays()); - parseServiceLinks(frame.getServiceLinks()); - parseScheduledStopPoints(frame.getScheduledStopPoints()); - parseRoutePoints(frame.getRoutePoints()); - - // Keep list sorted alphabetically - informOnElementIntentionallySkipped(LOG, frame.getCommonSections()); - informOnElementIntentionallySkipped(LOG, frame.getConnections()); - informOnElementIntentionallySkipped(LOG, frame.getDirections()); - informOnElementIntentionallySkipped(LOG, frame.getDisplayAssignments()); - informOnElementIntentionallySkipped(LOG, frame.getFlexibleLinkProperties()); - informOnElementIntentionallySkipped(LOG, frame.getFlexiblePointProperties()); - informOnElementIntentionallySkipped(LOG, frame.getGeneralSections()); - informOnElementIntentionallySkipped(LOG, frame.getGroupsOfLines()); - informOnElementIntentionallySkipped(LOG, frame.getGroupsOfLinks()); - informOnElementIntentionallySkipped(LOG, frame.getGroupsOfPoints()); - informOnElementIntentionallySkipped(LOG, frame.getLineNetworks()); - informOnElementIntentionallySkipped(LOG, frame.getLogicalDisplays()); - informOnElementIntentionallySkipped(LOG, frame.getPassengerInformationEquipments()); - informOnElementIntentionallySkipped(LOG, frame.getRouteLinks()); - informOnElementIntentionallySkipped(LOG, frame.getRoutingConstraintZones()); - informOnElementIntentionallySkipped(LOG, frame.getServiceExclusions()); - informOnElementIntentionallySkipped(LOG, frame.getServicePatterns()); - informOnElementIntentionallySkipped(LOG, frame.getStopAreas()); - informOnElementIntentionallySkipped(LOG, frame.getTariffZones()); - informOnElementIntentionallySkipped(LOG, frame.getTimeDemandTypes()); - informOnElementIntentionallySkipped(LOG, frame.getTimeDemandTypeAssignments()); - informOnElementIntentionallySkipped(LOG, frame.getTimingPoints()); - informOnElementIntentionallySkipped(LOG, frame.getTimingLinks()); - informOnElementIntentionallySkipped(LOG, frame.getTimingLinkGroups()); - informOnElementIntentionallySkipped(LOG, frame.getTimingPatterns()); - informOnElementIntentionallySkipped(LOG, frame.getTransferRestrictions()); - - verifyCommonUnusedPropertiesIsNotSet(LOG, frame); - } - - @Override - void setResultOnIndex(NetexEntitiesIndex index) { - // update entities - index.getDestinationDisplayIndex().putAll(destinationDisplays); - index.getGroupOfLinesIndex().putAll(groupOfLines); - index.getJourneyPatternIndex().putAll(journeyPatterns); - index.getFlexibleLineIndex().putAll(flexibleLines); - index.getLineIndex().putAll(lines); - index.getNetworkIndex().putAll(networks); - noticeParser.setResultOnIndex(index); - index.getQuayIdByStopPointRefIndex().putAll(quayIdByStopPointRef); - index.getStopPlaceIdByStopPointRefIndex().putAll(stopPlaceIdByStopPointRef); - index.getFlexibleStopPlaceIdByStopPointRefIndex().putAll(flexibleStopPlaceByStopPointRef); - index.getRouteIndex().putAll(routes); - index.getServiceLinkIndex().putAll(serviceLinks); - index.getScheduledStopPointIndex().putAll(scheduledStopPoints); - index.getRoutePointIndex().putAll(routePoints); - index.getPassengerStopAssignmentsByStopPointRefIndex().putAll(passengerStopAssignmentByStopPointRef); - - // update references - index.getNetworkIdByGroupOfLineIdIndex().putAll(networkIdByGroupOfLineId); - } + private static final Logger LOG = LoggerFactory.getLogger( + ServiceFrameParser.class + ); + + private final NetexEntityIndex flexibleStopPlaceById; + + private final Collection networks = new ArrayList<>(); + + private final Collection groupOfLines = new ArrayList<>(); + + private final Collection routes = new ArrayList<>(); + + private final Collection flexibleLines = new ArrayList<>(); + + private final Collection lines = new ArrayList<>(); + + private final Map networkIdByGroupOfLineId = new HashMap<>(); + + private final Collection journeyPatterns = new ArrayList<>(); + + private final Collection destinationDisplays = + new ArrayList<>(); + + private final Map quayIdByStopPointRef = new HashMap<>(); + + private final Map stopPlaceIdByStopPointRef = new HashMap<>(); + + private final Map flexibleStopPlaceByStopPointRef = + new HashMap<>(); + + private final Collection serviceLinks = new ArrayList<>(); + + private final Collection scheduledStopPoints = + new ArrayList<>(); + + private final Collection routePoints = new ArrayList<>(); + + private final Multimap passengerStopAssignmentByStopPointRef = + ArrayListMultimap.create(); + + private final NoticeParser noticeParser = new NoticeParser(); + + ServiceFrameParser( + NetexEntityIndex flexibleStopPlaceById + ) { + this.flexibleStopPlaceById = flexibleStopPlaceById; + } + + @Override + void parse(Service_VersionFrameStructure frame) { + parseStopAssignments(frame.getStopAssignments()); + parseRoutes(frame.getRoutes()); + parseNetwork(frame.getNetwork()); + parseAdditionalNetworks(frame.getAdditionalNetworks()); + noticeParser.parseNotices(frame.getNotices()); + noticeParser.parseNoticeAssignments(frame.getNoticeAssignments()); + parseLines(frame.getLines()); + parseJourneyPatterns(frame.getJourneyPatterns()); + parseDestinationDisplays(frame.getDestinationDisplays()); + parseServiceLinks(frame.getServiceLinks()); + parseScheduledStopPoints(frame.getScheduledStopPoints()); + parseRoutePoints(frame.getRoutePoints()); + + // Keep list sorted alphabetically + informOnElementIntentionallySkipped(LOG, frame.getCommonSections()); + informOnElementIntentionallySkipped(LOG, frame.getConnections()); + informOnElementIntentionallySkipped(LOG, frame.getDirections()); + informOnElementIntentionallySkipped(LOG, frame.getDisplayAssignments()); + informOnElementIntentionallySkipped(LOG, frame.getFlexibleLinkProperties()); + informOnElementIntentionallySkipped( + LOG, + frame.getFlexiblePointProperties() + ); + informOnElementIntentionallySkipped(LOG, frame.getGeneralSections()); + informOnElementIntentionallySkipped(LOG, frame.getGroupsOfLines()); + informOnElementIntentionallySkipped(LOG, frame.getGroupsOfLinks()); + informOnElementIntentionallySkipped(LOG, frame.getGroupsOfPoints()); + informOnElementIntentionallySkipped(LOG, frame.getLineNetworks()); + informOnElementIntentionallySkipped(LOG, frame.getLogicalDisplays()); + informOnElementIntentionallySkipped( + LOG, + frame.getPassengerInformationEquipments() + ); + informOnElementIntentionallySkipped(LOG, frame.getRouteLinks()); + informOnElementIntentionallySkipped(LOG, frame.getRoutingConstraintZones()); + informOnElementIntentionallySkipped(LOG, frame.getServiceExclusions()); + informOnElementIntentionallySkipped(LOG, frame.getServicePatterns()); + informOnElementIntentionallySkipped(LOG, frame.getStopAreas()); + informOnElementIntentionallySkipped(LOG, frame.getTariffZones()); + informOnElementIntentionallySkipped(LOG, frame.getTimeDemandTypes()); + informOnElementIntentionallySkipped( + LOG, + frame.getTimeDemandTypeAssignments() + ); + informOnElementIntentionallySkipped(LOG, frame.getTimingPoints()); + informOnElementIntentionallySkipped(LOG, frame.getTimingLinks()); + informOnElementIntentionallySkipped(LOG, frame.getTimingLinkGroups()); + informOnElementIntentionallySkipped(LOG, frame.getTimingPatterns()); + informOnElementIntentionallySkipped(LOG, frame.getTransferRestrictions()); + + verifyCommonUnusedPropertiesIsNotSet(LOG, frame); + } + + @Override + void setResultOnIndex(NetexEntitiesIndex index) { + // update entities + index.getDestinationDisplayIndex().putAll(destinationDisplays); + index.getGroupOfLinesIndex().putAll(groupOfLines); + index.getJourneyPatternIndex().putAll(journeyPatterns); + index.getFlexibleLineIndex().putAll(flexibleLines); + index.getLineIndex().putAll(lines); + index.getNetworkIndex().putAll(networks); + noticeParser.setResultOnIndex(index); + index.getQuayIdByStopPointRefIndex().putAll(quayIdByStopPointRef); + index.getStopPlaceIdByStopPointRefIndex().putAll(stopPlaceIdByStopPointRef); + index + .getFlexibleStopPlaceIdByStopPointRefIndex() + .putAll(flexibleStopPlaceByStopPointRef); + index.getRouteIndex().putAll(routes); + index.getServiceLinkIndex().putAll(serviceLinks); + index.getScheduledStopPointIndex().putAll(scheduledStopPoints); + index.getRoutePointIndex().putAll(routePoints); + index + .getPassengerStopAssignmentsByStopPointRefIndex() + .putAll(passengerStopAssignmentByStopPointRef); + + // update references + index.getNetworkIdByGroupOfLineIdIndex().putAll(networkIdByGroupOfLineId); + } + + private void parseStopAssignments( + StopAssignmentsInFrame_RelStructure stopAssignments + ) { + if (stopAssignments == null) return; + + for (JAXBElement stopAssignment : stopAssignments.getStopAssignment()) { + if (stopAssignment.getValue() instanceof PassengerStopAssignment) { + PassengerStopAssignment assignment = + (PassengerStopAssignment) stopAssignment.getValue(); + + String stopPointRef = assignment + .getScheduledStopPointRef() + .getValue() + .getRef(); + + passengerStopAssignmentByStopPointRef.put(stopPointRef, assignment); + + if (assignment.getQuayRef() != null) { + String quayRef = assignment.getQuayRef().getValue().getRef(); + quayIdByStopPointRef.put(stopPointRef, quayRef); + } - private void parseStopAssignments(StopAssignmentsInFrame_RelStructure stopAssignments) { - if (stopAssignments == null) return; - - for (JAXBElement stopAssignment : stopAssignments.getStopAssignment()) { - if (stopAssignment.getValue() instanceof PassengerStopAssignment) { - PassengerStopAssignment assignment = (PassengerStopAssignment) stopAssignment.getValue(); - - String stopPointRef = assignment.getScheduledStopPointRef().getValue().getRef(); - - passengerStopAssignmentByStopPointRef.put(stopPointRef, assignment); - - if (assignment.getQuayRef() != null) { - String quayRef = assignment.getQuayRef().getValue().getRef(); - quayIdByStopPointRef.put(stopPointRef, quayRef); - } - - if (assignment.getStopPlaceRef() != null) { - String stopPlaceRef = assignment.getStopPlaceRef().getValue().getRef(); - stopPlaceIdByStopPointRef.put(stopPointRef, stopPlaceRef); - } - } - else if (stopAssignment.getValue() instanceof FlexibleStopAssignment) { - FlexibleStopAssignment assignment = (FlexibleStopAssignment) stopAssignment.getValue(); - String flexibleStopPlaceRef = assignment.getFlexibleStopPlaceRef().getRef(); - - // TODO - This check belongs to the mapping or as a separate validation - // - step. The problem is that we do not want to relay on the - // - the order in witch elements are loaded. - FlexibleStopPlace flexibleStopPlace = flexibleStopPlaceById.get( - flexibleStopPlaceRef); - - if (flexibleStopPlace != null) { - String stopPointRef = assignment.getScheduledStopPointRef().getValue().getRef(); - flexibleStopPlaceByStopPointRef.put(stopPointRef, flexibleStopPlace.getId()); - } - else { - LOG.warn( - "FlexibleStopPlace {} not found in stop place file.", - flexibleStopPlaceRef - ); - } - } + if (assignment.getStopPlaceRef() != null) { + String stopPlaceRef = assignment + .getStopPlaceRef() + .getValue() + .getRef(); + stopPlaceIdByStopPointRef.put(stopPointRef, stopPlaceRef); } + } else if (stopAssignment.getValue() instanceof FlexibleStopAssignment) { + FlexibleStopAssignment assignment = + (FlexibleStopAssignment) stopAssignment.getValue(); + String flexibleStopPlaceRef = assignment + .getFlexibleStopPlaceRef() + .getRef(); + + // TODO - This check belongs to the mapping or as a separate validation + // - step. The problem is that we do not want to relay on the + // - the order in witch elements are loaded. + FlexibleStopPlace flexibleStopPlace = flexibleStopPlaceById.get( + flexibleStopPlaceRef + ); + + if (flexibleStopPlace != null) { + String stopPointRef = assignment + .getScheduledStopPointRef() + .getValue() + .getRef(); + flexibleStopPlaceByStopPointRef.put( + stopPointRef, + flexibleStopPlace.getId() + ); + } else { + LOG.warn( + "FlexibleStopPlace {} not found in stop place file.", + flexibleStopPlaceRef + ); + } + } } + } - private void parseRoutes(RoutesInFrame_RelStructure routes) { - if (routes == null) return; + private void parseRoutes(RoutesInFrame_RelStructure routes) { + if (routes == null) return; - for (JAXBElement element : routes.getRoute_()) { - if (element.getValue() instanceof Route route) { - this.routes.add(route); - } - } + for (JAXBElement element : routes.getRoute_()) { + if (element.getValue() instanceof Route route) { + this.routes.add(route); + } } + } - private void parseNetwork(Network network) { - if (network == null) return; + private void parseNetwork(Network network) { + if (network == null) return; - networks.add(network); + networks.add(network); - GroupsOfLinesInFrame_RelStructure groupsOfLines = network.getGroupsOfLines(); + GroupsOfLinesInFrame_RelStructure groupsOfLines = + network.getGroupsOfLines(); - if (groupsOfLines != null) { - parseGroupOfLines(groupsOfLines.getGroupOfLines(), network); - } + if (groupsOfLines != null) { + parseGroupOfLines(groupsOfLines.getGroupOfLines(), network); } + } - private void parseAdditionalNetworks(NetworksInFrame_RelStructure additionalNetworks) { - if (additionalNetworks == null) { return; } - - for (Network additionalNetwork : additionalNetworks.getNetwork()) { - parseNetwork(additionalNetwork); - } + private void parseAdditionalNetworks( + NetworksInFrame_RelStructure additionalNetworks + ) { + if (additionalNetworks == null) { + return; } - private void parseGroupOfLines(Collection groupOfLines, Network network) { - for (GroupOfLines group : groupOfLines) { - networkIdByGroupOfLineId.put(group.getId(), network.getId()); - this.groupOfLines.add(group); - } + for (Network additionalNetwork : additionalNetworks.getNetwork()) { + parseNetwork(additionalNetwork); } - - private void parseLines(LinesInFrame_RelStructure lines) { - if (lines == null) return; - - for (JAXBElement element : lines.getLine_()) { - if (element.getValue() instanceof Line) { - this.lines.add((Line) element.getValue()); - } else if (element.getValue() instanceof FlexibleLine) { - this.flexibleLines.add((FlexibleLine) element.getValue()); - } - else { - informOnElementIntentionallySkipped(LOG, element.getValue()); - } - } + } + + private void parseGroupOfLines( + Collection groupOfLines, + Network network + ) { + for (GroupOfLines group : groupOfLines) { + networkIdByGroupOfLineId.put(group.getId(), network.getId()); + this.groupOfLines.add(group); } - - private void parseJourneyPatterns(JourneyPatternsInFrame_RelStructure journeyPatterns) { - if (journeyPatterns == null) return; - - for (JAXBElement pattern : journeyPatterns.getJourneyPattern_OrJourneyPatternView()) { - if (pattern.getValue() instanceof JourneyPattern) { - this.journeyPatterns.add((JourneyPattern) pattern.getValue()); - } - else { - informOnElementIntentionallySkipped(LOG, pattern.getValue()); - } - } + } + + private void parseLines(LinesInFrame_RelStructure lines) { + if (lines == null) return; + + for (JAXBElement element : lines.getLine_()) { + if (element.getValue() instanceof Line) { + this.lines.add((Line) element.getValue()); + } else if (element.getValue() instanceof FlexibleLine) { + this.flexibleLines.add((FlexibleLine) element.getValue()); + } else { + informOnElementIntentionallySkipped(LOG, element.getValue()); + } + } + } + + private void parseJourneyPatterns( + JourneyPatternsInFrame_RelStructure journeyPatterns + ) { + if (journeyPatterns == null) return; + + for (JAXBElement pattern : journeyPatterns.getJourneyPattern_OrJourneyPatternView()) { + if (pattern.getValue() instanceof JourneyPattern) { + this.journeyPatterns.add((JourneyPattern) pattern.getValue()); + } else { + informOnElementIntentionallySkipped(LOG, pattern.getValue()); + } } + } - private void parseDestinationDisplays(DestinationDisplaysInFrame_RelStructure destDisplays) { - if (destDisplays == null) return; + private void parseDestinationDisplays( + DestinationDisplaysInFrame_RelStructure destDisplays + ) { + if (destDisplays == null) return; - this.destinationDisplays.addAll(destDisplays.getDestinationDisplay()); - } + this.destinationDisplays.addAll(destDisplays.getDestinationDisplay()); + } - private void parseServiceLinks(ServiceLinksInFrame_RelStructure serviceLinks) { - if (serviceLinks == null) return; + private void parseServiceLinks( + ServiceLinksInFrame_RelStructure serviceLinks + ) { + if (serviceLinks == null) return; - this.serviceLinks.addAll(serviceLinks.getServiceLink()); - } + this.serviceLinks.addAll(serviceLinks.getServiceLink()); + } - private void parseScheduledStopPoints(ScheduledStopPointsInFrame_RelStructure scheduledStopPoints) { - if (scheduledStopPoints == null) return; + private void parseScheduledStopPoints( + ScheduledStopPointsInFrame_RelStructure scheduledStopPoints + ) { + if (scheduledStopPoints == null) return; - this.scheduledStopPoints.addAll(scheduledStopPoints.getScheduledStopPoint()); - } + this.scheduledStopPoints.addAll( + scheduledStopPoints.getScheduledStopPoint() + ); + } - private void parseRoutePoints(RoutePointsInFrame_RelStructure routePoints) { - if (routePoints == null) return; + private void parseRoutePoints(RoutePointsInFrame_RelStructure routePoints) { + if (routePoints == null) return; - this.routePoints.addAll(routePoints.getRoutePoint()); - } + this.routePoints.addAll(routePoints.getRoutePoint()); + } } diff --git a/src/main/java/org/entur/netex/loader/parser/SiteFrameParser.java b/src/main/java/org/entur/netex/loader/parser/SiteFrameParser.java index ddf2140c..897b9654 100644 --- a/src/main/java/org/entur/netex/loader/parser/SiteFrameParser.java +++ b/src/main/java/org/entur/netex/loader/parser/SiteFrameParser.java @@ -2,179 +2,223 @@ import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; -import org.entur.netex.index.api.NetexEntitiesIndex; -import org.entur.netex.support.NetexVersionHelper; -import org.rutebanken.netex.model.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import jakarta.xml.bind.JAXBElement; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.entur.netex.index.api.NetexEntitiesIndex; +import org.entur.netex.support.NetexVersionHelper; +import org.rutebanken.netex.model.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; class SiteFrameParser extends NetexParser { - private static final Logger LOG = LoggerFactory.getLogger(NetexParser.class); - - private final Collection flexibleStopPlaces = new ArrayList<>(); - - private final Collection groupsOfStopPlaces = new ArrayList<>(); - private final Collection stopPlaces = new ArrayList<>(); + private static final Logger LOG = LoggerFactory.getLogger(NetexParser.class); - private final Collection tariffZones = new ArrayList<>(); + private final Collection flexibleStopPlaces = + new ArrayList<>(); - private final Collection groupsOfTariffZones = new ArrayList<>(); + private final Collection groupsOfStopPlaces = + new ArrayList<>(); - private final Collection topographicPlaces = new ArrayList<>(); + private final Collection stopPlaces = new ArrayList<>(); - private final Collection parkings = new ArrayList<>(); + private final Collection tariffZones = new ArrayList<>(); - private final Multimap quays = ArrayListMultimap.create(); + private final Collection groupsOfTariffZones = + new ArrayList<>(); - private final Map stopPlaceIdByQuayId = new HashMap<>(); + private final Collection topographicPlaces = + new ArrayList<>(); - private final Multimap parkingsByStopPlaceId = ArrayListMultimap.create(); + private final Collection parkings = new ArrayList<>(); - @Override - public void parse(Site_VersionFrameStructure frame) { - if (frame.getStopPlaces() != null) { - parseStopPlaces(frame.getStopPlaces().getStopPlace_()); - } + private final Multimap quays = ArrayListMultimap.create(); - if (frame.getGroupsOfStopPlaces() != null) { - parseGroupsOfStopPlaces(frame.getGroupsOfStopPlaces().getGroupOfStopPlaces()); - } + private final Map stopPlaceIdByQuayId = new HashMap<>(); - if (frame.getFlexibleStopPlaces() != null) { - parseFlexibleStopPlaces(frame.getFlexibleStopPlaces().getFlexibleStopPlace()); - } + private final Multimap parkingsByStopPlaceId = + ArrayListMultimap.create(); - if (frame.getTariffZones() != null) { - parseTariffZones(frame.getTariffZones().getTariffZone()); - } - - if (frame.getTopographicPlaces() != null) { - parseTopographicPlaces(frame.getTopographicPlaces().getTopographicPlace()); - } - - if (frame.getParkings() != null) { - parseParkings(frame.getParkings().getParking()); - } - - if (frame.getGroupsOfTariffZones() != null) { - parseGroupsOfTariffZones(frame.getGroupsOfTariffZones().getGroupOfTariffZones()); - } - - // Keep list sorted alphabetically - informOnElementIntentionallySkipped(LOG, frame.getAccesses()); - informOnElementIntentionallySkipped(LOG, frame.getAddresses()); - informOnElementIntentionallySkipped(LOG, frame.getCountries()); - informOnElementIntentionallySkipped(LOG, frame.getCheckConstraints()); - informOnElementIntentionallySkipped(LOG, frame.getCheckConstraintDelays()); - informOnElementIntentionallySkipped(LOG, frame.getCheckConstraintThroughputs()); - informOnElementIntentionallySkipped(LOG, frame.getNavigationPaths()); - informOnElementIntentionallySkipped(LOG, frame.getPathJunctions()); - informOnElementIntentionallySkipped(LOG, frame.getPathLinks()); - informOnElementIntentionallySkipped(LOG, frame.getPointsOfInterest()); - informOnElementIntentionallySkipped(LOG, frame.getPointOfInterestClassifications()); - informOnElementIntentionallySkipped(LOG, frame.getPointOfInterestClassificationHierarchies()); - informOnElementIntentionallySkipped(LOG, frame.getSiteFacilitySets()); - - verifyCommonUnusedPropertiesIsNotSet(LOG, frame); + @Override + public void parse(Site_VersionFrameStructure frame) { + if (frame.getStopPlaces() != null) { + parseStopPlaces(frame.getStopPlaces().getStopPlace_()); } - @Override - void setResultOnIndex(NetexEntitiesIndex netexIndex) { - netexIndex.getFlexibleStopPlaceIndex().putAll(flexibleStopPlaces); - netexIndex.getGroupOfStopPlacesIndex().putAll(groupsOfStopPlaces); - netexIndex.getStopPlaceIndex().putAll(stopPlaces); - netexIndex.getTariffZoneIndex().putAll(tariffZones); - netexIndex.getTopographicPlaceIndex().putAll(topographicPlaces); - netexIndex.getParkingIndex().putAll(parkings); - netexIndex.getQuayIndex().putAll(quays.values()); - netexIndex.getStopPlaceIdByQuayIdIndex().putAll(stopPlaceIdByQuayId); - netexIndex.getParkingsByParentSiteRefIndex().putAll(parkingsByStopPlaceId); - netexIndex.getGroupOfTariffZonesIndex().putAll(groupsOfTariffZones); + if (frame.getGroupsOfStopPlaces() != null) { + parseGroupsOfStopPlaces( + frame.getGroupsOfStopPlaces().getGroupOfStopPlaces() + ); } - private void parseFlexibleStopPlaces(Collection flexibleStopPlacesList) { - flexibleStopPlaces.addAll(flexibleStopPlacesList); + if (frame.getFlexibleStopPlaces() != null) { + parseFlexibleStopPlaces( + frame.getFlexibleStopPlaces().getFlexibleStopPlace() + ); } - private void parseGroupsOfStopPlaces(Collection groupsOfStopPlacesList) { - groupsOfStopPlaces.addAll(groupsOfStopPlacesList); + if (frame.getTariffZones() != null) { + parseTariffZones(frame.getTariffZones().getTariffZone()); } - private void parseStopPlaces(List> stopPlaceList) { - for (JAXBElement jaxbStopPlace : stopPlaceList) { - StopPlace stopPlace = (StopPlace) jaxbStopPlace.getValue(); - stopPlaces.add(stopPlace); - if (!isMultiModalStopPlace(stopPlace)) { - parseQuays(stopPlace.getQuays(), stopPlace.getId()); - } - } + if (frame.getTopographicPlaces() != null) { + parseTopographicPlaces( + frame.getTopographicPlaces().getTopographicPlace() + ); } - private void parseTariffZones(List> tariffZoneList) { - for (JAXBElement tariffZone : tariffZoneList) { - if (tariffZone.getValue() instanceof TariffZone) { - tariffZones.add((TariffZone) tariffZone.getValue()); - } - } + if (frame.getParkings() != null) { + parseParkings(frame.getParkings().getParking()); } - private void parseTopographicPlaces(Collection topographicPlaceList) { - topographicPlaces.addAll(topographicPlaceList); + if (frame.getGroupsOfTariffZones() != null) { + parseGroupsOfTariffZones( + frame.getGroupsOfTariffZones().getGroupOfTariffZones() + ); } - private void parseParkings(Collection parkingList) { - for (Parking parking : parkingList) { - parkings.add(parking); - parkingsByStopPlaceId.put(parking.getParentSiteRef().getRef(), parking); - } + // Keep list sorted alphabetically + informOnElementIntentionallySkipped(LOG, frame.getAccesses()); + informOnElementIntentionallySkipped(LOG, frame.getAddresses()); + informOnElementIntentionallySkipped(LOG, frame.getCountries()); + informOnElementIntentionallySkipped(LOG, frame.getCheckConstraints()); + informOnElementIntentionallySkipped(LOG, frame.getCheckConstraintDelays()); + informOnElementIntentionallySkipped( + LOG, + frame.getCheckConstraintThroughputs() + ); + informOnElementIntentionallySkipped(LOG, frame.getNavigationPaths()); + informOnElementIntentionallySkipped(LOG, frame.getPathJunctions()); + informOnElementIntentionallySkipped(LOG, frame.getPathLinks()); + informOnElementIntentionallySkipped(LOG, frame.getPointsOfInterest()); + informOnElementIntentionallySkipped( + LOG, + frame.getPointOfInterestClassifications() + ); + informOnElementIntentionallySkipped( + LOG, + frame.getPointOfInterestClassificationHierarchies() + ); + informOnElementIntentionallySkipped(LOG, frame.getSiteFacilitySets()); + + verifyCommonUnusedPropertiesIsNotSet(LOG, frame); + } + + @Override + void setResultOnIndex(NetexEntitiesIndex netexIndex) { + netexIndex.getFlexibleStopPlaceIndex().putAll(flexibleStopPlaces); + netexIndex.getGroupOfStopPlacesIndex().putAll(groupsOfStopPlaces); + netexIndex.getStopPlaceIndex().putAll(stopPlaces); + netexIndex.getTariffZoneIndex().putAll(tariffZones); + netexIndex.getTopographicPlaceIndex().putAll(topographicPlaces); + netexIndex.getParkingIndex().putAll(parkings); + netexIndex.getQuayIndex().putAll(quays.values()); + netexIndex.getStopPlaceIdByQuayIdIndex().putAll(stopPlaceIdByQuayId); + netexIndex.getParkingsByParentSiteRefIndex().putAll(parkingsByStopPlaceId); + netexIndex.getGroupOfTariffZonesIndex().putAll(groupsOfTariffZones); + } + + private void parseFlexibleStopPlaces( + Collection flexibleStopPlacesList + ) { + flexibleStopPlaces.addAll(flexibleStopPlacesList); + } + + private void parseGroupsOfStopPlaces( + Collection groupsOfStopPlacesList + ) { + groupsOfStopPlaces.addAll(groupsOfStopPlacesList); + } + + private void parseStopPlaces( + List> stopPlaceList + ) { + for (JAXBElement jaxbStopPlace : stopPlaceList) { + StopPlace stopPlace = (StopPlace) jaxbStopPlace.getValue(); + stopPlaces.add(stopPlace); + if (!isMultiModalStopPlace(stopPlace)) { + parseQuays(stopPlace.getQuays(), stopPlace.getId()); + } } - - - /** - * Parse Quays and update the Map (quay id --> stop place id). - * Special case: when a Quay is moved from one StopPlace to another, Quay versions are referenced under different StopPlaces. - * In this case, this is the latest version of the Quay across all StopPlaces that is indexed in the map (quay id --> stop place id). - * - * @param quayRefOrQuay - * @param stopPlaceId - */ - private void parseQuays(Quays_RelStructure quayRefOrQuay, String stopPlaceId) { - if (quayRefOrQuay == null) return; - - for (JAXBElement jaxbQuay : quayRefOrQuay.getQuayRefOrQuay()) { - if (jaxbQuay.getValue() instanceof Quay quay) { - String quayId = quay.getId(); - quays.put(quayId, quay); - if (!stopPlaceIdByQuayId.containsKey(quayId)) { - stopPlaceIdByQuayId.put(quayId, stopPlaceId); - } else if (!stopPlaceIdByQuayId.get(quayId).equals(stopPlaceId)) { - // the Quay has been moved to another StopPlace. The latest version of the Quay is used for updating the Map (quay id --> stop place id) - Quay latestVersion = NetexVersionHelper.latestVersionedElementIn(quays.get(quayId)); - if (quay.equals(latestVersion)) { - stopPlaceIdByQuayId.put(quayId, stopPlaceId); - } - } - } - } + } + + private void parseTariffZones( + List> tariffZoneList + ) { + for (JAXBElement tariffZone : tariffZoneList) { + if (tariffZone.getValue() instanceof TariffZone) { + tariffZones.add((TariffZone) tariffZone.getValue()); + } } - - private boolean isMultiModalStopPlace(StopPlace stopPlace) { - return stopPlace.getKeyList() != null - && stopPlace.getKeyList().getKeyValue().stream().anyMatch( - keyValueStructure -> - keyValueStructure.getKey().equals("IS_PARENT_STOP_PLACE") - && keyValueStructure.getValue().equals("true")); + } + + private void parseTopographicPlaces( + Collection topographicPlaceList + ) { + topographicPlaces.addAll(topographicPlaceList); + } + + private void parseParkings(Collection parkingList) { + for (Parking parking : parkingList) { + parkings.add(parking); + parkingsByStopPlaceId.put(parking.getParentSiteRef().getRef(), parking); } - - private void parseGroupsOfTariffZones(List groupOfTariffZones) { - groupsOfTariffZones.addAll(groupOfTariffZones); + } + + /** + * Parse Quays and update the Map (quay id --> stop place id). + * Special case: when a Quay is moved from one StopPlace to another, Quay versions are referenced under different StopPlaces. + * In this case, this is the latest version of the Quay across all StopPlaces that is indexed in the map (quay id --> stop place id). + * + * @param quayRefOrQuay + * @param stopPlaceId + */ + private void parseQuays( + Quays_RelStructure quayRefOrQuay, + String stopPlaceId + ) { + if (quayRefOrQuay == null) return; + + for (JAXBElement jaxbQuay : quayRefOrQuay.getQuayRefOrQuay()) { + if (jaxbQuay.getValue() instanceof Quay quay) { + String quayId = quay.getId(); + quays.put(quayId, quay); + if (!stopPlaceIdByQuayId.containsKey(quayId)) { + stopPlaceIdByQuayId.put(quayId, stopPlaceId); + } else if (!stopPlaceIdByQuayId.get(quayId).equals(stopPlaceId)) { + // the Quay has been moved to another StopPlace. The latest version of the Quay is used for updating the Map (quay id --> stop place id) + Quay latestVersion = NetexVersionHelper.latestVersionedElementIn( + quays.get(quayId) + ); + if (quay.equals(latestVersion)) { + stopPlaceIdByQuayId.put(quayId, stopPlaceId); + } + } + } } + } + + private boolean isMultiModalStopPlace(StopPlace stopPlace) { + return ( + stopPlace.getKeyList() != null && + stopPlace + .getKeyList() + .getKeyValue() + .stream() + .anyMatch(keyValueStructure -> + keyValueStructure.getKey().equals("IS_PARENT_STOP_PLACE") && + keyValueStructure.getValue().equals("true") + ) + ); + } + + private void parseGroupsOfTariffZones( + List groupOfTariffZones + ) { + groupsOfTariffZones.addAll(groupOfTariffZones); + } } diff --git a/src/main/java/org/entur/netex/loader/parser/TimeTableFrameParser.java b/src/main/java/org/entur/netex/loader/parser/TimeTableFrameParser.java index 4b1f2fd0..cdedfcbf 100644 --- a/src/main/java/org/entur/netex/loader/parser/TimeTableFrameParser.java +++ b/src/main/java/org/entur/netex/loader/parser/TimeTableFrameParser.java @@ -2,6 +2,8 @@ import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; +import java.util.ArrayList; +import java.util.List; import org.entur.netex.index.api.NetexEntitiesIndex; import org.rutebanken.netex.model.DatedServiceJourney; import org.rutebanken.netex.model.DeadRun; @@ -16,113 +18,149 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.ArrayList; -import java.util.List; - -class TimeTableFrameParser extends NetexParser { - - private static final Logger LOG = LoggerFactory.getLogger(TimeTableFrameParser.class); - - private final List serviceJourneys = new ArrayList<>(); - - private final List datedServiceJourneys = new ArrayList<>(); - private final Multimap datedServiceJourneyByServiceJourneyId = ArrayListMultimap.create(); - - private final List deadRuns = new ArrayList<>(); - - private final List serviceJourneyInterchanges = new ArrayList<>(); - private final Multimap serviceJourneyInterchangesByServiceJourneyId = ArrayListMultimap.create(); - - private final NoticeParser noticeParser = new NoticeParser(); - - - @Override - void parse(Timetable_VersionFrameStructure frame) { - parseJourneys(frame.getVehicleJourneys()); - parseInterchanges(frame.getJourneyInterchanges()); - - noticeParser.parseNotices(frame.getNotices()); - noticeParser.parseNoticeAssignments(frame.getNoticeAssignments()); - - informOnElementIntentionallySkipped(LOG, frame.getNetworkView()); - informOnElementIntentionallySkipped(LOG, frame.getLineView()); - informOnElementIntentionallySkipped(LOG, frame.getOperatorView()); - informOnElementIntentionallySkipped(LOG, frame.getAccessibilityAssessment()); - - // Keep list sorted alphabetically - informOnElementIntentionallySkipped(LOG, frame.getBookingTimes()); - informOnElementIntentionallySkipped(LOG, frame.getCoupledJourneys()); - informOnElementIntentionallySkipped(LOG, frame.getDefaultInterchanges()); - informOnElementIntentionallySkipped(LOG, frame.getFlexibleServiceProperties()); - informOnElementIntentionallySkipped(LOG, frame.getFrequencyGroups()); - informOnElementIntentionallySkipped(LOG, frame.getGroupsOfServices()); - informOnElementIntentionallySkipped(LOG, frame.getInterchangeRules()); - informOnElementIntentionallySkipped(LOG, frame.getJourneyAccountingRef()); - informOnElementIntentionallySkipped(LOG, frame.getJourneyAccountings()); - informOnElementIntentionallySkipped(LOG, frame.getJourneyMeetings()); - informOnElementIntentionallySkipped(LOG, frame.getJourneyPartCouples()); - informOnElementIntentionallySkipped(LOG, frame.getServiceCalendarFrameRef()); - informOnElementIntentionallySkipped(LOG, frame.getServiceFacilitySets()); - informOnElementIntentionallySkipped(LOG, frame.getTimeDemandTypes()); - informOnElementIntentionallySkipped(LOG, frame.getTimeDemandTypeAssignments()); - informOnElementIntentionallySkipped(LOG, frame.getTimingLinkGroups()); - informOnElementIntentionallySkipped(LOG, frame.getTrainNumbers()); - informOnElementIntentionallySkipped(LOG, frame.getTypesOfService()); - informOnElementIntentionallySkipped(LOG, frame.getVehicleTypes()); - - verifyCommonUnusedPropertiesIsNotSet(LOG, frame); - } - - @Override - void setResultOnIndex(NetexEntitiesIndex netexIndex) { - netexIndex.getServiceJourneyIndex().putAll(serviceJourneys); - - netexIndex.getDatedServiceJourneyIndex().putAll(datedServiceJourneys); - netexIndex.getDatedServiceJourneyByServiceJourneyRefIndex().putAll(datedServiceJourneyByServiceJourneyId); - - netexIndex.getDeadRunIndex().putAll(deadRuns); - - netexIndex.getServiceJourneyInterchangeIndex().putAll(serviceJourneyInterchanges); - netexIndex.getServiceJourneyInterchangeByServiceJourneyRefIndex().putAll(serviceJourneyInterchangesByServiceJourneyId); - - noticeParser.setResultOnIndex(netexIndex); +class TimeTableFrameParser + extends NetexParser { + + private static final Logger LOG = LoggerFactory.getLogger( + TimeTableFrameParser.class + ); + + private final List serviceJourneys = new ArrayList<>(); + + private final List datedServiceJourneys = + new ArrayList<>(); + private final Multimap datedServiceJourneyByServiceJourneyId = + ArrayListMultimap.create(); + + private final List deadRuns = new ArrayList<>(); + + private final List serviceJourneyInterchanges = + new ArrayList<>(); + private final Multimap serviceJourneyInterchangesByServiceJourneyId = + ArrayListMultimap.create(); + + private final NoticeParser noticeParser = new NoticeParser(); + + @Override + void parse(Timetable_VersionFrameStructure frame) { + parseJourneys(frame.getVehicleJourneys()); + parseInterchanges(frame.getJourneyInterchanges()); + + noticeParser.parseNotices(frame.getNotices()); + noticeParser.parseNoticeAssignments(frame.getNoticeAssignments()); + + informOnElementIntentionallySkipped(LOG, frame.getNetworkView()); + informOnElementIntentionallySkipped(LOG, frame.getLineView()); + informOnElementIntentionallySkipped(LOG, frame.getOperatorView()); + informOnElementIntentionallySkipped( + LOG, + frame.getAccessibilityAssessment() + ); + + // Keep list sorted alphabetically + informOnElementIntentionallySkipped(LOG, frame.getBookingTimes()); + informOnElementIntentionallySkipped(LOG, frame.getCoupledJourneys()); + informOnElementIntentionallySkipped(LOG, frame.getDefaultInterchanges()); + informOnElementIntentionallySkipped( + LOG, + frame.getFlexibleServiceProperties() + ); + informOnElementIntentionallySkipped(LOG, frame.getFrequencyGroups()); + informOnElementIntentionallySkipped(LOG, frame.getGroupsOfServices()); + informOnElementIntentionallySkipped(LOG, frame.getInterchangeRules()); + informOnElementIntentionallySkipped(LOG, frame.getJourneyAccountingRef()); + informOnElementIntentionallySkipped(LOG, frame.getJourneyAccountings()); + informOnElementIntentionallySkipped(LOG, frame.getJourneyMeetings()); + informOnElementIntentionallySkipped(LOG, frame.getJourneyPartCouples()); + informOnElementIntentionallySkipped( + LOG, + frame.getServiceCalendarFrameRef() + ); + informOnElementIntentionallySkipped(LOG, frame.getServiceFacilitySets()); + informOnElementIntentionallySkipped(LOG, frame.getTimeDemandTypes()); + informOnElementIntentionallySkipped( + LOG, + frame.getTimeDemandTypeAssignments() + ); + informOnElementIntentionallySkipped(LOG, frame.getTimingLinkGroups()); + informOnElementIntentionallySkipped(LOG, frame.getTrainNumbers()); + informOnElementIntentionallySkipped(LOG, frame.getTypesOfService()); + informOnElementIntentionallySkipped(LOG, frame.getVehicleTypes()); + + verifyCommonUnusedPropertiesIsNotSet(LOG, frame); + } + + @Override + void setResultOnIndex(NetexEntitiesIndex netexIndex) { + netexIndex.getServiceJourneyIndex().putAll(serviceJourneys); + + netexIndex.getDatedServiceJourneyIndex().putAll(datedServiceJourneys); + netexIndex + .getDatedServiceJourneyByServiceJourneyRefIndex() + .putAll(datedServiceJourneyByServiceJourneyId); + + netexIndex.getDeadRunIndex().putAll(deadRuns); + + netexIndex + .getServiceJourneyInterchangeIndex() + .putAll(serviceJourneyInterchanges); + netexIndex + .getServiceJourneyInterchangeByServiceJourneyRefIndex() + .putAll(serviceJourneyInterchangesByServiceJourneyId); + + noticeParser.setResultOnIndex(netexIndex); + } + + private void parseJourneys(JourneysInFrame_RelStructure element) { + for (Journey_VersionStructure it : element.getVehicleJourneyOrDatedVehicleJourneyOrNormalDatedVehicleJourney()) { + if (it instanceof ServiceJourney serviceJourney) { + serviceJourneys.add(serviceJourney); + } else if (it instanceof DatedServiceJourney datedServiceJourney) { + datedServiceJourneys.add(datedServiceJourney); + datedServiceJourney + .getJourneyRef() + .stream() + .filter(journeyRef -> + journeyRef.getValue() instanceof ServiceJourneyRefStructure + ) + .map(journeyRef -> journeyRef.getValue().getRef()) + .forEach(serviceJourneyId -> + datedServiceJourneyByServiceJourneyId.put( + serviceJourneyId, + datedServiceJourney + ) + ); + } else if (it instanceof DeadRun deadRun) { + deadRuns.add(deadRun); + } else { + informOnElementIntentionallySkipped(LOG, it); + } } + } - private void parseJourneys(JourneysInFrame_RelStructure element) { - for (Journey_VersionStructure it : element.getVehicleJourneyOrDatedVehicleJourneyOrNormalDatedVehicleJourney()) { - if (it instanceof ServiceJourney serviceJourney) { - serviceJourneys.add(serviceJourney); - } else if (it instanceof DatedServiceJourney datedServiceJourney) { - datedServiceJourneys.add(datedServiceJourney); - datedServiceJourney.getJourneyRef() - .stream() - .filter(journeyRef -> journeyRef.getValue() instanceof ServiceJourneyRefStructure) - .map(journeyRef -> journeyRef.getValue().getRef()) - .forEach(serviceJourneyId -> datedServiceJourneyByServiceJourneyId.put(serviceJourneyId, datedServiceJourney)); - } else if (it instanceof DeadRun deadRun) { - deadRuns.add(deadRun); - } else { - informOnElementIntentionallySkipped(LOG, it); - } - } + private void parseInterchanges( + JourneyInterchangesInFrame_RelStructure journeyInterchangesElement + ) { + if (journeyInterchangesElement == null) { + return; } - - private void parseInterchanges(JourneyInterchangesInFrame_RelStructure journeyInterchangesElement) { - if (journeyInterchangesElement == null) { - return; - } - for (Interchange_VersionStructure it : journeyInterchangesElement.getServiceJourneyPatternInterchangeOrServiceJourneyInterchange()) { - if (it instanceof ServiceJourneyInterchange serviceJourneyInterchange) { - serviceJourneyInterchanges.add(serviceJourneyInterchange); - - String fromRef = serviceJourneyInterchange.getFromJourneyRef().getRef(); - serviceJourneyInterchangesByServiceJourneyId.put(fromRef, serviceJourneyInterchange); - String toRef = serviceJourneyInterchange.getToJourneyRef().getRef(); - serviceJourneyInterchangesByServiceJourneyId.put(toRef, serviceJourneyInterchange); - - } else { - informOnElementIntentionallySkipped(LOG, it); - } - } + for (Interchange_VersionStructure it : journeyInterchangesElement.getServiceJourneyPatternInterchangeOrServiceJourneyInterchange()) { + if (it instanceof ServiceJourneyInterchange serviceJourneyInterchange) { + serviceJourneyInterchanges.add(serviceJourneyInterchange); + + String fromRef = serviceJourneyInterchange.getFromJourneyRef().getRef(); + serviceJourneyInterchangesByServiceJourneyId.put( + fromRef, + serviceJourneyInterchange + ); + String toRef = serviceJourneyInterchange.getToJourneyRef().getRef(); + serviceJourneyInterchangesByServiceJourneyId.put( + toRef, + serviceJourneyInterchange + ); + } else { + informOnElementIntentionallySkipped(LOG, it); + } } + } } diff --git a/src/main/java/org/entur/netex/loader/parser/VehicleScheduleFrameParser.java b/src/main/java/org/entur/netex/loader/parser/VehicleScheduleFrameParser.java index ea2dda56..683a3329 100644 --- a/src/main/java/org/entur/netex/loader/parser/VehicleScheduleFrameParser.java +++ b/src/main/java/org/entur/netex/loader/parser/VehicleScheduleFrameParser.java @@ -2,7 +2,6 @@ import java.util.ArrayList; import java.util.Collection; - import org.entur.netex.index.api.NetexEntitiesIndex; import org.rutebanken.netex.model.Block; import org.rutebanken.netex.model.Block_VersionStructure; @@ -12,33 +11,36 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -class VehicleScheduleFrameParser extends NetexParser { - private static final Logger LOG = LoggerFactory.getLogger(VehicleScheduleFrameParser.class); +class VehicleScheduleFrameParser + extends NetexParser { - private final Collection blocks = new ArrayList<>(); + private static final Logger LOG = LoggerFactory.getLogger( + VehicleScheduleFrameParser.class + ); - @Override - void parse(VehicleSchedule_VersionFrameStructure frame) { - parseBlocks(frame.getBlocks()); - } + private final Collection blocks = new ArrayList<>(); - @Override - void setResultOnIndex(NetexEntitiesIndex netexIndex) { - netexIndex.getBlockIndex().putAll(blocks); - } + @Override + void parse(VehicleSchedule_VersionFrameStructure frame) { + parseBlocks(frame.getBlocks()); + } - private void parseBlock(Block_VersionStructure element) { - if (element instanceof Block block) { - blocks.add(block); - } else { - informOnElementIntentionallySkipped(LOG, element); - } + @Override + void setResultOnIndex(NetexEntitiesIndex netexIndex) { + netexIndex.getBlockIndex().putAll(blocks); + } + + private void parseBlock(Block_VersionStructure element) { + if (element instanceof Block block) { + blocks.add(block); + } else { + informOnElementIntentionallySkipped(LOG, element); } + } - private void parseBlocks(BlocksInFrame_RelStructure elements) { - for (DataManagedObjectStructure e : elements.getBlockOrCompoundBlockOrTrainBlock()) { - parseBlock((Block_VersionStructure) e); - } + private void parseBlocks(BlocksInFrame_RelStructure elements) { + for (DataManagedObjectStructure e : elements.getBlockOrCompoundBlockOrTrainBlock()) { + parseBlock((Block_VersionStructure) e); } + } } - diff --git a/src/main/java/org/entur/netex/support/NetexVersionHelper.java b/src/main/java/org/entur/netex/support/NetexVersionHelper.java index d1ff3e89..23b84b26 100644 --- a/src/main/java/org/entur/netex/support/NetexVersionHelper.java +++ b/src/main/java/org/entur/netex/support/NetexVersionHelper.java @@ -1,11 +1,10 @@ package org.entur.netex.support; -import org.rutebanken.netex.model.EntityInVersionStructure; +import static java.util.Comparator.comparingInt; import java.util.Collection; import java.util.Comparator; - -import static java.util.Comparator.comparingInt; +import org.rutebanken.netex.model.EntityInVersionStructure; /** * Utility class to help working with versioned NeTEx element. @@ -14,38 +13,49 @@ */ public class NetexVersionHelper { - /** - * private constructor to prevent instantiation of utility class - */ - private NetexVersionHelper() { } - - /** - * According to the Norwegian Netex profile the version number must be a - * positive increasing integer. A bigger value indicate a later version. - */ - private static int versionOf(EntityInVersionStructure e) { - return Integer.parseInt(e.getVersion()); - } - - /** - * Return the element with the latest (maximum) version for a given {@code list} of elements. - * If no elements exist in the collection {@code null} is returned. - */ - public static T latestVersionedElementIn(Collection list) { - if (list.size() == 1) { - return list.iterator().next(); - } - return list.stream().max(comparingVersion()).orElse(null); - } - - public static T versionOfElementIn(Collection list, String version) { - return list.stream().filter(e -> e.getVersion().equals(version)).findFirst().orElse(null); - } - - /** - * Return a comparator to compare {@link EntityInVersionStructure} elements by version. - */ - private static Comparator comparingVersion() { - return comparingInt(NetexVersionHelper::versionOf); + /** + * private constructor to prevent instantiation of utility class + */ + private NetexVersionHelper() {} + + /** + * According to the Norwegian Netex profile the version number must be a + * positive increasing integer. A bigger value indicate a later version. + */ + private static int versionOf(EntityInVersionStructure e) { + return Integer.parseInt(e.getVersion()); + } + + /** + * Return the element with the latest (maximum) version for a given {@code list} of elements. + * If no elements exist in the collection {@code null} is returned. + */ + public static T latestVersionedElementIn( + Collection list + ) { + if (list.size() == 1) { + return list.iterator().next(); } + return list.stream().max(comparingVersion()).orElse(null); + } + + public static T versionOfElementIn( + Collection list, + String version + ) { + return list + .stream() + .filter(e -> e.getVersion().equals(version)) + .findFirst() + .orElse(null); + } + + /** + * Return a comparator to compare {@link EntityInVersionStructure} elements by version. + */ + private static < + T extends EntityInVersionStructure + > Comparator comparingVersion() { + return comparingInt(NetexVersionHelper::versionOf); + } } diff --git a/src/test/java/org/entur/netex/TestDeadRuns.java b/src/test/java/org/entur/netex/TestDeadRuns.java index 79ffe7dd..09f6ca0a 100644 --- a/src/test/java/org/entur/netex/TestDeadRuns.java +++ b/src/test/java/org/entur/netex/TestDeadRuns.java @@ -1,30 +1,29 @@ package org.entur.netex; +import java.util.Collection; import org.entur.netex.index.api.NetexEntitiesIndex; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.rutebanken.netex.model.DeadRun; -import java.util.Collection; - class TestDeadRuns { - private static NetexEntitiesIndex index; - @BeforeAll - static void init() { - try { - NetexParser parser = new NetexParser(); - index = parser.parse("src/test/resources/deadRuns.zip"); - } catch (Exception e) { - Assertions.fail(e.getMessage(), e); - } - } + private static NetexEntitiesIndex index; - @Test - void testDeadRuns() { - Collection deadRuns = index.getDeadRunIndex().getAll(); - Assertions.assertFalse(deadRuns.isEmpty()); + @BeforeAll + static void init() { + try { + NetexParser parser = new NetexParser(); + index = parser.parse("src/test/resources/deadRuns.zip"); + } catch (Exception e) { + Assertions.fail(e.getMessage(), e); } + } + @Test + void testDeadRuns() { + Collection deadRuns = index.getDeadRunIndex().getAll(); + Assertions.assertFalse(deadRuns.isEmpty()); + } } diff --git a/src/test/java/org/entur/netex/TestGroupOfTariffZones.java b/src/test/java/org/entur/netex/TestGroupOfTariffZones.java index c0327f19..9535a863 100644 --- a/src/test/java/org/entur/netex/TestGroupOfTariffZones.java +++ b/src/test/java/org/entur/netex/TestGroupOfTariffZones.java @@ -1,32 +1,36 @@ package org.entur.netex; +import java.io.File; +import java.nio.file.Files; +import java.util.Collection; import org.entur.netex.index.api.NetexEntitiesIndex; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.rutebanken.netex.model.GroupOfTariffZones; -import java.io.File; -import java.nio.file.Files; -import java.util.Collection; - class TestGroupOfTariffZones { - private static NetexEntitiesIndex index; - @BeforeAll - static void init() { - try { - NetexParser parser = new NetexParser(); - File file = new File("src/test/resources/FareZones_NOR_TzGroupTest_2.xml"); - index = parser.parse(Files.newInputStream(file.toPath())); - } catch (Exception e) { - Assertions.fail(e.getMessage(), e); - } - } + private static NetexEntitiesIndex index; - @Test - void testGetAllGroupsOfTariffZones() { - Collection groups = index.getGroupOfTariffZonesIndex().getLatestVersions(); - Assertions.assertFalse(groups.isEmpty()); + @BeforeAll + static void init() { + try { + NetexParser parser = new NetexParser(); + File file = new File( + "src/test/resources/FareZones_NOR_TzGroupTest_2.xml" + ); + index = parser.parse(Files.newInputStream(file.toPath())); + } catch (Exception e) { + Assertions.fail(e.getMessage(), e); } + } + + @Test + void testGetAllGroupsOfTariffZones() { + Collection groups = index + .getGroupOfTariffZonesIndex() + .getLatestVersions(); + Assertions.assertFalse(groups.isEmpty()); + } } diff --git a/src/test/java/org/entur/netex/TestLineExport.java b/src/test/java/org/entur/netex/TestLineExport.java index 3dfe461d..da074f22 100644 --- a/src/test/java/org/entur/netex/TestLineExport.java +++ b/src/test/java/org/entur/netex/TestLineExport.java @@ -1,5 +1,6 @@ package org.entur.netex; +import java.util.Collection; import org.entur.netex.index.api.NetexEntitiesIndex; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; @@ -7,32 +8,34 @@ import org.rutebanken.netex.model.DatedServiceJourney; import org.rutebanken.netex.model.ServiceJourneyInterchange; -import java.util.Collection; - class TestLineExport { - private static NetexEntitiesIndex index; - @BeforeAll - static void init() { - try { - NetexParser parser = new NetexParser(); - index = parser.parse("src/test/resources/line_file.zip"); - } catch (Exception e) { - Assertions.fail(e.getMessage(), e); - } - } + private static NetexEntitiesIndex index; - @Test - void testGetServiceJourneyInterchange() { - ServiceJourneyInterchange serviceJourneyInterchange = index.getServiceJourneyInterchangeIndex().get("GOA:ServiceJourneyInterchange:6"); - Assertions.assertNotNull(serviceJourneyInterchange); + @BeforeAll + static void init() { + try { + NetexParser parser = new NetexParser(); + index = parser.parse("src/test/resources/line_file.zip"); + } catch (Exception e) { + Assertions.fail(e.getMessage(), e); } + } - @Test - void testGetDatedServiceJourneysByServiceJourneyRef() { - Collection datedServiceJourneys = index.getDatedServiceJourneyByServiceJourneyRefIndex().get("GOA:ServiceJourney:B701-B5_200"); - Assertions.assertNotNull(datedServiceJourneys); - Assertions.assertFalse(datedServiceJourneys.isEmpty()); - } + @Test + void testGetServiceJourneyInterchange() { + ServiceJourneyInterchange serviceJourneyInterchange = index + .getServiceJourneyInterchangeIndex() + .get("GOA:ServiceJourneyInterchange:6"); + Assertions.assertNotNull(serviceJourneyInterchange); + } + @Test + void testGetDatedServiceJourneysByServiceJourneyRef() { + Collection datedServiceJourneys = index + .getDatedServiceJourneyByServiceJourneyRefIndex() + .get("GOA:ServiceJourney:B701-B5_200"); + Assertions.assertNotNull(datedServiceJourneys); + Assertions.assertFalse(datedServiceJourneys.isEmpty()); + } } diff --git a/src/test/java/org/entur/netex/TestMovedQuay.java b/src/test/java/org/entur/netex/TestMovedQuay.java index 57d78171..4fd9654e 100644 --- a/src/test/java/org/entur/netex/TestMovedQuay.java +++ b/src/test/java/org/entur/netex/TestMovedQuay.java @@ -1,39 +1,42 @@ package org.entur.netex; +import java.io.File; +import java.nio.file.Files; +import java.util.Collection; import org.entur.netex.index.api.NetexEntitiesIndex; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.rutebanken.netex.model.StopPlace; -import java.io.File; -import java.nio.file.Files; -import java.util.Collection; - class TestMovedQuay { - private static NetexEntitiesIndex index; - - @BeforeAll - static void init() { - try { - NetexParser parser = new NetexParser(); - File file = new File("src/test/resources/MovedQuay.xml"); - index = parser.parse(Files.newInputStream(file.toPath())); - } catch (Exception e) { - Assertions.fail(e.getMessage(), e); - } - } - @Test - void testGetAllVersionsOfStopPlace() { - Collection stopPlaces = index.getStopPlaceIndex().getAllVersions("NSR:StopPlace:5543"); - Assertions.assertEquals(2, stopPlaces.size()); - } + private static NetexEntitiesIndex index; - @Test - void testMovedQuayLinkedToNewStopPlace() { - Assertions.assertEquals("NSR:StopPlace:9999", index.getStopPlaceIdByQuayIdIndex().get("NSR:Quay:10149")); + @BeforeAll + static void init() { + try { + NetexParser parser = new NetexParser(); + File file = new File("src/test/resources/MovedQuay.xml"); + index = parser.parse(Files.newInputStream(file.toPath())); + } catch (Exception e) { + Assertions.fail(e.getMessage(), e); } - - + } + + @Test + void testGetAllVersionsOfStopPlace() { + Collection stopPlaces = index + .getStopPlaceIndex() + .getAllVersions("NSR:StopPlace:5543"); + Assertions.assertEquals(2, stopPlaces.size()); + } + + @Test + void testMovedQuayLinkedToNewStopPlace() { + Assertions.assertEquals( + "NSR:StopPlace:9999", + index.getStopPlaceIdByQuayIdIndex().get("NSR:Quay:10149") + ); + } } diff --git a/src/test/java/org/entur/netex/TestMultipleVersionsStopPlaces.java b/src/test/java/org/entur/netex/TestMultipleVersionsStopPlaces.java index e794fa99..6b818463 100644 --- a/src/test/java/org/entur/netex/TestMultipleVersionsStopPlaces.java +++ b/src/test/java/org/entur/netex/TestMultipleVersionsStopPlaces.java @@ -1,57 +1,67 @@ package org.entur.netex; +import java.io.File; +import java.nio.file.Files; +import java.util.Collection; +import java.util.Map; import org.entur.netex.index.api.NetexEntitiesIndex; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.rutebanken.netex.model.StopPlace; -import java.io.File; -import java.nio.file.Files; -import java.util.Collection; -import java.util.Map; - class TestMultipleVersionsStopPlaces { - private static NetexEntitiesIndex index; - - @BeforeAll - static void init() { - try { - NetexParser parser = new NetexParser(); - File file = new File("src/test/resources/MultipleVersionsStopPlaces.xml"); - index = parser.parse(Files.newInputStream(file.toPath())); - } catch (Exception e) { - Assertions.fail(e.getMessage(), e); - } - } - @Test - void testGetAllVersionsOfStopPlace() { - Collection stopPlaces = index.getStopPlaceIndex().getAllVersions("NSR:StopPlace:5543"); - Assertions.assertEquals(8, stopPlaces.size()); - } + private static NetexEntitiesIndex index; - @Test - void testGetAllVersionsOfAllStopPlaces() { - Map> stopPlaces = index.getStopPlaceIndex().getAllVersions(); - Assertions.assertEquals(8, stopPlaces.get("NSR:StopPlace:5543").size()); + @BeforeAll + static void init() { + try { + NetexParser parser = new NetexParser(); + File file = new File("src/test/resources/MultipleVersionsStopPlaces.xml"); + index = parser.parse(Files.newInputStream(file.toPath())); + } catch (Exception e) { + Assertions.fail(e.getMessage(), e); } + } - @Test - void testGetLatestVersionOfAllStopPlaces() { - Collection stopPlaces = index.getStopPlaceIndex().getLatestVersions(); - Assertions.assertEquals(2, stopPlaces.size()); - } + @Test + void testGetAllVersionsOfStopPlace() { + Collection stopPlaces = index + .getStopPlaceIndex() + .getAllVersions("NSR:StopPlace:5543"); + Assertions.assertEquals(8, stopPlaces.size()); + } - @Test - void testGetStopPlaceWithVersion() { - StopPlace stopPlace = index.getStopPlaceIndex().getVersion("NSR:StopPlace:5543", "1"); - Assertions.assertEquals(1, Integer.parseInt(stopPlace.getVersion())); - } + @Test + void testGetAllVersionsOfAllStopPlaces() { + Map> stopPlaces = index + .getStopPlaceIndex() + .getAllVersions(); + Assertions.assertEquals(8, stopPlaces.get("NSR:StopPlace:5543").size()); + } - @Test - void testGetLatestVersionOfVersionedStopPlace() { - StopPlace stopPlace = index.getStopPlaceIndex().getLatestVersion("NSR:StopPlace:5543"); - Assertions.assertEquals(8, Integer.parseInt(stopPlace.getVersion())); - } + @Test + void testGetLatestVersionOfAllStopPlaces() { + Collection stopPlaces = index + .getStopPlaceIndex() + .getLatestVersions(); + Assertions.assertEquals(2, stopPlaces.size()); + } + + @Test + void testGetStopPlaceWithVersion() { + StopPlace stopPlace = index + .getStopPlaceIndex() + .getVersion("NSR:StopPlace:5543", "1"); + Assertions.assertEquals(1, Integer.parseInt(stopPlace.getVersion())); + } + + @Test + void testGetLatestVersionOfVersionedStopPlace() { + StopPlace stopPlace = index + .getStopPlaceIndex() + .getLatestVersion("NSR:StopPlace:5543"); + Assertions.assertEquals(8, Integer.parseInt(stopPlace.getVersion())); + } } diff --git a/src/test/java/org/entur/netex/TestReferenceDataExport.java b/src/test/java/org/entur/netex/TestReferenceDataExport.java index d637b549..2436245a 100644 --- a/src/test/java/org/entur/netex/TestReferenceDataExport.java +++ b/src/test/java/org/entur/netex/TestReferenceDataExport.java @@ -7,22 +7,24 @@ import org.rutebanken.netex.model.RoutePoint; class TestReferenceDataExport { - private static NetexEntitiesIndex index; - @BeforeAll - static void init() { - try { - NetexParser parser = new NetexParser(); - index = parser.parse("src/test/resources/common_file.zip"); - } catch (Exception e) { - Assertions.fail(e.getMessage(), e); - } - } + private static NetexEntitiesIndex index; - @Test - void testGetRoutePoint() { - RoutePoint routePoint = index.getRoutePointIndex().get("AVI:RoutePoint:76586"); - Assertions.assertNotNull(routePoint); + @BeforeAll + static void init() { + try { + NetexParser parser = new NetexParser(); + index = parser.parse("src/test/resources/common_file.zip"); + } catch (Exception e) { + Assertions.fail(e.getMessage(), e); } + } + @Test + void testGetRoutePoint() { + RoutePoint routePoint = index + .getRoutePointIndex() + .get("AVI:RoutePoint:76586"); + Assertions.assertNotNull(routePoint); + } } diff --git a/src/test/java/org/entur/netex/TestStopPlacesExport.java b/src/test/java/org/entur/netex/TestStopPlacesExport.java index 5b59bde8..800adc4f 100644 --- a/src/test/java/org/entur/netex/TestStopPlacesExport.java +++ b/src/test/java/org/entur/netex/TestStopPlacesExport.java @@ -1,5 +1,7 @@ package org.entur.netex; +import java.time.LocalDateTime; +import java.util.Collection; import org.entur.netex.index.api.NetexEntitiesIndex; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; @@ -14,94 +16,125 @@ import org.rutebanken.netex.model.TariffZone; import org.rutebanken.netex.model.TopographicPlace; -import java.time.LocalDateTime; -import java.util.Collection; - class TestStopPlacesExport { - private static NetexEntitiesIndex index; - - @BeforeAll - static void init() { - try { - NetexParser parser = new NetexParser(); - index = parser.parse("src/test/resources/CurrentwithServiceFrame_latest.zip"); - } catch (Exception e) { - Assertions.fail(e.getMessage(), e); - } - } - - @Test - void testPublicationTimestamp() { - Assertions.assertEquals(LocalDateTime.parse("2021-05-04T03:24:52.46"), index.getPublicationTimestamp()); - } - - @Test - void testGetStopPlace() { - StopPlace stopPlace = index.getStopPlaceIndex().getLatestVersion("NSR:StopPlace:337"); - Assertions.assertEquals("Oslo S", stopPlace.getName().getValue()); - Assertions.assertEquals("NSR:StopPlace:59872", stopPlace.getParentSiteRef().getRef()); - } - - @Test - void testQuay() { - Quay quay = index.getQuayIndex().getLatestVersion("NSR:Quay:3691"); - Assertions.assertEquals("01", quay.getPrivateCode().getValue()); - } - - @Test - void getStopPlaceIdByQuayId() { - String stopPlaceId = index.getStopPlaceIdByQuayIdIndex().get("NSR:Quay:3691"); - Assertions.assertEquals("NSR:StopPlace:2133", stopPlaceId); - } - @Test - void testGetGroupOfStopPlaces() { - GroupOfStopPlaces groupOfStopPlaces = index.getGroupOfStopPlacesIndex().get("NSR:GroupOfStopPlaces:1"); - Assertions.assertEquals("Oslo", groupOfStopPlaces.getName().getValue()); - } - - @Test - void testGetTariffZone() { - TariffZone tariffZone = index.getTariffZoneIndex().getLatestVersion("MOR:TariffZone:108"); - Assertions.assertEquals("Standal", tariffZone.getName().getValue()); - } - - @Test - void testGetTopographicPlace() { - TopographicPlace topographicPlace = index.getTopographicPlaceIndex().getLatestVersion("KVE:TopographicPlace:50"); - Assertions.assertEquals("Trøndelag", topographicPlace.getDescriptor().getName().getValue()); - Assertions.assertEquals("no", topographicPlace.getCountryRef().getRef().value()); - } - - @Test - void testGetParking() { - Parking parking = index.getParkingIndex().getLatestVersion("NSR:Parking:1"); - Assertions.assertEquals("Drammen", parking.getName().getValue()); - } - - @Test - void testGetScheduledStopPoint() { - ScheduledStopPoint scheduledStopPoint = index.getScheduledStopPointIndex().getLatestVersion("NSR:ScheduledStopPoint:S5"); - Assertions.assertEquals("Gudå", scheduledStopPoint.getName().getValue()); - } - - @Test - void testGetPassengerStopAssignment() { - ScheduledStopPoint scheduledStopPoint = index.getScheduledStopPointIndex().getLatestVersion("NSR:ScheduledStopPoint:S5"); - Collection passengerStopAssignments = index.getPassengerStopAssignmentsByStopPointRefIndex().get(scheduledStopPoint.getId()); - - Assertions.assertEquals(1, passengerStopAssignments.size()); - } - - @Test - void testGetFareZone() { - FareZone fareZone = index.getFareZoneIndex().getLatestVersion("AKT:FareZone:27"); - Assertions.assertEquals("Kviteseid", fareZone.getName().getValue()); - } + private static NetexEntitiesIndex index; - @Test - void testGetParkingsByParentSiteRef() { - Collection parkings = index.getParkingsByParentSiteRefIndex().get("NSR:StopPlace:337"); - Assertions.assertFalse(parkings.isEmpty()); + @BeforeAll + static void init() { + try { + NetexParser parser = new NetexParser(); + index = + parser.parse("src/test/resources/CurrentwithServiceFrame_latest.zip"); + } catch (Exception e) { + Assertions.fail(e.getMessage(), e); } + } + + @Test + void testPublicationTimestamp() { + Assertions.assertEquals( + LocalDateTime.parse("2021-05-04T03:24:52.46"), + index.getPublicationTimestamp() + ); + } + + @Test + void testGetStopPlace() { + StopPlace stopPlace = index + .getStopPlaceIndex() + .getLatestVersion("NSR:StopPlace:337"); + Assertions.assertEquals("Oslo S", stopPlace.getName().getValue()); + Assertions.assertEquals( + "NSR:StopPlace:59872", + stopPlace.getParentSiteRef().getRef() + ); + } + + @Test + void testQuay() { + Quay quay = index.getQuayIndex().getLatestVersion("NSR:Quay:3691"); + Assertions.assertEquals("01", quay.getPrivateCode().getValue()); + } + + @Test + void getStopPlaceIdByQuayId() { + String stopPlaceId = index + .getStopPlaceIdByQuayIdIndex() + .get("NSR:Quay:3691"); + Assertions.assertEquals("NSR:StopPlace:2133", stopPlaceId); + } + + @Test + void testGetGroupOfStopPlaces() { + GroupOfStopPlaces groupOfStopPlaces = index + .getGroupOfStopPlacesIndex() + .get("NSR:GroupOfStopPlaces:1"); + Assertions.assertEquals("Oslo", groupOfStopPlaces.getName().getValue()); + } + + @Test + void testGetTariffZone() { + TariffZone tariffZone = index + .getTariffZoneIndex() + .getLatestVersion("MOR:TariffZone:108"); + Assertions.assertEquals("Standal", tariffZone.getName().getValue()); + } + + @Test + void testGetTopographicPlace() { + TopographicPlace topographicPlace = index + .getTopographicPlaceIndex() + .getLatestVersion("KVE:TopographicPlace:50"); + Assertions.assertEquals( + "Trøndelag", + topographicPlace.getDescriptor().getName().getValue() + ); + Assertions.assertEquals( + "no", + topographicPlace.getCountryRef().getRef().value() + ); + } + + @Test + void testGetParking() { + Parking parking = index.getParkingIndex().getLatestVersion("NSR:Parking:1"); + Assertions.assertEquals("Drammen", parking.getName().getValue()); + } + + @Test + void testGetScheduledStopPoint() { + ScheduledStopPoint scheduledStopPoint = index + .getScheduledStopPointIndex() + .getLatestVersion("NSR:ScheduledStopPoint:S5"); + Assertions.assertEquals("Gudå", scheduledStopPoint.getName().getValue()); + } + + @Test + void testGetPassengerStopAssignment() { + ScheduledStopPoint scheduledStopPoint = index + .getScheduledStopPointIndex() + .getLatestVersion("NSR:ScheduledStopPoint:S5"); + Collection passengerStopAssignments = index + .getPassengerStopAssignmentsByStopPointRefIndex() + .get(scheduledStopPoint.getId()); + + Assertions.assertEquals(1, passengerStopAssignments.size()); + } + + @Test + void testGetFareZone() { + FareZone fareZone = index + .getFareZoneIndex() + .getLatestVersion("AKT:FareZone:27"); + Assertions.assertEquals("Kviteseid", fareZone.getName().getValue()); + } + + @Test + void testGetParkingsByParentSiteRef() { + Collection parkings = index + .getParkingsByParentSiteRefIndex() + .get("NSR:StopPlace:337"); + Assertions.assertFalse(parkings.isEmpty()); + } } diff --git a/src/test/java/org/entur/netex/TestUpdateStopPlaces.java b/src/test/java/org/entur/netex/TestUpdateStopPlaces.java index 6274ed5f..646307d5 100644 --- a/src/test/java/org/entur/netex/TestUpdateStopPlaces.java +++ b/src/test/java/org/entur/netex/TestUpdateStopPlaces.java @@ -1,40 +1,53 @@ package org.entur.netex; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.Collection; import org.entur.netex.index.api.NetexEntitiesIndex; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.rutebanken.netex.model.StopPlace; -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.util.Collection; - class TestUpdateStopPlaces { - private static NetexEntitiesIndex index; - @BeforeAll - static void init() { - try { - NetexParser parser = new NetexParser(); - File file = new File("src/test/resources/MultipleVersionsStopPlaces.xml"); - index = parser.parse(Files.newInputStream(file.toPath())); - } catch (Exception e) { - Assertions.fail(e.getMessage(), e); - } - } + private static NetexEntitiesIndex index; - @Test - void testStopPlacesCanBeUpdatedAndRemoved() throws IOException { - Assertions.assertEquals(1, index.getStopPlaceIndex().getAllVersions("NSR:StopPlace:9999").size()); - NetexParser parser = new NetexParser(); - File file = new File("src/test/resources/StopPlaceUpdated.xml"); - NetexEntitiesIndex newIndex = parser.parse(Files.newInputStream(file.toPath())); - Collection updatedStopPlace = newIndex.getStopPlaceIndex().getAllVersions("NSR:StopPlace:9999"); - index.getStopPlaceIndex().put("NSR:StopPlace:9999", updatedStopPlace); - Assertions.assertEquals(2, index.getStopPlaceIndex().getAllVersions("NSR:StopPlace:9999").size()); - index.getStopPlaceIndex().remove("NSR:StopPlace:9999"); - Assertions.assertEquals(0, index.getStopPlaceIndex().getAllVersions("NSR:StopPlace:9999").size()); + @BeforeAll + static void init() { + try { + NetexParser parser = new NetexParser(); + File file = new File("src/test/resources/MultipleVersionsStopPlaces.xml"); + index = parser.parse(Files.newInputStream(file.toPath())); + } catch (Exception e) { + Assertions.fail(e.getMessage(), e); } + } + + @Test + void testStopPlacesCanBeUpdatedAndRemoved() throws IOException { + Assertions.assertEquals( + 1, + index.getStopPlaceIndex().getAllVersions("NSR:StopPlace:9999").size() + ); + NetexParser parser = new NetexParser(); + File file = new File("src/test/resources/StopPlaceUpdated.xml"); + NetexEntitiesIndex newIndex = parser.parse( + Files.newInputStream(file.toPath()) + ); + Collection updatedStopPlace = newIndex + .getStopPlaceIndex() + .getAllVersions("NSR:StopPlace:9999"); + index.getStopPlaceIndex().put("NSR:StopPlace:9999", updatedStopPlace); + Assertions.assertEquals( + 2, + index.getStopPlaceIndex().getAllVersions("NSR:StopPlace:9999").size() + ); + index.getStopPlaceIndex().remove("NSR:StopPlace:9999"); + Assertions.assertEquals( + 0, + index.getStopPlaceIndex().getAllVersions("NSR:StopPlace:9999").size() + ); + } } diff --git a/src/test/java/org/entur/netex/VehicleScheduleFrameTest.java b/src/test/java/org/entur/netex/VehicleScheduleFrameTest.java index 92c8a072..2ec0b96a 100644 --- a/src/test/java/org/entur/netex/VehicleScheduleFrameTest.java +++ b/src/test/java/org/entur/netex/VehicleScheduleFrameTest.java @@ -1,10 +1,9 @@ package org.entur.netex; +import jakarta.xml.bind.JAXBElement; import java.util.ArrayList; import java.util.Collection; import java.util.List; -import jakarta.xml.bind.JAXBElement; - import org.entur.netex.index.api.NetexEntitiesIndex; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; @@ -15,75 +14,91 @@ import org.rutebanken.netex.model.VehicleScheduleFrame; class VehicleScheduleFrameTest { - private static NetexEntitiesIndex index; - @BeforeAll - static void init() { - try { - NetexParser parser = new NetexParser(); - index = parser.parse("src/test/resources/data.zip"); - } catch (Exception e) { - Assertions.fail(e.getMessage(), e); - } - } + private static NetexEntitiesIndex index; - @Test - void testBlocks() { - Collection blocks = index.getBlockIndex().getAll(); - Assertions.assertEquals(2, blocks.size()); + @BeforeAll + static void init() { + try { + NetexParser parser = new NetexParser(); + index = parser.parse("src/test/resources/data.zip"); + } catch (Exception e) { + Assertions.fail(e.getMessage(), e); } + } - @Test - void testJourneys() { - Collection blocks = index.getBlockIndex().getAll(); - int journeysSize = 0; + @Test + void testBlocks() { + Collection blocks = index.getBlockIndex().getAll(); + Assertions.assertEquals(2, blocks.size()); + } - for (Block block : blocks) { - List journeys = new ArrayList<>(); - if (block.getJourneys() != null && block.getJourneys().getJourneyRefOrJourneyDesignatorOrServiceDesignator() != null) { - for (JAXBElement journeyElement : block.getJourneys().getJourneyRefOrJourneyDesignatorOrServiceDesignator()) { - journeys.add(journeyElement.getValue().toString()); - } - } - journeysSize = journeysSize + journeys.size(); + @Test + void testJourneys() { + Collection blocks = index.getBlockIndex().getAll(); + int journeysSize = 0; + + for (Block block : blocks) { + List journeys = new ArrayList<>(); + if ( + block.getJourneys() != null && + block + .getJourneys() + .getJourneyRefOrJourneyDesignatorOrServiceDesignator() != + null + ) { + for (JAXBElement journeyElement : block + .getJourneys() + .getJourneyRefOrJourneyDesignatorOrServiceDesignator()) { + journeys.add(journeyElement.getValue().toString()); } - Assertions.assertEquals(5, journeysSize); + } + journeysSize = journeysSize + journeys.size(); } + Assertions.assertEquals(5, journeysSize); + } - @Test - void testDayTypes() { - Collection blocks = index.getBlockIndex().getAll(); - int dayTypesSize = 0; + @Test + void testDayTypes() { + Collection blocks = index.getBlockIndex().getAll(); + int dayTypesSize = 0; - for (Block block : blocks) { - List dayTypes = new ArrayList<>(); - if (block.getDayTypes() != null && block.getDayTypes().getDayTypeRef() != null) { - for (JAXBElement dayTypeRef : block.getDayTypes().getDayTypeRef()) { - dayTypes.add(dayTypeRef.getValue().getRef()); - } - dayTypesSize = dayTypesSize + dayTypes.size(); - } + for (Block block : blocks) { + List dayTypes = new ArrayList<>(); + if ( + block.getDayTypes() != null && + block.getDayTypes().getDayTypeRef() != null + ) { + for (JAXBElement dayTypeRef : block + .getDayTypes() + .getDayTypeRef()) { + dayTypes.add(dayTypeRef.getValue().getRef()); } - Assertions.assertEquals(2, dayTypesSize); + dayTypesSize = dayTypesSize + dayTypes.size(); + } } + Assertions.assertEquals(2, dayTypesSize); + } - @Test - void testGetBlock() { - Block block = index.getBlockIndex().get("AAA:BBB:666"); - Assertions.assertNotNull(block); - } + @Test + void testGetBlock() { + Block block = index.getBlockIndex().get("AAA:BBB:666"); + Assertions.assertNotNull(block); + } - @Test - void testGetJourneys() { - Block block = index.getBlockIndex().get("AAA:BBB:666"); - JourneyRefs_RelStructure result = block.getJourneys(); - List> journeys = result.getJourneyRefOrJourneyDesignatorOrServiceDesignator(); - Assertions.assertEquals(2, journeys.size()); - } + @Test + void testGetJourneys() { + Block block = index.getBlockIndex().get("AAA:BBB:666"); + JourneyRefs_RelStructure result = block.getJourneys(); + List> journeys = + result.getJourneyRefOrJourneyDesignatorOrServiceDesignator(); + Assertions.assertEquals(2, journeys.size()); + } - @Test - void testVehicleScheduleFrames() { - Collection vehicleScheduleFrame = index.getVehicleScheduleFrames(); - Assertions.assertEquals(1, vehicleScheduleFrame.size()); - } + @Test + void testVehicleScheduleFrames() { + Collection vehicleScheduleFrame = + index.getVehicleScheduleFrames(); + Assertions.assertEquals(1, vehicleScheduleFrame.size()); + } }