diff --git a/docs/sandbox/VehicleRentalServiceDirectory.md b/docs/sandbox/VehicleRentalServiceDirectory.md index 2952a743ea3..29a45ebb062 100644 --- a/docs/sandbox/VehicleRentalServiceDirectory.md +++ b/docs/sandbox/VehicleRentalServiceDirectory.md @@ -28,17 +28,17 @@ the `router-config.json` -| Config Parameter | Type | Summary | Req./Opt. | Default Value | Since | -|-----------------------------------------------------|:---------------:|----------------------------------------------------------------------------|:----------:|---------------|:-----:| -| language | `string` | Language code. | *Optional* | | 2.1 | -| sourcesName | `string` | Json tag name for updater sources. | *Optional* | `"systems"` | 2.1 | -| updaterNetworkName | `string` | Json tag name for the network name for each source. | *Optional* | `"id"` | 2.1 | -| updaterUrlName | `string` | Json tag name for endpoint urls for each source. | *Optional* | `"url"` | 2.1 | -| url | `uri` | Endpoint for the VehicleRentalServiceDirectory | *Required* | | 2.1 | -| [headers](#vehicleRentalServiceDirectory_headers) | `map of string` | HTTP headers to add to the request. Any header key, value can be inserted. | *Optional* | | 2.1 | -| [networks](#vehicleRentalServiceDirectory_networks) | `object[]` | List all networks to include. | *Optional* | | 2.4 | -|       geofencingZones | `boolean` | Enables geofencingZones for the given network | *Optional* | `false` | 2.4 | -|       network | `string` | The network name | *Required* | | 2.4 | +| Config Parameter | Type | Summary | Req./Opt. | Default Value | Since | +|-----------------------------------------------------|:---------------:|---------------------------------------------------------------------------------|:----------:|---------------|:-----:| +| language | `string` | Language code. | *Optional* | | 2.1 | +| sourcesName | `string` | Json tag name for updater sources. | *Optional* | `"systems"` | 2.1 | +| updaterNetworkName | `string` | Json tag name for the network name for each source. | *Optional* | `"id"` | 2.1 | +| updaterUrlName | `string` | Json tag name for endpoint urls for each source. | *Optional* | `"url"` | 2.1 | +| url | `uri` | Endpoint for the VehicleRentalServiceDirectory | *Required* | | 2.1 | +| [headers](#vehicleRentalServiceDirectory_headers) | `map of string` | HTTP headers to add to the request. Any header key, value can be inserted. | *Optional* | | 2.1 | +| [networks](#vehicleRentalServiceDirectory_networks) | `object[]` | List all networks to include. Use "network": "default-network" to set defaults. | *Optional* | | 2.4 | +|       geofencingZones | `boolean` | Enables geofencingZones for the given network | *Optional* | `false` | 2.4 | +|       network | `string` | The network name | *Required* | | 2.4 | @@ -60,7 +60,13 @@ HTTP headers to add to the request. Any header key, value can be inserted. **Since version:** `2.4` ∙ **Type:** `object[]` ∙ **Cardinality:** `Optional` **Path:** /vehicleRentalServiceDirectory -List all networks to include. +List all networks to include. Use "network": "default-network" to set defaults. + +If no default network exist only the listed networks are used. Configure the a network +with name "default-network" to include all unlisted networks. If not present, all +unlisted networks is dropped. Note! The values int the "default-network" is not used to +set missing field values in networks listed. + diff --git a/src/ext/java/org/opentripplanner/ext/vehiclerentalservicedirectory/api/NetworkParameters.java b/src/ext/java/org/opentripplanner/ext/vehiclerentalservicedirectory/api/NetworkParameters.java index 8fb1142e4d0..2f4ae49de62 100644 --- a/src/ext/java/org/opentripplanner/ext/vehiclerentalservicedirectory/api/NetworkParameters.java +++ b/src/ext/java/org/opentripplanner/ext/vehiclerentalservicedirectory/api/NetworkParameters.java @@ -12,4 +12,8 @@ * @param network The network name * @param geofencingZones enable geofencingZones for the given network */ -public record NetworkParameters(String network, boolean geofencingZones) {} +public record NetworkParameters(String network, boolean geofencingZones) { + public NetworkParameters withName(String network) { + return new NetworkParameters(network, geofencingZones); + } +} diff --git a/src/ext/java/org/opentripplanner/ext/vehiclerentalservicedirectory/api/VehicleRentalServiceDirectoryFetcherParameters.java b/src/ext/java/org/opentripplanner/ext/vehiclerentalservicedirectory/api/VehicleRentalServiceDirectoryFetcherParameters.java index af84cef5c14..abd2b7d8afc 100644 --- a/src/ext/java/org/opentripplanner/ext/vehiclerentalservicedirectory/api/VehicleRentalServiceDirectoryFetcherParameters.java +++ b/src/ext/java/org/opentripplanner/ext/vehiclerentalservicedirectory/api/VehicleRentalServiceDirectoryFetcherParameters.java @@ -4,10 +4,12 @@ import java.util.Collection; import java.util.Map; import java.util.stream.Collectors; +import javax.annotation.Nullable; import org.opentripplanner.updater.spi.HttpHeaders; public class VehicleRentalServiceDirectoryFetcherParameters { + public static final String DEFAULT_NETWORK_NAME = "default-network"; private final URI url; private final String sourcesName; @@ -22,6 +24,9 @@ public class VehicleRentalServiceDirectoryFetcherParameters { private final Map parametersForNetwork; + @Nullable + private final NetworkParameters defaultNetwork; + public VehicleRentalServiceDirectoryFetcherParameters( URI url, String sourcesName, @@ -39,6 +44,7 @@ public VehicleRentalServiceDirectoryFetcherParameters( this.headers = headers; this.parametersForNetwork = networkParameters.stream().collect(Collectors.toMap(NetworkParameters::network, it -> it)); + this.defaultNetwork = parametersForNetwork.get(DEFAULT_NETWORK_NAME); } /** @@ -90,7 +96,8 @@ public String getLanguage() { return language; } + @Nullable public NetworkParameters networkParameters(String network) { - return parametersForNetwork.get(network); + return parametersForNetwork.getOrDefault(network, defaultNetwork); } } diff --git a/src/main/java/org/opentripplanner/standalone/config/sandbox/VehicleRentalServiceDirectoryFetcherConfig.java b/src/main/java/org/opentripplanner/standalone/config/sandbox/VehicleRentalServiceDirectoryFetcherConfig.java index 6d4edb1bc84..1576c0df560 100644 --- a/src/main/java/org/opentripplanner/standalone/config/sandbox/VehicleRentalServiceDirectoryFetcherConfig.java +++ b/src/main/java/org/opentripplanner/standalone/config/sandbox/VehicleRentalServiceDirectoryFetcherConfig.java @@ -56,7 +56,22 @@ private static List mapNetworkParameters( return root .of(parameterName) .since(V2_4) - .summary("List all networks to include.") + .summary( + "List all networks to include. Use \"network\": \"" + + VehicleRentalServiceDirectoryFetcherParameters.DEFAULT_NETWORK_NAME + + "\" to set defaults." + ) + .description( + """ + If no default network exist only the listed networks are used. Configure the a network + with name "{{default-network}}" to include all unlisted networks. If not present, all + unlisted networks is dropped. Note! The values int the "{{default-network}}" is not used to + set missing field values in networks listed. + """.replace( + "{{default-network}}", + VehicleRentalServiceDirectoryFetcherParameters.DEFAULT_NETWORK_NAME + ) + ) .asObjects(c -> new NetworkParameters( c.of("network").since(V2_4).summary("The network name").asString(),