Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make vehicleRentalStation query optionally accept id without feed #5411

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
61 changes: 31 additions & 30 deletions docs/Configuration.md
Expand Up @@ -219,36 +219,37 @@ Here is a list of all features which can be toggled on/off and their default val
<!-- OTP-FEATURE-TABLE BEGIN -->
<!-- NOTE! This section is auto-generated. Do not change, change doc in code instead. -->

| Feature | Description | Enabled by default | Sandbox |
|--------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:------------------:|:-------:|
| `APIBikeRental` | Enable the bike rental endpoint. | ✓️ | |
| `APIServerInfo` | Enable the server info endpoint. | ✓️ | |
| `APIGraphInspectorTile` | Enable the inspector endpoint for graph information for inspection/debugging purpose. | ✓️ | |
| `APIUpdaterStatus` | Enable endpoint for graph updaters status. | ✓️ | |
| `ConsiderPatternsForDirectTransfers` | Enable limiting transfers so that there is only a single transfer to each pattern. | ✓️ | |
| `DebugClient` | Enable the debug web client located at the root of the web server. | ✓️ | |
| `FloatingBike` | Enable floating bike routing. | ✓️ | |
| `GtfsGraphQlApi` | Enable GTFS GraphQL API. | ✓️ | |
| `MinimumTransferTimeIsDefinitive` | If the minimum transfer time is a lower bound (default) or the definitive time for the transfer. Set this to `true` if you want to set a transfer time lower than what OTP derives from OSM data. | | |
| `OptimizeTransfers` | OTP will inspect all itineraries found and optimize where (which stops) the transfer will happen. Waiting time, priority and guaranteed transfers are taken into account. | ✓️ | |
| `ParallelRouting` | Enable performing parts of the trip planning in parallel. | | |
| `TransferConstraints` | Enforce transfers to happen according to the _transfers.txt_(GTFS) and Interchanges(NeTEx). Turing this _off_ will increase the routing performance a little. | ✓️ | |
| `ActuatorAPI` | Endpoint for actuators (service health status). | | ✓️ |
| `AsyncGraphQLFetchers` | Whether the @async annotation in the GraphQL schema should lead to the fetch being executed asynchronously. This allows batch or alias queries to run in parallel at the cost of consuming extra threads. | | |
| `DataOverlay` | Enable usage of data overlay when calculating costs for the street network. | | ✓️ |
| `FaresV2` | Enable import of GTFS-Fares v2 data. | | ✓️ |
| `FlexRouting` | Enable FLEX routing. | | ✓️ |
| `GoogleCloudStorage` | Enable Google Cloud Storage integration. | | ✓️ |
| `RealtimeResolver` | When routing with ignoreRealtimeUpdates=true, add an extra step which populates results with realtime data | | ✓️ |
| `ReportApi` | Enable the report API. | | ✓️ |
| `RestAPIPassInDefaultConfigAsJson` | Enable a default RouteRequest to be passed in as JSON on the REST API - FOR DEBUGGING ONLY! | | |
| `SandboxAPIGeocoder` | Enable the Geocoder API. | | ✓️ |
| `SandboxAPIMapboxVectorTilesApi` | Enable Mapbox vector tiles API. | | ✓️ |
| `SandboxAPIParkAndRideApi` | Enable park-and-ride endpoint. | | ✓️ |
| `SandboxAPITransmodelApi` | Enable Entur Transmodel(NeTEx) GraphQL API. | | ✓️ |
| `SandboxAPITravelTime` | Enable the isochrone/travel time surface API. | | ✓️ |
| `TransferAnalyzer` | Analyze transfers during graph build. | | ✓️ |
| `VehicleToStopHeuristics` | Enable improved heuristic for park-and-ride queries. | | ✓️ |
| Feature | Description | Enabled by default | Sandbox |
|--------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:------------------:|:-------:|
| `APIBikeRental` | Enable the bike rental endpoint. | ✓️ | |
| `APIServerInfo` | Enable the server info endpoint. | ✓️ | |
| `APIGraphInspectorTile` | Enable the inspector endpoint for graph information for inspection/debugging purpose. | ✓️ | |
| `APIUpdaterStatus` | Enable endpoint for graph updaters status. | ✓️ | |
| `ConsiderPatternsForDirectTransfers` | Enable limiting transfers so that there is only a single transfer to each pattern. | ✓️ | |
| `DebugClient` | Enable the debug web client located at the root of the web server. | ✓️ | |
| `FloatingBike` | Enable floating bike routing. | ✓️ | |
| `GtfsGraphQlApi` | Enable GTFS GraphQL API. | ✓️ | |
| `GtfsGraphQlApiRentalStationFuzzyMatching` | Does vehicleRentalStation query also allow ids that are not feed scoped. | | |
| `MinimumTransferTimeIsDefinitive` | If the minimum transfer time is a lower bound (default) or the definitive time for the transfer. Set this to `true` if you want to set a transfer time lower than what OTP derives from OSM data. | | |
| `OptimizeTransfers` | OTP will inspect all itineraries found and optimize where (which stops) the transfer will happen. Waiting time, priority and guaranteed transfers are taken into account. | ✓️ | |
| `ParallelRouting` | Enable performing parts of the trip planning in parallel. | | |
| `TransferConstraints` | Enforce transfers to happen according to the _transfers.txt_(GTFS) and Interchanges(NeTEx). Turing this _off_ will increase the routing performance a little. | ✓️ | |
| `ActuatorAPI` | Endpoint for actuators (service health status). | | ✓️ |
| `AsyncGraphQLFetchers` | Whether the @async annotation in the GraphQL schema should lead to the fetch being executed asynchronously. This allows batch or alias queries to run in parallel at the cost of consuming extra threads. | | |
| `DataOverlay` | Enable usage of data overlay when calculating costs for the street network. | | ✓️ |
| `FaresV2` | Enable import of GTFS-Fares v2 data. | | ✓️ |
| `FlexRouting` | Enable FLEX routing. | | ✓️ |
| `GoogleCloudStorage` | Enable Google Cloud Storage integration. | | ✓️ |
| `RealtimeResolver` | When routing with ignoreRealtimeUpdates=true, add an extra step which populates results with realtime data | | ✓️ |
| `ReportApi` | Enable the report API. | | ✓️ |
| `RestAPIPassInDefaultConfigAsJson` | Enable a default RouteRequest to be passed in as JSON on the REST API - FOR DEBUGGING ONLY! | | |
| `SandboxAPIGeocoder` | Enable the Geocoder API. | | ✓️ |
| `SandboxAPIMapboxVectorTilesApi` | Enable Mapbox vector tiles API. | | ✓️ |
| `SandboxAPIParkAndRideApi` | Enable park-and-ride endpoint. | | ✓️ |
| `SandboxAPITransmodelApi` | Enable Entur Transmodel(NeTEx) GraphQL API. | | ✓️ |
| `SandboxAPITravelTime` | Enable the isochrone/travel time surface API. | | ✓️ |
| `TransferAnalyzer` | Analyze transfers during graph build. | | ✓️ |
| `VehicleToStopHeuristics` | Enable improved heuristic for park-and-ride queries. | | ✓️ |

<!-- OTP-FEATURE-TABLE END -->

Expand Down
Expand Up @@ -33,6 +33,7 @@
import org.opentripplanner.ext.fares.impl.DefaultFareService;
import org.opentripplanner.ext.fares.impl.GtfsFaresService;
import org.opentripplanner.ext.fares.model.FareRuleSet;
import org.opentripplanner.framework.application.OTPFeature;
import org.opentripplanner.framework.time.ServiceDateUtils;
import org.opentripplanner.graph_builder.issue.api.DataImportIssueStore;
import org.opentripplanner.gtfs.mapping.DirectionMapper;
Expand Down Expand Up @@ -841,11 +842,16 @@ public DataFetcher<VehicleRentalStation> vehicleRentalStation() {
.<GraphQLRequestContext>getContext()
.vehicleRentalService();

var id = args.getGraphQLId();

// TODO the fuzzy matching can be potentially removed after a while.
return vehicleRentalStationService
.getVehicleRentalStations()
.stream()
.filter(vehicleRentalStation ->
vehicleRentalStation.getId().toString().equals(args.getGraphQLId())
OTPFeature.GtfsGraphQlApiRentalStationFuzzyMatching.isOn()
? stationIdFuzzyMatches(vehicleRentalStation, id)
: stationIdMatches(vehicleRentalStation, id)
)
.findAny()
.orElse(null);
Expand Down Expand Up @@ -890,6 +896,28 @@ public DataFetcher<Object> viewer() {
return environment -> new Object();
}

/**
* This matches station's feedScopedId to the given string.
*/
private boolean stationIdMatches(VehicleRentalStation station, String feedScopedId) {
return station.getId().toString().equals(feedScopedId);
}

/**
* This matches station's feedScopedId to the given string if the string is feed scoped (i.e
* contains a `:` separator) or only matches the station's id without the feed to the given
* string. This approach can lead to a random station matching the criteria if there are multiple
* stations with the same id in different feeds.
* <p>
* TODO this can be potentially removed after a while, only used by Digitransit as of now.
*/
private boolean stationIdFuzzyMatches(VehicleRentalStation station, String idWithoutFeed) {
if (idWithoutFeed != null && idWithoutFeed.contains(":")) {
return stationIdMatches(station, idWithoutFeed);
}
return station.getId().getId().equals(idWithoutFeed);
}

private TransitService getTransitService(DataFetchingEnvironment environment) {
return environment.<GraphQLRequestContext>getContext().transitService();
}
Expand Down