Skip to content

Commit f2a76c2

Browse files
Add tag handling
1 parent a1f51da commit f2a76c2

File tree

6 files changed

+124
-33
lines changed

6 files changed

+124
-33
lines changed

doc-templates/VehicleParking.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Contact Info
44

55
- For HSL Park and Ride updater: Digitransit team, HSL, Helsinki, Finland
6-
- For Bikely and NOI updater: Leonard Ehrenfried, [[email protected]](mailto:[email protected])
6+
- For Bikely, NOI and Bikeep updater: Leonard Ehrenfried, [[email protected]](mailto:[email protected])
77

88

99
## Documentation
@@ -44,6 +44,9 @@ All updaters have the following parameters in common:
4444

4545
<!-- INSERT: noi-open-data-hub -->
4646

47+
## Bikeep
48+
49+
<!-- INSERT: bikeep -->
4750

4851
## Changelog
4952

docs/RouterConfiguration.md

+6
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,12 @@ Used to group requests when monitoring OTP.
844844
"fromDateTime" : "-P1D",
845845
"timeout" : 300000
846846
}
847+
},
848+
{
849+
"type" : "vehicle-parking",
850+
"feedId" : "bikeep",
851+
"sourceType" : "bikeep",
852+
"url" : "https://services.bikeep.com/location/v1/public-areas/no-baia-mobility/locations"
847853
}
848854
],
849855
"rideHailingServices" : [

docs/sandbox/VehicleParking.md

+61-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Contact Info
44

55
- For HSL Park and Ride updater: Digitransit team, HSL, Helsinki, Finland
6-
- For Bikely and NOI updater: Leonard Ehrenfried, [[email protected]](mailto:[email protected])
6+
- For Bikely, NOI and Bikeep updater: Leonard Ehrenfried, [[email protected]](mailto:[email protected])
77

88

99
## Documentation
@@ -312,6 +312,66 @@ HTTP headers to add to the request. Any header key, value can be inserted.
312312

313313
<!-- noi-open-data-hub END -->
314314

315+
## Bikeep
316+
317+
<!-- bikeep BEGIN -->
318+
<!-- NOTE! This section is auto-generated. Do not change, change doc in code instead. -->
319+
320+
| Config Parameter | Type | Summary | Req./Opt. | Default Value | Since |
321+
|----------------------------------|:---------------:|----------------------------------------------------------------------------|:----------:|---------------|:-----:|
322+
| type = "vehicle-parking" | `enum` | The type of the updater. | *Required* | | 1.5 |
323+
| [feedId](#u__13__feedId) | `string` | The name of the data source. | *Required* | | 2.2 |
324+
| frequency | `duration` | How often to update the source. | *Optional* | `"PT1M"` | 2.6 |
325+
| [sourceType](#u__13__sourceType) | `enum` | The source of the vehicle updates. | *Required* | | 2.2 |
326+
| url | `uri` | URL of the locations endpoint. | *Required* | | 2.6 |
327+
| [headers](#u__13__headers) | `map of string` | HTTP headers to add to the request. Any header key, value can be inserted. | *Optional* | | 2.6 |
328+
329+
330+
#### Details
331+
332+
<h4 id="u__13__feedId">feedId</h4>
333+
334+
**Since version:** `2.2`**Type:** `string`**Cardinality:** `Required`
335+
**Path:** /updaters/[13]
336+
337+
The name of the data source.
338+
339+
This will end up in the API responses as the feed id of of the parking lot.
340+
341+
<h4 id="u__13__sourceType">sourceType</h4>
342+
343+
**Since version:** `2.2`**Type:** `enum`**Cardinality:** `Required`
344+
**Path:** /updaters/[13]
345+
**Enum values:** `park-api` | `bicycle-park-api` | `hsl-park` | `bikely` | `noi-open-data-hub` | `bikeep`
346+
347+
The source of the vehicle updates.
348+
349+
<h4 id="u__13__headers">headers</h4>
350+
351+
**Since version:** `2.6`**Type:** `map of string`**Cardinality:** `Optional`
352+
**Path:** /updaters/[13]
353+
354+
HTTP headers to add to the request. Any header key, value can be inserted.
355+
356+
357+
358+
##### Example configuration
359+
360+
```JSON
361+
// router-config.json
362+
{
363+
"updaters" : [
364+
{
365+
"type" : "vehicle-parking",
366+
"feedId" : "bikeep",
367+
"sourceType" : "bikeep",
368+
"url" : "https://services.bikeep.com/location/v1/public-areas/no-baia-mobility/locations"
369+
}
370+
]
371+
}
372+
```
373+
374+
<!-- bikeep END -->
315375

316376
## Changelog
317377

src/ext-test/java/org/opentripplanner/ext/vehicleparking/bikeep/BikeepUpdaterTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static org.junit.jupiter.api.Assertions.assertNotNull;
55

66
import java.time.Duration;
7+
import java.util.Set;
78
import org.junit.jupiter.api.Test;
89
import org.opentripplanner.test.support.ResourceLoader;
910
import org.opentripplanner.updater.spi.HttpHeaders;
@@ -34,6 +35,7 @@ void parse() {
3435
assertEquals("Ågotnes Terminal", first.getName().toString());
3536
assertEquals(10, first.getAvailability().getBicycleSpaces());
3637
assertEquals(10, first.getCapacity().getBicycleSpaces());
38+
assertEquals(Set.of("FREE", "PRIVATE", "BIKE", "BOOKABLE"), first.getTags());
3739

3840
var last = lots.getLast();
3941
assertEquals("bikeep:224111", last.getId().toString());

src/ext/java/org/opentripplanner/ext/vehicleparking/bikeep/BikeepUpdater.java

+45-31
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package org.opentripplanner.ext.vehicleparking.bikeep;
22

33
import com.fasterxml.jackson.databind.JsonNode;
4+
import com.fasterxml.jackson.databind.ObjectReader;
5+
import java.io.IOException;
6+
import java.util.List;
47
import org.opentripplanner.framework.geometry.WgsCoordinate;
58
import org.opentripplanner.framework.i18n.NonLocalizedString;
9+
import org.opentripplanner.framework.json.ObjectMappers;
610
import org.opentripplanner.framework.tostring.ToStringBuilder;
711
import org.opentripplanner.routing.vehicle_parking.VehicleParking;
812
import org.opentripplanner.routing.vehicle_parking.VehicleParkingSpaces;
@@ -16,6 +20,9 @@
1620
public class BikeepUpdater extends GenericJsonDataSource<VehicleParking> {
1721

1822
private static final String JSON_PARSE_PATH = "features";
23+
private static final ObjectReader STRING_LIST_READER = ObjectMappers
24+
.ignoringExtraFields()
25+
.readerForListOf(String.class);
1926
private final BikeepUpdaterParameters params;
2027

2128
public BikeepUpdater(BikeepUpdaterParameters parameters) {
@@ -25,41 +32,48 @@ public BikeepUpdater(BikeepUpdaterParameters parameters) {
2532

2633
@Override
2734
protected VehicleParking parseElement(JsonNode jsonNode) {
28-
var coords = jsonNode.path("geometry").path("coordinates");
29-
var coordinate = new WgsCoordinate(coords.get(1).asDouble(), coords.get(0).asDouble());
35+
try {
36+
var coords = jsonNode.path("geometry").path("coordinates");
37+
var coordinate = new WgsCoordinate(coords.get(1).asDouble(), coords.get(0).asDouble());
3038

31-
var props = jsonNode.path("properties");
32-
var vehicleParkId = new FeedScopedId(params.feedId(), props.path("code").asText());
33-
var name = new NonLocalizedString(props.path("label").asText());
34-
var parking = props.path("parking");
39+
var props = jsonNode.path("properties");
40+
var vehicleParkId = new FeedScopedId(params.feedId(), props.path("code").asText());
41+
var name = new NonLocalizedString(props.path("label").asText());
42+
var parking = props.path("parking");
3543

36-
var availability = VehicleParkingSpaces
37-
.builder()
38-
.bicycleSpaces(parking.get("available").asInt())
39-
.build();
40-
var capacity = VehicleParkingSpaces
41-
.builder()
42-
.bicycleSpaces(parking.get("total").asInt())
43-
.build();
44+
List<String> tags = STRING_LIST_READER.readValue(props.path("tags"));
4445

45-
VehicleParking.VehicleParkingEntranceCreator entrance = builder ->
46-
builder
47-
.entranceId(new FeedScopedId(params.feedId(), vehicleParkId.getId() + "/entrance"))
48-
.coordinate(coordinate)
49-
.walkAccessible(true)
50-
.carAccessible(true);
46+
var availability = VehicleParkingSpaces
47+
.builder()
48+
.bicycleSpaces(parking.get("available").asInt())
49+
.build();
50+
var capacity = VehicleParkingSpaces
51+
.builder()
52+
.bicycleSpaces(parking.get("total").asInt())
53+
.build();
54+
55+
VehicleParking.VehicleParkingEntranceCreator entrance = builder ->
56+
builder
57+
.entranceId(new FeedScopedId(params.feedId(), vehicleParkId.getId() + "/entrance"))
58+
.coordinate(coordinate)
59+
.walkAccessible(true)
60+
.carAccessible(true);
5161

52-
return VehicleParking
53-
.builder()
54-
.id(vehicleParkId)
55-
.name(name)
56-
.state(VehicleParkingState.OPERATIONAL)
57-
.coordinate(coordinate)
58-
.bicyclePlaces(true)
59-
.availability(availability)
60-
.capacity(capacity)
61-
.entrance(entrance)
62-
.build();
62+
return VehicleParking
63+
.builder()
64+
.id(vehicleParkId)
65+
.name(name)
66+
.state(VehicleParkingState.OPERATIONAL)
67+
.coordinate(coordinate)
68+
.bicyclePlaces(true)
69+
.availability(availability)
70+
.tags(tags)
71+
.capacity(capacity)
72+
.entrance(entrance)
73+
.build();
74+
} catch (IOException e) {
75+
throw new RuntimeException(e);
76+
}
6377
}
6478

6579
@Override

src/test/resources/standalone/config/router-config.json

+6
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,12 @@
420420
"fromDateTime": "-P1D",
421421
"timeout": 300000
422422
}
423+
},
424+
{
425+
"type": "vehicle-parking",
426+
"feedId": "bikeep",
427+
"sourceType": "bikeep",
428+
"url": "https://services.bikeep.com/location/v1/public-areas/no-baia-mobility/locations"
423429
}
424430
],
425431
"rideHailingServices": [

0 commit comments

Comments
 (0)