diff --git a/application/src/main/java/org/opentripplanner/graph_builder/module/configure/GraphBuilderModules.java b/application/src/main/java/org/opentripplanner/graph_builder/module/configure/GraphBuilderModules.java index 46c74b52a2d..7dbdc8b8c6a 100644 --- a/application/src/main/java/org/opentripplanner/graph_builder/module/configure/GraphBuilderModules.java +++ b/application/src/main/java/org/opentripplanner/graph_builder/module/configure/GraphBuilderModules.java @@ -41,6 +41,7 @@ import org.opentripplanner.netex.NetexModule; import org.opentripplanner.netex.configure.NetexConfigure; import org.opentripplanner.osm.OsmProvider; +import org.opentripplanner.osm.DefaultOsmProvider; import org.opentripplanner.routing.api.request.preference.WalkPreferences; import org.opentripplanner.routing.graph.Graph; import org.opentripplanner.service.osminfo.OsmInfoGraphBuildRepository; @@ -69,7 +70,7 @@ static OsmModule provideOsmModule( List providers = new ArrayList<>(); for (ConfiguredDataSource osmConfiguredDataSource : dataSources.getOsmConfiguredDatasource()) { providers.add( - new OsmProvider( + new DefaultOsmProvider( osmConfiguredDataSource.dataSource(), osmConfiguredDataSource.config().osmTagMapper(), osmConfiguredDataSource.config().timeZone(), diff --git a/application/src/main/java/org/opentripplanner/graph_builder/module/osm/OsmModule.java b/application/src/main/java/org/opentripplanner/graph_builder/module/osm/OsmModule.java index 39d27a5739b..a204ce03e23 100644 --- a/application/src/main/java/org/opentripplanner/graph_builder/module/osm/OsmModule.java +++ b/application/src/main/java/org/opentripplanner/graph_builder/module/osm/OsmModule.java @@ -20,6 +20,7 @@ import org.opentripplanner.graph_builder.model.GraphBuilderModule; import org.opentripplanner.graph_builder.module.osm.parameters.OsmProcessingParameters; import org.opentripplanner.osm.OsmProvider; +import org.opentripplanner.osm.DefaultOsmProvider; import org.opentripplanner.osm.model.OsmLevel; import org.opentripplanner.osm.model.OsmNode; import org.opentripplanner.osm.model.OsmWay; @@ -112,7 +113,7 @@ public static OsmModuleBuilder of( @Override public void buildGraph() { - for (OsmProvider provider : providers) { + for (var provider : providers) { LOG.info("Gathering OSM from provider: {}", provider); LOG.info( "Using OSM way configuration from {}.", @@ -130,7 +131,7 @@ public void buildGraph() { @Override public void checkInputs() { - for (OsmProvider provider : providers) { + for (var provider : providers) { provider.checkInputs(); } } @@ -613,7 +614,7 @@ private StreetEdge getEdgeForStreet( private float getMaxCarSpeed() { float maxSpeed = 0f; - for (OsmProvider provider : providers) { + for (var provider : providers) { var carSpeed = provider.getOsmTagMapper().getMaxUsedCarSpeed(provider.getWayPropertySet()); if (carSpeed > maxSpeed) { maxSpeed = carSpeed; diff --git a/application/src/main/java/org/opentripplanner/osm/DefaultOsmProvider.java b/application/src/main/java/org/opentripplanner/osm/DefaultOsmProvider.java new file mode 100644 index 00000000000..5e90057074c --- /dev/null +++ b/application/src/main/java/org/opentripplanner/osm/DefaultOsmProvider.java @@ -0,0 +1,158 @@ +package org.opentripplanner.osm; + +import crosby.binary.file.BlockInputStream; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZoneId; +import org.opentripplanner.datastore.api.DataSource; +import org.opentripplanner.datastore.api.FileType; +import org.opentripplanner.datastore.file.FileDataSource; +import org.opentripplanner.framework.application.OtpFileNames; +import org.opentripplanner.graph_builder.issue.api.DataImportIssueStore; +import org.opentripplanner.graph_builder.module.osm.OsmDatabase; +import org.opentripplanner.osm.tagmapping.OsmTagMapper; +import org.opentripplanner.osm.tagmapping.OsmTagMapperSource; +import org.opentripplanner.osm.wayproperty.WayPropertySet; +import org.opentripplanner.utils.logging.ProgressTracker; +import org.opentripplanner.utils.tostring.ToStringBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Parser for the OpenStreetMap PBF format. Parses files in three passes: First the relations, then + * the ways, then the nodes are also loaded. + */ +public class DefaultOsmProvider implements OsmProvider { + + private static final Logger LOG = LoggerFactory.getLogger(DefaultOsmProvider.class); + + private final DataSource source; + private final boolean cacheDataInMem; + + private final ZoneId zoneId; + + private boolean hasWarnedAboutMissingTimeZone = false; + + private final OsmTagMapper osmTagMapper; + + private final WayPropertySet wayPropertySet; + private byte[] cachedBytes = null; + + /** For tests */ + public DefaultOsmProvider(File file, boolean cacheDataInMem) { + this( + new FileDataSource(file, FileType.OSM), + OsmTagMapperSource.DEFAULT, + null, + cacheDataInMem, + DataImportIssueStore.NOOP + ); + } + + public DefaultOsmProvider( + DataSource dataSource, + OsmTagMapperSource tagMapperSource, + ZoneId zoneId, + boolean cacheDataInMem, + DataImportIssueStore issueStore + ) { + this.source = dataSource; + this.zoneId = zoneId; + this.osmTagMapper = tagMapperSource.getInstance(); + this.wayPropertySet = new WayPropertySet(issueStore); + osmTagMapper.populateProperties(wayPropertySet); + this.cacheDataInMem = cacheDataInMem; + } + + public void readOsm(OsmDatabase osmdb) { + try { + OsmParser parser = new OsmParser(osmdb, this); + + parsePhase(parser, OsmParserPhase.Relations); + osmdb.doneFirstPhaseRelations(); + + parsePhase(parser, OsmParserPhase.Ways); + osmdb.doneSecondPhaseWays(); + + parsePhase(parser, OsmParserPhase.Nodes); + osmdb.doneThirdPhaseNodes(); + } catch (Exception ex) { + throw new IllegalStateException("error loading OSM from path " + source.path(), ex); + } + } + + @Override + public String toString() { + return ToStringBuilder + .of(DefaultOsmProvider.class) + .addObj("source", source) + .addBool("cacheDataInMem", cacheDataInMem) + .toString(); + } + + public void checkInputs() { + if (!source.exists()) { + throw new RuntimeException("Can't read OSM path: " + source.path()); + } + } + + @SuppressWarnings("Convert2MethodRef") + private static InputStream track(OsmParserPhase phase, long size, InputStream inputStream) { + // Keep logging lambda, replacing it with a method-ref will cause the + // logging to report incorrect class and line number + return ProgressTracker.track("Parse OSM " + phase, 1000, size, inputStream, m -> LOG.info(m)); + } + + private void parsePhase(OsmParser parser, OsmParserPhase phase) throws IOException { + parser.setPhase(phase); + BlockInputStream in = null; + try { + in = new BlockInputStream(createInputStream(phase), parser); + in.process(); + } finally { + // Close + try { + if (in != null) { + in.close(); + } + } catch (Exception e) { + LOG.error(e.getMessage(), e); + } + } + } + + private InputStream createInputStream(OsmParserPhase phase) { + if (cacheDataInMem) { + if (cachedBytes == null) { + cachedBytes = source.asBytes(); + } + return track(phase, cachedBytes.length, new ByteArrayInputStream(cachedBytes)); + } + return track(phase, source.size(), source.asInputStream()); + } + + public ZoneId getZoneId() { + if (zoneId == null) { + if (!hasWarnedAboutMissingTimeZone) { + hasWarnedAboutMissingTimeZone = true; + LOG.warn( + "Missing time zone for OSM source {} - time-restricted entities will " + + "not be created, please configure it in the {}", + source.uri(), + OtpFileNames.BUILD_CONFIG_FILENAME + ); + } + } + return zoneId; + } + + public OsmTagMapper getOsmTagMapper() { + return osmTagMapper; + } + + public WayPropertySet getWayPropertySet() { + return wayPropertySet; + } +} diff --git a/application/src/main/java/org/opentripplanner/osm/OsmParser.java b/application/src/main/java/org/opentripplanner/osm/OsmParser.java index 4b443e6a505..9a7fea47d8c 100644 --- a/application/src/main/java/org/opentripplanner/osm/OsmParser.java +++ b/application/src/main/java/org/opentripplanner/osm/OsmParser.java @@ -23,10 +23,10 @@ class OsmParser extends BinaryParser { private final OsmDatabase osmdb; private final Map stringTable = new HashMap<>(); - private final OsmProvider provider; + private final DefaultOsmProvider provider; private OsmParserPhase parsePhase; - public OsmParser(OsmDatabase osmdb, OsmProvider provider) { + public OsmParser(OsmDatabase osmdb, DefaultOsmProvider provider) { this.osmdb = Objects.requireNonNull(osmdb); this.provider = Objects.requireNonNull(provider); } diff --git a/application/src/main/java/org/opentripplanner/osm/OsmProvider.java b/application/src/main/java/org/opentripplanner/osm/OsmProvider.java index 91944a95b86..70abf9b93df 100644 --- a/application/src/main/java/org/opentripplanner/osm/OsmProvider.java +++ b/application/src/main/java/org/opentripplanner/osm/OsmProvider.java @@ -1,158 +1,18 @@ package org.opentripplanner.osm; -import crosby.binary.file.BlockInputStream; -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; import java.time.ZoneId; -import org.opentripplanner.datastore.api.DataSource; -import org.opentripplanner.datastore.api.FileType; -import org.opentripplanner.datastore.file.FileDataSource; -import org.opentripplanner.framework.application.OtpFileNames; -import org.opentripplanner.graph_builder.issue.api.DataImportIssueStore; import org.opentripplanner.graph_builder.module.osm.OsmDatabase; import org.opentripplanner.osm.tagmapping.OsmTagMapper; -import org.opentripplanner.osm.tagmapping.OsmTagMapperSource; import org.opentripplanner.osm.wayproperty.WayPropertySet; -import org.opentripplanner.utils.logging.ProgressTracker; -import org.opentripplanner.utils.tostring.ToStringBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -/** - * Parser for the OpenStreetMap PBF format. Parses files in three passes: First the relations, then - * the ways, then the nodes are also loaded. - */ -public class OsmProvider { +public interface OsmProvider { + void readOsm(OsmDatabase osmdb); - private static final Logger LOG = LoggerFactory.getLogger(OsmProvider.class); + OsmTagMapper getOsmTagMapper(); - private final DataSource source; - private final boolean cacheDataInMem; + void checkInputs(); - private final ZoneId zoneId; + WayPropertySet getWayPropertySet(); - private boolean hasWarnedAboutMissingTimeZone = false; - - private final OsmTagMapper osmTagMapper; - - private final WayPropertySet wayPropertySet; - private byte[] cachedBytes = null; - - /** For tests */ - public OsmProvider(File file, boolean cacheDataInMem) { - this( - new FileDataSource(file, FileType.OSM), - OsmTagMapperSource.DEFAULT, - null, - cacheDataInMem, - DataImportIssueStore.NOOP - ); - } - - public OsmProvider( - DataSource dataSource, - OsmTagMapperSource tagMapperSource, - ZoneId zoneId, - boolean cacheDataInMem, - DataImportIssueStore issueStore - ) { - this.source = dataSource; - this.zoneId = zoneId; - this.osmTagMapper = tagMapperSource.getInstance(); - this.wayPropertySet = new WayPropertySet(issueStore); - osmTagMapper.populateProperties(wayPropertySet); - this.cacheDataInMem = cacheDataInMem; - } - - public void readOsm(OsmDatabase osmdb) { - try { - OsmParser parser = new OsmParser(osmdb, this); - - parsePhase(parser, OsmParserPhase.Relations); - osmdb.doneFirstPhaseRelations(); - - parsePhase(parser, OsmParserPhase.Ways); - osmdb.doneSecondPhaseWays(); - - parsePhase(parser, OsmParserPhase.Nodes); - osmdb.doneThirdPhaseNodes(); - } catch (Exception ex) { - throw new IllegalStateException("error loading OSM from path " + source.path(), ex); - } - } - - @Override - public String toString() { - return ToStringBuilder - .of(OsmProvider.class) - .addObj("source", source) - .addBool("cacheDataInMem", cacheDataInMem) - .toString(); - } - - public void checkInputs() { - if (!source.exists()) { - throw new RuntimeException("Can't read OSM path: " + source.path()); - } - } - - @SuppressWarnings("Convert2MethodRef") - private static InputStream track(OsmParserPhase phase, long size, InputStream inputStream) { - // Keep logging lambda, replacing it with a method-ref will cause the - // logging to report incorrect class and line number - return ProgressTracker.track("Parse OSM " + phase, 1000, size, inputStream, m -> LOG.info(m)); - } - - private void parsePhase(OsmParser parser, OsmParserPhase phase) throws IOException { - parser.setPhase(phase); - BlockInputStream in = null; - try { - in = new BlockInputStream(createInputStream(phase), parser); - in.process(); - } finally { - // Close - try { - if (in != null) { - in.close(); - } - } catch (Exception e) { - LOG.error(e.getMessage(), e); - } - } - } - - private InputStream createInputStream(OsmParserPhase phase) { - if (cacheDataInMem) { - if (cachedBytes == null) { - cachedBytes = source.asBytes(); - } - return track(phase, cachedBytes.length, new ByteArrayInputStream(cachedBytes)); - } - return track(phase, source.size(), source.asInputStream()); - } - - public ZoneId getZoneId() { - if (zoneId == null) { - if (!hasWarnedAboutMissingTimeZone) { - hasWarnedAboutMissingTimeZone = true; - LOG.warn( - "Missing time zone for OSM source {} - time-restricted entities will " + - "not be created, please configure it in the {}", - source.uri(), - OtpFileNames.BUILD_CONFIG_FILENAME - ); - } - } - return zoneId; - } - - public OsmTagMapper getOsmTagMapper() { - return osmTagMapper; - } - - public WayPropertySet getWayPropertySet() { - return wayPropertySet; - } + ZoneId getZoneId(); } diff --git a/application/src/main/java/org/opentripplanner/osm/model/OsmWithTags.java b/application/src/main/java/org/opentripplanner/osm/model/OsmWithTags.java index 3f47d4454bd..f39eb9a8a1d 100644 --- a/application/src/main/java/org/opentripplanner/osm/model/OsmWithTags.java +++ b/application/src/main/java/org/opentripplanner/osm/model/OsmWithTags.java @@ -18,6 +18,7 @@ import org.opentripplanner.framework.i18n.NonLocalizedString; import org.opentripplanner.framework.i18n.TranslatedString; import org.opentripplanner.graph_builder.module.osm.OsmModule; +import org.opentripplanner.osm.DefaultOsmProvider; import org.opentripplanner.osm.OsmProvider; import org.opentripplanner.street.model.StreetTraversalPermission; import org.opentripplanner.transit.model.basic.Accessibility; diff --git a/application/src/test/java/org/opentripplanner/ConstantsForTests.java b/application/src/test/java/org/opentripplanner/ConstantsForTests.java index 3f188ff2c89..97a73196733 100644 --- a/application/src/test/java/org/opentripplanner/ConstantsForTests.java +++ b/application/src/test/java/org/opentripplanner/ConstantsForTests.java @@ -28,7 +28,7 @@ import org.opentripplanner.model.impl.OtpTransitServiceBuilder; import org.opentripplanner.netex.NetexBundle; import org.opentripplanner.netex.configure.NetexConfigure; -import org.opentripplanner.osm.OsmProvider; +import org.opentripplanner.osm.DefaultOsmProvider; import org.opentripplanner.routing.api.request.RouteRequest; import org.opentripplanner.routing.fares.FareServiceFactory; import org.opentripplanner.routing.graph.Graph; @@ -138,7 +138,7 @@ public static TestOtpModel buildNewPortlandGraph(boolean withElevation) { var timetableRepository = new TimetableRepository(new SiteRepository(), deduplicator); // Add street data from OSM { - var osmProvider = new OsmProvider(PORTLAND_CENTRAL_OSM, false); + var osmProvider = new DefaultOsmProvider(PORTLAND_CENTRAL_OSM, false); var osmInfoRepository = new DefaultOsmInfoGraphBuildRepository(); var vehicleParkingRepository = new DefaultVehicleParkingRepository(); var osmModule = OsmModule @@ -198,7 +198,7 @@ public static TestOtpModel buildOsmGraph(File osmFile) { var graph = new Graph(deduplicator); var timetableRepository = new TimetableRepository(siteRepository, deduplicator); // Add street data from OSM - var osmProvider = new OsmProvider(osmFile, true); + var osmProvider = new DefaultOsmProvider(osmFile, true); var osmInfoRepository = new DefaultOsmInfoGraphBuildRepository(); var vehicleParkingRepository = new DefaultVehicleParkingRepository(); var osmModule = OsmModule @@ -250,7 +250,7 @@ public static TestOtpModel buildNewMinimalNetexGraph() { var timetableRepository = new TimetableRepository(siteRepository, deduplicator); // Add street data from OSM { - var osmProvider = new OsmProvider(OSLO_EAST_OSM, false); + var osmProvider = new DefaultOsmProvider(OSLO_EAST_OSM, false); var osmInfoRepository = new DefaultOsmInfoGraphBuildRepository(); var osmModule = OsmModule.of(osmProvider, graph, osmInfoRepository, parkingService).build(); osmModule.buildGraph(); diff --git a/application/src/test/java/org/opentripplanner/graph_builder/module/OsmBoardingLocationsModuleTest.java b/application/src/test/java/org/opentripplanner/graph_builder/module/OsmBoardingLocationsModuleTest.java index a4d5e86ced8..99770e5ab5e 100644 --- a/application/src/test/java/org/opentripplanner/graph_builder/module/OsmBoardingLocationsModuleTest.java +++ b/application/src/test/java/org/opentripplanner/graph_builder/module/OsmBoardingLocationsModuleTest.java @@ -19,7 +19,7 @@ import org.opentripplanner.framework.i18n.I18NString; import org.opentripplanner.framework.i18n.NonLocalizedString; import org.opentripplanner.graph_builder.module.osm.OsmModule; -import org.opentripplanner.osm.OsmProvider; +import org.opentripplanner.osm.DefaultOsmProvider; import org.opentripplanner.routing.graph.Graph; import org.opentripplanner.service.osminfo.internal.DefaultOsmInfoGraphBuildRepository; import org.opentripplanner.service.osminfo.internal.DefaultOsmInfoGraphBuildService; @@ -82,7 +82,7 @@ void addAndLinkBoardingLocations(boolean areaVisibility, Set linkedVerti var timetableRepository = new TimetableRepository(new SiteRepository(), deduplicator); var factory = new VertexFactory(graph); - var provider = new OsmProvider(file, false); + var provider = new DefaultOsmProvider(file, false); var floatingBusVertex = factory.transitStop( TransitStopVertex.of().withStop(floatingBusStop).withModes(Set.of(TransitMode.BUS)) ); @@ -200,7 +200,7 @@ void testLinearPlatforms() { var osmInfoRepository = new DefaultOsmInfoGraphBuildRepository(); var osmModule = OsmModule .of( - new OsmProvider( + new DefaultOsmProvider( ResourceLoader.of(OsmBoardingLocationsModuleTest.class).file("moorgate.osm.pbf"), false ), diff --git a/application/src/test/java/org/opentripplanner/graph_builder/module/islandpruning/IslandPruningUtils.java b/application/src/test/java/org/opentripplanner/graph_builder/module/islandpruning/IslandPruningUtils.java index 8e5a455095b..1f37eeeeb65 100644 --- a/application/src/test/java/org/opentripplanner/graph_builder/module/islandpruning/IslandPruningUtils.java +++ b/application/src/test/java/org/opentripplanner/graph_builder/module/islandpruning/IslandPruningUtils.java @@ -3,7 +3,7 @@ import java.io.File; import org.opentripplanner.graph_builder.issue.api.DataImportIssueStore; import org.opentripplanner.graph_builder.module.osm.OsmModule; -import org.opentripplanner.osm.OsmProvider; +import org.opentripplanner.osm.DefaultOsmProvider; import org.opentripplanner.routing.graph.Graph; import org.opentripplanner.service.osminfo.internal.DefaultOsmInfoGraphBuildRepository; import org.opentripplanner.service.vehicleparking.internal.DefaultVehicleParkingRepository; @@ -25,7 +25,7 @@ static Graph buildOsmGraph( var graph = new Graph(deduplicator); var timetableRepository = new TimetableRepository(new SiteRepository(), deduplicator); // Add street data from OSM - var osmProvider = new OsmProvider(osmFile, true); + var osmProvider = new DefaultOsmProvider(osmFile, true); var osmInfoRepository = new DefaultOsmInfoGraphBuildRepository(); var vehicleParkingRepository = new DefaultVehicleParkingRepository(); var osmModule = OsmModule diff --git a/application/src/test/java/org/opentripplanner/graph_builder/module/linking/LinkingTest.java b/application/src/test/java/org/opentripplanner/graph_builder/module/linking/LinkingTest.java index 6c51235e703..6c45d97a825 100644 --- a/application/src/test/java/org/opentripplanner/graph_builder/module/linking/LinkingTest.java +++ b/application/src/test/java/org/opentripplanner/graph_builder/module/linking/LinkingTest.java @@ -19,7 +19,7 @@ import org.opentripplanner.framework.geometry.SphericalDistanceLibrary; import org.opentripplanner.framework.i18n.NonLocalizedString; import org.opentripplanner.graph_builder.module.osm.OsmModule; -import org.opentripplanner.osm.OsmProvider; +import org.opentripplanner.osm.DefaultOsmProvider; import org.opentripplanner.routing.graph.Graph; import org.opentripplanner.service.osminfo.internal.DefaultOsmInfoGraphBuildRepository; import org.opentripplanner.service.vehicleparking.internal.DefaultVehicleParkingRepository; @@ -157,7 +157,7 @@ public static TestOtpModel buildGraphNoTransit() { var timetableRepository = new TimetableRepository(siteRepository, deduplicator); File file = ResourceLoader.of(LinkingTest.class).file("columbus.osm.pbf"); - var provider = new OsmProvider(file, false); + var provider = new DefaultOsmProvider(file, false); var osmInfoRepository = new DefaultOsmInfoGraphBuildRepository(); var vehicleParkingRepository = new DefaultVehicleParkingRepository(); diff --git a/application/src/test/java/org/opentripplanner/graph_builder/module/osm/OsmDatabaseTest.java b/application/src/test/java/org/opentripplanner/graph_builder/module/osm/OsmDatabaseTest.java index 88003e9218f..732ac354ad3 100644 --- a/application/src/test/java/org/opentripplanner/graph_builder/module/osm/OsmDatabaseTest.java +++ b/application/src/test/java/org/opentripplanner/graph_builder/module/osm/OsmDatabaseTest.java @@ -5,7 +5,7 @@ import org.junit.jupiter.api.Test; import org.opentripplanner.graph_builder.issue.api.DataImportIssueStore; -import org.opentripplanner.osm.OsmProvider; +import org.opentripplanner.osm.DefaultOsmProvider; import org.opentripplanner.test.support.ResourceLoader; public class OsmDatabaseTest { @@ -20,7 +20,7 @@ public class OsmDatabaseTest { @Test void bicycleRouteRelations() { var osmdb = new OsmDatabase(DataImportIssueStore.NOOP); - var provider = new OsmProvider(RESOURCE_LOADER.file("ehningen-minimal.osm.pbf"), true); + var provider = new DefaultOsmProvider(RESOURCE_LOADER.file("ehningen-minimal.osm.pbf"), true); provider.readOsm(osmdb); osmdb.postLoad(); @@ -40,7 +40,7 @@ void bicycleRouteRelations() { void invalidPublicTransportRelation() { var osmdb = new OsmDatabase(DataImportIssueStore.NOOP); var file = RESOURCE_LOADER.file("brenner-invalid-relation-reference.osm.pbf"); - var provider = new OsmProvider(file, true); + var provider = new DefaultOsmProvider(file, true); provider.readOsm(osmdb); osmdb.postLoad(); diff --git a/application/src/test/java/org/opentripplanner/graph_builder/module/osm/OsmModuleTest.java b/application/src/test/java/org/opentripplanner/graph_builder/module/osm/OsmModuleTest.java index a25bc6ef033..cbc29803277 100644 --- a/application/src/test/java/org/opentripplanner/graph_builder/module/osm/OsmModuleTest.java +++ b/application/src/test/java/org/opentripplanner/graph_builder/module/osm/OsmModuleTest.java @@ -1,5 +1,6 @@ package org.opentripplanner.graph_builder.module.osm; +import static com.google.common.truth.Truth.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -10,18 +11,22 @@ import static org.opentripplanner.street.model.StreetTraversalPermission.PEDESTRIAN; import java.io.File; +import java.time.ZoneId; import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Set; import java.util.stream.Stream; import org.junit.jupiter.api.Test; +import org.opentripplanner._support.time.ZoneIds; import org.opentripplanner.astar.model.GraphPath; import org.opentripplanner.framework.i18n.LocalizedString; import org.opentripplanner.framework.i18n.NonLocalizedString; +import org.opentripplanner.osm.DefaultOsmProvider; import org.opentripplanner.osm.OsmProvider; import org.opentripplanner.osm.model.OsmWay; import org.opentripplanner.osm.model.OsmWithTags; +import org.opentripplanner.osm.tagmapping.OsmTagMapper; import org.opentripplanner.osm.wayproperty.CreativeNamer; import org.opentripplanner.osm.wayproperty.MixinPropertiesBuilder; import org.opentripplanner.osm.wayproperty.WayProperties; @@ -58,7 +63,7 @@ public void testGraphBuilder() { File file = RESOURCE_LOADER.file("map.osm.pbf"); - OsmProvider provider = new OsmProvider(file, true); + DefaultOsmProvider provider = new DefaultOsmProvider(file, true); OsmModule osmModule = OsmModule .of( @@ -123,7 +128,7 @@ public void testBuildGraphDetailed() { var gg = new Graph(deduplicator); File file = RESOURCE_LOADER.file("NYC_small.osm.pbf"); - var provider = new OsmProvider(file, true); + var provider = new DefaultOsmProvider(file, true); var osmInfoRepository = new DefaultOsmInfoGraphBuildRepository(); var vehicleParkingRepository = new DefaultVehicleParkingRepository(); var osmModule = OsmModule @@ -164,17 +169,50 @@ public void testBuildGraphDetailed() { } } + + /** * There is a one-way road which is also marked as a platform in Sky Campus which crashed OSM */ @Test void testCrappyOsmPlatform() { + + var provider = new OsmProvider() { + @Override + public void readOsm(OsmDatabase osmdb) { + final OsmWay way = new OsmWay(); + way.addTag("public_transport", "platform"); + way.addTag("ref", "123"); + way.setOsmProvider(this); + osmdb.addWay(way); + } + + @Override + public OsmTagMapper getOsmTagMapper() { + return new OsmTagMapper(); + } + + @Override + public void checkInputs() { + + } + + @Override + public WayPropertySet getWayPropertySet() { + return new WayPropertySet(); + } + + @Override + public ZoneId getZoneId() { + return ZoneIds.LONDON; + } + }; var deduplicator = new Deduplicator(); var graph = new Graph(deduplicator); var osmInfoRepository = new DefaultOsmInfoGraphBuildRepository(); var osmModule = OsmModule .of( - new OsmProvider(RESOURCE_LOADER.file("sky_campus.osm.pbf"), false), + provider, graph, osmInfoRepository, new DefaultVehicleParkingRepository() @@ -182,7 +220,7 @@ void testCrappyOsmPlatform() { .withBoardingAreaRefTags(Set.of("naptan:AtcoCode")) .build(); osmModule.buildGraph(); - assertTrue(true); + assertThat(graph.getEdges()).isNotEmpty(); } @Test @@ -343,7 +381,7 @@ void testBarrierAtEnd() { var graph = new Graph(deduplicator); File file = RESOURCE_LOADER.file("accessno-at-end.pbf"); - OsmProvider provider = new OsmProvider(file, false); + DefaultOsmProvider provider = new DefaultOsmProvider(file, false); OsmModule loader = OsmModule .of( provider, @@ -369,10 +407,10 @@ void testBarrierAtEnd() { private BuildResult buildParkingLots() { var graph = new Graph(); var service = new DefaultVehicleParkingRepository(); - var providers = Stream + List providers = Stream .of("B+R.osm.pbf", "P+R.osm.pbf") .map(RESOURCE_LOADER::file) - .map(f -> new OsmProvider(f, false)) + .map(f -> (OsmProvider) new DefaultOsmProvider(f, false)) .toList(); var module = OsmModule .of(providers, graph, new DefaultOsmInfoGraphBuildRepository(), service) @@ -399,7 +437,7 @@ private void testBuildingAreas(boolean skipVisibility) { var graph = new Graph(deduplicator); File file = RESOURCE_LOADER.file("usf_area.osm.pbf"); - var provider = new OsmProvider(file, false); + var provider = new DefaultOsmProvider(file, false); var osmInfoRepository = new DefaultOsmInfoGraphBuildRepository(); var vehicleParkingRepository = new DefaultVehicleParkingRepository(); diff --git a/application/src/test/java/org/opentripplanner/graph_builder/module/osm/OsmParserTest.java b/application/src/test/java/org/opentripplanner/graph_builder/module/osm/OsmParserTest.java index f477f76fc60..721ec47bbec 100644 --- a/application/src/test/java/org/opentripplanner/graph_builder/module/osm/OsmParserTest.java +++ b/application/src/test/java/org/opentripplanner/graph_builder/module/osm/OsmParserTest.java @@ -7,7 +7,7 @@ import java.io.File; import org.junit.jupiter.api.Test; import org.opentripplanner.graph_builder.issue.api.DataImportIssueStore; -import org.opentripplanner.osm.OsmProvider; +import org.opentripplanner.osm.DefaultOsmProvider; import org.opentripplanner.osm.model.OsmNode; import org.opentripplanner.osm.model.OsmWay; import org.opentripplanner.test.support.ResourceLoader; @@ -17,7 +17,7 @@ public class OsmParserTest { @Test public void testBinaryParser() { File osmFile = ResourceLoader.of(this).file("map.osm.pbf"); - OsmProvider pr = new OsmProvider(osmFile, true); + DefaultOsmProvider pr = new DefaultOsmProvider(osmFile, true); OsmDatabase osmdb = new OsmDatabase(DataImportIssueStore.NOOP); pr.readOsm(osmdb); diff --git a/application/src/test/java/org/opentripplanner/graph_builder/module/osm/PlatformLinkerTest.java b/application/src/test/java/org/opentripplanner/graph_builder/module/osm/PlatformLinkerTest.java index 97ccbdd7719..76f4b25c3ef 100644 --- a/application/src/test/java/org/opentripplanner/graph_builder/module/osm/PlatformLinkerTest.java +++ b/application/src/test/java/org/opentripplanner/graph_builder/module/osm/PlatformLinkerTest.java @@ -4,7 +4,7 @@ import java.io.File; import org.junit.jupiter.api.Test; -import org.opentripplanner.osm.OsmProvider; +import org.opentripplanner.osm.DefaultOsmProvider; import org.opentripplanner.routing.graph.Graph; import org.opentripplanner.service.osminfo.internal.DefaultOsmInfoGraphBuildRepository; import org.opentripplanner.service.vehicleparking.internal.DefaultVehicleParkingRepository; @@ -29,7 +29,7 @@ public void testLinkEntriesToPlatforms() { File file = ResourceLoader.of(this).file("skoyen.osm.pbf"); - OsmProvider provider = new OsmProvider(file, false); + DefaultOsmProvider provider = new DefaultOsmProvider(file, false); OsmModule osmModule = OsmModule .of( diff --git a/application/src/test/java/org/opentripplanner/graph_builder/module/osm/TriangleInequalityTest.java b/application/src/test/java/org/opentripplanner/graph_builder/module/osm/TriangleInequalityTest.java index 1b8f7c9c58a..f43faef27c5 100644 --- a/application/src/test/java/org/opentripplanner/graph_builder/module/osm/TriangleInequalityTest.java +++ b/application/src/test/java/org/opentripplanner/graph_builder/module/osm/TriangleInequalityTest.java @@ -15,7 +15,7 @@ import org.opentripplanner.astar.model.GraphPath; import org.opentripplanner.astar.model.ShortestPathTree; import org.opentripplanner.model.modes.ExcludeAllTransitFilter; -import org.opentripplanner.osm.OsmProvider; +import org.opentripplanner.osm.DefaultOsmProvider; import org.opentripplanner.routing.api.request.RequestModes; import org.opentripplanner.routing.api.request.RouteRequest; import org.opentripplanner.routing.api.request.request.filter.AllowAllTransitFilter; @@ -51,7 +51,7 @@ public static void onlyOnce() { graph = new Graph(new Deduplicator()); File file = ResourceLoader.of(TriangleInequalityTest.class).file("NYC_small.osm.pbf"); - OsmProvider provider = new OsmProvider(file, true); + DefaultOsmProvider provider = new DefaultOsmProvider(file, true); OsmModule osmModule = OsmModule .of( provider, diff --git a/application/src/test/java/org/opentripplanner/graph_builder/module/osm/UnconnectedAreasTest.java b/application/src/test/java/org/opentripplanner/graph_builder/module/osm/UnconnectedAreasTest.java index 22b486d7cd6..9c83bd1b2bb 100644 --- a/application/src/test/java/org/opentripplanner/graph_builder/module/osm/UnconnectedAreasTest.java +++ b/application/src/test/java/org/opentripplanner/graph_builder/module/osm/UnconnectedAreasTest.java @@ -11,7 +11,7 @@ import org.opentripplanner.graph_builder.issue.service.DefaultDataImportIssueStore; import org.opentripplanner.graph_builder.issues.ParkAndRideUnlinked; import org.opentripplanner.graph_builder.module.TestStreetLinkerModule; -import org.opentripplanner.osm.OsmProvider; +import org.opentripplanner.osm.DefaultOsmProvider; import org.opentripplanner.routing.graph.Graph; import org.opentripplanner.service.osminfo.internal.DefaultOsmInfoGraphBuildRepository; import org.opentripplanner.service.vehicleparking.internal.DefaultVehicleParkingRepository; @@ -162,7 +162,7 @@ private Graph buildOsmGraph(String osmFileName, DataImportIssueStore issueStore) var siteRepository = new SiteRepository(); var graph = new Graph(deduplicator); var timetableRepository = new TimetableRepository(siteRepository, deduplicator); - OsmProvider provider = new OsmProvider(RESOURCE_LOADER.file(osmFileName), false); + DefaultOsmProvider provider = new DefaultOsmProvider(RESOURCE_LOADER.file(osmFileName), false); OsmModule loader = OsmModule .of( provider, diff --git a/application/src/test/java/org/opentripplanner/graph_builder/module/osm/UnroutableTest.java b/application/src/test/java/org/opentripplanner/graph_builder/module/osm/UnroutableTest.java index 835c5a7fbcb..465c5ab13df 100644 --- a/application/src/test/java/org/opentripplanner/graph_builder/module/osm/UnroutableTest.java +++ b/application/src/test/java/org/opentripplanner/graph_builder/module/osm/UnroutableTest.java @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test; import org.opentripplanner.astar.model.GraphPath; import org.opentripplanner.astar.model.ShortestPathTree; -import org.opentripplanner.osm.OsmProvider; +import org.opentripplanner.osm.DefaultOsmProvider; import org.opentripplanner.routing.api.request.RouteRequest; import org.opentripplanner.routing.api.request.StreetMode; import org.opentripplanner.routing.graph.Graph; @@ -38,7 +38,7 @@ public void setUp() throws Exception { graph = new Graph(deduplicator); var osmDataFile = ResourceLoader.of(UnroutableTest.class).file("bridge_construction.osm.pbf"); - OsmProvider provider = new OsmProvider(osmDataFile, true); + DefaultOsmProvider provider = new DefaultOsmProvider(osmDataFile, true); OsmModule osmBuilder = OsmModule .of( provider, diff --git a/application/src/test/java/org/opentripplanner/graph_builder/module/osm/WalkableAreaBuilderTest.java b/application/src/test/java/org/opentripplanner/graph_builder/module/osm/WalkableAreaBuilderTest.java index b712ee48c5a..c354c6671a2 100644 --- a/application/src/test/java/org/opentripplanner/graph_builder/module/osm/WalkableAreaBuilderTest.java +++ b/application/src/test/java/org/opentripplanner/graph_builder/module/osm/WalkableAreaBuilderTest.java @@ -19,7 +19,7 @@ import org.junit.jupiter.api.TestInfo; import org.opentripplanner.graph_builder.issue.api.DataImportIssueStore; import org.opentripplanner.graph_builder.module.osm.naming.DefaultNamer; -import org.opentripplanner.osm.OsmProvider; +import org.opentripplanner.osm.DefaultOsmProvider; import org.opentripplanner.osm.model.OsmLevel; import org.opentripplanner.routing.graph.Graph; import org.opentripplanner.street.model.edge.AreaEdge; @@ -42,7 +42,7 @@ public Graph buildGraph(final TestInfo testInfo) { final File file = ResourceLoader.of(WalkableAreaBuilderTest.class).file(osmFile); assertTrue(file.exists()); - new OsmProvider(file, false).readOsm(osmdb); + new DefaultOsmProvider(file, false).readOsm(osmdb); osmdb.postLoad(); final WalkableAreaBuilder walkableAreaBuilder = new WalkableAreaBuilder(