Skip to content

Commit 56fa489

Browse files
authored
Merge pull request opentripplanner#7090 from HSLdevcom/via-place
Add information to GraphQL schemas about if a place in an itinerary is a via location
2 parents 5296d48 + 8253d34 commit 56fa489

36 files changed

Lines changed: 460 additions & 51 deletions

application/src/ext/java/org/opentripplanner/ext/flex/FlexRouter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.opentripplanner.model.PathTransfer;
2424
import org.opentripplanner.model.plan.Itinerary;
2525
import org.opentripplanner.routing.algorithm.mapping.GraphPathToItineraryMapper;
26+
import org.opentripplanner.routing.api.request.RouteRequest;
2627
import org.opentripplanner.routing.graph.Graph;
2728
import org.opentripplanner.routing.graphfinder.NearbyStop;
2829
import org.opentripplanner.routing.graphfinder.TransitServiceResolver;
@@ -120,7 +121,7 @@ public FlexRouter(
120121
);
121122
}
122123

123-
public List<Itinerary> createFlexOnlyItineraries(boolean arriveBy) {
124+
public List<Itinerary> createFlexOnlyItineraries(boolean arriveBy, RouteRequest request) {
124125
OTPRequestTimeoutException.checkForTimeout();
125126

126127
var directFlexPaths = new FlexDirectPathFactory(
@@ -136,7 +137,7 @@ public List<Itinerary> createFlexOnlyItineraries(boolean arriveBy) {
136137
for (DirectFlexPath it : directFlexPaths) {
137138
var startTime = startOfTime.plusSeconds(it.startTime());
138139
var itinerary = graphPathToItineraryMapper
139-
.generateItinerary(new GraphPath<>(it.state()))
140+
.generateItinerary(new GraphPath<>(it.state()), request)
140141
.withTimeShiftToStartAt(startTime);
141142

142143
if (itinerary != null) {

application/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/LegImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ public DataFetcher<StopArrival> from() {
110110
source.start(),
111111
source.start(),
112112
source.boardStopPosInPattern(),
113-
source.boardingGtfsStopSequence()
113+
source.boardingGtfsStopSequence(),
114+
source.from().viaLocationType
114115
);
115116
};
116117
}
@@ -271,7 +272,8 @@ public DataFetcher<StopArrival> to() {
271272
source.end(),
272273
source.end(),
273274
source.alightStopPosInPattern(),
274-
source.alightGtfsStopSequence()
275+
source.alightGtfsStopSequence(),
276+
source.to().viaLocationType
275277
);
276278
};
277279
}

application/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/PlaceImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.opentripplanner.model.plan.VertexType;
1212
import org.opentripplanner.model.plan.leg.LegCallTime;
1313
import org.opentripplanner.model.plan.leg.StopArrival;
14+
import org.opentripplanner.model.plan.leg.ViaLocationType;
1415
import org.opentripplanner.service.vehicleparking.model.VehicleParking;
1516
import org.opentripplanner.service.vehiclerental.model.VehicleRentalPlace;
1617
import org.opentripplanner.service.vehiclerental.model.VehicleRentalStation;
@@ -168,6 +169,14 @@ public DataFetcher<String> vertexType() {
168169
};
169170
}
170171

172+
@Override
173+
public DataFetcher<ViaLocationType> viaLocationType() {
174+
return environment -> {
175+
var stopArrival = getSource(environment);
176+
return stopArrival.viaLocationType;
177+
};
178+
}
179+
171180
private VehicleParking getBikePark(DataFetchingEnvironment environment) {
172181
StopArrival stopArrival = getSource(environment);
173182
var vehicleParkingWithEntrance = stopArrival.place.vehicleParkingWithEntrance;

application/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/PlanImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public DataFetcher<DebugOutput> debugOutput() {
2828
@Override
2929
public DataFetcher<StopArrival> from() {
3030
return environment ->
31-
new StopArrival(getSource(environment).getTripPlan().from, null, null, null, null);
31+
new StopArrival(getSource(environment).getTripPlan().from, null, null, null, null, null);
3232
}
3333

3434
@Override
@@ -115,7 +115,7 @@ public DataFetcher<Long> searchWindowUsed() {
115115
@Override
116116
public DataFetcher<StopArrival> to() {
117117
return environment ->
118-
new StopArrival(getSource(environment).getTripPlan().to, null, null, null, null);
118+
new StopArrival(getSource(environment).getTripPlan().to, null, null, null, null, null);
119119
}
120120

121121
private RoutingResponse getSource(DataFetchingEnvironment environment) {

application/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.opentripplanner.model.plan.leg.LegCallTime;
4747
import org.opentripplanner.model.plan.leg.LegRealTimeEstimate;
4848
import org.opentripplanner.model.plan.leg.StopArrival;
49+
import org.opentripplanner.model.plan.leg.ViaLocationType;
4950
import org.opentripplanner.model.plan.walkstep.WalkStep;
5051
import org.opentripplanner.routing.alertpatch.TransitAlert;
5152
import org.opentripplanner.routing.api.response.RoutingError;
@@ -761,6 +762,8 @@ public interface GraphQLPlace {
761762
public DataFetcher<VehicleRentalStation> vehicleRentalStation();
762763

763764
public DataFetcher<String> vertexType();
765+
766+
public DataFetcher<ViaLocationType> viaLocationType();
764767
}
765768

766769
/** Interface for places, e.g. stops, stations, parking areas.. */

application/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLTypes.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5693,6 +5693,12 @@ public enum GraphQLVertexType {
56935693
TRANSIT,
56945694
}
56955695

5696+
/** Categorization for via locations. */
5697+
public enum GraphQLViaLocationType {
5698+
PASS_THROUGH,
5699+
VISIT,
5700+
}
5701+
56965702
public static class GraphQLWalkPreferencesInput {
56975703

56985704
private org.opentripplanner.framework.model.Cost boardCost;

application/src/main/java/org/opentripplanner/apis/gtfs/generated/graphql-codegen.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,4 @@ config:
136136
CallSchedule: org.opentripplanner.apis.gtfs.model.CallSchedule#CallSchedule
137137
CallScheduledTime: org.opentripplanner.apis.gtfs.model.CallScheduledTime#CallScheduledTime
138138
RentalVehicleFuel: org.opentripplanner.service.vehiclerental.model.RentalVehicleFuel#RentalVehicleFuel
139-
139+
ViaLocationType: org.opentripplanner.model.plan.leg.ViaLocationType#ViaLocationType

application/src/main/java/org/opentripplanner/apis/transmodel/model/EnumTypes.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.function.Function;
88
import org.opentripplanner.framework.doc.DocumentedEnum;
99
import org.opentripplanner.model.plan.VertexType;
10+
import org.opentripplanner.model.plan.leg.ViaLocationType;
1011
import org.opentripplanner.model.plan.walkstep.AbsoluteDirection;
1112
import org.opentripplanner.model.plan.walkstep.RelativeDirection;
1213
import org.opentripplanner.model.transfer.TransferPriority;
@@ -468,6 +469,24 @@ public class EnumTypes {
468469
//TODO QL: .value("parkAndRide", VertexType.PARKANDRIDE)
469470
.build();
470471

472+
public static final GraphQLEnumType VIA_LOCATION_TYPE = GraphQLEnumType.newEnum()
473+
.name("ViaLocationType")
474+
.description("Categorization for via locations.")
475+
.value(
476+
"passThrough",
477+
ViaLocationType.PASS_THROUGH,
478+
"The via stop location must be visited as part of a transit trip as at the " +
479+
"boarding stop, the intermediate stop, or the alighting stop."
480+
)
481+
.value(
482+
"visit",
483+
ViaLocationType.VISIT,
484+
"The location is visited physically by boarding or alighting a transit trip at " +
485+
"a given stop, or by traveling via requested coordinate location as part of a access, " +
486+
"transfer, egress or direct segment. Intermediate stops visited on-board do not count."
487+
)
488+
.build();
489+
471490
public static final GraphQLEnumType WHEELCHAIR_BOARDING = GraphQLEnumType.newEnum()
472491
.name("WheelchairBoarding")
473492
.value(

application/src/main/java/org/opentripplanner/apis/transmodel/model/plan/PlanPlaceType.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,17 @@ public static GraphQLObjectType create(
131131
)
132132
.build()
133133
)
134+
.field(
135+
GraphQLFieldDefinition.newFieldDefinition()
136+
.name("viaLocationType")
137+
.type(EnumTypes.VIA_LOCATION_TYPE)
138+
.description(
139+
"This defines if the place is a requested via location, and what kind it is. If the " +
140+
"value is `null`, this place is not a via location."
141+
)
142+
.dataFetcher(environment -> ((Place) environment.getSource()).viaLocationType)
143+
.build()
144+
)
134145
// .field(GraphQLFieldDefinition.newFieldDefinition()
135146
// .name("bikePark")
136147
// .type(bikeParkType)

application/src/main/java/org/opentripplanner/model/plan/Place.java

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.opentripplanner.framework.i18n.LocalizedString;
77
import org.opentripplanner.framework.i18n.NonLocalizedString;
88
import org.opentripplanner.model.GenericLocation;
9+
import org.opentripplanner.model.plan.leg.ViaLocationType;
910
import org.opentripplanner.service.vehiclerental.model.VehicleRentalPlace;
1011
import org.opentripplanner.service.vehiclerental.street.VehicleRentalPlaceVertex;
1112
import org.opentripplanner.street.model.vertex.StreetVertex;
@@ -42,32 +43,43 @@ public class Place {
4243
/**
4344
* Reference to the stop if the type is {@link VertexType#TRANSIT}.
4445
*/
46+
@Nullable
4547
public final StopLocation stop;
4648

4749
/**
4850
* The vehicle rental place if the type is {@link VertexType#VEHICLERENTAL}.
4951
*/
52+
@Nullable
5053
public final VehicleRentalPlace vehicleRentalPlace;
5154

5255
/**
5356
* The vehicle parking entrance if the type is {@link VertexType#VEHICLEPARKING}.
5457
*/
58+
@Nullable
5559
public final VehicleParkingWithEntrance vehicleParkingWithEntrance;
5660

61+
/**
62+
* Categorization for a via location, if the place is a via location in the request.
63+
*/
64+
@Nullable
65+
public final ViaLocationType viaLocationType;
66+
5767
private Place(
5868
I18NString name,
5969
WgsCoordinate coordinate,
6070
VertexType vertexType,
61-
StopLocation stop,
62-
VehicleRentalPlace vehicleRentalPlace,
63-
VehicleParkingWithEntrance vehicleParkingWithEntrance
71+
@Nullable StopLocation stop,
72+
@Nullable VehicleRentalPlace vehicleRentalPlace,
73+
@Nullable VehicleParkingWithEntrance vehicleParkingWithEntrance,
74+
@Nullable ViaLocationType viaLocationType
6475
) {
6576
this.name = name;
6677
this.coordinate = coordinate;
6778
this.vertexType = vertexType;
6879
this.stop = stop;
6980
this.vehicleRentalPlace = vehicleRentalPlace;
7081
this.vehicleParkingWithEntrance = vehicleParkingWithEntrance;
82+
this.viaLocationType = viaLocationType;
7183
}
7284

7385
public static Place normal(Double lat, Double lon, I18NString name) {
@@ -77,23 +89,61 @@ public static Place normal(Double lat, Double lon, I18NString name) {
7789
VertexType.NORMAL,
7890
null,
7991
null,
92+
null,
8093
null
8194
);
8295
}
8396

97+
public static Place normal(
98+
Vertex vertex,
99+
I18NString name,
100+
@Nullable ViaLocationType viaLocationType
101+
) {
102+
return new Place(
103+
name,
104+
WgsCoordinate.creatOptionalCoordinate(vertex.getLat(), vertex.getLon()),
105+
VertexType.NORMAL,
106+
null,
107+
null,
108+
null,
109+
viaLocationType
110+
);
111+
}
112+
84113
public static Place normal(Vertex vertex, I18NString name) {
85114
return new Place(
86115
name,
87116
WgsCoordinate.creatOptionalCoordinate(vertex.getLat(), vertex.getLon()),
88117
VertexType.NORMAL,
89118
null,
90119
null,
120+
null,
91121
null
92122
);
93123
}
94124

125+
public static Place forStop(StopLocation stop, @Nullable ViaLocationType viaLocationType) {
126+
return new Place(
127+
stop.getName(),
128+
stop.getCoordinate(),
129+
VertexType.TRANSIT,
130+
stop,
131+
null,
132+
null,
133+
viaLocationType
134+
);
135+
}
136+
95137
public static Place forStop(StopLocation stop) {
96-
return new Place(stop.getName(), stop.getCoordinate(), VertexType.TRANSIT, stop, null, null);
138+
return new Place(
139+
stop.getName(),
140+
stop.getCoordinate(),
141+
VertexType.TRANSIT,
142+
stop,
143+
null,
144+
null,
145+
null
146+
);
97147
}
98148

99149
public static Place forFlexStop(StopLocation stop, Vertex vertex) {
@@ -114,6 +164,7 @@ public static Place forFlexStop(StopLocation stop, Vertex vertex) {
114164
VertexType.TRANSIT,
115165
stop,
116166
null,
167+
null,
117168
null
118169
);
119170
}
@@ -140,6 +191,7 @@ public static Place forVehicleRentalPlace(VehicleRentalPlaceVertex vertex) {
140191
VertexType.VEHICLERENTAL,
141192
null,
142193
vertex.getStation(),
194+
null,
143195
null
144196
);
145197
}
@@ -166,7 +218,8 @@ public static Place forVehicleParkingEntrance(VehicleParkingEntranceVertex verte
166218
.vehicleParking(vertex.getVehicleParking())
167219
.entrance(vertex.getParkingEntrance())
168220
.realtime(realTime)
169-
.build()
221+
.build(),
222+
null
170223
);
171224
}
172225

@@ -208,6 +261,7 @@ public String toString() {
208261
.addEnum("vertexType", vertexType)
209262
.addObj("vehicleRentalPlace", vehicleRentalPlace)
210263
.addObj("vehicleParkingEntrance", vehicleParkingWithEntrance)
264+
.addObj("viaLocationType", viaLocationType)
211265
.toString();
212266
}
213267
}

0 commit comments

Comments
 (0)