Skip to content

Commit

Permalink
Take into account the newest schema
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Sep 26, 2024
1 parent a09793b commit dab0b59
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1421,6 +1421,35 @@ public void setGraphQLTags(List<String> tags) {
}
}

public static class GraphQLPassThroughLocationInput {

private String label;
private String stopLocationId;

public GraphQLPassThroughLocationInput(Map<String, Object> args) {
if (args != null) {
this.label = (String) args.get("label");
this.stopLocationId = (String) args.get("stopLocationId");
}
}

public String getGraphQLLabel() {
return this.label;
}

public String getGraphQLStopLocationId() {
return this.stopLocationId;
}

public void setGraphQLLabel(String label) {
this.label = label;
}

public void setGraphQLStopLocationId(String stopLocationId) {
this.stopLocationId = stopLocationId;
}
}

public static class GraphQLPatternAlertsArgs {

private List<GraphQLPatternAlertType> types;
Expand Down Expand Up @@ -2673,7 +2702,7 @@ public static class GraphQLQueryTypePlanArgs {
private List<GraphQLTransportModeInput> transportModes;
private GraphQLInputTriangleInput triangle;
private GraphQLInputUnpreferredInput unpreferred;
private List<GraphQLViaPointInput> viaPoints;
private List<GraphQLViaLocationInput> via;
private Double waitAtBeginningFactor;
private Double waitReluctance;
private Integer walkBoardCost;
Expand Down Expand Up @@ -2755,8 +2784,8 @@ public GraphQLQueryTypePlanArgs(Map<String, Object> args) {
this.triangle = new GraphQLInputTriangleInput((Map<String, Object>) args.get("triangle"));
this.unpreferred =
new GraphQLInputUnpreferredInput((Map<String, Object>) args.get("unpreferred"));
if (args.get("viaPoints") != null) {
this.viaPoints = (List<GraphQLViaPointInput>) args.get("viaPoints");
if (args.get("via") != null) {
this.via = (List<GraphQLViaLocationInput>) args.get("via");
}
this.waitAtBeginningFactor = (Double) args.get("waitAtBeginningFactor");
this.waitReluctance = (Double) args.get("waitReluctance");
Expand Down Expand Up @@ -2989,8 +3018,8 @@ public GraphQLInputUnpreferredInput getGraphQLUnpreferred() {
return this.unpreferred;
}

public List<GraphQLViaPointInput> getGraphQLViaPoints() {
return this.viaPoints;
public List<GraphQLViaLocationInput> getGraphQLVia() {
return this.via;
}

public Double getGraphQLWaitAtBeginningFactor() {
Expand Down Expand Up @@ -3251,8 +3280,8 @@ public void setGraphQLUnpreferred(GraphQLInputUnpreferredInput unpreferred) {
this.unpreferred = unpreferred;
}

public void setGraphQLViaPoints(List<GraphQLViaPointInput> viaPoints) {
this.viaPoints = viaPoints;
public void setGraphQLVia(List<GraphQLViaLocationInput> via) {
this.via = via;
}

public void setGraphQLWaitAtBeginningFactor(Double waitAtBeginningFactor) {
Expand Down Expand Up @@ -5075,49 +5104,23 @@ public enum GraphQLVertexType {

public static class GraphQLViaLocationInput {

private List<String> locationIds;
private GraphQLPassThroughLocationInput passThroughLocation;

public GraphQLViaLocationInput(Map<String, Object> args) {
if (args != null) {
this.locationIds = (List<String>) args.get("locationIds");
}
}

public List<String> getGraphQLLocationIds() {
return this.locationIds;
}

public void setGraphQLLocationIds(List<String> locationIds) {
this.locationIds = locationIds;
}
}

public static class GraphQLViaPointInput {

private String label;
private GraphQLViaLocationInput place;

public GraphQLViaPointInput(Map<String, Object> args) {
if (args != null) {
this.label = (String) args.get("label");
this.place = new GraphQLViaLocationInput((Map<String, Object>) args.get("place"));
this.passThroughLocation =
new GraphQLPassThroughLocationInput(
(Map<String, Object>) args.get("passThroughLocation")
);
}
}

public String getGraphQLLabel() {
return this.label;
}

public GraphQLViaLocationInput getGraphQLPlace() {
return this.place;
}

public void setGraphQLLabel(String label) {
this.label = label;
public GraphQLPassThroughLocationInput getGraphQLPassThroughLocation() {
return this.passThroughLocation;
}

public void setGraphQLPlace(GraphQLViaLocationInput place) {
this.place = place;
public void setGraphQLPassThroughLocation(GraphQLPassThroughLocationInput passThroughLocation) {
this.passThroughLocation = passThroughLocation;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ static void mapViaPoints(
TransitService transitService
) {
callWith.argument(
"viaPoints",
"via",
(List<Map<String, Object>> v) ->
request.setPassThroughPoints(PassThroughLocationMapper.toLocations(transitService, v))
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package org.opentripplanner.apis.gtfs.mapping.routerequest;

import static java.util.stream.Collectors.collectingAndThen;
import static java.util.stream.Collectors.toList;

import java.util.List;
import java.util.Map;
import org.opentripplanner.framework.lang.StringUtils;
import org.opentripplanner.routing.api.request.PassThroughPoint;
import org.opentripplanner.transit.model.framework.FeedScopedId;
import org.opentripplanner.transit.service.TransitService;
Expand All @@ -22,24 +20,19 @@ private static PassThroughPoint handlePoint(
final TransitService transitService,
Map<String, Object> map
) {
Map<String, Object> element = (Map<String, Object>) map.get("place");
List<String> stops = (List<String>) element.get("locationIds");
Map<String, Object> element = (Map<String, Object>) map.get("passThroughLocation");
String id = (String) element.get("stopLocationId");

final String name = (String) element.get("name");
if (stops == null || stops.isEmpty()) {
if (StringUtils.hasNoValue(id)) {
throw new IllegalArgumentException("No stops in pass-through point");
}

return stops
.stream()
.map(FeedScopedId::parse)
.flatMap(id -> {
var stopLocations = transitService.getStopOrChildStops(id);
if (stopLocations.isEmpty()) {
throw new IllegalArgumentException("No match for %s.".formatted(id));
}
return stopLocations.stream();
})
.collect(collectingAndThen(toList(), sls -> new PassThroughPoint(sls, name)));
var stopLocationId = FeedScopedId.parse(id);
var stopLocations = List.copyOf(transitService.getStopOrChildStops(stopLocationId));
if (stopLocations.isEmpty()) {
throw new IllegalArgumentException("No match for %s.".formatted(id));
}
return new PassThroughPoint(stopLocations, name);
}
}
28 changes: 10 additions & 18 deletions src/main/resources/org/opentripplanner/apis/gtfs/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -1473,7 +1473,7 @@ type QueryType {
"List of routes and agencies which are given lower preference when planning the itinerary"
unpreferred: InputUnpreferred,
"The list of points the journey is required to pass through."
viaPoints: [ViaPointInput!],
via: [ViaLocationInput!],
"""
How much less bad is waiting at the beginning of the trip (replaces
`waitReluctance` on the first boarding). Default value: 0.4
Expand Down Expand Up @@ -3945,6 +3945,14 @@ input ParkingFilterOperation {
tags: [String]
}

"A stop that must be visited by the routing result."
input PassThroughLocationInput {
"Optional label of the via point for debugging and logging. It is not used in routing."
label: String
"The ID of the stop or station to visit. Should be in the format <FeedId>:<LocationId>."
stopLocationId: String!
}

"A coordinate used for a location in a plan query."
input PlanCoordinateInput {
"Latitude as a WGS84 format number."
Expand Down Expand Up @@ -4324,23 +4332,7 @@ Right now only stop or station IDs are supported but this will be extended to su
coordinates as well.
"""
input ViaLocationInput {
"""
The list of *stop location ids* which define the pass-through point. At least one id is required.
Stop and Station are supported location types.
The journey must pass through at least one of these entities - not all of them.
"""
locationIds: [String!]
}

"Defines a point which the routing result must visit."
input ViaPointInput {
"Optional label of the via point for debugging and logging. It is not used in routing."
label: String
"""
The place that must be visited by the via routing result. Right now only stops and stations are
supported but this will be extended to cover coordinates as well.
"""
place: ViaLocationInput!
passThroughLocation: PassThroughLocationInput
}

"Preferences related to walking (excluding walking a bicycle or a scooter)."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ void transferSlack() {
@Test
void passThroughPoints() {
Map<String, Object> arguments = Map.of(
"viaPoints",
List.of(Map.of("place", Map.of("locationIds", List.of("F:stop1"))))
"via",
List.of(Map.of("passThroughLocation", Map.of("stopLocationId", "F:stop1")))
);

var routeRequest = LegacyRouteRequestMapper.toRouteRequest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@ class PassThroughLocationMapperTest {

public static List<List<Map<?, ?>>> failureCases() {
return List.of(
List.of(Map.of("place", Map.of("locationIds", List.of("fantasy:id")))),
List.of(Map.of("place", Map.of("locationIds", List.of()))),
List.of(
Map.of("place", Map.of("locationIds", List.of())),
Map.of("place", Map.of("locationIds", List.of()))
)
List.of(Map.of("passThroughLocation", Map.of("stopLocationId", "fantasy:id"))),
List.of(Map.of("passThroughLocation", Map.of())),
List.of(Map.of("passThroughLocation", Map.of()), Map.of("passThroughLocation", Map.of()))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@
filters: [{ select: [{ tags: ["e"] }] }]
}
transportModes: [{ mode: CAR, qualifier: HAIL }]
viaPoints: [
{ label: "Flower shop", place: { locationIds: ["F:A", "F:B"] } }
via: [
{
passThroughLocation: {
label: "A stop that you want to visit along the route"
stopLocationId: "F:A"
}
}
]
) {
itineraries {
Expand Down

0 comments on commit dab0b59

Please sign in to comment.