Skip to content

Commit

Permalink
feature: Add "default-network" to allow all networks to be merged, ev…
Browse files Browse the repository at this point in the history
…en not listed.
  • Loading branch information
t2gran committed Sep 12, 2023
1 parent d014d0f commit 933a0fa
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 15 deletions.
30 changes: 18 additions & 12 deletions docs/sandbox/VehicleRentalServiceDirectory.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ the `router-config.json`
<!-- PARAMETERS-TABLE BEGIN -->
<!-- NOTE! This section is auto-generated. Do not change, change doc in code instead. -->

| 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 |

<!-- PARAMETERS-TABLE END -->

Expand All @@ -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.



<!-- PARAMETERS-DETAILS END -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,6 +24,9 @@ public class VehicleRentalServiceDirectoryFetcherParameters {

private final Map<String, NetworkParameters> parametersForNetwork;

@Nullable
private final NetworkParameters defaultNetwork;

public VehicleRentalServiceDirectoryFetcherParameters(
URI url,
String sourcesName,
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -90,7 +96,8 @@ public String getLanguage() {
return language;
}

@Nullable
public NetworkParameters networkParameters(String network) {
return parametersForNetwork.get(network);
return parametersForNetwork.getOrDefault(network, defaultNetwork);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,22 @@ private static List<NetworkParameters> 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(),
Expand Down

0 comments on commit 933a0fa

Please sign in to comment.