Search in sources :

Example 76 with ServiceDate

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());
    }
}
Also used : ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate)

Example 77 with ServiceDate

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());
}
Also used : ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) StringReader(java.io.StringReader) FeedInfo(org.onebusaway.gtfs.model.FeedInfo) Test(org.junit.Test)

Example 78 with ServiceDate

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);
    }
}
Also used : ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate)

Example 79 with ServiceDate

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)));
    }
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) Set(java.util.Set) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) CalendarService(org.onebusaway.gtfs.services.calendar.CalendarService) Test(org.junit.Test)

Example 80 with ServiceDate

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());
    }
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar) Test(org.junit.Test)

Aggregations

ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)134 Test (org.junit.Test)49 Date (java.util.Date)46 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)45 ArrayList (java.util.ArrayList)23 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)23 Calendar (java.util.Calendar)22 ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)22 HashSet (java.util.HashSet)17 ServiceIdActivation (org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation)14 CalendarServiceData (org.onebusaway.gtfs.model.calendar.CalendarServiceData)13 CalendarService (org.onebusaway.gtfs.services.calendar.CalendarService)13 Set (java.util.Set)11 Trip (org.onebusaway.gtfs.model.Trip)11 TimeZone (java.util.TimeZone)10 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)10 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)9 LocalizedServiceId (org.onebusaway.gtfs.model.calendar.LocalizedServiceId)9 Agency (org.onebusaway.gtfs.model.Agency)8 TripDescriptor (com.google.transit.realtime.GtfsRealtime.TripDescriptor)7