Skip to content

Commit

Permalink
Copy latest API change from via point PR
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Sep 26, 2024
1 parent dab0b59 commit 66ccaa6
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 87 deletions.
157 changes: 102 additions & 55 deletions src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -1421,35 +1421,6 @@ 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 @@ -1792,6 +1763,35 @@ public void setGraphQLTransitOnly(Boolean transitOnly) {
}
}

public static class GraphQLPlanPassThroughViaLocationInput {

private String label;
private List<String> stopLocationIds;

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

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

public List<String> getGraphQLStopLocationIds() {
return this.stopLocationIds;
}

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

public void setGraphQLStopLocationIds(List<String> stopLocationIds) {
this.stopLocationIds = stopLocationIds;
}
}

public static class GraphQLPlanPreferencesInput {

private GraphQLAccessibilityPreferencesInput accessibility;
Expand Down Expand Up @@ -2024,6 +2024,75 @@ public void setGraphQLTransit(List<GraphQLPlanTransitModePreferenceInput> transi
}
}

public static class GraphQLPlanViaLocationInput {

private GraphQLPlanPassThroughViaLocationInput passThrough;
private GraphQLPlanVisitViaLocationInput visit;

public GraphQLPlanViaLocationInput(Map<String, Object> args) {
if (args != null) {
this.passThrough =
new GraphQLPlanPassThroughViaLocationInput((Map<String, Object>) args.get("passThrough"));
this.visit = new GraphQLPlanVisitViaLocationInput((Map<String, Object>) args.get("visit"));
}
}

public GraphQLPlanPassThroughViaLocationInput getGraphQLPassThrough() {
return this.passThrough;
}

public GraphQLPlanVisitViaLocationInput getGraphQLVisit() {
return this.visit;
}

public void setGraphQLPassThrough(GraphQLPlanPassThroughViaLocationInput passThrough) {
this.passThrough = passThrough;
}

public void setGraphQLVisit(GraphQLPlanVisitViaLocationInput visit) {
this.visit = visit;
}
}

public static class GraphQLPlanVisitViaLocationInput {

private String label;
private java.time.Duration minimumWaitTime;
private List<String> stopLocationIds;

public GraphQLPlanVisitViaLocationInput(Map<String, Object> args) {
if (args != null) {
this.label = (String) args.get("label");
this.minimumWaitTime = (java.time.Duration) args.get("minimumWaitTime");
this.stopLocationIds = (List<String>) args.get("stopLocationIds");
}
}

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

public java.time.Duration getGraphQLMinimumWaitTime() {
return this.minimumWaitTime;
}

public List<String> getGraphQLStopLocationIds() {
return this.stopLocationIds;
}

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

public void setGraphQLMinimumWaitTime(java.time.Duration minimumWaitTime) {
this.minimumWaitTime = minimumWaitTime;
}

public void setGraphQLStopLocationIds(List<String> stopLocationIds) {
this.stopLocationIds = stopLocationIds;
}
}

public enum GraphQLPropulsionType {
COMBUSTION,
COMBUSTION_DIESEL,
Expand Down Expand Up @@ -2702,7 +2771,7 @@ public static class GraphQLQueryTypePlanArgs {
private List<GraphQLTransportModeInput> transportModes;
private GraphQLInputTriangleInput triangle;
private GraphQLInputUnpreferredInput unpreferred;
private List<GraphQLViaLocationInput> via;
private List<GraphQLPlanViaLocationInput> via;
private Double waitAtBeginningFactor;
private Double waitReluctance;
private Integer walkBoardCost;
Expand Down Expand Up @@ -2785,7 +2854,7 @@ public GraphQLQueryTypePlanArgs(Map<String, Object> args) {
this.unpreferred =
new GraphQLInputUnpreferredInput((Map<String, Object>) args.get("unpreferred"));
if (args.get("via") != null) {
this.via = (List<GraphQLViaLocationInput>) args.get("via");
this.via = (List<GraphQLPlanViaLocationInput>) args.get("via");
}
this.waitAtBeginningFactor = (Double) args.get("waitAtBeginningFactor");
this.waitReluctance = (Double) args.get("waitReluctance");
Expand Down Expand Up @@ -3018,7 +3087,7 @@ public GraphQLInputUnpreferredInput getGraphQLUnpreferred() {
return this.unpreferred;
}

public List<GraphQLViaLocationInput> getGraphQLVia() {
public List<GraphQLPlanViaLocationInput> getGraphQLVia() {
return this.via;
}

Expand Down Expand Up @@ -3280,7 +3349,7 @@ public void setGraphQLUnpreferred(GraphQLInputUnpreferredInput unpreferred) {
this.unpreferred = unpreferred;
}

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

Expand Down Expand Up @@ -5102,28 +5171,6 @@ public enum GraphQLVertexType {
TRANSIT,
}

public static class GraphQLViaLocationInput {

private GraphQLPassThroughLocationInput passThroughLocation;

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

public GraphQLPassThroughLocationInput getGraphQLPassThroughLocation() {
return this.passThroughLocation;
}

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

public static class GraphQLWalkPreferencesInput {

private org.opentripplanner.framework.model.Cost boardCost;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.List;
import java.util.Map;
import org.opentripplanner.framework.lang.StringUtils;
import org.opentripplanner.framework.collection.CollectionUtils;
import org.opentripplanner.routing.api.request.PassThroughPoint;
import org.opentripplanner.transit.model.framework.FeedScopedId;
import org.opentripplanner.transit.service.TransitService;
Expand All @@ -20,18 +20,21 @@ private static PassThroughPoint handlePoint(
final TransitService transitService,
Map<String, Object> map
) {
Map<String, Object> element = (Map<String, Object>) map.get("passThroughLocation");
String id = (String) element.get("stopLocationId");
Map<String, Object> element = (Map<String, Object>) map.get("passThrough");
List<String> ids = (List<String>) element.get("stopLocationIds");

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

var stopLocationId = FeedScopedId.parse(id);
var stopLocations = List.copyOf(transitService.getStopOrChildStops(stopLocationId));
var stopLocations = ids
.stream()
.map(FeedScopedId::parse)
.flatMap(id -> transitService.getStopOrChildStops(id).stream())
.toList();
if (stopLocations.isEmpty()) {
throw new IllegalArgumentException("No match for %s.".formatted(id));
throw new IllegalArgumentException("No stop locations found for %s.".formatted(ids));
}
return new PassThroughPoint(stopLocations, name);
}
Expand Down
72 changes: 53 additions & 19 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."
via: [ViaLocationInput!],
via: [PlanViaLocationInput!],
"""
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,14 +3945,6 @@ 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 @@ -4063,6 +4055,21 @@ input PlanModesInput {
transitOnly: Boolean = false
}

"""
One of the listed stop locations must be visited on-board a transit vehicle or the journey must
alight or board at the location.
"""
input PlanPassThroughViaLocationInput {
"The label/name of the location. This is pass-through information and is not used in routing."
label: String
"""
A list of stop locations. A stop location can be a quay, a stop place, a multimodal
stop place or a group of stop places. It is enough to visit ONE of the locations
listed.
"""
stopLocationIds: [String]
}

"Wrapper type for different types of preferences related to plan query."
input PlanPreferencesInput {
"Accessibility preferences that affect both the street and transit routing."
Expand Down Expand Up @@ -4156,6 +4163,43 @@ input PlanTransitModesInput {
transit: [PlanTransitModePreferenceInput!]
}

"""
A via-location is used to specifying a location as an intermediate place the router must
route through. The via-location must be either a pass-through-location or a
visit-via-location. An on-board "visit" is only allowed for pass-through-via-locations, while
the visit-via-location can visit a stop-location or a coordinate and specify a
minimum-wait-time.
"""
input PlanViaLocationInput @oneOf {
passThrough: PlanPassThroughViaLocationInput
visit: PlanVisitViaLocationInput
}

"""
A visit-via-location is a physical visit to one of the stops or coordinates listed. An
on-board visit does not count, the traveler must alight or board at the given stop for
it to to be accepted. To visit a coordinate, the traveler must walk(bike or drive) to
the closest point in the street network from a stop and back to another stop to join
the transit network.
NOTE! Coordinates are NOT supported jet.
"""
input PlanVisitViaLocationInput {
"The label/name of the location. This is pass-through information and is not used in routing."
label: String
"""
The minimum wait time is used to force the trip to stay the given duration at the
via-location before the trip is continued.
"""
minimumWaitTime: Duration = "PT0S"
"""
A list of stop locations. A stop location can be a quay, a stop place, a multimodal
stop place or a group of stop places. It is enough to visit ONE of the locations
listed.
"""
stopLocationIds: [String]
}

"What criteria should be used when optimizing a scooter route."
input ScooterOptimizationInput @oneOf {
"Define optimization by weighing three criteria."
Expand Down Expand Up @@ -4325,16 +4369,6 @@ input VehicleParkingInput {
unpreferredCost: Int
}

"""
Represents an element that must be visited by the routing result.
Right now only stop or station IDs are supported but this will be extended to support via point
coordinates as well.
"""
input ViaLocationInput {
passThroughLocation: PassThroughLocationInput
}

"Preferences related to walking (excluding walking a bicycle or a scooter)."
input WalkPreferencesInput {
"The cost of boarding a vehicle while walking."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ void transferSlack() {
void passThroughPoints() {
Map<String, Object> arguments = Map.of(
"via",
List.of(Map.of("passThroughLocation", Map.of("stopLocationId", "F:stop1")))
List.of(Map.of("passThrough", Map.of("stopLocationIds", List.of("F:stop1"))))
);

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

public static List<List<Map<?, ?>>> failureCases() {
return 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()))
List.of(Map.of("passThrough", Map.of("stopLocationIds", List.of("fantasy:id")))),
List.of(Map.of("passThrough", Map.of())),
List.of(Map.of("passThrough", Map.of()), Map.of("passThroughLocation", Map.of()))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
transportModes: [{ mode: CAR, qualifier: HAIL }]
via: [
{
passThroughLocation: {
passThrough: {
label: "A stop that you want to visit along the route"
stopLocationId: "F:A"
stopLocationIds: ["F:A"]
}
}
]
Expand Down

0 comments on commit 66ccaa6

Please sign in to comment.