Search in sources :

Example 21 with Route

use of org.opentripplanner.model.Route 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();
        VehicleParkingService vehicleParkingService = routingService.getVehicleParkingService();
        VehicleRentalStationService vehicleRentalStationService = routingService.getVehicleRentalStationService();
        switch(type) {
            case "Agency":
                return routingService.getAgencyForId(FeedScopedId.parseId(id));
            case "Alert":
                // TODO
                return null;
            case "BikePark":
                var bikeParkId = FeedScopedId.parseId(id);
                return vehicleParkingService == null ? null : vehicleParkingService.getBikeParks().filter(bikePark -> bikePark.getId().equals(bikeParkId)).findAny().orElse(null);
            case "BikeRentalStation":
                return vehicleRentalStationService == null ? null : vehicleRentalStationService.getVehicleRentalPlace(FeedScopedId.parseId(id));
            case "VehicleRentalStation":
                return vehicleRentalStationService == null ? null : vehicleRentalStationService.getVehicleRentalStation(FeedScopedId.parseId(id));
            case "RentalVehicle":
                return vehicleRentalStationService == null ? null : vehicleRentalStationService.getVehicleRentalVehicle(FeedScopedId.parseId(id));
            case "CarPark":
                var carParkId = FeedScopedId.parseId(id);
                return vehicleParkingService == null ? null : vehicleParkingService.getCarParks().filter(carPark -> carPark.getId().equals(carParkId)).findAny().orElse(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(";");
                    var stop = routingService.getStopForId(FeedScopedId.parseId(parts[1]));
                    // TODO: Add geometry
                    return new NearbyStop(stop, Integer.parseInt(parts[0]), null, null, null);
                }
            case "TicketType":
                // TODO
                return null;
            case "Trip":
                var scopedId = FeedScopedId.parseId(id);
                var trip = routingService.getTripForId().get(scopedId);
                return trip;
            case "VehicleParking":
                var vehicleParkingId = FeedScopedId.parseId(id);
                return vehicleParkingService == null ? null : vehicleParkingService.getVehicleParkings().filter(bikePark -> bikePark.getId().equals(vehicleParkingId)).findAny().orElse(null);
            default:
                return null;
        }
    };
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) Arrays(java.util.Arrays) RoutingService(org.opentripplanner.routing.RoutingService) NearbyStop(org.opentripplanner.routing.graphfinder.NearbyStop) 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) VehicleRentalStation(org.opentripplanner.routing.vehicle_rental.VehicleRentalStation) LegacyGraphQLRequestContext(org.opentripplanner.ext.legacygraphqlapi.LegacyGraphQLRequestContext) PlaceType(org.opentripplanner.routing.graphfinder.PlaceType) VehicleRentalVehicle(org.opentripplanner.routing.vehicle_rental.VehicleRentalVehicle) LegacyGraphQLCauseMapper.getLegacyGraphQLCause(org.opentripplanner.ext.legacygraphqlapi.mapping.LegacyGraphQLCauseMapper.getLegacyGraphQLCause) PatternAtStop(org.opentripplanner.routing.graphfinder.PatternAtStop) 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) GenericLocation(org.opentripplanner.model.GenericLocation) TripPattern(org.opentripplanner.model.TripPattern) Collection(java.util.Collection) Stop(org.opentripplanner.model.Stop) EntitySelector(org.opentripplanner.routing.alertpatch.EntitySelector) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) TransitAlert(org.opentripplanner.routing.alertpatch.TransitAlert) List(java.util.List) Stream(java.util.stream.Stream) VehicleParking(org.opentripplanner.routing.vehicle_parking.VehicleParking) VehicleParkingService(org.opentripplanner.routing.vehicle_parking.VehicleParkingService) ResourceBundleSingleton(org.opentripplanner.util.ResourceBundleSingleton) Relay(graphql.relay.Relay) PlaceAtDistance(org.opentripplanner.routing.graphfinder.PlaceAtDistance) VehicleRentalStationService(org.opentripplanner.routing.vehicle_rental.VehicleRentalStationService) LegacyGraphQLTypes(org.opentripplanner.ext.legacygraphqlapi.generated.LegacyGraphQLTypes) Multimaps(com.google.common.collect.Multimaps) ArrayList(java.util.ArrayList) RoutingValidationException(org.opentripplanner.routing.error.RoutingValidationException) Lists(com.google.common.collect.Lists) Connection(graphql.relay.Connection) QualifiedModeSet(org.opentripplanner.api.parameter.QualifiedModeSet) LegacyGraphQLSeverityMapper.getLegacyGraphQLSeverity(org.opentripplanner.ext.legacygraphqlapi.mapping.LegacyGraphQLSeverityMapper.getLegacyGraphQLSeverity) QualifiedMode(org.opentripplanner.api.parameter.QualifiedMode) DataFetcher(graphql.schema.DataFetcher) DataFetcherResult(graphql.execution.DataFetcherResult) StreamSupport(java.util.stream.StreamSupport) GtfsRealtimeFuzzyTripMatcher(org.opentripplanner.updater.GtfsRealtimeFuzzyTripMatcher) VehicleRentalPlace(org.opentripplanner.routing.vehicle_rental.VehicleRentalPlace) LegacyGraphQLEffectMapper.getLegacyGraphQLEffect(org.opentripplanner.ext.legacygraphqlapi.mapping.LegacyGraphQLEffectMapper.getLegacyGraphQLEffect) 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) TripTimeOnDate(org.opentripplanner.model.TripTimeOnDate) LegacyGraphQLDataFetchers(org.opentripplanner.ext.legacygraphqlapi.generated.LegacyGraphQLDataFetchers) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) Collections(java.util.Collections) Envelope(org.locationtech.jts.geom.Envelope) FareRuleSet(org.opentripplanner.routing.core.FareRuleSet) LegacyGraphQLRequestContext(org.opentripplanner.ext.legacygraphqlapi.LegacyGraphQLRequestContext) Relay(graphql.relay.Relay) NearbyStop(org.opentripplanner.routing.graphfinder.NearbyStop) PlaceAtDistance(org.opentripplanner.routing.graphfinder.PlaceAtDistance) RoutingService(org.opentripplanner.routing.RoutingService) VehicleRentalStationService(org.opentripplanner.routing.vehicle_rental.VehicleRentalStationService) LegacyGraphQLTypes(org.opentripplanner.ext.legacygraphqlapi.generated.LegacyGraphQLTypes) VehicleParkingService(org.opentripplanner.routing.vehicle_parking.VehicleParkingService)

Example 22 with Route

use of org.opentripplanner.model.Route 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 VehicleParking) {
        var vehicleParking = (VehicleParking) o;
        if (queryContainsFragment("BikePark", environment) && vehicleParking.hasBicyclePlaces()) {
            return schema.getObjectType("BikePark");
        }
        if (queryContainsFragment("CarPark", environment) && vehicleParking.hasAnyCarPlaces()) {
            return schema.getObjectType("CarPark");
        }
        return schema.getObjectType("VehicleParking");
    }
    if (o instanceof VehicleRentalVehicle) {
        return schema.getObjectType("RentalVehicle");
    }
    if (o instanceof VehicleRentalStation) {
        if (queryContainsFragment("BikeRentalStation", environment)) {
            return schema.getObjectType("BikeRentalStation");
        }
        return schema.getObjectType("VehicleRentalStation");
    }
    // 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 TripTimeOnDate) {
        return schema.getObjectType("Stoptime");
    }
    if (o instanceof NearbyStop) {
        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) NearbyStop(org.opentripplanner.routing.graphfinder.NearbyStop) Stop(org.opentripplanner.model.Stop) PatternAtStop(org.opentripplanner.routing.graphfinder.PatternAtStop) NearbyStop(org.opentripplanner.routing.graphfinder.NearbyStop) PlaceAtDistance(org.opentripplanner.routing.graphfinder.PlaceAtDistance) VehicleRentalStation(org.opentripplanner.routing.vehicle_rental.VehicleRentalStation) FareRuleSet(org.opentripplanner.routing.core.FareRuleSet) GraphQLSchema(graphql.schema.GraphQLSchema) TripPattern(org.opentripplanner.model.TripPattern) Station(org.opentripplanner.model.Station) VehicleRentalStation(org.opentripplanner.routing.vehicle_rental.VehicleRentalStation) VehicleParking(org.opentripplanner.routing.vehicle_parking.VehicleParking) PatternAtStop(org.opentripplanner.routing.graphfinder.PatternAtStop) VehicleRentalVehicle(org.opentripplanner.routing.vehicle_rental.VehicleRentalVehicle) TripTimeOnDate(org.opentripplanner.model.TripTimeOnDate) Route(org.opentripplanner.model.Route)

Example 23 with Route

use of org.opentripplanner.model.Route in project OpenTripPlanner by opentripplanner.

the class IndexAPI method getTripsForRoute.

/**
 * Return all trips in any pattern on the given route.
 */
@GET
@Path("/routes/{routeId}/trips")
public List<ApiTripShort> getTripsForRoute(@PathParam("routeId") String routeId) {
    RoutingService routingService = createRoutingService();
    Route route = getRoute(routingService, routeId);
    var patterns = routingService.getPatternsForRoute().get(route);
    return patterns.stream().flatMap(TripPattern::scheduledTripsAsStream).map(TripMapper::mapToApiShort).collect(Collectors.toList());
}
Also used : RoutingService(org.opentripplanner.routing.RoutingService) ApiRoute(org.opentripplanner.api.model.ApiRoute) Route(org.opentripplanner.model.Route) TripPattern(org.opentripplanner.model.TripPattern) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 24 with Route

use of org.opentripplanner.model.Route in project OpenTripPlanner by opentripplanner.

the class IndexAPI method getStopsForRoute.

/**
 * Return all stops in any pattern on a given route.
 */
@GET
@Path("/routes/{routeId}/stops")
public List<ApiStopShort> getStopsForRoute(@PathParam("routeId") String routeId) {
    RoutingService routingService = createRoutingService();
    Route route = getRoute(routingService, routeId);
    Set<StopLocation> stops = new HashSet<>();
    Collection<TripPattern> patterns = routingService.getPatternsForRoute().get(route);
    for (TripPattern pattern : patterns) {
        stops.addAll(pattern.getStops());
    }
    return StopMapper.mapToApiShort(stops);
}
Also used : RoutingService(org.opentripplanner.routing.RoutingService) StopLocation(org.opentripplanner.model.StopLocation) ApiRoute(org.opentripplanner.api.model.ApiRoute) Route(org.opentripplanner.model.Route) TripPattern(org.opentripplanner.model.TripPattern) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 25 with Route

use of org.opentripplanner.model.Route in project OpenTripPlanner by opentripplanner.

the class RouteMapper method doMap.

private Route doMap(org.onebusaway.gtfs.model.Route rhs) {
    Route lhs = new Route(AgencyAndIdMapper.mapAgencyAndId(rhs.getId()));
    lhs.setAgency(agencyMapper.map(rhs.getAgency()));
    lhs.setShortName(rhs.getShortName());
    lhs.setLongName(rhs.getLongName());
    int routeType = rhs.getType();
    lhs.setGtfsType(routeType);
    TransitMode mode = TransitModeMapper.mapMode(routeType);
    if (mode == null) {
        issueStore.add("RouteMapper", "Treating %s route type for route %s as BUS.", routeType, lhs.getId().toString());
        lhs.setMode(TransitMode.BUS);
    } else {
        lhs.setMode(mode);
    }
    lhs.setDesc(rhs.getDesc());
    lhs.setUrl(rhs.getUrl());
    lhs.setColor(rhs.getColor());
    lhs.setTextColor(rhs.getTextColor());
    lhs.setBikesAllowed(BikeAccessMapper.mapForRoute(rhs));
    lhs.setSortOrder(rhs.getSortOrder());
    lhs.setBranding(brandingMapper.map(rhs));
    return lhs;
}
Also used : TransitMode(org.opentripplanner.model.TransitMode) Route(org.opentripplanner.model.Route)

Aggregations

Route (org.opentripplanner.model.Route)58 FeedScopedId (org.opentripplanner.model.FeedScopedId)22 Trip (org.opentripplanner.model.Trip)22 TripPattern (org.opentripplanner.model.TripPattern)16 Test (org.junit.Test)14 Line (org.rutebanken.netex.model.Line)11 Agency (org.opentripplanner.model.Agency)10 ArrayList (java.util.ArrayList)7 Test (org.junit.jupiter.api.Test)7 DataImportIssueStore (org.opentripplanner.graph_builder.DataImportIssueStore)7 Stop (org.opentripplanner.model.Stop)7 HashSet (java.util.HashSet)6 List (java.util.List)6 ServiceDate (org.opentripplanner.model.calendar.ServiceDate)6 OtpTransitServiceBuilder (org.opentripplanner.model.impl.OtpTransitServiceBuilder)6 NetexEntityIndex (org.opentripplanner.netex.index.NetexEntityIndex)6 RoutingService (org.opentripplanner.routing.RoutingService)6 RoutingRequest (org.opentripplanner.routing.api.request.RoutingRequest)6 StopTime (org.opentripplanner.model.StopTime)5 TransitMode (org.opentripplanner.model.TransitMode)5