use of org.onebusaway.gtfs.model.Agency in project onebusaway-gtfs-modules by OneBusAway.
the class CalendarServiceDataFactoryImplSyntheticTest method testBadTimezone.
@Test
public void testBadTimezone() throws IOException {
CalendarServiceDataFactoryImpl factory = new CalendarServiceDataFactoryImpl();
Agency agencyA = agency("A", "America/SomewhereThatDoesNotExist");
GtfsRelationalDaoImpl dao = new GtfsRelationalDaoImpl();
factory.setGtfsDao(dao);
saveEntities(dao, agencyA);
try {
factory.createData();
fail("should detect that TimeZone ID is not valid");
} catch (UnknownAgencyTimezoneException ex) {
}
}
use of org.onebusaway.gtfs.model.Agency in project onebusaway-gtfs-modules by OneBusAway.
the class CalendarServiceDataFactoryImplSyntheticTest method testDaylightSavingTime.
@Test
public void testDaylightSavingTime() {
CalendarServiceDataFactoryImpl factory = new CalendarServiceDataFactoryImpl();
Agency agencyA = agency("A", "America/Los_Angeles");
AgencyAndId serviceId = new AgencyAndId("A", "2");
ServiceDate dStart = new ServiceDate(2012, 3, 1);
ServiceDate dEnd = new ServiceDate(2012, 3, 31);
ServiceCalendar c = calendar(serviceId, dStart, dEnd, "1111111");
GtfsRelationalDaoImpl dao = new GtfsRelationalDaoImpl();
factory.setGtfsDao(dao);
saveEntities(dao, agencyA);
saveEntities(dao, c);
CalendarServiceData data = factory.createData();
List<ServiceDate> serviceDates = data.getServiceDatesForServiceId(serviceId);
assertTrue(serviceDates.contains(new ServiceDate(2012, 3, 11)));
}
use of org.onebusaway.gtfs.model.Agency in project onebusaway-gtfs-modules by OneBusAway.
the class TranslationServiceImplTest method testTranslations.
@Test
public void testTranslations() throws IOException {
String agencyId = "agency";
GtfsRelationalDaoImpl dao = new GtfsRelationalDaoImpl();
GtfsTestData.readGtfs(dao, GtfsTestData.getTestAgencyGtfs(), agencyId);
TranslationServiceImpl ts = new TranslationServiceImpl();
ts.setData(TranslationServiceDataFactoryImpl.createData(dao));
Agency agency = dao.getAgencyForId(agencyId);
assertEquals("Fake Agency Spanish", ts.getTranslatedEntity("es", Agency.class, agency).getName());
assertEquals("Fake Agency French", ts.getTranslatedEntity("fr", Agency.class, agency).getName());
Stop stop = dao.getStopForId(aid("A"));
assertEquals("A Spanish", ts.getTranslatedEntity("es", Stop.class, stop).getName());
assertEquals("A French", ts.getTranslatedEntity("fr", Stop.class, stop).getName());
Route route = dao.getRouteForId(aid("3"));
assertEquals("3 Spanish", ts.getTranslatedEntity("es", Route.class, route).getLongName());
assertEquals("3 French", ts.getTranslatedEntity("fr", Route.class, route).getLongName());
Trip trip3 = dao.getTripForId(aid("3.1"));
assertEquals("headsign Spanish", ts.getTranslatedEntity("es", Trip.class, trip3).getTripHeadsign());
assertEquals("headsign French", ts.getTranslatedEntity("fr", Trip.class, trip3).getTripHeadsign());
Trip trip4 = dao.getTripForId(aid("4.3"));
List<StopTime> stopTimes = dao.getStopTimesForTrip(trip4);
StopTime st1 = stopTimes.get(0);
StopTime st2 = stopTimes.get(1);
assertEquals("to G Spanish", ts.getTranslatedEntity("es", StopTime.class, st1).getStopHeadsign());
assertEquals("to H Spanish", ts.getTranslatedEntity("es", StopTime.class, st2).getStopHeadsign());
assertEquals("to G French", ts.getTranslatedEntity("fr", StopTime.class, st1).getStopHeadsign());
assertEquals("to H French", ts.getTranslatedEntity("fr", StopTime.class, st2).getStopHeadsign());
FeedInfo feedInfo = dao.getAllFeedInfos().iterator().next();
assertEquals("Fake Feed Publisher Spanish", ts.getTranslatedEntity("es", FeedInfo.class, feedInfo).getPublisherName());
assertEquals("http://fake.example.es", ts.getTranslatedEntity("es", FeedInfo.class, feedInfo).getPublisherUrl());
assertEquals("Fake Feed Publisher French", ts.getTranslatedEntity("fr", FeedInfo.class, feedInfo).getPublisherName());
assertEquals("http://fake.example.fr", ts.getTranslatedEntity("fr", FeedInfo.class, feedInfo).getPublisherUrl());
// Check default translations
assertEquals("Fake Agency", ts.getTranslatedEntity("en", Agency.class, agency).getName());
assertEquals("A", ts.getTranslatedEntity("en", Stop.class, stop).getName());
assertEquals("3", ts.getTranslatedEntity("en", Route.class, route).getLongName());
assertEquals("headsign", ts.getTranslatedEntity("en", Trip.class, trip3).getTripHeadsign());
assertEquals("to G", ts.getTranslatedEntity("en", StopTime.class, st1).getStopHeadsign());
assertEquals("to H", ts.getTranslatedEntity("en", StopTime.class, st2).getStopHeadsign());
assertEquals("Fake Feed Publisher", ts.getTranslatedEntity("en", FeedInfo.class, feedInfo).getPublisherName());
assertEquals("http://fake.example.com", ts.getTranslatedEntity("en", FeedInfo.class, feedInfo).getPublisherUrl());
}
use of org.onebusaway.gtfs.model.Agency in project onebusaway-application-modules by camsys.
the class GtfsMultiReaderImpl method run.
@Override
public void run() {
if (_readers.isEmpty())
return;
if (_entityLogger != null) {
_entityReplacementStrategy.setEntityReplacementLogger(_entityLogger);
_entityLogger.setStore(_store);
_entityLogger.setRejectionStore(_rejectionStore);
}
try {
StoreImpl store = new StoreImpl(_store);
for (GtfsReader reader : _readers) {
reader.setEntityStore(store);
reader.addEntityHandler(new EntityCounter());
}
store.open();
List<Agency> agencies = new ArrayList<Agency>();
List<Class<?>> entityClasses = _readers.get(0).getEntityClasses();
for (Class<?> entityClass : entityClasses) {
_log.info("reading entities: " + entityClass.getName());
for (GtfsReader reader : _readers) {
// multiple feeds
if (entityClass.equals(Agency.class))
reader.setAgencies(agencies);
reader.readEntities(entityClass);
if (entityClass.equals(Agency.class))
agencies = new ArrayList<Agency>(reader.getAgencies());
store.flush();
}
}
store.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
use of org.onebusaway.gtfs.model.Agency in project onebusaway-application-modules by camsys.
the class GtfsStatisticsTask method run.
public void run() {
File basePath = _bundle.getPath();
_log.info("Starting GTFS stats to basePath=" + basePath);
GtfsStatisticsService service = new GtfsStatisticsService(_dao);
// create logger file
GtfsCsvLogger csvLogger = new GtfsCsvLogger();
csvLogger.setBasePath(basePath);
csvLogger.open();
csvLogger.header();
// per agency status
Collection<Agency> agencies = service.getAllAgencies();
for (Agency agency : agencies) {
_log.info("processing stats for agency: " + agency.getId() + " (" + agency.getName() + ")");
csvLogger.logStat(agency.getId(), service.getStatistic(agency.getId()));
}
// overall stats/totals
Statistic all = new Statistic();
Agency allAgency = new Agency();
allAgency.setId(ALL_AGENCIES);
all.setAgencyId(ALL_AGENCIES);
all.setRouteCount(service.getRouteCount());
all.setTripCount(service.getTripCount());
all.setStopCount(service.getStopCount());
all.setStopTimeCount(service.getStopTimesCount());
all.setCalendarStartDate(service.getCalendarServiceRangeStart());
all.setCalendarEndDate(service.getCalendarServiceRangeEnd());
csvLogger.logStat(allAgency.getId(), all);
_log.info("cleaning up");
// cleanup
csvLogger.close();
_log.info("exiting");
}
Aggregations