Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract journey request from RouteRequest #4446

Merged
merged 9 commits into from
Sep 15, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,14 @@ private Itinerary getItinerary(
request.setNumItineraries(10);
request.setSearchWindow(Duration.ofHours(2));

var modes = request.modes.copyOf();
var modes = request.journey().modes().copyOf();
modes.withEgressMode(FLEXIBLE);

if (onlyDirect) {
modes.withDirectMode(FLEXIBLE);
modes.clearTransitModes();
}
request.modes = modes.build();
request.journey().setModes(modes.build());

var result = service.route(request);
var itineraries = result.getTripPlan().itineraries;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.stream.StreamSupport;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Envelope;
import org.opentripplanner.api.common.LocationStringParser;
import org.opentripplanner.api.parameter.QualifiedMode;
import org.opentripplanner.api.parameter.QualifiedModeSet;
import org.opentripplanner.ext.fares.impl.DefaultFareServiceImpl;
Expand Down Expand Up @@ -599,8 +600,14 @@ public DataFetcher<DataFetcherResult<RoutingResponse>> plan() {

CallerWithEnvironment callWith = new CallerWithEnvironment(environment);

callWith.argument("fromPlace", request::setFromString);
callWith.argument("toPlace", request::setToString);
callWith.argument(
"fromPlace",
(String from) -> request.setFrom(LocationStringParser.fromOldStyleString(from))
);
callWith.argument(
"toPlace",
(String to) -> request.setTo(LocationStringParser.fromOldStyleString(to))
);

callWith.argument("from", (Map<String, Object> v) -> request.setFrom(toGenericLocation(v)));
callWith.argument("to", (Map<String, Object> v) -> request.setTo(toGenericLocation(v)));
Expand Down Expand Up @@ -632,11 +639,11 @@ public DataFetcher<DataFetcherResult<RoutingResponse>> plan() {
callWith.argument("bikeSwitchCost", preferences.bike()::setSwitchCost);
callWith.argument(
"allowKeepingRentedBicycleAtDestination",
(Boolean v) -> request.allowKeepingRentedVehicleAtDestination = v
request.journey().rental()::setAllowArrivingInRentedVehicleAtDestination
);
callWith.argument(
"keepingRentedBicycleAtDestinationCost",
preferences.rental()::setKeepingVehicleAtDestinationCost
preferences.rental()::setArrivingInRentalVehicleAtDestinationCost
);

callWith.argument(
Expand All @@ -658,7 +665,7 @@ public DataFetcher<DataFetcherResult<RoutingResponse>> plan() {
(Boolean v) -> preferences.system().itineraryFilters().debug = v
);
callWith.argument("arriveBy", request::setArriveBy);
// TODO VIA: 2022-08-24 I'm just commenting this out since we have to refactor it anyway
// TODO VIA (HSL): 2022-08-24 I'm just commenting this out since we have to refactor it anyway
// callWith.argument(
// "intermediatePlaces",
// (List<Map<String, Object>> v) ->
Expand All @@ -667,15 +674,28 @@ public DataFetcher<DataFetcherResult<RoutingResponse>> plan() {
// .stream()
// .map(LegacyGraphQLQueryTypeImpl::toGenericLocation)
// .collect(Collectors.toList())
// )
callWith.argument("preferred.routes", request::setPreferredRoutesFromString);
// );
callWith.argument(
"preferred.routes",
request.journey().transit()::setPreferredRoutesFromString
);
callWith.argument(
"preferred.otherThanPreferredRoutesPenalty",
preferences.transit()::setOtherThanPreferredRoutesPenalty
);
callWith.argument("preferred.agencies", request::setPreferredAgenciesFromString);
callWith.argument("unpreferred.routes", request::setUnpreferredRoutesFromString);
callWith.argument("unpreferred.agencies", request::setUnpreferredAgenciesFromString);
callWith.argument(
"preferred.agencies",
request.journey().transit()::setPreferredAgenciesFromString
);
callWith.argument(
"unpreferred.routes",
request.journey().transit()::setUnpreferredRoutesFromString
);
callWith.argument(
"unpreferred.agencies",
request.journey().transit()::setUnpreferredAgenciesFromString
);
// This is deprecated, if both are set, the proper one will override this
callWith.argument(
"unpreferred.useUnpreferredRoutesPenalty",
(Integer v) ->
Expand All @@ -691,9 +711,9 @@ public DataFetcher<DataFetcherResult<RoutingResponse>> plan() {
);
callWith.argument("walkBoardCost", preferences.walk()::setBoardCost);
callWith.argument("bikeBoardCost", preferences.bike()::setBoardCost);
callWith.argument("banned.routes", request::setBannedRoutesFromString);
callWith.argument("banned.agencies", request::setBannedAgenciesFromSting);
callWith.argument("banned.trips", request::setBannedTripsFromString);
callWith.argument("banned.routes", request.journey().transit()::setBannedRoutesFromString);
callWith.argument("banned.agencies", request.journey().transit()::setBannedAgenciesFromSting);
callWith.argument("banned.trips", request.journey().transit()::setBannedTripsFromString);
// callWith.argument("banned.stops", request::setBannedStops);
// callWith.argument("banned.stopsHard", request::setBannedStopsHard);
callWith.argument("transferPenalty", preferences.transfer()::setCost);
Expand Down Expand Up @@ -734,25 +754,28 @@ public DataFetcher<DataFetcherResult<RoutingResponse>> plan() {
)
.collect(Collectors.toSet());

request.modes = modes.getRequestModes();
request.journey().setModes(modes.getRequestModes());
}

if (hasArgument(environment, "allowedTicketTypes")) {
// request.allowedFares = new HashSet();
// ((List<String>)environment.getArgument("allowedTicketTypes")).forEach(ticketType -> request.allowedFares.add(ticketType.replaceFirst("_", ":")));
}

var vehicleRental = request.journey().rental();

// Deprecated, the next one will override this, if both are set
callWith.argument(
"allowedBikeRentalNetworks",
(Collection<String> v) -> request.allowedVehicleRentalNetworks = new HashSet<>(v)
(Collection<String> v) -> vehicleRental.setAllowedNetworks(new HashSet<>(v))
);
callWith.argument(
"allowedVehicleRentalNetworks",
(Collection<String> v) -> request.allowedVehicleRentalNetworks = new HashSet<>(v)
(Collection<String> v) -> vehicleRental.setAllowedNetworks(new HashSet<>(v))
);
callWith.argument(
"bannedVehicleRentalNetworks",
(Collection<String> v) -> request.bannedVehicleRentalNetworks = new HashSet<>(v)
(Collection<String> v) -> vehicleRental.setBannedNetworks(new HashSet<>(v))
);

if (request.vehicleRental && !hasArgument(environment, "bikeSpeed")) {
Expand All @@ -775,14 +798,6 @@ public DataFetcher<DataFetcherResult<RoutingResponse>> plan() {

preferences.rental().setUseAvailabilityInformation(request.isTripPlannedForNow());

callWith.argument(
"startTransitStopId",
(String v) -> request.startingTransitStopId = FeedScopedId.parseId(v)
);
callWith.argument(
"startTransitTripId",
(String v) -> request.startingTransitTripId = FeedScopedId.parseId(v)
);
//callWith.argument("reverseOptimizeOnTheFly", (Boolean v) -> request.reverseOptimizeOnTheFly = v);
//callWith.argument("omitCanceled", (Boolean v) -> request.omitCanceled = v);
callWith.argument("ignoreRealtimeUpdates", preferences.transit()::setIgnoreRealtimeUpdates);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.opentripplanner.routing.api.response.RoutingErrorCode;
import org.opentripplanner.routing.api.response.RoutingResponse;
import org.opentripplanner.routing.core.BicycleOptimizeType;
import org.opentripplanner.routing.core.RouteMatcher;
import org.opentripplanner.standalone.api.OtpServerRequestContext;
import org.opentripplanner.transit.model.basic.MainAndSubMode;
import org.opentripplanner.transit.model.basic.TransitMode;
Expand Down Expand Up @@ -141,7 +142,7 @@ private RouteRequest createRequest(DataFetchingEnvironment environment) {
}

callWith.argument("arriveBy", request::setArriveBy);
// TODO VIA: 2022-08-24 refactor
// TODO VIA (Skånetrafiken): 2022-08-24 refactor
// callWith.argument(
// "vias",
// (List<Map<String, Object>> v) ->
Expand All @@ -151,21 +152,23 @@ private RouteRequest createRequest(DataFetchingEnvironment environment) {

callWith.argument(
"preferred.authorities",
(Collection<String> authorities) -> request.setPreferredAgencies(mapIDsToDomain(authorities))
(Collection<String> authorities) ->
request.journey().transit().setPreferredAgencies(mapIDsToDomain(authorities))
);
callWith.argument(
"unpreferred.authorities",
(Collection<String> authorities) ->
request.setUnpreferredAgencies(mapIDsToDomain(authorities))
request.journey().transit().setUnpreferredAgencies(mapIDsToDomain(authorities))
);
callWith.argument(
"whiteListed.authorities",
(Collection<String> authorities) ->
request.setWhiteListedAgencies(mapIDsToDomain(authorities))
request.journey().transit().setWhiteListedAgencies(mapIDsToDomain(authorities))
);
callWith.argument(
"banned.authorities",
(Collection<String> authorities) -> request.setBannedAgencies(mapIDsToDomain(authorities))
(Collection<String> authorities) ->
request.journey().transit().setBannedAgencies(mapIDsToDomain(authorities))
);

callWith.argument(
Expand All @@ -174,25 +177,30 @@ private RouteRequest createRequest(DataFetchingEnvironment environment) {
);
callWith.argument(
"preferred.lines",
(List<String> lines) -> request.setPreferredRoutes(mapIDsToDomain(lines))
(List<String> lines) -> request.journey().transit().setPreferredRoutes(mapIDsToDomain(lines))
);
callWith.argument(
"unpreferred.lines",
(List<String> lines) -> request.setUnpreferredRoutes(mapIDsToDomain(lines))
(List<String> lines) ->
request.journey().transit().setUnpreferredRoutes(mapIDsToDomain(lines))
);
callWith.argument(
"whiteListed.lines",
(List<String> lines) -> request.setWhiteListedRoutes(mapIDsToDomain(lines))
(List<String> lines) ->
request
.journey()
.transit()
.setWhiteListedRoutes(RouteMatcher.idMatcher(mapIDsToDomain(lines)))
);
callWith.argument(
"banned.lines",
(List<String> lines) -> request.setBannedRoutes(mapIDsToDomain(lines))
(List<String> lines) ->
request.journey().transit().setBannedRoutes(RouteMatcher.idMatcher(mapIDsToDomain(lines)))
);

callWith.argument(
"banned.serviceJourneys",
(Collection<String> serviceJourneys) ->
request.setBannedTrips(mapIDsToDomain(serviceJourneys))
request.journey().transit().setBannedTrips(mapIDsToDomain(serviceJourneys))
);

// callWith.argument("banned.quays", quays -> request.setBannedStops(mappingUtil.prepareListOfFeedScopedId((List<String>) quays)));
Expand All @@ -213,7 +221,7 @@ private RouteRequest createRequest(DataFetchingEnvironment environment) {

RequestModes modes = getModes(environment, callWith);
if (modes != null) {
request.modes = modes;
request.journey().setModes(modes);
}
ItineraryFiltersInputType.mapToRequest(
environment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public TravelTimeResource(
routingRequest = serverContext.defaultRouteRequest();
routingRequest.setFrom(LocationStringParser.fromOldStyleString(location));
if (modes != null) {
routingRequest.modes = new QualifiedModeSet(modes).getRequestModes();
routingRequest.journey().setModes(new QualifiedModeSet(modes).getRequestModes());
}

traveltimeRequest =
Expand All @@ -114,7 +114,7 @@ public TravelTimeResource(
.preferences()
.street()
.maxAccessEgressDuration()
.valueOf(routingRequest.modes.accessMode)
.valueOf(routingRequest.journey().access().mode())
);

if (time != null) {
Expand Down Expand Up @@ -251,7 +251,7 @@ private Collection<AccessEgress> getAccess(
final Collection<NearbyStop> accessStops = AccessEgressRouter.streetSearch(
new RoutingContext(accessRequest, graph, temporaryVertices),
transitService,
routingRequest.modes.accessMode,
routingRequest.journey().access().mode(),
false
);
return new AccessEgressMapper().mapNearbyStops(accessStops, false);
Expand Down
Loading