use of org.onebusaway.gtfs.model.Route in project onebusaway-gtfs-modules by OneBusAway.
the class MergeRouteFromReferenceStrategyById method run.
@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
GtfsMutableRelationalDao reference = (GtfsMutableRelationalDao) context.getReferenceReader().getEntityStore();
RemoveEntityLibrary removeEntityLibrary = new RemoveEntityLibrary();
ArrayList<Route> routesToRemove = new ArrayList();
HashMap<String, Route> referenceRoutes = new HashMap<>();
for (Route route : reference.getAllRoutes()) {
referenceRoutes.put(route.getId().getId(), route);
}
_log.info("Routes: {}, Trips: {}", dao.getAllRoutes().size(), dao.getAllTrips().size());
for (Route route : dao.getAllRoutes()) {
String identifier = route.getId().getId();
Route refRoute = referenceRoutes.get(identifier);
if (refRoute != null) {
setRoute(route, refRoute);
} else {
// if yes, check if it matches w/out LTD
if (identifier.contains("-LTD")) {
identifier = identifier.replace("-LTD", "");
refRoute = referenceRoutes.get(identifier);
if (refRoute != null) {
updateTripHeadsign(dao, route);
// dao.getRouteForId only works with route ids that have not changed at all from input
if (dao.getRouteForId(new AgencyAndId(route.getId().getAgencyId(), refRoute.getId().getId())) != null) {
routesToRemove.add(route);
for (Trip trip : dao.getTripsForRoute(route)) {
trip.setRoute(dao.getRouteForId(new AgencyAndId(route.getId().getAgencyId(), refRoute.getId().getId())));
}
} else // otherwise, update the route id etc
{
setLTDRoute(route, refRoute);
}
} else if (identifier.equals("Q6")) {
refRoute = referenceRoutes.get("Q06");
if (refRoute != null) {
updateTripHeadsign(dao, route);
if (dao.getRouteForId(new AgencyAndId(route.getId().getAgencyId(), "Q6")) != null) {
routesToRemove.add(route);
for (Trip trip : dao.getTripsForRoute(route)) {
trip.setRoute(dao.getRouteForId(new AgencyAndId(route.getId().getAgencyId(), "Q6")));
}
}
}
} else {
_log.info("No reference route for route: " + route.getId().getId());
}
}
}
}
_log.info("Routes to remove: " + routesToRemove.size());
for (Route route : routesToRemove) {
dao.removeEntity(route);
}
_log.info("Routes: {}, Trips: {}", dao.getAllRoutes().size(), dao.getAllTrips().size());
}
use of org.onebusaway.gtfs.model.Route in project onebusaway-gtfs-modules by OneBusAway.
the class DeferredValueConverterTest method testEntity.
@Test
public void testEntity() {
Agency agency = new Agency();
agency.setId("1");
_dao.saveEntity(agency);
Route route = new Route();
Object value = convert(route, "agency", "1");
assertEquals(agency, value);
}
use of org.onebusaway.gtfs.model.Route in project onebusaway-gtfs-modules by OneBusAway.
the class DeferredValueConverterTest method testEntity_AgencyAndId.
@Test
public void testEntity_AgencyAndId() {
Route route = new Route();
route.setId(new AgencyAndId("1", "10"));
_reader.injectEntity(route);
_dao.saveEntity(route);
Trip trip = new Trip();
Object value = convert(trip, "route", "10");
assertEquals(route, value);
}
use of org.onebusaway.gtfs.model.Route in project onebusaway-gtfs-modules by OneBusAway.
the class DeferredValueMatcherTest method testEntity.
@Test
public void testEntity() {
DeferredValueMatcher matcher = matcher("R10");
Route routeA = new Route();
routeA.setId(new AgencyAndId("1", "R10"));
Route routeB = new Route();
routeB.setId(new AgencyAndId("1", "R20"));
assertTrue(matcher.matches(Trip.class, "route", routeA));
assertFalse(matcher.matches(Trip.class, "route", routeB));
}
use of org.onebusaway.gtfs.model.Route in project onebusaway-gtfs-modules by OneBusAway.
the class PropertyPathExpressionValueSetterTest method test.
@Test
public void test() {
PropertyPathExpression expression = new PropertyPathExpression("route.shortName");
PropertyPathExpressionValueSetter setter = new PropertyPathExpressionValueSetter(_reader, _schemaCache, _dao, expression);
Route route = new Route();
route.setShortName("10");
Trip trip = new Trip();
trip.setRoute(route);
setter.setValue(BeanWrapperFactory.wrap(trip), "tripShortName");
assertEquals("10", trip.getTripShortName());
}
Aggregations