Search in sources :

Example 6 with GtfsMutableRelationalDao

use of org.onebusaway.gtfs.services.GtfsMutableRelationalDao in project onebusaway-gtfs-modules by OneBusAway.

the class StopMergeStrategy method save.

@Override
protected void save(GtfsMergeContext context, IdentityBean<?> entity) {
    GtfsRelationalDao source = context.getSource();
    GtfsMutableRelationalDao target = context.getTarget();
    Stop stop = (Stop) entity;
    super.save(context, entity);
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) Stop(org.onebusaway.gtfs.model.Stop)

Example 7 with GtfsMutableRelationalDao

use of org.onebusaway.gtfs.services.GtfsMutableRelationalDao in project onebusaway-gtfs-modules by OneBusAway.

the class TrimTripTransformStrategyTest method testStopTimeTrimming.

@Test
public void testStopTimeTrimming() throws IOException {
    _gtfs.putAgencies(1);
    _gtfs.putStops(6);
    _gtfs.putRoutes(1);
    _gtfs.putTrips(1, "r0", "sid0");
    _gtfs.putStopTimes("t0", "s0,s1,s2,s3,s4,s5");
    GtfsMutableRelationalDao dao = _gtfs.read();
    TrimOperation operation = new TrimOperation();
    operation.setMatch(new TypedEntityMatch(Trip.class, new AlwaysMatch()));
    operation.setToStopId("s1");
    operation.setFromStopId("s4");
    _strategy.addOperation(operation);
    _strategy.run(_context, dao);
    Collection<Trip> allTrips = dao.getAllTrips();
    assertEquals(1, allTrips.size());
    Trip trip = allTrips.iterator().next();
    assertEquals(new AgencyAndId("a0", "t0-s1-s4"), trip.getId());
    List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
    assertEquals(2, stopTimes.size());
    assertEquals("s2", stopTimes.get(0).getStop().getId().getId());
    assertEquals("s3", stopTimes.get(1).getStop().getId().getId());
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) TypedEntityMatch(org.onebusaway.gtfs_transformer.match.TypedEntityMatch) Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TrimOperation(org.onebusaway.gtfs_transformer.updates.TrimTripTransformStrategy.TrimOperation) AlwaysMatch(org.onebusaway.gtfs_transformer.match.AlwaysMatch) StopTime(org.onebusaway.gtfs.model.StopTime) Test(org.junit.Test)

Example 8 with GtfsMutableRelationalDao

use of org.onebusaway.gtfs.services.GtfsMutableRelationalDao in project onebusaway-gtfs-modules by OneBusAway.

the class TrimTripTransformStrategyTest method testShapeTrimming.

@Test
public void testShapeTrimming() throws IOException {
    _gtfs.putAgencies(1);
    _gtfs.putLines("stops.txt", "stop_id,stop_name,stop_lat,stop_lon", "s0,S0,47.668422,-122.290149", "s1,S1,47.670300,-122.290235", "s2,S2,47.672172,-122.290213", "s3,S3,47.673985,-122.290277", "s4,S4,47.675791,-122.290213", "s5,S5,47.677626,-122.290320");
    _gtfs.putRoutes(1);
    _gtfs.putTrips(1, "r0", "sid0", "shape_id=shape0");
    _gtfs.putStopTimes("t0", "s0,s1,s2,s3,s4,s5");
    _gtfs.putLines("shapes.txt", "shape_id,shape_pt_sequence,shape_pt_lat,shape_pt_lon", "shape0,0,47.668422,-122.290149", "shape0,1,47.670300,-122.290235", "shape0,2,47.672172,-122.290213", "shape0,3,47.673985,-122.290277", "shape0,4,47.675791,-122.290213", "shape0,5,47.677626,-122.290320");
    GtfsMutableRelationalDao dao = _gtfs.read();
    TrimOperation operation = new TrimOperation();
    operation.setMatch(new TypedEntityMatch(Trip.class, new AlwaysMatch()));
    operation.setToStopId("s0");
    operation.setFromStopId("s4");
    _strategy.addOperation(operation);
    _strategy.run(_context, dao);
    Trip trip = dao.getTripForId(new AgencyAndId("a0", "t0-s0-s4"));
    assertEquals(new AgencyAndId("a0", "shape0-s1-s3"), trip.getShapeId());
    List<ShapePoint> shapePoints = dao.getShapePointsForShapeId(trip.getShapeId());
    assertEquals(3, shapePoints.size());
    assertEquals(47.670300, shapePoints.get(0).getLat(), 1e-6);
    assertEquals(47.673985, shapePoints.get(2).getLat(), 1e-6);
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) TypedEntityMatch(org.onebusaway.gtfs_transformer.match.TypedEntityMatch) Trip(org.onebusaway.gtfs.model.Trip) ShapePoint(org.onebusaway.gtfs.model.ShapePoint) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TrimOperation(org.onebusaway.gtfs_transformer.updates.TrimTripTransformStrategy.TrimOperation) AlwaysMatch(org.onebusaway.gtfs_transformer.match.AlwaysMatch) Test(org.junit.Test)

Example 9 with GtfsMutableRelationalDao

use of org.onebusaway.gtfs.services.GtfsMutableRelationalDao 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());
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransformContext(org.onebusaway.gtfs_transformer.services.TransformContext) GtfsTransformStrategy(org.onebusaway.gtfs_transformer.services.GtfsTransformStrategy) GtfsRelationalDaoImpl(org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl) Route(org.onebusaway.gtfs.model.Route) Test(org.junit.Test)

Example 10 with GtfsMutableRelationalDao

use of org.onebusaway.gtfs.services.GtfsMutableRelationalDao in project onebusaway-gtfs-modules by OneBusAway.

the class TransformFactoryTest method testReplaceValueInUpdate.

@Test
public void testReplaceValueInUpdate() throws IOException, TransformSpecificationException {
    _factory.addModificationsFromString("{'op':'update', " + "'match':{'file':'trips.txt'}, " + "'update':{'trip_headsign': 's/Downtown/Uptown/'}}");
    GtfsTransformStrategy transform = _transformer.getLastTransform();
    TransformContext context = new TransformContext();
    GtfsMutableRelationalDao dao = new GtfsRelationalDaoImpl();
    Trip trip = new Trip();
    trip.setId(new AgencyAndId("1", "1"));
    trip.setTripHeadsign("Downtown Express");
    dao.saveEntity(trip);
    transform.run(context, dao);
    assertEquals("Uptown Express", trip.getTripHeadsign());
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransformContext(org.onebusaway.gtfs_transformer.services.TransformContext) GtfsTransformStrategy(org.onebusaway.gtfs_transformer.services.GtfsTransformStrategy) GtfsRelationalDaoImpl(org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl) Test(org.junit.Test)

Aggregations

GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)29 Test (org.junit.Test)16 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)15 Trip (org.onebusaway.gtfs.model.Trip)9 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)7 GtfsRelationalDao (org.onebusaway.gtfs.services.GtfsRelationalDao)7 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)5 GtfsReader (org.onebusaway.gtfs.serialization.GtfsReader)5 GtfsRelationalDaoImpl (org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl)4 Stop (org.onebusaway.gtfs.model.Stop)4 MockGtfs (org.onebusaway.gtfs.services.MockGtfs)4 CalendarService (org.onebusaway.gtfs.services.calendar.CalendarService)4 TransformContext (org.onebusaway.gtfs_transformer.services.TransformContext)4 Collection (java.util.Collection)3 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)3 StopTime (org.onebusaway.gtfs.model.StopTime)3 HibernateGtfsFactory (org.onebusaway.gtfs.services.HibernateGtfsFactory)3 TypedEntityMatch (org.onebusaway.gtfs_transformer.match.TypedEntityMatch)3 TrimOperation (org.onebusaway.gtfs_transformer.updates.TrimTripTransformStrategy.TrimOperation)3 File (java.io.File)2