Search in sources :

Example 1 with PlaceAtDistance

use of org.opentripplanner.routing.graphfinder.PlaceAtDistance 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)

Example 2 with PlaceAtDistance

use of org.opentripplanner.routing.graphfinder.PlaceAtDistance in project OpenTripPlanner by opentripplanner.

the class LegacyGraphQLNodeTypeResolver method getType.

@Override
public GraphQLObjectType getType(TypeResolutionEnvironment environment) {
    Object o = environment.getObject();
    GraphQLSchema schema = environment.getSchema();
    if (o instanceof Agency)
        return schema.getObjectType("Agency");
    if (o instanceof TransitAlert)
        return schema.getObjectType("Alert");
    if (o instanceof BikePark)
        return schema.getObjectType("BikePark");
    if (o instanceof BikeRentalStation)
        return schema.getObjectType("BikeRentalStation");
    // if (o instanceof Cluster) return schema.getObjectType("Cluster");
    if (o instanceof PatternAtStop)
        return schema.getObjectType("DepartureRow");
    if (o instanceof TripPattern)
        return schema.getObjectType("Pattern");
    if (o instanceof PlaceAtDistance)
        return schema.getObjectType("placeAtDistance");
    if (o instanceof Route)
        return schema.getObjectType("Route");
    if (o instanceof Stop)
        return schema.getObjectType("Stop");
    if (o instanceof Station)
        return schema.getObjectType("Stop");
    if (o instanceof TripTimeShort)
        return schema.getObjectType("Stoptime");
    if (o instanceof StopAtDistance)
        return schema.getObjectType("stopAtDistance");
    if (o instanceof FareRuleSet)
        return schema.getObjectType("TicketType");
    if (o instanceof Trip)
        return schema.getObjectType("Trip");
    return null;
}
Also used : TransitAlert(org.opentripplanner.routing.alertpatch.TransitAlert) Trip(org.opentripplanner.model.Trip) Agency(org.opentripplanner.model.Agency) Stop(org.opentripplanner.model.Stop) PatternAtStop(org.opentripplanner.routing.graphfinder.PatternAtStop) PlaceAtDistance(org.opentripplanner.routing.graphfinder.PlaceAtDistance) FareRuleSet(org.opentripplanner.routing.core.FareRuleSet) BikePark(org.opentripplanner.routing.bike_park.BikePark) GraphQLSchema(graphql.schema.GraphQLSchema) BikeRentalStation(org.opentripplanner.routing.bike_rental.BikeRentalStation) TripPattern(org.opentripplanner.model.TripPattern) Station(org.opentripplanner.model.Station) BikeRentalStation(org.opentripplanner.routing.bike_rental.BikeRentalStation) TripTimeShort(org.opentripplanner.model.TripTimeShort) PatternAtStop(org.opentripplanner.routing.graphfinder.PatternAtStop) StopAtDistance(org.opentripplanner.routing.graphfinder.StopAtDistance) Route(org.opentripplanner.model.Route)

Aggregations

Agency (org.opentripplanner.model.Agency)2 Route (org.opentripplanner.model.Route)2 Station (org.opentripplanner.model.Station)2 Stop (org.opentripplanner.model.Stop)2 Trip (org.opentripplanner.model.Trip)2 TripPattern (org.opentripplanner.model.TripPattern)2 TripTimeShort (org.opentripplanner.model.TripTimeShort)2 TransitAlert (org.opentripplanner.routing.alertpatch.TransitAlert)2 BikePark (org.opentripplanner.routing.bike_park.BikePark)2 BikeRentalStation (org.opentripplanner.routing.bike_rental.BikeRentalStation)2 FareRuleSet (org.opentripplanner.routing.core.FareRuleSet)2 PatternAtStop (org.opentripplanner.routing.graphfinder.PatternAtStop)2 PlaceAtDistance (org.opentripplanner.routing.graphfinder.PlaceAtDistance)2 StopAtDistance (org.opentripplanner.routing.graphfinder.StopAtDistance)2 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