From 125e8b29e6e597cff90ea0739fa975afdf60201f Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Fri, 29 Nov 2024 08:13:25 +0100 Subject: [PATCH 1/7] Remove fare service from Graph --- .../ScheduledDeviatedTripIntegrationTest.java | 3 +- .../fares/configure/FareServiceModule.java | 14 ++++++++++ .../StopConsolidationServiceModule.java | 28 +++++++++++++++++++ .../apis/gtfs/GraphQLRequestContext.java | 2 +- .../gtfs/graphbuilder/GtfsModule.java | 6 ++-- .../GTFSToOtpTransitServiceMapper.java | 3 +- .../RouteRequestToFilterChainMapper.java | 2 +- .../routing/fares/FareService.java | 2 +- .../opentripplanner/routing/graph/Graph.java | 11 -------- .../api/OtpServerRequestContext.java | 3 ++ .../ConstructApplicationFactory.java | 5 ++++ .../configure/ConstructApplicationModule.java | 7 +++-- .../server/DefaultServerRequestContext.java | 17 +++++++++-- .../mapping/TripRequestMapperTest.java | 4 ++- 14 files changed, 81 insertions(+), 26 deletions(-) create mode 100644 application/src/ext/java/org/opentripplanner/ext/fares/configure/FareServiceModule.java create mode 100644 application/src/ext/java/org/opentripplanner/ext/fares/configure/StopConsolidationServiceModule.java diff --git a/application/src/ext-test/java/org/opentripplanner/ext/flex/trip/ScheduledDeviatedTripIntegrationTest.java b/application/src/ext-test/java/org/opentripplanner/ext/flex/trip/ScheduledDeviatedTripIntegrationTest.java index 3a8e33cfbf2..7fb7b825c97 100644 --- a/application/src/ext-test/java/org/opentripplanner/ext/flex/trip/ScheduledDeviatedTripIntegrationTest.java +++ b/application/src/ext-test/java/org/opentripplanner/ext/flex/trip/ScheduledDeviatedTripIntegrationTest.java @@ -18,6 +18,7 @@ import org.opentripplanner.TestServerContext; import org.opentripplanner._support.time.ZoneIds; import org.opentripplanner.ext.fares.DecorateWithFare; +import org.opentripplanner.ext.fares.impl.DefaultFareService; import org.opentripplanner.ext.flex.FlexIntegrationTestData; import org.opentripplanner.ext.flex.FlexParameters; import org.opentripplanner.ext.flex.FlexRouter; @@ -112,7 +113,7 @@ void calculateDirectFare() { List.of(to) ); - var filter = new DecorateWithFare(graph.getFareService()); + var filter = new DecorateWithFare(new DefaultFareService()); var itineraries = router .createFlexOnlyItineraries(false) diff --git a/application/src/ext/java/org/opentripplanner/ext/fares/configure/FareServiceModule.java b/application/src/ext/java/org/opentripplanner/ext/fares/configure/FareServiceModule.java new file mode 100644 index 00000000000..5b6269f6a89 --- /dev/null +++ b/application/src/ext/java/org/opentripplanner/ext/fares/configure/FareServiceModule.java @@ -0,0 +1,14 @@ +package org.opentripplanner.ext.fares.configure; + +import dagger.Module; +import dagger.Provides; +import org.opentripplanner.routing.fares.FareService; +import org.opentripplanner.standalone.config.BuildConfig; + +@Module +public class FareServiceModule { + @Provides + FareService bindRepository(BuildConfig config) { + return config.fareServiceFactory.makeFareService(); + }; +} diff --git a/application/src/ext/java/org/opentripplanner/ext/fares/configure/StopConsolidationServiceModule.java b/application/src/ext/java/org/opentripplanner/ext/fares/configure/StopConsolidationServiceModule.java new file mode 100644 index 00000000000..820ddaee86b --- /dev/null +++ b/application/src/ext/java/org/opentripplanner/ext/fares/configure/StopConsolidationServiceModule.java @@ -0,0 +1,28 @@ +package org.opentripplanner.ext.fares.configure; + +import dagger.Module; +import dagger.Provides; +import jakarta.inject.Singleton; +import javax.annotation.Nullable; +import org.opentripplanner.ext.stopconsolidation.StopConsolidationRepository; +import org.opentripplanner.ext.stopconsolidation.StopConsolidationService; +import org.opentripplanner.ext.stopconsolidation.internal.DefaultStopConsolidationService; +import org.opentripplanner.transit.service.TimetableRepository; + +@Module +public class StopConsolidationServiceModule { + + @Provides + @Singleton + @Nullable + StopConsolidationService service( + @Nullable StopConsolidationRepository repo, + TimetableRepository tm + ) { + if (repo == null) { + return null; + } else { + return new DefaultStopConsolidationService(repo, tm); + } + } +} diff --git a/application/src/main/java/org/opentripplanner/apis/gtfs/GraphQLRequestContext.java b/application/src/main/java/org/opentripplanner/apis/gtfs/GraphQLRequestContext.java index c3ca214b62f..76876b53e4a 100644 --- a/application/src/main/java/org/opentripplanner/apis/gtfs/GraphQLRequestContext.java +++ b/application/src/main/java/org/opentripplanner/apis/gtfs/GraphQLRequestContext.java @@ -24,7 +24,7 @@ public static GraphQLRequestContext ofServerContext(OtpServerRequestContext cont return new GraphQLRequestContext( context.routingService(), context.transitService(), - context.graph().getFareService(), + context.fareService(), context.vehicleRentalService(), context.vehicleParkingService(), context.realtimeVehicleService(), diff --git a/application/src/main/java/org/opentripplanner/gtfs/graphbuilder/GtfsModule.java b/application/src/main/java/org/opentripplanner/gtfs/graphbuilder/GtfsModule.java index 39f88f13281..19236cc003b 100644 --- a/application/src/main/java/org/opentripplanner/gtfs/graphbuilder/GtfsModule.java +++ b/application/src/main/java/org/opentripplanner/gtfs/graphbuilder/GtfsModule.java @@ -142,7 +142,7 @@ public void buildGraph() { mapper.mapStopTripAndRouteDataIntoBuilder(); OtpTransitServiceBuilder builder = mapper.getBuilder(); - var fareRulesService = mapper.getFareRulesService(); + var fareRulesData = mapper.fareRulesData(); builder.limitServiceDays(transitPeriodLimit); @@ -195,8 +195,8 @@ public void buildGraph() { .run(otpTransitService.getTripPatterns()); } - fareServiceFactory.processGtfs(fareRulesService, otpTransitService); - graph.setFareService(fareServiceFactory.makeFareService()); + fareServiceFactory.processGtfs(fareRulesData, otpTransitService); + var fareService = fareServiceFactory.makeFareService(); } } catch (IOException e) { throw new RuntimeException(e); diff --git a/application/src/main/java/org/opentripplanner/gtfs/mapping/GTFSToOtpTransitServiceMapper.java b/application/src/main/java/org/opentripplanner/gtfs/mapping/GTFSToOtpTransitServiceMapper.java index 8e3718be4c6..e1f287027c2 100644 --- a/application/src/main/java/org/opentripplanner/gtfs/mapping/GTFSToOtpTransitServiceMapper.java +++ b/application/src/main/java/org/opentripplanner/gtfs/mapping/GTFSToOtpTransitServiceMapper.java @@ -138,12 +138,11 @@ public OtpTransitServiceBuilder getBuilder() { return builder; } - public FareRulesData getFareRulesService() { + public FareRulesData fareRulesData() { return fareRulesBuilder; } public void mapStopTripAndRouteDataIntoBuilder() { - var siteRepository = builder.siteRepository(); translationHelper.importTranslations(data.getAllTranslations(), data.getAllFeedInfos()); builder.getAgenciesById().addAll(agencyMapper.map(data.getAllAgencies())); diff --git a/application/src/main/java/org/opentripplanner/routing/algorithm/mapping/RouteRequestToFilterChainMapper.java b/application/src/main/java/org/opentripplanner/routing/algorithm/mapping/RouteRequestToFilterChainMapper.java index 277efda3810..e4ebda2fd97 100644 --- a/application/src/main/java/org/opentripplanner/routing/algorithm/mapping/RouteRequestToFilterChainMapper.java +++ b/application/src/main/java/org/opentripplanner/routing/algorithm/mapping/RouteRequestToFilterChainMapper.java @@ -99,7 +99,7 @@ public static ItineraryListFilterChain createFilterChain( builder.withTransitGroupPriority(); } - var fareService = context.graph().getFareService(); + var fareService = context.fareService(); if (fareService != null) { builder.withFareDecorator(new DecorateWithFare(fareService)); } diff --git a/application/src/main/java/org/opentripplanner/routing/fares/FareService.java b/application/src/main/java/org/opentripplanner/routing/fares/FareService.java index af850a5c5a9..3c1ecc4f41e 100644 --- a/application/src/main/java/org/opentripplanner/routing/fares/FareService.java +++ b/application/src/main/java/org/opentripplanner/routing/fares/FareService.java @@ -5,7 +5,7 @@ import org.opentripplanner.model.plan.Itinerary; /** - * Computes a fare for a given sequence of Rides. The FareService is serialized as part of the + * Computes a fare for a given sequence of legs. The FareService is serialized as part of the * Graph; Hence it should be {@link Serializable}. */ public interface FareService extends Serializable { diff --git a/application/src/main/java/org/opentripplanner/routing/graph/Graph.java b/application/src/main/java/org/opentripplanner/routing/graph/Graph.java index 70ce563700c..658d32629e5 100644 --- a/application/src/main/java/org/opentripplanner/routing/graph/Graph.java +++ b/application/src/main/java/org/opentripplanner/routing/graph/Graph.java @@ -18,7 +18,6 @@ import org.opentripplanner.framework.geometry.CompactElevationProfile; import org.opentripplanner.framework.geometry.GeometryUtils; import org.opentripplanner.model.calendar.openinghours.OpeningHoursCalendarService; -import org.opentripplanner.routing.fares.FareService; import org.opentripplanner.routing.graph.index.StreetIndex; import org.opentripplanner.routing.linking.VertexLinker; import org.opentripplanner.routing.services.notes.StreetNotesService; @@ -110,8 +109,6 @@ public class Graph implements Serializable { // static variable in CompactElevationProfile in SerializedGraphObject private double distanceBetweenElevationSamples; - private FareService fareService; - /** * Hack. I've tried three different ways of generating unique labels. Previously we were just * tolerating edge label collisions. For some reason we're repeatedly generating splits on the @@ -360,14 +357,6 @@ public void setDistanceBetweenElevationSamples(double distanceBetweenElevationSa CompactElevationProfile.setDistanceBetweenSamplesM(distanceBetweenElevationSamples); } - public FareService getFareService() { - return fareService; - } - - public void setFareService(FareService fareService) { - this.fareService = fareService; - } - private void indexIfNotIndexed(SiteRepository siteRepository) { if (streetIndex == null) { index(siteRepository); diff --git a/application/src/main/java/org/opentripplanner/standalone/api/OtpServerRequestContext.java b/application/src/main/java/org/opentripplanner/standalone/api/OtpServerRequestContext.java index b5b39ddee18..4e09f027a5b 100644 --- a/application/src/main/java/org/opentripplanner/standalone/api/OtpServerRequestContext.java +++ b/application/src/main/java/org/opentripplanner/standalone/api/OtpServerRequestContext.java @@ -20,6 +20,7 @@ import org.opentripplanner.routing.algorithm.raptoradapter.transit.TripSchedule; import org.opentripplanner.routing.api.RoutingService; import org.opentripplanner.routing.api.request.RouteRequest; +import org.opentripplanner.routing.fares.FareService; import org.opentripplanner.routing.graph.Graph; import org.opentripplanner.routing.graphfinder.GraphFinder; import org.opentripplanner.service.realtimevehicles.RealtimeVehicleService; @@ -150,4 +151,6 @@ default DataOverlayContext dataOverlayContext(RouteRequest request) { @Nullable SorlandsbanenNorwayService sorlandsbanenService(); + + FareService fareService(); } diff --git a/application/src/main/java/org/opentripplanner/standalone/configure/ConstructApplicationFactory.java b/application/src/main/java/org/opentripplanner/standalone/configure/ConstructApplicationFactory.java index d6310c0c616..47d16ac5634 100644 --- a/application/src/main/java/org/opentripplanner/standalone/configure/ConstructApplicationFactory.java +++ b/application/src/main/java/org/opentripplanner/standalone/configure/ConstructApplicationFactory.java @@ -6,6 +6,7 @@ import javax.annotation.Nullable; import org.opentripplanner.ext.emissions.EmissionsDataModel; import org.opentripplanner.ext.emissions.EmissionsServiceModule; +import org.opentripplanner.ext.fares.configure.FareServiceModule; import org.opentripplanner.ext.geocoder.LuceneIndex; import org.opentripplanner.ext.geocoder.configure.GeocoderModule; import org.opentripplanner.ext.interactivelauncher.configuration.InteractiveLauncherModule; @@ -17,6 +18,7 @@ import org.opentripplanner.graph_builder.issue.api.DataImportIssueSummary; import org.opentripplanner.raptor.configure.RaptorConfig; import org.opentripplanner.routing.algorithm.raptoradapter.transit.TripSchedule; +import org.opentripplanner.routing.fares.FareService; import org.opentripplanner.routing.graph.Graph; import org.opentripplanner.service.realtimevehicles.RealtimeVehicleRepository; import org.opentripplanner.service.realtimevehicles.RealtimeVehicleService; @@ -66,6 +68,7 @@ InteractiveLauncherModule.class, StreetLimitationParametersServiceModule.class, GeocoderModule.class, + FareServiceModule.class, } ) public interface ConstructApplicationFactory { @@ -105,6 +108,8 @@ public interface ConstructApplicationFactory { @Nullable LuceneIndex luceneIndex(); + FareService fareService(); + @Component.Builder interface Builder { @BindsInstance diff --git a/application/src/main/java/org/opentripplanner/standalone/configure/ConstructApplicationModule.java b/application/src/main/java/org/opentripplanner/standalone/configure/ConstructApplicationModule.java index bbdd39c57d5..6d40893a576 100644 --- a/application/src/main/java/org/opentripplanner/standalone/configure/ConstructApplicationModule.java +++ b/application/src/main/java/org/opentripplanner/standalone/configure/ConstructApplicationModule.java @@ -14,6 +14,7 @@ import org.opentripplanner.ext.stopconsolidation.StopConsolidationService; import org.opentripplanner.raptor.configure.RaptorConfig; import org.opentripplanner.routing.algorithm.raptoradapter.transit.TripSchedule; +import org.opentripplanner.routing.fares.FareService; import org.opentripplanner.routing.graph.Graph; import org.opentripplanner.service.realtimevehicles.RealtimeVehicleService; import org.opentripplanner.service.vehicleparking.VehicleParkingService; @@ -46,7 +47,8 @@ OtpServerRequestContext providesServerContext( EmissionsService emissionsService, @Nullable SorlandsbanenNorwayService sorlandsbanenService, LauncherRequestDecorator launcherRequestDecorator, - @Nullable LuceneIndex luceneIndex + @Nullable LuceneIndex luceneIndex, + FareService fareService ) { var defaultRequest = launcherRequestDecorator.intercept(routerConfig.routingRequestDefaults()); @@ -69,7 +71,8 @@ OtpServerRequestContext providesServerContext( stopConsolidationService, streetLimitationParametersService, traverseVisitor, - luceneIndex + luceneIndex, + fareService ); } diff --git a/application/src/main/java/org/opentripplanner/standalone/server/DefaultServerRequestContext.java b/application/src/main/java/org/opentripplanner/standalone/server/DefaultServerRequestContext.java index 1427dcf1971..2be04dd3f44 100644 --- a/application/src/main/java/org/opentripplanner/standalone/server/DefaultServerRequestContext.java +++ b/application/src/main/java/org/opentripplanner/standalone/server/DefaultServerRequestContext.java @@ -18,6 +18,7 @@ import org.opentripplanner.routing.algorithm.raptoradapter.transit.TripSchedule; import org.opentripplanner.routing.api.RoutingService; import org.opentripplanner.routing.api.request.RouteRequest; +import org.opentripplanner.routing.fares.FareService; import org.opentripplanner.routing.graph.Graph; import org.opentripplanner.routing.service.DefaultRoutingService; import org.opentripplanner.service.realtimevehicles.RealtimeVehicleService; @@ -57,6 +58,7 @@ public class DefaultServerRequestContext implements OtpServerRequestContext { private final StopConsolidationService stopConsolidationService; private final StreetLimitationParametersService streetLimitationParametersService; private final LuceneIndex luceneIndex; + private final FareService fareService; private RouteRequest defaultRouteRequestWithTimeSet = null; @@ -83,7 +85,8 @@ private DefaultServerRequestContext( StreetLimitationParametersService streetLimitationParametersService, FlexParameters flexParameters, @Nullable TraverseVisitor traverseVisitor, - @Nullable LuceneIndex luceneIndex + @Nullable LuceneIndex luceneIndex, + FareService fareService ) { this.graph = graph; this.transitService = transitService; @@ -105,6 +108,7 @@ private DefaultServerRequestContext( this.stopConsolidationService = stopConsolidationService; this.streetLimitationParametersService = streetLimitationParametersService; this.luceneIndex = luceneIndex; + this.fareService = fareService; } /** @@ -129,7 +133,8 @@ public static DefaultServerRequestContext create( @Nullable StopConsolidationService stopConsolidationService, StreetLimitationParametersService streetLimitationParametersService, @Nullable TraverseVisitor traverseVisitor, - @Nullable LuceneIndex luceneIndex + @Nullable LuceneIndex luceneIndex, + FareService fareService ) { return new DefaultServerRequestContext( graph, @@ -151,7 +156,8 @@ public static DefaultServerRequestContext create( streetLimitationParametersService, flexParameters, traverseVisitor, - luceneIndex + luceneIndex, + fareService ); } @@ -277,4 +283,9 @@ public EmissionsService emissionsService() { public SorlandsbanenNorwayService sorlandsbanenService() { return sorlandsbanenService; } + + @Override + public FareService fareService() { + return fareService; + } } diff --git a/application/src/test/java/org/opentripplanner/apis/transmodel/mapping/TripRequestMapperTest.java b/application/src/test/java/org/opentripplanner/apis/transmodel/mapping/TripRequestMapperTest.java index b3c64e0aecb..7d982a20f5d 100644 --- a/application/src/test/java/org/opentripplanner/apis/transmodel/mapping/TripRequestMapperTest.java +++ b/application/src/test/java/org/opentripplanner/apis/transmodel/mapping/TripRequestMapperTest.java @@ -31,6 +31,7 @@ import org.opentripplanner.apis.transmodel.TransmodelRequestContext; import org.opentripplanner.ext.emissions.DefaultEmissionsService; import org.opentripplanner.ext.emissions.EmissionsDataModel; +import org.opentripplanner.ext.fares.impl.NoopFareServiceFactory; import org.opentripplanner.graph_builder.issue.api.DataImportIssueStore; import org.opentripplanner.model.calendar.CalendarServiceData; import org.opentripplanner.model.plan.Itinerary; @@ -154,7 +155,8 @@ void setup() { null, new DefaultStreetLimitationParametersService(new StreetLimitationParameters()), null, - null + null, + new NoopFareServiceFactory().makeFareService() ), null, transitService From b70c09f06ca6eecbcc1ef455fc315b8abfd51017 Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Fri, 29 Nov 2024 08:21:25 +0100 Subject: [PATCH 2/7] Fix tests --- .../StopConsolidationServiceModule.java | 28 ------------------- .../opentripplanner/TestServerContext.java | 4 ++- .../transit/speed_test/SpeedTest.java | 4 ++- 3 files changed, 6 insertions(+), 30 deletions(-) delete mode 100644 application/src/ext/java/org/opentripplanner/ext/fares/configure/StopConsolidationServiceModule.java diff --git a/application/src/ext/java/org/opentripplanner/ext/fares/configure/StopConsolidationServiceModule.java b/application/src/ext/java/org/opentripplanner/ext/fares/configure/StopConsolidationServiceModule.java deleted file mode 100644 index 820ddaee86b..00000000000 --- a/application/src/ext/java/org/opentripplanner/ext/fares/configure/StopConsolidationServiceModule.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.opentripplanner.ext.fares.configure; - -import dagger.Module; -import dagger.Provides; -import jakarta.inject.Singleton; -import javax.annotation.Nullable; -import org.opentripplanner.ext.stopconsolidation.StopConsolidationRepository; -import org.opentripplanner.ext.stopconsolidation.StopConsolidationService; -import org.opentripplanner.ext.stopconsolidation.internal.DefaultStopConsolidationService; -import org.opentripplanner.transit.service.TimetableRepository; - -@Module -public class StopConsolidationServiceModule { - - @Provides - @Singleton - @Nullable - StopConsolidationService service( - @Nullable StopConsolidationRepository repo, - TimetableRepository tm - ) { - if (repo == null) { - return null; - } else { - return new DefaultStopConsolidationService(repo, tm); - } - } -} diff --git a/application/src/test/java/org/opentripplanner/TestServerContext.java b/application/src/test/java/org/opentripplanner/TestServerContext.java index e20720bd7d8..948f1bc5fc7 100644 --- a/application/src/test/java/org/opentripplanner/TestServerContext.java +++ b/application/src/test/java/org/opentripplanner/TestServerContext.java @@ -7,6 +7,7 @@ import org.opentripplanner.ext.emissions.DefaultEmissionsService; import org.opentripplanner.ext.emissions.EmissionsDataModel; import org.opentripplanner.ext.emissions.EmissionsService; +import org.opentripplanner.ext.fares.impl.DefaultFareService; import org.opentripplanner.raptor.configure.RaptorConfig; import org.opentripplanner.routing.graph.Graph; import org.opentripplanner.service.realtimevehicles.RealtimeVehicleService; @@ -65,7 +66,8 @@ public static OtpServerRequestContext createServerContext( null, createStreetLimitationParametersService(), null, - null + null, + new DefaultFareService() ); creatTransitLayerForRaptor(timetableRepository, routerConfig.transitTuningConfig()); return context; diff --git a/application/src/test/java/org/opentripplanner/transit/speed_test/SpeedTest.java b/application/src/test/java/org/opentripplanner/transit/speed_test/SpeedTest.java index c55ddff854f..2ca06e3e16e 100644 --- a/application/src/test/java/org/opentripplanner/transit/speed_test/SpeedTest.java +++ b/application/src/test/java/org/opentripplanner/transit/speed_test/SpeedTest.java @@ -15,6 +15,7 @@ import java.util.function.Predicate; import org.opentripplanner.TestServerContext; import org.opentripplanner.datastore.OtpDataStore; +import org.opentripplanner.ext.fares.impl.DefaultFareService; import org.opentripplanner.framework.application.OtpAppException; import org.opentripplanner.model.plan.Itinerary; import org.opentripplanner.raptor.configure.RaptorConfig; @@ -130,7 +131,8 @@ public SpeedTest( null, TestServerContext.createStreetLimitationParametersService(), null, - null + null, + new DefaultFareService() ); // Creating transitLayerForRaptor should be integrated into the TimetableRepository, but for now // we do it manually here From 58aae9fbca134e3f0d2087dd917b3ed8f973add0 Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Fri, 29 Nov 2024 10:07:50 +0100 Subject: [PATCH 3/7] Save fare service in graph explicitly --- .../ext/fares/impl/FaresIntegrationTest.java | 4 +- .../ext/flex/FlexIntegrationTest.java | 15 ++-- .../ext/flex/FlexIntegrationTestData.java | 6 +- .../ScheduledDeviatedTripIntegrationTest.java | 72 +------------------ .../vectortiles/VectorTilesResourceTest.java | 3 +- .../fares/configure/FareServiceModule.java | 2 + .../gtfs/graphbuilder/GtfsModule.java | 18 ----- .../routing/graph/SerializedGraphObject.java | 6 +- .../opentripplanner/standalone/OTPMain.java | 3 +- .../opentripplanner/ConstantsForTests.java | 13 ++-- .../java/org/opentripplanner/GtfsTest.java | 14 +++- .../org/opentripplanner/TestOtpModel.java | 12 +++- .../opentripplanner/TestServerContext.java | 7 +- .../resources/PlannerResourceTest.java | 7 +- .../graph_builder/module/GtfsModuleTest.java | 14 +++- .../vector/VectorTileResponseFactoryTest.java | 4 +- .../algorithm/mapping/SnapshotTestBase.java | 6 +- .../routing/graph/GraphSerializationTest.java | 13 ++-- 18 files changed, 94 insertions(+), 125 deletions(-) diff --git a/application/src/ext-test/java/org/opentripplanner/ext/fares/impl/FaresIntegrationTest.java b/application/src/ext-test/java/org/opentripplanner/ext/fares/impl/FaresIntegrationTest.java index f5ad2b471ab..74a54794461 100644 --- a/application/src/ext-test/java/org/opentripplanner/ext/fares/impl/FaresIntegrationTest.java +++ b/application/src/ext-test/java/org/opentripplanner/ext/fares/impl/FaresIntegrationTest.java @@ -34,7 +34,7 @@ public void testBasic() { var feedId = timetableRepository.getFeedIds().iterator().next(); - var serverContext = TestServerContext.createServerContext(graph, timetableRepository); + var serverContext = TestServerContext.createServerContext(graph, timetableRepository, model.fareServiceFactory().makeFareService()); var start = LocalDateTime .of(2009, Month.AUGUST, 7, 12, 0, 0) @@ -56,7 +56,7 @@ public void testPortland() { TimetableRepository timetableRepository = model.timetableRepository(); var portlandId = timetableRepository.getFeedIds().iterator().next(); - var serverContext = TestServerContext.createServerContext(graph, timetableRepository); + var serverContext = TestServerContext.createServerContext(graph, timetableRepository, model.fareServiceFactory().makeFareService()); // from zone 3 to zone 2 var from = GenericLocation.fromStopId( diff --git a/application/src/ext-test/java/org/opentripplanner/ext/flex/FlexIntegrationTest.java b/application/src/ext-test/java/org/opentripplanner/ext/flex/FlexIntegrationTest.java index fb19f1dff36..51143fb3a40 100644 --- a/application/src/ext-test/java/org/opentripplanner/ext/flex/FlexIntegrationTest.java +++ b/application/src/ext-test/java/org/opentripplanner/ext/flex/FlexIntegrationTest.java @@ -18,6 +18,7 @@ import org.junit.jupiter.api.Test; import org.opentripplanner.TestOtpModel; import org.opentripplanner.TestServerContext; +import org.opentripplanner.ext.fares.impl.DefaultFareServiceFactory; import org.opentripplanner.framework.application.OTPFeature; import org.opentripplanner.graph_builder.issue.api.DataImportIssueStore; import org.opentripplanner.graph_builder.module.DirectTransferGenerator; @@ -32,6 +33,7 @@ import org.opentripplanner.routing.api.request.RouteRequest; import org.opentripplanner.routing.api.request.framework.TimeAndCostPenalty; import org.opentripplanner.routing.api.request.request.filter.AllowAllTransitFilter; +import org.opentripplanner.routing.fares.FareServiceFactory; import org.opentripplanner.routing.graph.Graph; import org.opentripplanner.transit.service.TimetableRepository; @@ -58,7 +60,6 @@ static void setup() { TestOtpModel model = FlexIntegrationTestData.cobbOsm(); graph = model.graph(); timetableRepository = model.timetableRepository(); - addGtfsToGraph( graph, timetableRepository, @@ -66,9 +67,10 @@ static void setup() { FlexIntegrationTestData.COBB_BUS_30_GTFS, FlexIntegrationTestData.MARTA_BUS_856_GTFS, FlexIntegrationTestData.COBB_FLEX_GTFS - ) + ), + new DefaultFareServiceFactory() ); - service = TestServerContext.createServerContext(graph, timetableRepository).routingService(); + service = TestServerContext.createServerContext(graph, timetableRepository, model.fareServiceFactory().makeFareService()).routingService(); } @Test @@ -179,7 +181,8 @@ static void teardown() { private static void addGtfsToGraph( Graph graph, TimetableRepository timetableRepository, - List gtfsFiles + List gtfsFiles, + FareServiceFactory fareServiceFactory ) { // GTFS var gtfsBundles = gtfsFiles.stream().map(GtfsBundle::new).toList(); @@ -187,7 +190,9 @@ private static void addGtfsToGraph( gtfsBundles, timetableRepository, graph, - ServiceDateInterval.unbounded() + DataImportIssueStore.NOOP, + ServiceDateInterval.unbounded(), + fareServiceFactory ); gtfsModule.buildGraph(); diff --git a/application/src/ext-test/java/org/opentripplanner/ext/flex/FlexIntegrationTestData.java b/application/src/ext-test/java/org/opentripplanner/ext/flex/FlexIntegrationTestData.java index 87106394708..76f10fa18d0 100644 --- a/application/src/ext-test/java/org/opentripplanner/ext/flex/FlexIntegrationTestData.java +++ b/application/src/ext-test/java/org/opentripplanner/ext/flex/FlexIntegrationTestData.java @@ -8,7 +8,9 @@ import java.util.Map; import org.opentripplanner.ConstantsForTests; import org.opentripplanner.TestOtpModel; +import org.opentripplanner.ext.fares.impl.DefaultFareServiceFactory; import org.opentripplanner.framework.application.OTPFeature; +import org.opentripplanner.graph_builder.issue.api.DataImportIssueStore; import org.opentripplanner.gtfs.graphbuilder.GtfsBundle; import org.opentripplanner.gtfs.graphbuilder.GtfsModule; import org.opentripplanner.model.calendar.ServiceDateInterval; @@ -49,7 +51,9 @@ private static TestOtpModel buildFlexGraph(File file) { List.of(gtfsBundle), timetableRepository, graph, - new ServiceDateInterval(LocalDate.of(2021, 1, 1), LocalDate.of(2022, 1, 1)) + DataImportIssueStore.NOOP, + new ServiceDateInterval(LocalDate.of(2021, 1, 1), LocalDate.of(2022, 1, 1)), + new DefaultFareServiceFactory() ); OTPFeature.enableFeatures(Map.of(OTPFeature.FlexRouting, true)); module.buildGraph(); diff --git a/application/src/ext-test/java/org/opentripplanner/ext/flex/trip/ScheduledDeviatedTripIntegrationTest.java b/application/src/ext-test/java/org/opentripplanner/ext/flex/trip/ScheduledDeviatedTripIntegrationTest.java index 7fb7b825c97..acfb2607fef 100644 --- a/application/src/ext-test/java/org/opentripplanner/ext/flex/trip/ScheduledDeviatedTripIntegrationTest.java +++ b/application/src/ext-test/java/org/opentripplanner/ext/flex/trip/ScheduledDeviatedTripIntegrationTest.java @@ -6,25 +6,17 @@ import java.time.LocalDateTime; import java.time.Month; -import java.time.OffsetDateTime; import java.util.List; -import java.util.Map; import java.util.Set; import java.util.stream.Collectors; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import org.locationtech.jts.geom.Coordinate; import org.opentripplanner.TestOtpModel; import org.opentripplanner.TestServerContext; import org.opentripplanner._support.time.ZoneIds; -import org.opentripplanner.ext.fares.DecorateWithFare; import org.opentripplanner.ext.fares.impl.DefaultFareService; import org.opentripplanner.ext.flex.FlexIntegrationTestData; -import org.opentripplanner.ext.flex.FlexParameters; -import org.opentripplanner.ext.flex.FlexRouter; -import org.opentripplanner.framework.application.OTPFeature; import org.opentripplanner.framework.geometry.EncodedPolyline; -import org.opentripplanner.framework.i18n.I18NString; import org.opentripplanner.graph_builder.module.ValidateAndInterpolateStopTimesForEachTrip; import org.opentripplanner.model.GenericLocation; import org.opentripplanner.model.StopTime; @@ -35,15 +27,9 @@ import org.opentripplanner.routing.api.request.request.filter.AllowAllTransitFilter; import org.opentripplanner.routing.framework.DebugTimingAggregator; import org.opentripplanner.routing.graph.Graph; -import org.opentripplanner.routing.graphfinder.NearbyStop; import org.opentripplanner.standalone.api.OtpServerRequestContext; -import org.opentripplanner.street.model.vertex.StreetLocation; -import org.opentripplanner.street.search.request.StreetSearchRequest; -import org.opentripplanner.street.search.state.State; import org.opentripplanner.transit.model.framework.FeedScopedId; import org.opentripplanner.transit.model.network.grouppriority.TransitGroupPriorityService; -import org.opentripplanner.transit.model.site.AreaStop; -import org.opentripplanner.transit.service.DefaultTransitService; import org.opentripplanner.transit.service.TimetableRepository; import org.opentripplanner.utils.time.ServiceDateUtils; @@ -93,41 +79,6 @@ void parseCobbCountyAsScheduledDeviatedTrip() { assertEquals(-84.63430143459385, flexZone.getLon(), delta); } - @Test - void calculateDirectFare() { - OTPFeature.enableFeatures(Map.of(OTPFeature.FlexRouting, true)); - var trip = getFlexTrip(); - - var from = getNearbyStop(trip, "from-stop"); - var to = getNearbyStop(trip, "to-stop"); - - var router = new FlexRouter( - graph, - new DefaultTransitService(timetableRepository), - FlexParameters.defaultValues(), - OffsetDateTime.parse("2021-11-12T10:15:24-05:00").toInstant(), - null, - 1, - 1, - List.of(from), - List.of(to) - ); - - var filter = new DecorateWithFare(new DefaultFareService()); - - var itineraries = router - .createFlexOnlyItineraries(false) - .stream() - .peek(filter::decorate) - .toList(); - - var itinerary = itineraries.getFirst(); - - assertFalse(itinerary.getFares().getLegProducts().isEmpty()); - - OTPFeature.enableFeatures(Map.of(OTPFeature.FlexRouting, false)); - } - /** * Trips which consist of flex and fixed-schedule stops should work in transit mode. *

@@ -138,7 +89,7 @@ void calculateDirectFare() { void flexTripInTransitMode() { var feedId = timetableRepository.getFeedIds().iterator().next(); - var serverContext = TestServerContext.createServerContext(graph, timetableRepository); + var serverContext = TestServerContext.createServerContext(graph, timetableRepository, new DefaultFareService()); // from zone 3 to zone 2 var from = GenericLocation.fromStopId("Transfer Point for Route 30", feedId, "cujv"); @@ -224,27 +175,6 @@ private static List getItineraries( return result.getItineraries(); } - private static NearbyStop getNearbyStop(FlexTrip trip, String id) { - // getStops() returns a set of stops and the order doesn't correspond to the stop times - // of the trip - var stopLocation = trip - .getStops() - .stream() - .filter(s -> s instanceof AreaStop) - .findFirst() - .orElseThrow(); - - return new NearbyStop( - stopLocation, - 0, - List.of(), - new State( - new StreetLocation(id, new Coordinate(0, 0), I18NString.of(id)), - StreetSearchRequest.of().build() - ) - ); - } - private static FlexTrip getFlexTrip() { var feedId = timetableRepository.getFeedIds().iterator().next(); var tripId = new FeedScopedId(feedId, "a326c618-d42c-4bd1-9624-c314fbf8ecd8"); diff --git a/application/src/ext-test/java/org/opentripplanner/ext/vectortiles/VectorTilesResourceTest.java b/application/src/ext-test/java/org/opentripplanner/ext/vectortiles/VectorTilesResourceTest.java index be379fb6fa6..ad945bd2fa2 100644 --- a/application/src/ext-test/java/org/opentripplanner/ext/vectortiles/VectorTilesResourceTest.java +++ b/application/src/ext-test/java/org/opentripplanner/ext/vectortiles/VectorTilesResourceTest.java @@ -6,6 +6,7 @@ import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.opentripplanner.TestServerContext; +import org.opentripplanner.ext.fares.impl.DefaultFareService; import org.opentripplanner.routing.graph.Graph; import org.opentripplanner.test.support.HttpForTest; import org.opentripplanner.transit.service.TimetableRepository; @@ -17,7 +18,7 @@ void tileJson() { // the Grizzly request is awful to instantiate, using Mockito var grizzlyRequest = Mockito.mock(Request.class); var resource = new VectorTilesResource( - TestServerContext.createServerContext(new Graph(), new TimetableRepository()), + TestServerContext.createServerContext(new Graph(), new TimetableRepository(), new DefaultFareService()), grizzlyRequest, "default" ); diff --git a/application/src/ext/java/org/opentripplanner/ext/fares/configure/FareServiceModule.java b/application/src/ext/java/org/opentripplanner/ext/fares/configure/FareServiceModule.java index 5b6269f6a89..341af9fdd9a 100644 --- a/application/src/ext/java/org/opentripplanner/ext/fares/configure/FareServiceModule.java +++ b/application/src/ext/java/org/opentripplanner/ext/fares/configure/FareServiceModule.java @@ -2,12 +2,14 @@ import dagger.Module; import dagger.Provides; +import jakarta.inject.Singleton; import org.opentripplanner.routing.fares.FareService; import org.opentripplanner.standalone.config.BuildConfig; @Module public class FareServiceModule { @Provides + @Singleton FareService bindRepository(BuildConfig config) { return config.fareServiceFactory.makeFareService(); }; diff --git a/application/src/main/java/org/opentripplanner/gtfs/graphbuilder/GtfsModule.java b/application/src/main/java/org/opentripplanner/gtfs/graphbuilder/GtfsModule.java index 19236cc003b..98dc5df8b88 100644 --- a/application/src/main/java/org/opentripplanner/gtfs/graphbuilder/GtfsModule.java +++ b/application/src/main/java/org/opentripplanner/gtfs/graphbuilder/GtfsModule.java @@ -30,7 +30,6 @@ import org.onebusaway.gtfs.serialization.GtfsReader; import org.onebusaway.gtfs.services.GenericMutableDao; import org.onebusaway.gtfs.services.GtfsMutableRelationalDao; -import org.opentripplanner.ext.fares.impl.DefaultFareServiceFactory; import org.opentripplanner.ext.flex.FlexTripsMapper; import org.opentripplanner.framework.application.OTPFeature; import org.opentripplanner.graph_builder.issue.api.DataImportIssueStore; @@ -98,22 +97,6 @@ public GtfsModule( this.fareServiceFactory = fareServiceFactory; } - public GtfsModule( - List bundles, - TimetableRepository timetableRepository, - Graph graph, - ServiceDateInterval transitPeriodLimit - ) { - this( - bundles, - timetableRepository, - graph, - DataImportIssueStore.NOOP, - transitPeriodLimit, - new DefaultFareServiceFactory() - ); - } - @Override public void buildGraph() { CalendarServiceData calendarServiceData = new CalendarServiceData(); @@ -196,7 +179,6 @@ public void buildGraph() { } fareServiceFactory.processGtfs(fareRulesData, otpTransitService); - var fareService = fareServiceFactory.makeFareService(); } } catch (IOException e) { throw new RuntimeException(e); diff --git a/application/src/main/java/org/opentripplanner/routing/graph/SerializedGraphObject.java b/application/src/main/java/org/opentripplanner/routing/graph/SerializedGraphObject.java index a152b96682d..242d1ea9a0d 100644 --- a/application/src/main/java/org/opentripplanner/routing/graph/SerializedGraphObject.java +++ b/application/src/main/java/org/opentripplanner/routing/graph/SerializedGraphObject.java @@ -24,6 +24,7 @@ import org.opentripplanner.graph_builder.issue.api.DataImportIssueSummary; import org.opentripplanner.model.projectinfo.GraphFileHeader; import org.opentripplanner.model.projectinfo.OtpProjectInfo; +import org.opentripplanner.routing.fares.FareService; import org.opentripplanner.routing.graph.kryosupport.KryoBuilder; import org.opentripplanner.service.vehicleparking.VehicleParkingRepository; import org.opentripplanner.service.worldenvelope.WorldEnvelopeRepository; @@ -79,6 +80,7 @@ public class SerializedGraphObject implements Serializable { public final StopConsolidationRepository stopConsolidationRepository; private final int routingTripPatternCounter; public final EmissionsDataModel emissionsDataModel; + public final FareService fareService; public final StreetLimitationParameters streetLimitationParameters; public final VehicleParkingRepository parkingRepository; @@ -92,7 +94,8 @@ public SerializedGraphObject( DataImportIssueSummary issueSummary, EmissionsDataModel emissionsDataModel, StopConsolidationRepository stopConsolidationRepository, - StreetLimitationParameters streetLimitationParameters + StreetLimitationParameters streetLimitationParameters, + FareService fareService ) { this.graph = graph; this.edges = graph.getEdges(); @@ -107,6 +110,7 @@ public SerializedGraphObject( this.routingTripPatternCounter = RoutingTripPattern.indexCounter(); this.stopConsolidationRepository = stopConsolidationRepository; this.streetLimitationParameters = streetLimitationParameters; + this.fareService = fareService; } public static void verifyTheOutputGraphIsWritableIfDataSourceExist(DataSource graphOutput) { diff --git a/application/src/main/java/org/opentripplanner/standalone/OTPMain.java b/application/src/main/java/org/opentripplanner/standalone/OTPMain.java index ade5067a981..74d4da621d5 100644 --- a/application/src/main/java/org/opentripplanner/standalone/OTPMain.java +++ b/application/src/main/java/org/opentripplanner/standalone/OTPMain.java @@ -158,7 +158,8 @@ private static void startOTPServer(CommandLineParameters cli) { DataImportIssueSummary.combine(graphBuilder.issueSummary(), app.dataImportIssueSummary()), app.emissionsDataModel(), app.stopConsolidationRepository(), - app.streetLimitationParameters() + app.streetLimitationParameters(), + app.buildConfig().fareServiceFactory.makeFareService() ) .save(app.graphOutputDataSource()); // Log size info for the deduplicator diff --git a/application/src/test/java/org/opentripplanner/ConstantsForTests.java b/application/src/test/java/org/opentripplanner/ConstantsForTests.java index e5ab48cee54..be2b4019b08 100644 --- a/application/src/test/java/org/opentripplanner/ConstantsForTests.java +++ b/application/src/test/java/org/opentripplanner/ConstantsForTests.java @@ -135,6 +135,7 @@ public static TestOtpModel buildNewPortlandGraph(boolean withElevation) { var deduplicator = new Deduplicator(); var graph = new Graph(deduplicator); var timetableRepository = new TimetableRepository(new SiteRepository(), deduplicator); + var fareFactory = new DefaultFareServiceFactory(); // Add street data from OSM { OsmProvider osmProvider = new OsmProvider(PORTLAND_CENTRAL_OSM, false); @@ -147,13 +148,7 @@ public static TestOtpModel buildNewPortlandGraph(boolean withElevation) { } // Add transit data from GTFS { - addGtfsToGraph( - graph, - timetableRepository, - PORTLAND_GTFS, - new DefaultFareServiceFactory(), - "prt" - ); + addGtfsToGraph(graph, timetableRepository, PORTLAND_GTFS, fareFactory, "prt"); } // Link transit stops to streets TestStreetLinkerModule.link(graph, timetableRepository); @@ -182,7 +177,7 @@ public static TestOtpModel buildNewPortlandGraph(boolean withElevation) { graph.index(timetableRepository.getSiteRepository()); - return new TestOtpModel(graph, timetableRepository); + return new TestOtpModel(graph, timetableRepository, fareFactory); } catch (Exception e) { throw new RuntimeException(e); } @@ -233,7 +228,7 @@ public static TestOtpModel buildGtfsGraph(File gtfsFile, FareServiceFactory fare var graph = new Graph(deduplicator); var timetableRepository = new TimetableRepository(siteRepository, deduplicator); addGtfsToGraph(graph, timetableRepository, gtfsFile, fareServiceFactory, null); - return new TestOtpModel(graph, timetableRepository); + return new TestOtpModel(graph, timetableRepository, fareServiceFactory); } public static TestOtpModel buildNewMinimalNetexGraph() { diff --git a/application/src/test/java/org/opentripplanner/GtfsTest.java b/application/src/test/java/org/opentripplanner/GtfsTest.java index 5d548e4012c..d59938ad7ed 100644 --- a/application/src/test/java/org/opentripplanner/GtfsTest.java +++ b/application/src/test/java/org/opentripplanner/GtfsTest.java @@ -21,6 +21,8 @@ import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.opentripplanner.api.common.LocationStringParser; +import org.opentripplanner.ext.fares.impl.DefaultFareServiceFactory; +import org.opentripplanner.graph_builder.issue.api.DataImportIssueStore; import org.opentripplanner.graph_builder.module.GtfsFeedId; import org.opentripplanner.gtfs.graphbuilder.GtfsBundle; import org.opentripplanner.gtfs.graphbuilder.GtfsModule; @@ -197,17 +199,25 @@ protected void setUp() throws Exception { graph = new Graph(deduplicator); timetableRepository = new TimetableRepository(new SiteRepository(), deduplicator); + var fareServiceFactory = new DefaultFareServiceFactory(); GtfsModule gtfsGraphBuilderImpl = new GtfsModule( gtfsBundleList, timetableRepository, graph, - ServiceDateInterval.unbounded() + DataImportIssueStore.NOOP, + ServiceDateInterval.unbounded(), + fareServiceFactory ); gtfsGraphBuilderImpl.buildGraph(); timetableRepository.index(); graph.index(timetableRepository.getSiteRepository()); - serverContext = TestServerContext.createServerContext(graph, timetableRepository); + serverContext = + TestServerContext.createServerContext( + graph, + timetableRepository, + fareServiceFactory.makeFareService() + ); timetableSnapshotSource = new TimetableSnapshotSource( TimetableSnapshotSourceParameters.DEFAULT diff --git a/application/src/test/java/org/opentripplanner/TestOtpModel.java b/application/src/test/java/org/opentripplanner/TestOtpModel.java index 62b5fce3416..55613e9f77c 100644 --- a/application/src/test/java/org/opentripplanner/TestOtpModel.java +++ b/application/src/test/java/org/opentripplanner/TestOtpModel.java @@ -1,9 +1,19 @@ package org.opentripplanner; +import org.opentripplanner.ext.fares.impl.DefaultFareServiceFactory; +import org.opentripplanner.routing.fares.FareServiceFactory; import org.opentripplanner.routing.graph.Graph; import org.opentripplanner.transit.service.TimetableRepository; -public record TestOtpModel(Graph graph, TimetableRepository timetableRepository) { +public record TestOtpModel( + Graph graph, + TimetableRepository timetableRepository, + FareServiceFactory fareServiceFactory +) { + public TestOtpModel(Graph graph, TimetableRepository timetableRepository) { + this(graph, timetableRepository, new DefaultFareServiceFactory()); + } + public TestOtpModel index() { timetableRepository.index(); graph.index(timetableRepository.getSiteRepository()); diff --git a/application/src/test/java/org/opentripplanner/TestServerContext.java b/application/src/test/java/org/opentripplanner/TestServerContext.java index 948f1bc5fc7..201f189b62d 100644 --- a/application/src/test/java/org/opentripplanner/TestServerContext.java +++ b/application/src/test/java/org/opentripplanner/TestServerContext.java @@ -7,8 +7,8 @@ import org.opentripplanner.ext.emissions.DefaultEmissionsService; import org.opentripplanner.ext.emissions.EmissionsDataModel; import org.opentripplanner.ext.emissions.EmissionsService; -import org.opentripplanner.ext.fares.impl.DefaultFareService; import org.opentripplanner.raptor.configure.RaptorConfig; +import org.opentripplanner.routing.fares.FareService; import org.opentripplanner.routing.graph.Graph; import org.opentripplanner.service.realtimevehicles.RealtimeVehicleService; import org.opentripplanner.service.realtimevehicles.internal.DefaultRealtimeVehicleService; @@ -39,7 +39,8 @@ private TestServerContext() {} /** Create a context for unit testing, using the default RouteRequest. */ public static OtpServerRequestContext createServerContext( Graph graph, - TimetableRepository timetableRepository + TimetableRepository timetableRepository, + FareService fareService ) { timetableRepository.index(); final RouterConfig routerConfig = RouterConfig.DEFAULT; @@ -67,7 +68,7 @@ public static OtpServerRequestContext createServerContext( createStreetLimitationParametersService(), null, null, - new DefaultFareService() + fareService ); creatTransitLayerForRaptor(timetableRepository, routerConfig.transitTuningConfig()); return context; diff --git a/application/src/test/java/org/opentripplanner/ext/restapi/resources/PlannerResourceTest.java b/application/src/test/java/org/opentripplanner/ext/restapi/resources/PlannerResourceTest.java index dc924ac765a..621b40a0ac4 100644 --- a/application/src/test/java/org/opentripplanner/ext/restapi/resources/PlannerResourceTest.java +++ b/application/src/test/java/org/opentripplanner/ext/restapi/resources/PlannerResourceTest.java @@ -12,6 +12,7 @@ import org.opentripplanner.TestServerContext; import org.opentripplanner._support.time.ZoneIds; import org.opentripplanner.api.parameter.QualifiedModeSet; +import org.opentripplanner.ext.fares.impl.DefaultFareService; import org.opentripplanner.routing.api.request.RequestModes; import org.opentripplanner.routing.graph.Graph; import org.opentripplanner.standalone.api.OtpServerRequestContext; @@ -22,7 +23,11 @@ class PlannerResourceTest { static OtpServerRequestContext context() { var timetableRepository = new TimetableRepository(); timetableRepository.initTimeZone(ZoneIds.BERLIN); - return TestServerContext.createServerContext(new Graph(), timetableRepository); + return TestServerContext.createServerContext( + new Graph(), + timetableRepository, + new DefaultFareService() + ); } @Test diff --git a/application/src/test/java/org/opentripplanner/graph_builder/module/GtfsModuleTest.java b/application/src/test/java/org/opentripplanner/graph_builder/module/GtfsModuleTest.java index 75f7077eb7d..c041c433b7e 100644 --- a/application/src/test/java/org/opentripplanner/graph_builder/module/GtfsModuleTest.java +++ b/application/src/test/java/org/opentripplanner/graph_builder/module/GtfsModuleTest.java @@ -12,6 +12,8 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.opentripplanner.ConstantsForTests; +import org.opentripplanner.ext.fares.impl.DefaultFareServiceFactory; +import org.opentripplanner.graph_builder.issue.api.DataImportIssueStore; import org.opentripplanner.gtfs.graphbuilder.GtfsBundle; import org.opentripplanner.gtfs.graphbuilder.GtfsModule; import org.opentripplanner.model.calendar.ServiceDateInterval; @@ -32,7 +34,9 @@ void addShapesForFrequencyTrips() { List.of(bundle), model.timetableRepository, model.graph, - ServiceDateInterval.unbounded() + DataImportIssueStore.NOOP, + ServiceDateInterval.unbounded(), + new DefaultFareServiceFactory() ); module.buildGraph(); @@ -63,7 +67,9 @@ void duplicateFeedId() { bundles, model.timetableRepository, model.graph, - ServiceDateInterval.unbounded() + DataImportIssueStore.NOOP, + ServiceDateInterval.unbounded(), + new DefaultFareServiceFactory() ); assertThrows(IllegalArgumentException.class, module::buildGraph); } @@ -111,7 +117,9 @@ void interline(List bundles, int expectedTransfers) { bundles, model.timetableRepository, model.graph, - ServiceDateInterval.unbounded() + DataImportIssueStore.NOOP, + ServiceDateInterval.unbounded(), + new DefaultFareServiceFactory() ); module.buildGraph(); diff --git a/application/src/test/java/org/opentripplanner/inspector/vector/VectorTileResponseFactoryTest.java b/application/src/test/java/org/opentripplanner/inspector/vector/VectorTileResponseFactoryTest.java index 6c874c7108f..12da84a4bb2 100644 --- a/application/src/test/java/org/opentripplanner/inspector/vector/VectorTileResponseFactoryTest.java +++ b/application/src/test/java/org/opentripplanner/inspector/vector/VectorTileResponseFactoryTest.java @@ -8,6 +8,7 @@ import java.util.Locale; import org.junit.jupiter.api.Test; import org.opentripplanner.TestServerContext; +import org.opentripplanner.ext.fares.impl.DefaultFareService; import org.opentripplanner.inspector.vector.geofencing.GeofencingZonesLayerBuilder; import org.opentripplanner.routing.graph.Graph; import org.opentripplanner.standalone.api.OtpServerRequestContext; @@ -17,7 +18,8 @@ class VectorTileResponseFactoryTest { public static final OtpServerRequestContext SERVER_CONTEXT = TestServerContext.createServerContext( new Graph(), - new TimetableRepository() + new TimetableRepository(), + new DefaultFareService() ); enum LayerType { diff --git a/application/src/test/java/org/opentripplanner/routing/algorithm/mapping/SnapshotTestBase.java b/application/src/test/java/org/opentripplanner/routing/algorithm/mapping/SnapshotTestBase.java index cab308c092b..fee4515f2b9 100644 --- a/application/src/test/java/org/opentripplanner/routing/algorithm/mapping/SnapshotTestBase.java +++ b/application/src/test/java/org/opentripplanner/routing/algorithm/mapping/SnapshotTestBase.java @@ -86,7 +86,11 @@ protected OtpServerRequestContext serverContext() { if (serverContext == null) { TestOtpModel model = getGraph(); serverContext = - TestServerContext.createServerContext(model.graph(), model.timetableRepository()); + TestServerContext.createServerContext( + model.graph(), + model.timetableRepository(), + model.fareServiceFactory().makeFareService() + ); } return serverContext; diff --git a/application/src/test/java/org/opentripplanner/routing/graph/GraphSerializationTest.java b/application/src/test/java/org/opentripplanner/routing/graph/GraphSerializationTest.java index 400a9eba2ba..cb2b9caaf65 100644 --- a/application/src/test/java/org/opentripplanner/routing/graph/GraphSerializationTest.java +++ b/application/src/test/java/org/opentripplanner/routing/graph/GraphSerializationTest.java @@ -23,6 +23,7 @@ import org.opentripplanner.ext.emissions.EmissionsDataModel; import org.opentripplanner.framework.geometry.HashGridSpatialIndex; import org.opentripplanner.graph_builder.issue.api.DataImportIssueSummary; +import org.opentripplanner.routing.fares.FareServiceFactory; import org.opentripplanner.service.vehicleparking.VehicleParkingRepository; import org.opentripplanner.service.vehicleparking.internal.DefaultVehicleParkingRepository; import org.opentripplanner.service.worldenvelope.WorldEnvelopeRepository; @@ -75,7 +76,8 @@ public void testRoundTripSerializationForGTFSGraph() throws Exception { model.timetableRepository(), weRepo, parkingRepository, - emissionsDataModel + emissionsDataModel, + model.fareServiceFactory() ); } @@ -93,7 +95,8 @@ public void testRoundTripSerializationForNetexGraph() throws Exception { model.timetableRepository(), worldEnvelopeRepository, parkingRepository, - emissionsDataModel + emissionsDataModel, + model.fareServiceFactory() ); } @@ -194,7 +197,8 @@ private void testRoundTrip( TimetableRepository originalTimetableRepository, WorldEnvelopeRepository worldEnvelopeRepository, VehicleParkingRepository vehicleParkingRepository, - EmissionsDataModel emissionsDataModel + EmissionsDataModel emissionsDataModel, + FareServiceFactory fareServiceFactory ) throws Exception { // Now round-trip the graph through serialization. File tempFile = TempFile.createTempFile("graph", "pdx"); @@ -210,7 +214,8 @@ private void testRoundTrip( DataImportIssueSummary.empty(), emissionsDataModel, null, - streetLimitationParameters + streetLimitationParameters, + fareServiceFactory.makeFareService() ); serializedObj.save(new FileDataSource(tempFile, FileType.GRAPH)); SerializedGraphObject deserializedGraph = SerializedGraphObject.load(tempFile); From 223eb951566712cfb3b999638a697d4153785b43 Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Fri, 29 Nov 2024 11:04:30 +0100 Subject: [PATCH 4/7] Store fare service in Graph --- .../ext/fares/configure/FareServiceModule.java | 16 ---------------- .../configure/ConstructApplication.java | 5 ++++- .../configure/ConstructApplicationFactory.java | 7 ++++--- .../standalone/configure/LoadApplication.java | 14 ++++++++++---- 4 files changed, 18 insertions(+), 24 deletions(-) delete mode 100644 application/src/ext/java/org/opentripplanner/ext/fares/configure/FareServiceModule.java diff --git a/application/src/ext/java/org/opentripplanner/ext/fares/configure/FareServiceModule.java b/application/src/ext/java/org/opentripplanner/ext/fares/configure/FareServiceModule.java deleted file mode 100644 index 341af9fdd9a..00000000000 --- a/application/src/ext/java/org/opentripplanner/ext/fares/configure/FareServiceModule.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.opentripplanner.ext.fares.configure; - -import dagger.Module; -import dagger.Provides; -import jakarta.inject.Singleton; -import org.opentripplanner.routing.fares.FareService; -import org.opentripplanner.standalone.config.BuildConfig; - -@Module -public class FareServiceModule { - @Provides - @Singleton - FareService bindRepository(BuildConfig config) { - return config.fareServiceFactory.makeFareService(); - }; -} diff --git a/application/src/main/java/org/opentripplanner/standalone/configure/ConstructApplication.java b/application/src/main/java/org/opentripplanner/standalone/configure/ConstructApplication.java index eb3fae5275f..8fdaddb53a0 100644 --- a/application/src/main/java/org/opentripplanner/standalone/configure/ConstructApplication.java +++ b/application/src/main/java/org/opentripplanner/standalone/configure/ConstructApplication.java @@ -17,6 +17,7 @@ import org.opentripplanner.routing.algorithm.raptoradapter.transit.TripSchedule; import org.opentripplanner.routing.algorithm.raptoradapter.transit.mappers.TransitLayerMapper; import org.opentripplanner.routing.algorithm.raptoradapter.transit.mappers.TransitLayerUpdater; +import org.opentripplanner.routing.fares.FareService; import org.opentripplanner.routing.graph.Graph; import org.opentripplanner.service.realtimevehicles.RealtimeVehicleRepository; import org.opentripplanner.service.vehicleparking.VehicleParkingRepository; @@ -79,7 +80,8 @@ public class ConstructApplication { EmissionsDataModel emissionsDataModel, VehicleParkingRepository vehicleParkingRepository, @Nullable StopConsolidationRepository stopConsolidationRepository, - StreetLimitationParameters streetLimitationParameters + StreetLimitationParameters streetLimitationParameters, + FareService fareService ) { this.cli = cli; this.graphBuilderDataSources = graphBuilderDataSources; @@ -101,6 +103,7 @@ public class ConstructApplication { .dataImportIssueSummary(issueSummary) .stopConsolidationRepository(stopConsolidationRepository) .streetLimitationParameters(streetLimitationParameters) + .fareService(fareService) .build(); } diff --git a/application/src/main/java/org/opentripplanner/standalone/configure/ConstructApplicationFactory.java b/application/src/main/java/org/opentripplanner/standalone/configure/ConstructApplicationFactory.java index 47d16ac5634..dfcc91b9c88 100644 --- a/application/src/main/java/org/opentripplanner/standalone/configure/ConstructApplicationFactory.java +++ b/application/src/main/java/org/opentripplanner/standalone/configure/ConstructApplicationFactory.java @@ -6,7 +6,6 @@ import javax.annotation.Nullable; import org.opentripplanner.ext.emissions.EmissionsDataModel; import org.opentripplanner.ext.emissions.EmissionsServiceModule; -import org.opentripplanner.ext.fares.configure.FareServiceModule; import org.opentripplanner.ext.geocoder.LuceneIndex; import org.opentripplanner.ext.geocoder.configure.GeocoderModule; import org.opentripplanner.ext.interactivelauncher.configuration.InteractiveLauncherModule; @@ -67,8 +66,7 @@ StopConsolidationServiceModule.class, InteractiveLauncherModule.class, StreetLimitationParametersServiceModule.class, - GeocoderModule.class, - FareServiceModule.class, + GeocoderModule.class } ) public interface ConstructApplicationFactory { @@ -144,6 +142,9 @@ Builder stopConsolidationRepository( @BindsInstance Builder streetLimitationParameters(StreetLimitationParameters streetLimitationParameters); + @BindsInstance + Builder fareService(FareService fareService); + ConstructApplicationFactory build(); } } diff --git a/application/src/main/java/org/opentripplanner/standalone/configure/LoadApplication.java b/application/src/main/java/org/opentripplanner/standalone/configure/LoadApplication.java index 021af778345..48d7506cd32 100644 --- a/application/src/main/java/org/opentripplanner/standalone/configure/LoadApplication.java +++ b/application/src/main/java/org/opentripplanner/standalone/configure/LoadApplication.java @@ -3,9 +3,11 @@ import javax.annotation.Nullable; import org.opentripplanner.datastore.api.DataSource; import org.opentripplanner.ext.emissions.EmissionsDataModel; +import org.opentripplanner.ext.fares.impl.DefaultFareService; import org.opentripplanner.ext.stopconsolidation.StopConsolidationRepository; import org.opentripplanner.graph_builder.GraphBuilderDataSources; import org.opentripplanner.graph_builder.issue.api.DataImportIssueSummary; +import org.opentripplanner.routing.fares.FareService; import org.opentripplanner.routing.graph.Graph; import org.opentripplanner.routing.graph.SerializedGraphObject; import org.opentripplanner.service.vehicleparking.VehicleParkingRepository; @@ -61,7 +63,8 @@ public ConstructApplication appConstruction(SerializedGraphObject obj) { obj.issueSummary, obj.emissionsDataModel, obj.stopConsolidationRepository, - obj.streetLimitationParameters + obj.streetLimitationParameters, + obj.fareService ); } @@ -75,7 +78,8 @@ public ConstructApplication appConstruction() { DataImportIssueSummary.empty(), factory.emptyEmissionsDataModel(), factory.emptyStopConsolidationRepository(), - factory.emptyStreetLimitationParameters() + factory.emptyStreetLimitationParameters(), + new DefaultFareService() ); } @@ -98,7 +102,8 @@ private ConstructApplication createAppConstruction( DataImportIssueSummary issueSummary, @Nullable EmissionsDataModel emissionsDataModel, @Nullable StopConsolidationRepository stopConsolidationRepository, - StreetLimitationParameters streetLimitationParameters + StreetLimitationParameters streetLimitationParameters, + FareService fareService ) { return new ConstructApplication( cli, @@ -111,7 +116,8 @@ private ConstructApplication createAppConstruction( emissionsDataModel, parkingRepository, stopConsolidationRepository, - streetLimitationParameters + streetLimitationParameters, + fareService ); } } From a234a9360e4de24cf5b54cefd92995c75c1a5de0 Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Fri, 29 Nov 2024 11:47:38 +0100 Subject: [PATCH 5/7] Convert record to class --- .../opentripplanner/ext/fares/DecorateWithFare.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/application/src/ext/java/org/opentripplanner/ext/fares/DecorateWithFare.java b/application/src/ext/java/org/opentripplanner/ext/fares/DecorateWithFare.java index a47392a3fbf..ada8db821fb 100644 --- a/application/src/ext/java/org/opentripplanner/ext/fares/DecorateWithFare.java +++ b/application/src/ext/java/org/opentripplanner/ext/fares/DecorateWithFare.java @@ -6,10 +6,14 @@ /** * Computes the fares of an itinerary and adds them. - *

- * TODO: Convert to a class - exposing a service in a DTO is a risk. */ -public record DecorateWithFare(FareService fareService) implements ItineraryDecorator { +public final class DecorateWithFare implements ItineraryDecorator { + private final FareService fareService; + + public DecorateWithFare(FareService fareService) { + this.fareService = fareService; + } + @Override public void decorate(Itinerary itinerary) { var fare = fareService.calculateFares(itinerary); @@ -18,4 +22,5 @@ public void decorate(Itinerary itinerary) { FaresToItineraryMapper.addFaresToLegs(fare, itinerary); } } + } From c19f2ff67acc0a4be36b6a126ada465eb816f904 Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Fri, 29 Nov 2024 12:06:53 +0100 Subject: [PATCH 6/7] Fix formatting --- .../standalone/configure/ConstructApplicationFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/opentripplanner/standalone/configure/ConstructApplicationFactory.java b/application/src/main/java/org/opentripplanner/standalone/configure/ConstructApplicationFactory.java index dfcc91b9c88..efd732b057b 100644 --- a/application/src/main/java/org/opentripplanner/standalone/configure/ConstructApplicationFactory.java +++ b/application/src/main/java/org/opentripplanner/standalone/configure/ConstructApplicationFactory.java @@ -66,7 +66,7 @@ StopConsolidationServiceModule.class, InteractiveLauncherModule.class, StreetLimitationParametersServiceModule.class, - GeocoderModule.class + GeocoderModule.class, } ) public interface ConstructApplicationFactory { From 0a49291897c7aa2120c068beee6a815385b4e0b0 Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Tue, 10 Dec 2024 21:11:39 +0100 Subject: [PATCH 7/7] Resolve merge --- .../standalone/server/DefaultServerRequestContext.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/opentripplanner/standalone/server/DefaultServerRequestContext.java b/application/src/main/java/org/opentripplanner/standalone/server/DefaultServerRequestContext.java index 6832779ac0e..30770a5be70 100644 --- a/application/src/main/java/org/opentripplanner/standalone/server/DefaultServerRequestContext.java +++ b/application/src/main/java/org/opentripplanner/standalone/server/DefaultServerRequestContext.java @@ -111,6 +111,8 @@ private DefaultServerRequestContext( this.stopConsolidationService = stopConsolidationService; this.streetLimitationParametersService = streetLimitationParametersService; this.luceneIndex = luceneIndex; + this.debugUiConfig = debugUiConfig; + this.fareService = fareService; } /** @@ -160,8 +162,8 @@ public static DefaultServerRequestContext create( flexParameters, traverseVisitor, luceneIndex, - fareService, - debugUiConfig + debugUiConfig, + fareService ); }