use of org.opentripplanner.ext.transmodelapi.model.PlanResponse in project OpenTripPlanner by opentripplanner.
the class TransmodelGraphQLSchema method createPlanType.
public GraphQLObjectType createPlanType(GraphQLOutputType bookingArrangementType, GraphQLOutputType interchangeType, GraphQLOutputType linkGeometryType, GraphQLOutputType systemNoticeType, GraphQLOutputType authorityType, GraphQLOutputType operatorType, GraphQLOutputType bikeRentalStationType, GraphQLOutputType quayType, GraphQLOutputType estimatedCallType, GraphQLOutputType lineType, GraphQLOutputType serviceJourneyType, GraphQLOutputType ptSituationElementType) {
final GraphQLObjectType placeType = GraphQLObjectType.newObject().name("Place").description("Common super class for all places (stop places, quays, car parks, bike parks and bike rental stations )").field(GraphQLFieldDefinition.newFieldDefinition().name("name").description("For transit quays, the name of the quay. For points of interest, the name of the POI.").type(Scalars.GraphQLString).dataFetcher(environment -> ((Place) environment.getSource()).name).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("vertexType").description("Type of vertex. (Normal, Bike sharing station, Bike P+R, Transit quay) Mostly used for better localization of bike sharing and P+R station names").type(EnumTypes.VERTEX_TYPE).dataFetcher(environment -> ((Place) environment.getSource()).vertexType).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("latitude").description("The latitude of the place.").type(new GraphQLNonNull(Scalars.GraphQLFloat)).dataFetcher(environment -> ((Place) environment.getSource()).coordinate.latitude()).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("longitude").description("The longitude of the place.").type(new GraphQLNonNull(Scalars.GraphQLFloat)).dataFetcher(environment -> ((Place) environment.getSource()).coordinate.longitude()).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("quay").description("The quay related to the place.").type(quayType).dataFetcher(environment -> ((Place) environment.getSource()).vertexType.equals(VertexType.TRANSIT) ? GqlUtil.getRoutingService(environment).getStopForId(((Place) environment.getSource()).stopId) : null).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("bikeRentalStation").type(bikeRentalStationType).description("The bike rental station related to the place").dataFetcher(environment -> {
return ((Place) environment.getSource()).vertexType.equals(VertexType.BIKESHARE) ? GqlUtil.getRoutingService(environment).getBikerentalStationService().getBikeRentalStations().stream().filter(bikeRentalStation -> bikeRentalStation.id.equals(((Place) environment.getSource()).bikeShareId)).findFirst().orElse(null) : null;
}).build()).build();
final GraphQLObjectType pathGuidanceType = GraphQLObjectType.newObject().name("PathGuidance").description("A series of turn by turn instructions used for walking, biking and driving.").field(GraphQLFieldDefinition.newFieldDefinition().name("distance").description("The distance in meters that this step takes.").type(Scalars.GraphQLFloat).dataFetcher(environment -> ((WalkStep) environment.getSource()).distance).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("relativeDirection").description("The relative direction of this step.").type(EnumTypes.RELATIVE_DIRECTION).dataFetcher(environment -> ((WalkStep) environment.getSource()).relativeDirection).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("streetName").description("The name of the street.").type(Scalars.GraphQLString).dataFetcher(environment -> ((WalkStep) environment.getSource()).streetName).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("heading").description("The absolute direction of this step.").type(EnumTypes.ABSOLUTE_DIRECTION).dataFetcher(environment -> ((WalkStep) environment.getSource()).absoluteDirection).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("exit").description("When exiting a highway or traffic circle, the exit name/number.").type(Scalars.GraphQLString).dataFetcher(environment -> ((WalkStep) environment.getSource()).exit).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("stayOn").description("Indicates whether or not a street changes direction at an intersection.").type(Scalars.GraphQLBoolean).dataFetcher(environment -> ((WalkStep) environment.getSource()).stayOn).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("area").description("This step is on an open area, such as a plaza or train platform, and thus the directions should say something like \"cross\"").type(Scalars.GraphQLBoolean).dataFetcher(environment -> ((WalkStep) environment.getSource()).area).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("bogusName").description("The name of this street was generated by the system, so we should only display it once, and generally just display right/left directions").type(Scalars.GraphQLBoolean).dataFetcher(environment -> ((WalkStep) environment.getSource()).bogusName).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("latitude").description("The latitude of the step.").type(Scalars.GraphQLFloat).dataFetcher(environment -> ((WalkStep) environment.getSource()).startLocation.latitude()).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("longitude").description("The longitude of the step.").type(Scalars.GraphQLFloat).dataFetcher(environment -> ((WalkStep) environment.getSource()).startLocation.longitude()).build()).build();
final GraphQLObjectType legType = GraphQLObjectType.newObject().name("Leg").description("Part of a trip pattern. Either a ride on a public transport vehicle or access or path link to/from/between places").field(GraphQLFieldDefinition.newFieldDefinition().name("aimedStartTime").description("The aimed date and time this leg starts.").type(gqlUtil.dateTimeScalar).dataFetcher(environment -> ((Leg) environment.getSource()).startTime.getTimeInMillis() - (1000 * ((Leg) environment.getSource()).departureDelay)).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("expectedStartTime").description("The expected, realtime adjusted date and time this leg starts.").type(gqlUtil.dateTimeScalar).dataFetcher(environment -> ((Leg) environment.getSource()).startTime.getTimeInMillis()).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("aimedEndTime").description("The aimed date and time this leg ends.").type(gqlUtil.dateTimeScalar).dataFetcher(environment -> ((Leg) environment.getSource()).endTime.getTimeInMillis() - (1000 * ((Leg) environment.getSource()).arrivalDelay)).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("expectedEndTime").description("The expected, realtime adjusted date and time this leg ends.").type(gqlUtil.dateTimeScalar).dataFetcher(environment -> ((Leg) environment.getSource()).endTime.getTimeInMillis()).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("mode").description("The mode of transport or access (e.g., foot) used when traversing this leg.").type(EnumTypes.MODE).dataFetcher(environment -> ((Leg) environment.getSource()).mode).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("transportSubmode").description("The transport sub mode (e.g., localBus or expressBus) used when traversing this leg. Null if leg is not a ride").type(EnumTypes.TRANSPORT_SUBMODE).dataFetcher(environment -> TransmodelTransportSubmode.UNDEFINED).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("duration").description("The legs's duration in seconds").type(Scalars.GraphQLLong).dataFetcher(environment -> ((Leg) environment.getSource()).getDuration()).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("directDuration").type(Scalars.GraphQLLong).description("NOT IMPLEMENTED").dataFetcher(environment -> ((Leg) environment.getSource()).getDuration()).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("pointsOnLink").description("The legs's geometry.").type(linkGeometryType).dataFetcher(environment -> ((Leg) environment.getSource()).legGeometry).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("authority").description("For ride legs, the service authority used for this legs. For non-ride legs, null.").type(authorityType).dataFetcher(environment -> ((Leg) environment.getSource()).getAgency()).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("operator").description("For ride legs, the operator used for this legs. For non-ride legs, null.").type(operatorType).dataFetcher(environment -> ((Leg) environment.getSource()).getOperator()).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("realtime").description("Whether there is real-time data about this leg").type(Scalars.GraphQLBoolean).dataFetcher(environment -> ((Leg) environment.getSource()).realTime).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("distance").description("The distance traveled while traversing the leg in meters.").type(Scalars.GraphQLFloat).dataFetcher(environment -> ((Leg) environment.getSource()).distanceMeters).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("ride").description("Whether this leg is a ride leg or not.").type(Scalars.GraphQLBoolean).dataFetcher(environment -> ((Leg) environment.getSource()).isTransitLeg()).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("rentedBike").description("Whether this leg is with a rented bike.").type(Scalars.GraphQLBoolean).dataFetcher(environment -> ((Leg) environment.getSource()).rentedBike).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("fromPlace").description("The Place where the leg originates.").type(new GraphQLNonNull(placeType)).dataFetcher(environment -> ((Leg) environment.getSource()).from).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("toPlace").description("The Place where the leg ends.").type(new GraphQLNonNull(placeType)).dataFetcher(environment -> ((Leg) environment.getSource()).to).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("fromEstimatedCall").description("EstimatedCall for the quay where the leg originates.").type(estimatedCallType).dataFetcher(environment -> tripTimeShortHelper.getTripTimeShortForFromPlace(environment.getSource(), gqlUtil.getRoutingService(environment))).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("toEstimatedCall").description("EstimatedCall for the quay where the leg ends.").type(estimatedCallType).dataFetcher(environment -> tripTimeShortHelper.getTripTimeShortForToPlace(environment.getSource(), gqlUtil.getRoutingService(environment))).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("line").description("For ride legs, the line. For non-ride legs, null.").type(lineType).dataFetcher(environment -> ((Leg) environment.getSource()).getRoute()).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("serviceJourney").description("For ride legs, the service journey. For non-ride legs, null.").type(serviceJourneyType).dataFetcher(environment -> ((Leg) environment.getSource()).getTrip()).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("intermediateQuays").description("For ride legs, intermediate quays between the Place where the leg originates and the Place where the leg ends. For non-ride legs, empty list.").type(new GraphQLNonNull(new GraphQLList(quayType))).dataFetcher(environment -> {
List<StopArrival> stops = ((Leg) environment.getSource()).intermediateStops;
if (stops == null || stops.isEmpty()) {
return List.of();
} else {
return (stops.stream().filter(stop -> stop.place.stopId != null).map(s -> {
return GqlUtil.getRoutingService(environment).getStopForId(s.place.stopId);
}).filter(Objects::nonNull).collect(Collectors.toList()));
}
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("intermediateEstimatedCalls").description("For ride legs, estimated calls for quays between the Place where the leg originates and the Place where the leg ends. For non-ride legs, empty list.").type(new GraphQLNonNull(new GraphQLList(estimatedCallType))).dataFetcher(environment -> tripTimeShortHelper.getIntermediateTripTimeShortsForLeg((environment.getSource()), GqlUtil.getRoutingService(environment))).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("serviceJourneyEstimatedCalls").description("For ride legs, all estimated calls for the service journey. For non-ride legs, empty list.").type(new GraphQLNonNull(new GraphQLList(estimatedCallType))).dataFetcher(environment -> {
return tripTimeShortHelper.getAllTripTimeShortsForLegsTrip(environment.getSource(), GqlUtil.getRoutingService(environment));
}).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("situations").description("All relevant situations for this leg").type(new GraphQLNonNull(new GraphQLList(ptSituationElementType))).dataFetcher(environment -> ((Leg) environment.getSource()).transitAlerts).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("steps").description("Do we continue from a specified via place").type(new GraphQLNonNull(new GraphQLList(pathGuidanceType))).dataFetcher(environment -> ((Leg) environment.getSource()).walkSteps).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("interchangeFrom").description("NOT IMPLEMENTED").type(interchangeType).dataFetcher(environment -> null).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("interchangeTo").description("NOT IMPLEMENTED").type(interchangeType).dataFetcher(environment -> null).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("bookingArrangements").type(bookingArrangementType).build()).build();
final GraphQLObjectType tripPatternType = GraphQLObjectType.newObject().name("TripPattern").description("List of legs constituting a suggested sequence of rides and links for a specific trip.").field(GraphQLFieldDefinition.newFieldDefinition().name("startTime").description("Time that the trip departs.").type(gqlUtil.dateTimeScalar).dataFetcher(environment -> ((Itinerary) environment.getSource()).startTime().getTime().getTime()).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("endTime").description("Time that the trip arrives.").type(gqlUtil.dateTimeScalar).dataFetcher(environment -> ((Itinerary) environment.getSource()).endTime().getTime().getTime()).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("duration").description("Duration of the trip, in seconds.").type(Scalars.GraphQLLong).dataFetcher(environment -> ((Itinerary) environment.getSource()).durationSeconds).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("directDuration").description("NOT IMPLEMENTED.").type(Scalars.GraphQLLong).dataFetcher(environment -> ((Itinerary) environment.getSource()).durationSeconds).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("waitingTime").description("How much time is spent waiting for transit to arrive, in seconds.").type(Scalars.GraphQLLong).dataFetcher(environment -> ((Itinerary) environment.getSource()).waitingTimeSeconds).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("distance").description("Total distance for the trip, in meters. NOT IMPLEMENTED").type(Scalars.GraphQLFloat).dataFetcher(environment -> ((Itinerary) environment.getSource()).distanceMeters()).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("walkTime").description("How much time is spent walking, in seconds.").type(Scalars.GraphQLLong).dataFetcher(environment -> ((Itinerary) environment.getSource()).nonTransitTimeSeconds).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("walkDistance").description("How far the user has to walk, in meters.").type(Scalars.GraphQLFloat).dataFetcher(environment -> ((Itinerary) environment.getSource()).nonTransitDistanceMeters).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("legs").description("A list of legs. Each leg is either a walking (cycling, car) portion of the trip, or a ride leg on a particular vehicle. So a trip where the use walks to the Q train, transfers to the 6, then walks to their destination, has four legs.").type(new GraphQLNonNull(new GraphQLList(legType))).dataFetcher(environment -> ((Itinerary) environment.getSource()).legs).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("systemNotices").description("Get all system notices.").type(new GraphQLNonNull(new GraphQLList(systemNoticeType))).dataFetcher(env -> ((Itinerary) env.getSource()).systemNotices).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("weight").description("Generalized cost or weight of the itinerary. Used for debugging.").type(Scalars.GraphQLFloat).dataFetcher(env -> ((Itinerary) env.getSource()).generalizedCost).build()).build();
GraphQLObjectType tripMetadataType = TripMetadataType.create(gqlUtil);
return GraphQLObjectType.newObject().name("Trip").description("Description of a travel between two places.").field(GraphQLFieldDefinition.newFieldDefinition().name("dateTime").description("The time and date of travel").type(gqlUtil.dateTimeScalar).dataFetcher(env -> ((PlanResponse) env.getSource()).plan.date.getTime()).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("metadata").description("The trip request metadata.").type(tripMetadataType).dataFetcher(env -> ((PlanResponse) env.getSource()).metadata).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("fromPlace").description("The origin").type(new GraphQLNonNull(placeType)).dataFetcher(env -> ((PlanResponse) env.getSource()).plan.from).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("toPlace").description("The destination").type(new GraphQLNonNull(placeType)).dataFetcher(env -> ((PlanResponse) env.getSource()).plan.to).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("tripPatterns").description("A list of possible trip patterns").type(new GraphQLNonNull(new GraphQLList(tripPatternType))).dataFetcher(env -> ((PlanResponse) env.getSource()).plan.itineraries).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("messageEnums").description("A list of possible error messages as enum").type(new GraphQLNonNull(new GraphQLList(Scalars.GraphQLString))).dataFetcher(env -> ((PlanResponse) env.getSource()).messages.stream().map(Enum::name).collect(Collectors.toList())).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("messageStrings").description("A list of possible error messages in cleartext").type(new GraphQLNonNull(new GraphQLList(Scalars.GraphQLString))).dataFetcher(env -> ((PlanResponse) env.getSource()).listErrorMessages(env.getArgument("locale"))).build()).field(GraphQLFieldDefinition.newFieldDefinition().name("debugOutput").description("Information about the timings for the trip generation").type(new GraphQLNonNull(GraphQLObjectType.newObject().name("debugOutput").field(GraphQLFieldDefinition.newFieldDefinition().name("totalTime").type(Scalars.GraphQLLong).build()).build())).dataFetcher(env -> ((PlanResponse) env.getSource()).debugOutput).build()).build();
}
use of org.opentripplanner.ext.transmodelapi.model.PlanResponse in project OpenTripPlanner by opentripplanner.
the class TransmodelGraphQLPlanner method plan.
public PlanResponse plan(DataFetchingEnvironment environment) {
PlanResponse response = new PlanResponse();
RoutingRequest request = null;
try {
TransmodelRequestContext ctx = environment.getContext();
Router router = ctx.getRouter();
request = createRequest(environment);
RoutingResponse res = ctx.getRoutingService().route(request, router);
response.plan = res.getTripPlan();
response.metadata = res.getMetadata();
for (RoutingError routingError : res.getRoutingErrors()) {
response.messages.add(PlannerErrorMapper.mapMessage(routingError).message);
}
response.debugOutput = res.getDebugAggregator().finishedRendering();
} catch (Exception e) {
LOG.warn("System error");
LOG.error("Root cause: " + e.getMessage(), e);
PlannerError error = new PlannerError();
error.setMsg(Message.SYSTEM_ERROR);
response.messages.add(error.message);
}
return response;
}
Aggregations