Search in sources :

Example 1 with GtfsTransformStrategy

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

the class UpdateStopNameFromParentStationIfInvalidStrategyTest method test.

@Test
public void test() throws IOException {
    _gtfs.putAgencies(1);
    _gtfs.putLines("stops.txt", "stop_id,stop_name,stop_lat,stop_lon,location_type,parent_station,platform_code", "stop0,2,1,1,0,,", "stop1,Station A Platform 1,0,0,0,station0,1", "stop2,2,0,0,0,station0,2", "station0,Station A,0,0,1,,");
    _gtfs.putCalendars(1);
    _gtfs.putRoutes(1);
    _gtfs.putTrips(2, "r0", "sid0");
    _gtfs.putStopTimes("t0", "stop0,stop1");
    _gtfs.putStopTimes("t0", "stop2,stop0");
    GtfsMutableRelationalDao dao = _gtfs.read();
    TransformContext tc = new TransformContext();
    tc.setDefaultAgencyId("a0");
    GtfsTransformStrategy strategy = new UpdateStopNameFromParentStationIfInvalidStrategy();
    strategy.run(tc, dao);
    UpdateLibrary.clearDaoCache(dao);
    assertEquals("2", getStopName(dao, "stop0"));
    assertEquals("Station A Platform 1", getStopName(dao, "stop1"));
    assertEquals("Station A", getStopName(dao, "stop2"));
    assertEquals("Station A", getStopName(dao, "station0"));
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) TransformContext(org.onebusaway.gtfs_transformer.services.TransformContext) GtfsTransformStrategy(org.onebusaway.gtfs_transformer.services.GtfsTransformStrategy) Test(org.junit.Test)

Example 2 with GtfsTransformStrategy

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

the class GtfsTransformer method updateGtfs.

private void updateGtfs() {
    for (GtfsTransformStrategy strategy : _transformStrategies) {
        String strategyName = strategy.toString();
        try {
            strategyName = strategy.getName();
        } catch (AbstractMethodError ame) {
            _log.info("(AbstractMethodError) strategy " + strategy + " does not support getName");
        }
        _log.info("Running strategy {} ....", strategyName);
        try {
            strategy.run(_context, _dao);
        } catch (Throwable t) {
            _log.error("Exception in strategy (v1) " + strategyName, t);
            throw new RuntimeException(t);
        }
        _log.info("Strategy {} complete.", strategyName);
    }
}
Also used : GtfsTransformStrategy(org.onebusaway.gtfs_transformer.services.GtfsTransformStrategy)

Example 3 with GtfsTransformStrategy

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

the class TransformFactory method configureStopNameUpdates.

// private void configureCalendarUpdates(GtfsTransformer transformer, String path) {
// 
// if (path == null)
// return;
// 
// try {
// CalendarUpdateStrategy updateStrategy = new CalendarUpdateStrategy();
// 
// TripScheduleModificationFactoryBean factory = new TripScheduleModificationFactoryBean();
// factory.setPath(path);
// 
// TripScheduleModificationStrategy modification = factory.createModificationStrategy();
// updateStrategy.addModificationStrategy(modification);
// 
// transformer.addTransform(updateStrategy);
// 
// } catch (IOException ex) {
// throw new IllegalStateException(ex);
// }
// }
private void configureStopNameUpdates(GtfsTransformer transformer, String path) {
    if (path == null)
        return;
    try {
        StopNameUpdateFactoryStrategy factory = new StopNameUpdateFactoryStrategy();
        if (path.startsWith("http")) {
            GtfsTransformStrategy strategy = factory.createFromUrl(new URL(path));
            transformer.addTransform(strategy);
        } else {
            GtfsTransformStrategy strategy = factory.createFromFile(new File(path));
            transformer.addTransform(strategy);
        }
    } catch (IOException ex) {
        throw new IllegalStateException(ex);
    }
}
Also used : GtfsTransformStrategy(org.onebusaway.gtfs_transformer.services.GtfsTransformStrategy) URL(java.net.URL)

Example 4 with GtfsTransformStrategy

use of org.onebusaway.gtfs_transformer.services.GtfsTransformStrategy 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)

Example 5 with GtfsTransformStrategy

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

the class TransformFactoryTest method testReplaceIdInUpdateComplex.

@Test
public void testReplaceIdInUpdateComplex() throws IOException, TransformSpecificationException {
    _factory.addModificationsFromString("{'op':'update', " + "'match':{'file':'trips.txt'}, " + "'update':{'trip_id': 's/^([^_]*)_([0-9]*).*/$2/'}}");
    GtfsTransformStrategy transform = _transformer.getLastTransform();
    TransformContext context = new TransformContext();
    context.setDefaultAgencyId("2");
    GtfsMutableRelationalDao dao = new GtfsRelationalDaoImpl();
    Trip trip = new Trip();
    trip.setId(new AgencyAndId("2", "1234-this-text-to-remove"));
    dao.saveEntity(trip);
    transform.run(context, dao);
    assertEquals("1234", trip.getId().getId());
}
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

GtfsTransformStrategy (org.onebusaway.gtfs_transformer.services.GtfsTransformStrategy)13 Test (org.junit.Test)9 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)6 TransformContext (org.onebusaway.gtfs_transformer.services.TransformContext)6 GtfsRelationalDaoImpl (org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl)5 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)5 Trip (org.onebusaway.gtfs.model.Trip)5 Route (org.onebusaway.gtfs.model.Route)2 MatchAndTransform (org.onebusaway.gtfs_transformer.factory.EntitiesTransformStrategy.MatchAndTransform)2 URL (java.net.URL)1 TransformSpecificationException (org.onebusaway.gtfs_transformer.TransformSpecificationException)1 EntityMatch (org.onebusaway.gtfs_transformer.match.EntityMatch)1 EntityTransformStrategy (org.onebusaway.gtfs_transformer.services.EntityTransformStrategy)1 GtfsEntityTransformStrategy (org.onebusaway.gtfs_transformer.services.GtfsEntityTransformStrategy)1 GtfsTransformStrategyFactory (org.onebusaway.gtfs_transformer.services.GtfsTransformStrategyFactory)1 CalendarSimplicationStrategy (org.onebusaway.gtfs_transformer.updates.CalendarSimplicationStrategy)1