use of org.onebusaway.gtfs.services.GtfsMutableRelationalDao in project onebusaway-gtfs-modules by OneBusAway.
the class CalendarExtensionStrategyTest method testCalendarDateSelectiveExtension.
@Test
public void testCalendarDateSelectiveExtension() throws IOException {
/**
* Tuesday is only partially active for sid0
*/
_gtfs.putCalendarDates("sid0=20121210,20121211,20121212,20121213,20121214," + "20121217,20121219,20121220,20121221," + "20121224,20121226,20121227,20121228", "sid1=20121208,20121209,20121215,20121216");
GtfsMutableRelationalDao dao = _gtfs.read();
ServiceDate endDate = new ServiceDate(2013, 01, 06);
_strategy.setEndDate(endDate);
_strategy.run(_context, dao);
CalendarService service = CalendarServiceDataFactoryImpl.createService(dao);
{
Set<ServiceDate> dates = service.getServiceDatesForServiceId(new AgencyAndId("a0", "sid0"));
assertEquals(17, dates.size());
assertTrue(dates.contains(new ServiceDate(2012, 12, 31)));
assertFalse(dates.contains(new ServiceDate(2013, 01, 01)));
assertTrue(dates.contains(new ServiceDate(2013, 01, 02)));
assertTrue(dates.contains(new ServiceDate(2013, 01, 03)));
assertTrue(dates.contains(new ServiceDate(2013, 01, 04)));
}
{
Set<ServiceDate> dates = service.getServiceDatesForServiceId(new AgencyAndId("a0", "sid1"));
assertEquals(4, dates.size());
}
}
use of org.onebusaway.gtfs.services.GtfsMutableRelationalDao in project onebusaway-gtfs-modules by OneBusAway.
the class CalendarExtensionStrategyTest method testCalendarSelectiveExtension.
@Test
public void testCalendarSelectiveExtension() throws IOException {
_gtfs.putCalendars(2, "start_date=20110630,20120701", "end_date=20120630,20121231", "mask=1111111");
GtfsMutableRelationalDao dao = _gtfs.read();
ServiceDate endDate = new ServiceDate(2013, 12, 31);
_strategy.setEndDate(endDate);
_strategy.run(_context, dao);
{
ServiceCalendar calendar = dao.getCalendarForServiceId(new AgencyAndId("a0", "sid0"));
assertEquals(new ServiceDate(2012, 6, 30), calendar.getEndDate());
}
{
ServiceCalendar calendar = dao.getCalendarForServiceId(new AgencyAndId("a0", "sid1"));
assertEquals(endDate, calendar.getEndDate());
}
}
use of org.onebusaway.gtfs.services.GtfsMutableRelationalDao in project onebusaway-gtfs-modules by OneBusAway.
the class CalendarSimplicationLibraryTest method test.
@Test
public void test() throws IOException {
MockGtfs gtfs = MockGtfs.create();
gtfs.putAgencies(1, "agency_timezone=America/New_York");
gtfs.putRoutes(1);
gtfs.putTrips(1, "r0", "sid0");
gtfs.putStops(1);
gtfs.putStopTimes("t0", "s0");
gtfs.putCalendarDates("sid0=20120305,20120306,20120307,20120308,20120309," + "20120312,20120313,20120314,20120315,20120316,20120319,20120320,20120321,20120323," + "20120326,20120327,20120328,20120329,20120330");
GtfsMutableRelationalDao dao = gtfs.read();
CalendarService calendarService = CalendarServiceDataFactoryImpl.createService(dao);
AgencyAndId originalId = new AgencyAndId("a0", "sid0");
AgencyAndId updatedId = new AgencyAndId("a0", "sidX");
ServiceCalendarSummary summary = _library.getSummaryForServiceDates(calendarService.getServiceDatesForServiceId(originalId));
List<Object> newEntities = new ArrayList<Object>();
_library.computeSimplifiedCalendar(updatedId, summary, newEntities);
List<ServiceCalendar> calendars = getEntities(newEntities, ServiceCalendar.class);
assertEquals(1, calendars.size());
ServiceCalendar calendar = calendars.get(0);
assertEquals(updatedId, calendar.getServiceId());
assertEquals(new ServiceDate(2012, 03, 05), calendar.getStartDate());
assertEquals(new ServiceDate(2012, 03, 30), calendar.getEndDate());
assertEquals(1, calendar.getMonday());
assertEquals(1, calendar.getTuesday());
assertEquals(1, calendar.getWednesday());
assertEquals(1, calendar.getThursday());
assertEquals(1, calendar.getFriday());
assertEquals(0, calendar.getSaturday());
assertEquals(0, calendar.getSunday());
List<ServiceCalendarDate> calendarDates = getEntities(newEntities, ServiceCalendarDate.class);
assertEquals(1, calendarDates.size());
ServiceCalendarDate date = calendarDates.get(0);
assertEquals(updatedId, date.getServiceId());
assertEquals(new ServiceDate(2012, 03, 22), date.getDate());
assertEquals(ServiceCalendarDate.EXCEPTION_TYPE_REMOVE, date.getExceptionType());
}
use of org.onebusaway.gtfs.services.GtfsMutableRelationalDao in project onebusaway-gtfs-modules by OneBusAway.
the class GtfsReaderTest method testDefaultAgencyForRoutes.
@Test
public void testDefaultAgencyForRoutes() throws IOException {
MockGtfs gtfs = MockGtfs.create();
gtfs.putAgencies(1);
gtfs.putRoutes(1);
gtfs.putTrips(1, "r0", "sid0");
gtfs.putStops(1);
gtfs.putStopTimes("t0", "s0");
{
GtfsMutableRelationalDao dao = gtfs.read(newReader("tacos"));
assertNotNull(dao.getRouteForId(new AgencyAndId("a0", "r0")));
}
{
gtfs.putAgencies(2);
try {
gtfs.read(newReader("tacos"));
fail();
} catch (CsvEntityIOException e) {
MissingRequiredFieldException ex = (MissingRequiredFieldException) e.getCause();
assertEquals("agency_id", ex.getFieldName());
assertEquals(Route.class, ex.getEntityType());
}
}
{
gtfs.putAgencies(2);
gtfs.putRoutes(1, "agency_id=a1");
GtfsMutableRelationalDao dao = gtfs.read(newReader("tacos"));
assertNotNull(dao.getRouteForId(new AgencyAndId("a1", "r0")));
}
{
gtfs.putAgencies(2);
gtfs.putRoutes(1, "agency_id=a2");
try {
gtfs.read(newReader("tacos"));
fail();
} catch (CsvEntityIOException e) {
assertTrue(e.getCause() instanceof AgencyNotFoundForRouteException);
}
}
}
use of org.onebusaway.gtfs.services.GtfsMutableRelationalDao in project onebusaway-application-modules by camsys.
the class GtfsArchiveTask method run.
@Override
public void run() {
if (!requestResponse.getRequest().getArchiveFlag()) {
_log.info("archive flag not set, exiting");
return;
}
long start = SystemTime.currentTimeMillis();
_log.info("archiving gtfs");
Configuration config = getConfiguration();
if (config == null) {
_log.error("missing configuration, GTFS will not be archived");
return;
}
SessionFactory sessionFactory = config.buildSessionFactory();
Session session = sessionFactory.openSession();
Transaction transaction = session.beginTransaction();
HibernateGtfsFactory factory = new HibernateGtfsFactory(sessionFactory);
GtfsBundles gtfsBundles = getGtfsBundles(_applicationContext);
Integer gtfsBundleInfoId = createMetaData(session, requestResponse);
for (GtfsBundle gtfsBundle : gtfsBundles.getBundles()) {
GtfsReader reader = new GtfsReader();
reader.getEntityClasses().add(PatternPair.class);
try {
cleanTempTables(session);
reader.setInputLocation(gtfsBundle.getPath());
GtfsMutableRelationalDao dao = factory.getDao();
reader.setEntityStore(dao);
_log.info("running for gtfs=" + gtfsBundle.getPath());
reader.run();
reader.close();
archiveData(session, gtfsBundleInfoId);
} catch (IOException e) {
_log.error("gtfs archive failure:", e);
}
}
cleanTempTables(session);
transaction.commit();
session.flush();
session.close();
long stop = SystemTime.currentTimeMillis();
_log.info("archiving gtfs complete in " + (stop - start) / 1000 + "s");
}
Aggregations