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"));
}
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);
}
}
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);
}
}
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());
}
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());
}
Aggregations