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;
}
};
}
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;
}
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());
}
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);
}
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;
}
Aggregations