use of org.onebusaway.gtfs.model.Route in project onebusaway-gtfs-modules by OneBusAway.
the class PropertyMethodResolverImplTest method testAgencyRoutesVirtualMethod.
@Test
public void testAgencyRoutesVirtualMethod() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
Agency agency = new Agency();
agency.setId("1");
Route route = new Route();
route.setId(new AgencyAndId("1", "r0"));
route.setAgency(agency);
_dao.saveEntity(route);
PropertyMethod method = _resolver.getPropertyMethod(Agency.class, "routes");
assertEquals(Arrays.asList(route), method.invoke(agency));
}
use of org.onebusaway.gtfs.model.Route in project onebusaway-gtfs-modules by OneBusAway.
the class TransformFactoryTest method testPathInUpdate.
@Test
public void testPathInUpdate() throws IOException, TransformSpecificationException {
_factory.addModificationsFromString("{'op':'update', " + "'match':{'file':'trips.txt'}, " + "'update':{'trip_headsign': 'path(route.longName)'}}");
GtfsTransformStrategy transform = _transformer.getLastTransform();
TransformContext context = new TransformContext();
GtfsMutableRelationalDao dao = new GtfsRelationalDaoImpl();
Route route = new Route();
route.setLongName("long cat");
Trip trip = new Trip();
trip.setId(new AgencyAndId("1", "1"));
trip.setRoute(route);
dao.saveEntity(trip);
transform.run(context, dao);
assertEquals("long cat", trip.getTripHeadsign());
}
use of org.onebusaway.gtfs.model.Route in project onebusaway-gtfs-modules by OneBusAway.
the class DeduplicateRoutesStrategy method run.
@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
Map<AgencyAndId, List<Route>> routesById = new FactoryMap<AgencyAndId, List<Route>>(new ArrayList<Route>());
for (Route route : dao.getAllRoutes()) {
AgencyAndId aid = route.getId();
String id = aid.getId();
int index = id.indexOf('_');
if (index == -1)
continue;
String commonId = id.substring(index + 1);
AgencyAndId commonIdFull = new AgencyAndId(aid.getAgencyId(), commonId);
routesById.get(commonIdFull).add(route);
}
for (Map.Entry<AgencyAndId, List<Route>> entry : routesById.entrySet()) {
AgencyAndId routeId = entry.getKey();
List<Route> routes = entry.getValue();
if (routes.size() == 1)
continue;
// Remove the route with the old id
Route route = routes.get(0);
dao.removeEntity(route);
// Add the route with the new id
route.setId(routeId);
dao.saveEntity(route);
for (int i = 1; i < routes.size(); i++) {
Route duplicateRoute = routes.get(i);
dao.removeEntity(duplicateRoute);
List<Trip> trips = dao.getTripsForRoute(duplicateRoute);
for (Trip trip : trips) trip.setRoute(route);
}
}
UpdateLibrary.clearDaoCache(dao);
}
use of org.onebusaway.gtfs.model.Route in project OpenTripPlanner by opentripplanner.
the class OTPRequest method handle.
@Override
public Object handle(OTPRequest oreq) {
Map<String, Route> routes = Maps.newHashMap();
for (TransitBoardAlight ba : Iterables.filter(oreq.graph.getEdges(), TransitBoardAlight.class)) {
Route route = ba.getPattern().route;
routes.put(route.getId().toString(), route);
}
if (oreq.id != null) {
return routes.get(oreq.id);
} else {
return routes;
}
}
use of org.onebusaway.gtfs.model.Route in project OpenTripPlanner by opentripplanner.
the class TimetableFilterTest method setUp.
@Override
protected void setUp() {
agency = new Agency();
agency.setId("AGENCY");
route = new Route();
route.setType(com.conveyal.gtfs.model.Route.BUS);
route.setShortName("T");
route.setLongName("TEST");
route.setAgency(agency);
route.setId(new AgencyAndId(agency.getId(), "TEST"));
metro = new Route();
metro.setType(com.conveyal.gtfs.model.Route.SUBWAY);
metro.setShortName("M");
metro.setLongName("METRO");
metro.setAgency(agency);
metro.setId(new AgencyAndId(agency.getId(), "METRO"));
trip = new Trip();
trip.setRoute(route);
trip.setId(new AgencyAndId(agency.getId(), "TRIP"));
trip2 = new Trip();
trip2.setRoute(route);
trip2.setId(new AgencyAndId(agency.getId(), "TRIP2"));
stops = new Stop[4];
for (int i = 0; i < stops.length; i++) {
Stop s = new Stop();
s.setLat(-122.123);
s.setLon(37.363 + i * 0.001);
s.setId(new AgencyAndId(agency.getId(), "" + i));
stops[i] = s;
}
List<StopTime> stopTimes = makeStopTimes(trip);
StopPattern sp = new StopPattern(stopTimes);
pattern = new TripPattern(route, sp);
// make a triptimes
times = makeTripTimes(trip, stopTimes);
pattern.scheduledTimetable.addTripTimes(times);
pattern.scheduledTimetable.addTripTimes(makeTripTimes(trip2, makeStopTimes(trip2)));
// ten-minute frequency
frequencyEntry = new FrequencyEntry(7 * 3600, 12 * 3600, 600, false, makeTripTimes(trip, makeStopTimes(trip)));
pattern.scheduledTimetable.addFrequencyEntry(frequencyEntry);
pattern.scheduledTimetable.addFrequencyEntry(new FrequencyEntry(7 * 3600, 12 * 3600, 600, false, makeTripTimes(trip2, makeStopTimes(trip2))));
metroTrip = new Trip();
metroTrip.setRoute(metro);
metroTrip.setId(new AgencyAndId(agency.getId(), "TRIP"));
stopTimes = makeStopTimes(metroTrip);
sp = new StopPattern(stopTimes);
metroPattern = new TripPattern(metro, sp);
metroTimes = makeTripTimes(metroTrip, stopTimes);
metroPattern.scheduledTimetable.addTripTimes(metroTimes);
}
Aggregations