Search in sources :

Example 1 with LegacyGraphQLRequestContext

use of org.opentripplanner.ext.legacygraphqlapi.LegacyGraphQLRequestContext in project OpenTripPlanner by opentripplanner.

the class LegacyGraphQLQueryTypeImpl method node.

@Override
public DataFetcher<Object> node() {
    return environment -> {
        var args = new LegacyGraphQLTypes.LegacyGraphQLQueryTypeNodeArgs(environment.getArguments());
        String type = args.getLegacyGraphQLId().getType();
        String id = args.getLegacyGraphQLId().getId();
        RoutingService routingService = environment.<LegacyGraphQLRequestContext>getContext().getRoutingService();
        BikeRentalStationService bikerentalStationService = routingService.getBikerentalStationService();
        switch(type) {
            case "Agency":
                return routingService.getAgencyForId(FeedScopedId.parseId(id));
            case "Alert":
                // TODO
                return null;
            case "BikePark":
                return bikerentalStationService == null ? null : bikerentalStationService.getBikeParks().stream().filter(bikePark -> bikePark.id.equals(id)).findAny().orElse(null);
            case "BikeRentalStation":
                return bikerentalStationService == null ? null : bikerentalStationService.getBikeRentalStations().stream().filter(bikeRentalStation -> bikeRentalStation.id.equals(id)).findAny().orElse(null);
            case "CarPark":
                // TODO
                return null;
            case "Cluster":
                // TODO
                return null;
            case "DepartureRow":
                return PatternAtStop.fromId(routingService, id);
            case "Pattern":
                return routingService.getTripPatternForId(FeedScopedId.parseId(id));
            case "placeAtDistance":
                {
                    String[] parts = id.split(";");
                    Relay.ResolvedGlobalId internalId = new Relay().fromGlobalId(parts[1]);
                    Object place = node().get(DataFetchingEnvironmentImpl.newDataFetchingEnvironment(environment).source(new Object()).arguments(Map.of("id", internalId)).build());
                    return new PlaceAtDistance(place, Double.parseDouble(parts[0]));
                }
            case "Route":
                return routingService.getRouteForId(FeedScopedId.parseId(id));
            case "Stop":
                return routingService.getStopForId(FeedScopedId.parseId(id));
            case "Stoptime":
                // TODO
                return null;
            case "stopAtDistance":
                {
                    String[] parts = id.split(";");
                    Stop stop = routingService.getStopForId(FeedScopedId.parseId(parts[1]));
                    // TODO: Add geometry
                    return new StopAtDistance(stop, Integer.parseInt(parts[0]), null, null, null);
                }
            case "TicketType":
                // TODO
                return null;
            case "Trip":
                return routingService.getTripForId().get(FeedScopedId.parseId(id));
            default:
                return null;
        }
    };
}
Also used : DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) Arrays(java.util.Arrays) RoutingService(org.opentripplanner.routing.RoutingService) Trip(org.opentripplanner.model.Trip) Date(java.util.Date) TransitStopVertex(org.opentripplanner.routing.vertextype.TransitStopVertex) Coordinate(org.locationtech.jts.geom.Coordinate) ServiceDate(org.opentripplanner.model.calendar.ServiceDate) LegacyGraphQLRequestContext(org.opentripplanner.ext.legacygraphqlapi.LegacyGraphQLRequestContext) PlaceType(org.opentripplanner.routing.graphfinder.PlaceType) PatternAtStop(org.opentripplanner.routing.graphfinder.PatternAtStop) TripTimeShort(org.opentripplanner.model.TripTimeShort) Duration(java.time.Duration) Map(java.util.Map) BicycleOptimizeType(org.opentripplanner.routing.core.BicycleOptimizeType) TransitMode(org.opentripplanner.model.TransitMode) FeedScopedId(org.opentripplanner.model.FeedScopedId) Station(org.opentripplanner.model.Station) BikePark(org.opentripplanner.routing.bike_park.BikePark) GenericLocation(org.opentripplanner.model.GenericLocation) TripPattern(org.opentripplanner.model.TripPattern) Stop(org.opentripplanner.model.Stop) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) TransitAlert(org.opentripplanner.routing.alertpatch.TransitAlert) List(java.util.List) Stream(java.util.stream.Stream) BikeRentalStation(org.opentripplanner.routing.bike_rental.BikeRentalStation) ResourceBundleSingleton(org.opentripplanner.util.ResourceBundleSingleton) Relay(graphql.relay.Relay) PlaceAtDistance(org.opentripplanner.routing.graphfinder.PlaceAtDistance) StopAtDistance(org.opentripplanner.routing.graphfinder.StopAtDistance) LegacyGraphQLTypes(org.opentripplanner.ext.legacygraphqlapi.generated.LegacyGraphQLTypes) RoutingValidationException(org.opentripplanner.routing.error.RoutingValidationException) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) Connection(graphql.relay.Connection) QualifiedModeSet(org.opentripplanner.api.parameter.QualifiedModeSet) QualifiedMode(org.opentripplanner.api.parameter.QualifiedMode) DataFetcher(graphql.schema.DataFetcher) ParameterException(org.opentripplanner.api.common.ParameterException) StreamSupport(java.util.stream.StreamSupport) GtfsRealtimeFuzzyTripMatcher(org.opentripplanner.updater.GtfsRealtimeFuzzyTripMatcher) SimpleListConnection(graphql.relay.SimpleListConnection) RoutingResponse(org.opentripplanner.routing.api.response.RoutingResponse) Agency(org.opentripplanner.model.Agency) DataFetchingEnvironmentImpl(graphql.schema.DataFetchingEnvironmentImpl) Consumer(java.util.function.Consumer) Route(org.opentripplanner.model.Route) BikeRentalStationService(org.opentripplanner.routing.bike_rental.BikeRentalStationService) LegacyGraphQLDataFetchers(org.opentripplanner.ext.legacygraphqlapi.generated.LegacyGraphQLDataFetchers) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) Envelope(org.locationtech.jts.geom.Envelope) Collections(java.util.Collections) FeedInfo(org.opentripplanner.model.FeedInfo) FareRuleSet(org.opentripplanner.routing.core.FareRuleSet) LegacyGraphQLRequestContext(org.opentripplanner.ext.legacygraphqlapi.LegacyGraphQLRequestContext) Relay(graphql.relay.Relay) PatternAtStop(org.opentripplanner.routing.graphfinder.PatternAtStop) Stop(org.opentripplanner.model.Stop) PlaceAtDistance(org.opentripplanner.routing.graphfinder.PlaceAtDistance) RoutingService(org.opentripplanner.routing.RoutingService) BikeRentalStationService(org.opentripplanner.routing.bike_rental.BikeRentalStationService) LegacyGraphQLTypes(org.opentripplanner.ext.legacygraphqlapi.generated.LegacyGraphQLTypes) StopAtDistance(org.opentripplanner.routing.graphfinder.StopAtDistance)

Aggregations

Lists (com.google.common.collect.Lists)1 Connection (graphql.relay.Connection)1 Relay (graphql.relay.Relay)1 SimpleListConnection (graphql.relay.SimpleListConnection)1 DataFetcher (graphql.schema.DataFetcher)1 DataFetchingEnvironment (graphql.schema.DataFetchingEnvironment)1 DataFetchingEnvironmentImpl (graphql.schema.DataFetchingEnvironmentImpl)1 Duration (java.time.Duration)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 StreamSupport (java.util.stream.StreamSupport)1 Coordinate (org.locationtech.jts.geom.Coordinate)1