use of org.onebusaway.gtfs.model.calendar.ServiceDate in project onebusaway-gtfs-modules by OneBusAway.
the class ServiceDateUserType method nullSafeSet.
@Override
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor sessionImplementor) throws HibernateException, SQLException {
if (value == null) {
st.setNull(index, SQL_TYPES[0]);
} else {
ServiceDate serviceDate = (ServiceDate) value;
st.setString(index, serviceDate.getAsString());
}
}
use of org.onebusaway.gtfs.model.calendar.ServiceDate in project onebusaway-gtfs-modules by OneBusAway.
the class GtfsMappingTest method testFeedInfo.
@Test
public void testFeedInfo() throws CsvEntityIOException, IOException {
StringBuilder b = new StringBuilder();
b.append("feed_publisher_name,feed_publisher_url,feed_lang,feed_start_date,feed_end_date,feed_version\n");
b.append("Test,http://test/,en,20110928,20120131,1.0\n");
_reader.readEntities(FeedInfo.class, new StringReader(b.toString()));
FeedInfo feedInfo = _dao.getFeedInfoForId("1");
assertEquals("Test", feedInfo.getPublisherName());
assertEquals("http://test/", feedInfo.getPublisherUrl());
assertEquals("en", feedInfo.getLang());
assertEquals(new ServiceDate(2011, 9, 28), feedInfo.getStartDate());
assertEquals(new ServiceDate(2012, 1, 31), feedInfo.getEndDate());
assertEquals("1.0", feedInfo.getVersion());
}
use of org.onebusaway.gtfs.model.calendar.ServiceDate in project onebusaway-gtfs-modules by OneBusAway.
the class FeedInfoMergeStrategy method replaceDuplicateEntry.
@Override
protected void replaceDuplicateEntry(GtfsMergeContext context, FeedInfo oldEntity, FeedInfo newEntity) {
// merge the two version strings together
if (oldEntity.getVersion() != null && newEntity.getVersion() != null) {
newEntity.setVersion(oldEntity.getVersion() + ":" + newEntity.getVersion());
}
if (oldEntity.getStartDate() != null && newEntity.getStartDate() != null) {
// startDate should be the lesser of the two dates
ServiceDate startDate = oldEntity.getStartDate();
if (newEntity.getStartDate().compareTo(oldEntity.getStartDate()) < 0) {
startDate = newEntity.getStartDate();
}
newEntity.setStartDate(startDate);
}
if (oldEntity.getEndDate() != null && newEntity.getEndDate() != null) {
// endDate should be the greater of the two dates
ServiceDate endDate = newEntity.getEndDate();
if (oldEntity.getEndDate().compareTo(newEntity.getEndDate()) > 0) {
endDate = oldEntity.getEndDate();
}
newEntity.setEndDate(endDate);
}
}
use of org.onebusaway.gtfs.model.calendar.ServiceDate in project onebusaway-gtfs-modules by OneBusAway.
the class CalendarExtensionStrategyTest method testCalendarDateExtension.
@Test
public void testCalendarDateExtension() throws IOException {
_gtfs.putCalendarDates("sid0=20121217,20121218,20121219,20121220,20121221," + "20121224,20121225,20121226,20121227,20121228", "sid1=20121222,20121223,20121229,20121230");
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(15, dates.size());
assertTrue(dates.contains(new ServiceDate(2012, 12, 31)));
assertTrue(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(6, dates.size());
assertTrue(dates.contains(new ServiceDate(2013, 01, 05)));
assertTrue(dates.contains(new ServiceDate(2013, 01, 06)));
}
}
use of org.onebusaway.gtfs.model.calendar.ServiceDate in project onebusaway-gtfs-modules by OneBusAway.
the class CalendarExtensionStrategyTest method testCalendarExtension.
@Test
public void testCalendarExtension() throws IOException {
_gtfs.putCalendars(2, "start_date=20120630,20120731", "end_date=20121224,20121231", "mask=1111100,0000011");
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(endDate, calendar.getEndDate());
}
{
ServiceCalendar calendar = dao.getCalendarForServiceId(new AgencyAndId("a0", "sid1"));
assertEquals(endDate, calendar.getEndDate());
}
}
Aggregations