Search in sources :

Example 31 with Route

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());
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Route(org.onebusaway.gtfs.model.Route)

Example 32 with Route

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);
}
Also used : Agency(org.onebusaway.gtfs.model.Agency) Route(org.onebusaway.gtfs.model.Route) Test(org.junit.Test)

Example 33 with Route

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);
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Route(org.onebusaway.gtfs.model.Route) Test(org.junit.Test)

Example 34 with Route

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));
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Route(org.onebusaway.gtfs.model.Route) Test(org.junit.Test)

Example 35 with Route

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());
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) PropertyPathExpression(org.onebusaway.collections.beans.PropertyPathExpression) Route(org.onebusaway.gtfs.model.Route) Test(org.junit.Test)

Aggregations

Route (org.onebusaway.gtfs.model.Route)90 Trip (org.onebusaway.gtfs.model.Trip)52 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)46 Test (org.junit.Test)33 Stop (org.onebusaway.gtfs.model.Stop)28 Agency (org.onebusaway.gtfs.model.Agency)21 ArrayList (java.util.ArrayList)16 StopTime (org.onebusaway.gtfs.model.StopTime)14 TripPattern (org.opentripplanner.routing.edgetype.TripPattern)14 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)12 HashMap (java.util.HashMap)10 Edge (org.opentripplanner.routing.graph.Edge)8 GET (javax.ws.rs.GET)7 Path (javax.ws.rs.Path)7 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)7 TransitGraphImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl)7 List (java.util.List)6 RouteEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl)6 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)6 Coordinate (com.vividsolutions.jts.geom.Coordinate)5