diff --git a/src/main/java/org/opentripplanner/client/OtpApiClient.java b/src/main/java/org/opentripplanner/client/OtpApiClient.java index 0ae664b..e9963cd 100644 --- a/src/main/java/org/opentripplanner/client/OtpApiClient.java +++ b/src/main/java/org/opentripplanner/client/OtpApiClient.java @@ -143,6 +143,14 @@ public Stop stop(String gtfsId) throws IOException { return deserialize(jsonNode, "/data/stop", Stop.class); } + public List stops(String nameMask) throws IOException { + var stopQuery = GraphQLQueries.stops(); + var formattedQuery = stopQuery.formatted(nameMask); + + final var jsonNode = sendRequest(formattedQuery); + return deserializeList(jsonNode, listType(Stop.class), "/data/stops"); + } + private T deserialize(JsonNode jsonNode, String path, Class clazz) throws IOException { try { var plan = jsonNode.at(path); diff --git a/src/main/java/org/opentripplanner/client/model/Stop.java b/src/main/java/org/opentripplanner/client/model/Stop.java index 59ad5af..5a28166 100644 --- a/src/main/java/org/opentripplanner/client/model/Stop.java +++ b/src/main/java/org/opentripplanner/client/model/Stop.java @@ -8,6 +8,7 @@ public record Stop( String name, @JsonProperty("gtfsId") String id, Optional code, + Optional vehicleMode, Optional zoneId, ParentStation parentStation) { public Stop { diff --git a/src/main/java/org/opentripplanner/client/model/VehicleMode.java b/src/main/java/org/opentripplanner/client/model/VehicleMode.java new file mode 100644 index 0000000..b006bbf --- /dev/null +++ b/src/main/java/org/opentripplanner/client/model/VehicleMode.java @@ -0,0 +1,28 @@ +package org.opentripplanner.client.model; + +public enum VehicleMode { + AIRPLANE, + BICYCLE, + BUS, + CABLE_CAR, + CAR, + COACH, + FERRY, + FLEX, + @Deprecated + FLEXIBLE, + FUNICULAR, + GONDOLA, + @Deprecated + LEG_SWITCH, + RAIL, + SCOOTER, + SUBWAY, + TRAM, + CARPOOL, + TAXI, + TRANSIT, + WALK, + TROLLEYBUS, + MONORAIL +} diff --git a/src/main/java/org/opentripplanner/client/query/GraphQLQueries.java b/src/main/java/org/opentripplanner/client/query/GraphQLQueries.java index 87d3b42..d1a4e03 100644 --- a/src/main/java/org/opentripplanner/client/query/GraphQLQueries.java +++ b/src/main/java/org/opentripplanner/client/query/GraphQLQueries.java @@ -29,6 +29,10 @@ public static String stop() { return loadQuery("stop"); } + public static String stops() { + return loadQuery("stops"); + } + private static String loadQuery(String name) { var is = GraphQLQueries.class diff --git a/src/main/resources/queries/stop.graphql b/src/main/resources/queries/stop.graphql index b58aa32..d5e5b1c 100644 --- a/src/main/resources/queries/stop.graphql +++ b/src/main/resources/queries/stop.graphql @@ -3,9 +3,12 @@ query { name gtfsId code + vehicleMode zoneId parentStation { gtfsId + name + code } } } \ No newline at end of file diff --git a/src/main/resources/queries/stops.graphql b/src/main/resources/queries/stops.graphql new file mode 100644 index 0000000..bef349c --- /dev/null +++ b/src/main/resources/queries/stops.graphql @@ -0,0 +1,14 @@ +query { + stops(name: "%s") { + name + gtfsId + code + vehicleMode + zoneId + parentStation { + gtfsId + name + code + } + } +} diff --git a/src/test/java/org/opentripplanner/IntegrationTest.java b/src/test/java/org/opentripplanner/IntegrationTest.java index 9ccde6f..c28a4c8 100644 --- a/src/test/java/org/opentripplanner/IntegrationTest.java +++ b/src/test/java/org/opentripplanner/IntegrationTest.java @@ -325,6 +325,20 @@ public void stop() throws IOException { assertNotNull(result.id()); } + @Test + public void stops() throws IOException { + var result = client.stops("Oslo"); + + LOG.info("Received stops"); + + assertNotNull(result); + assertFalse(result.isEmpty()); + + var stop = result.get(0); + + assertNotNull(stop.id()); + } + @Disabled @Test public void seattleFares() throws IOException {