Search in sources :

Example 81 with AgencyAndId

use of org.onebusaway.gtfs.model.AgencyAndId in project onebusaway-gtfs-modules by OneBusAway.

the class ExtensionsTest method testExtensionWrite.

@Test
public void testExtensionWrite() throws IOException {
    DefaultEntitySchemaFactory factory = GtfsEntitySchemaFactory.createEntitySchemaFactory();
    factory.addExtension(Stop.class, StopExtension.class);
    {
        MockGtfs gtfs = MockGtfs.create();
        gtfs.putMinimal();
        gtfs.putStops(2, "label=a,b");
        GtfsReader reader = new GtfsReader();
        reader.setEntitySchemaFactory(factory);
        GtfsMutableRelationalDao dao = gtfs.read(reader);
        Stop stop = dao.getStopForId(new AgencyAndId("a0", "s0"));
        StopExtension extension = stop.getExtension(StopExtension.class);
        assertEquals("a", extension.getLabel());
        GtfsWriter writer = new GtfsWriter();
        writer.setEntitySchemaFactory(factory);
        writer.setOutputLocation(_tmpDirectory);
        writer.run(dao);
        writer.close();
    }
    {
        GtfsReader reader2 = new GtfsReader();
        reader2.setEntitySchemaFactory(factory);
        reader2.setInputLocation(_tmpDirectory);
        GtfsRelationalDaoImpl dao2 = new GtfsRelationalDaoImpl();
        reader2.setDefaultAgencyId("a0");
        reader2.setEntityStore(dao2);
        reader2.readEntities(Stop.class);
        Stop stop2 = dao2.getStopForId(new AgencyAndId("a0", "s0"));
        StopExtension extension2 = stop2.getExtension(StopExtension.class);
        assertEquals("a", extension2.getLabel());
    }
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) GtfsReader(org.onebusaway.gtfs.serialization.GtfsReader) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) MockGtfs(org.onebusaway.gtfs.services.MockGtfs) DefaultEntitySchemaFactory(org.onebusaway.csv_entities.schema.DefaultEntitySchemaFactory) GtfsRelationalDaoImpl(org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl) GtfsWriter(org.onebusaway.gtfs.serialization.GtfsWriter) Test(org.junit.Test) GtfsWriterTest(org.onebusaway.gtfs.serialization.GtfsWriterTest)

Example 82 with AgencyAndId

use of org.onebusaway.gtfs.model.AgencyAndId in project onebusaway-gtfs-modules by OneBusAway.

the class GenericDaoImplTest method testSaveOrUpdate.

@Test
public void testSaveOrUpdate() {
    GenericDaoImpl impl = new GenericDaoImpl();
    AgencyAndId id = new AgencyAndId("1", "stopA");
    Stop entity = impl.getEntityForId(Stop.class, id);
    assertNull(entity);
    Stop stopA = new Stop();
    stopA.setId(id);
    impl.saveOrUpdateEntity(stopA);
    entity = impl.getEntityForId(Stop.class, id);
    assertSame(stopA, entity);
    impl.saveOrUpdateEntity(stopA);
    entity = impl.getEntityForId(Stop.class, id);
    assertSame(stopA, entity);
    Stop stopB = new Stop();
    stopB.setId(id);
    impl.saveOrUpdateEntity(stopB);
    entity = impl.getEntityForId(Stop.class, id);
    assertSame(stopB, entity);
    Collection<Stop> entities = impl.getAllEntitiesForType(Stop.class);
    assertEquals(1, entities.size());
    assertSame(stopB, entities.iterator().next());
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) Test(org.junit.Test)

Example 83 with AgencyAndId

use of org.onebusaway.gtfs.model.AgencyAndId in project onebusaway-gtfs-modules by OneBusAway.

the class CalendarServiceDataFactoryImpl method createData.

@Override
public CalendarServiceData createData() {
    CalendarServiceData data = new CalendarServiceData();
    setTimeZonesForAgencies(data);
    List<AgencyAndId> serviceIds = _dao.getAllServiceIds();
    int index = 0;
    for (AgencyAndId serviceId : serviceIds) {
        index++;
        _log.info("serviceId=" + serviceId + " (" + index + "/" + serviceIds.size() + ")");
        TimeZone serviceIdTimeZone = data.getTimeZoneForAgencyId(serviceId.getAgencyId());
        if (serviceIdTimeZone == null) {
            serviceIdTimeZone = TimeZone.getDefault();
        }
        Set<ServiceDate> activeDates = getServiceDatesForServiceId(serviceId, serviceIdTimeZone);
        List<ServiceDate> serviceDates = new ArrayList<ServiceDate>(activeDates);
        Collections.sort(serviceDates);
        data.putServiceDatesForServiceId(serviceId, serviceDates);
        List<String> tripAgencyIds = _dao.getTripAgencyIdsReferencingServiceId(serviceId);
        Set<TimeZone> timeZones = new HashSet<TimeZone>();
        for (String tripAgencyId : tripAgencyIds) {
            TimeZone timeZone = data.getTimeZoneForAgencyId(tripAgencyId);
            timeZones.add(timeZone);
        }
        for (TimeZone timeZone : timeZones) {
            List<Date> dates = new ArrayList<Date>(serviceDates.size());
            for (ServiceDate serviceDate : serviceDates) dates.add(serviceDate.getAsDate(timeZone));
            LocalizedServiceId id = new LocalizedServiceId(serviceId, timeZone);
            data.putDatesForLocalizedServiceId(id, dates);
        }
    }
    return data;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) Date(java.util.Date) ServiceCalendarDate(org.onebusaway.gtfs.model.ServiceCalendarDate) CalendarServiceData(org.onebusaway.gtfs.model.calendar.CalendarServiceData) TimeZone(java.util.TimeZone) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) LocalizedServiceId(org.onebusaway.gtfs.model.calendar.LocalizedServiceId) HashSet(java.util.HashSet)

Example 84 with AgencyAndId

use of org.onebusaway.gtfs.model.AgencyAndId in project onebusaway-gtfs-modules by OneBusAway.

the class ServiceCalendarComparator method compare.

@Override
public int compare(ServiceCalendar o1, ServiceCalendar o2) {
    AgencyAndId id1 = o1.getServiceId();
    AgencyAndId id2 = o2.getServiceId();
    return id1.compareTo(id2);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId)

Example 85 with AgencyAndId

use of org.onebusaway.gtfs.model.AgencyAndId in project onebusaway-gtfs-modules by OneBusAway.

the class EntityFieldMappingImpl method translateFromObjectToCSV.

@SuppressWarnings("unchecked")
public void translateFromObjectToCSV(CsvEntityContext context, BeanWrapper object, Map<String, Object> csvValues) {
    IdentityBean<AgencyAndId> entity = (IdentityBean<AgencyAndId>) object.getPropertyValue(_objFieldName);
    if (isOptional() && entity == null)
        return;
    AgencyAndId id = entity.getId();
    csvValues.put(_csvFieldName, id.getId());
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) IdentityBean(org.onebusaway.gtfs.model.IdentityBean)

Aggregations

AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)102 Test (org.junit.Test)63 Trip (org.onebusaway.gtfs.model.Trip)37 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)25 Stop (org.onebusaway.gtfs.model.Stop)24 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)17 ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)16 ArrayList (java.util.ArrayList)15 Route (org.onebusaway.gtfs.model.Route)15 StopTime (org.onebusaway.gtfs.model.StopTime)15 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)15 Agency (org.onebusaway.gtfs.model.Agency)13 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)12 GtfsRelationalDao (org.onebusaway.gtfs.services.GtfsRelationalDao)11 HashSet (java.util.HashSet)10 GtfsRelationalDaoImpl (org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl)10 List (java.util.List)9 Frequency (org.onebusaway.gtfs.model.Frequency)9 CalendarService (org.onebusaway.gtfs.services.calendar.CalendarService)7 Set (java.util.Set)6