use of org.onebusaway.gtfs.serialization.GtfsReader in project onebusaway-gtfs-modules by OneBusAway.
the class LongRouteDescriptionTest method setup.
@BeforeClass
public static void setup() throws IOException {
Configuration config = new Configuration();
config = config.configure("org/onebusaway/gtfs/hibernate-configuration.xml");
_sessionFactory = config.buildSessionFactory();
_dao = new HibernateGtfsRelationalDaoImpl(_sessionFactory);
GtfsReader reader = new GtfsReader();
reader.setInputLocation(new File("src/test/resources/org/onebusaway/gtfs/caltrain-long-route.zip"));
reader.setEntityStore(_dao);
reader.setDefaultAgencyId(_agencyId);
List<Class<?>> entityClasses = reader.getEntityClasses();
entityClasses.clear();
entityClasses.add(Agency.class);
entityClasses.add(Route.class);
reader.run();
}
use of org.onebusaway.gtfs.serialization.GtfsReader in project onebusaway-gtfs-modules by OneBusAway.
the class GtfsMerger method run.
public void run(List<File> inputPaths, File outputPath) throws IOException {
GtfsRelationalDaoImpl mergedDao = new GtfsRelationalDaoImpl();
mergedDao.setPackShapePoints(true);
mergedDao.setPackStopTimes(true);
List<EntityMergeStrategy> strategies = new ArrayList<EntityMergeStrategy>();
buildStrategies(strategies);
/**
* For each entity merge strategy, we keep track of a mapping from raw GTFS
* ids to entities, if the particular entity type has an identifier. This
* will be used to detect id conflicts between subsequent runs of each merge
* strategy on different feeds. We can't use the AgencyAndId ids in the DAO
* because it might be possible for two entities with the same id but
* different agency prefixes to sneak in. Since we ultimately serialize the
* data to a GTFS feed with no agency prefixes, we need to track the raw id.
*/
Map<EntityMergeStrategy, Map<String, Object>> rawEntityIdMapsByMergeStrategy = new HashMap<EntityMergeStrategy, Map<String, Object>>();
for (EntityMergeStrategy strategy : strategies) {
rawEntityIdMapsByMergeStrategy.put(strategy, new HashMap<String, Object>());
}
/**
* We iterate over the input feeds in reverse order, such that entities from
* the newest feeds are added first and older entities are potentially
* dropped.
*/
for (int index = inputPaths.size() - 1; index >= 0; --index) {
File inputPath = inputPaths.get(index);
String prefix = getIndexAsPrefix(index, inputPaths.size());
_log.info("reading input: " + inputPath);
GtfsReader reader = new GtfsReader();
reader.setInputLocation(inputPath);
GtfsRelationalDaoImpl dao = new GtfsRelationalDaoImpl();
dao.setPackShapePoints(true);
dao.setPackStopTimes(true);
reader.setEntityStore(dao);
reader.run();
for (EntityMergeStrategy strategy : strategies) {
_log.info("strategy=" + strategy.getClass());
GtfsMergeContext context = new GtfsMergeContext(dao, mergedDao, prefix, rawEntityIdMapsByMergeStrategy.get(strategy));
strategy.merge(context);
}
}
_log.info("writing merged output: " + outputPath);
GtfsWriter writer = new GtfsWriter();
writer.setOutputLocation(outputPath);
writer.run(mergedDao);
}
use of org.onebusaway.gtfs.serialization.GtfsReader in project onebusaway-gtfs-modules by OneBusAway.
the class GtfsHibernateReaderExampleMain method main.
public static void main(String[] args) throws IOException {
if (!(args.length == 1 || args.length == 2)) {
System.err.println("usage: gtfsPath [hibernate-config.xml]");
System.exit(-1);
}
String resource = "classpath:org/onebusaway/gtfs/examples/hibernate-configuration-examples.xml";
if (args.length == 2)
resource = args[1];
HibernateGtfsFactory factory = createHibernateGtfsFactory(resource);
GtfsReader reader = new GtfsReader();
reader.setInputLocation(new File(args[0]));
GtfsMutableRelationalDao dao = factory.getDao();
reader.setEntityStore(dao);
reader.run();
Collection<Stop> stops = dao.getAllStops();
for (Stop stop : stops) System.out.println(stop.getName());
CalendarService calendarService = factory.getCalendarService();
Set<AgencyAndId> serviceIds = calendarService.getServiceIds();
for (AgencyAndId serviceId : serviceIds) {
Set<ServiceDate> dates = calendarService.getServiceDatesForServiceId(serviceId);
ServiceDate from = null;
ServiceDate to = null;
for (ServiceDate date : dates) {
from = min(from, date);
to = max(to, date);
}
System.out.println("serviceId=" + serviceId + " from=" + from + " to=" + to);
}
}
use of org.onebusaway.gtfs.serialization.GtfsReader in project onebusaway-gtfs-modules by OneBusAway.
the class GtfsMappingTest method setup.
@Before
public void setup() throws IOException {
Configuration config = new Configuration();
config = config.configure("org/onebusaway/gtfs/hibernate-configuration.xml");
_sessionFactory = config.buildSessionFactory();
_dao = new HibernateGtfsRelationalDaoImpl(_sessionFactory);
_dao.open();
_reader = new GtfsReader();
_reader.setEntityStore(_dao);
}
use of org.onebusaway.gtfs.serialization.GtfsReader in project onebusaway-gtfs-modules by OneBusAway.
the class HibernateGtfsRelationalImplBartTest method setup.
@BeforeClass
public static void setup() throws IOException {
Configuration config = new Configuration();
config = config.configure("org/onebusaway/gtfs/hibernate-configuration.xml");
_sessionFactory = config.buildSessionFactory();
_dao = new HibernateGtfsRelationalDaoImpl(_sessionFactory);
GtfsReader reader = new GtfsReader();
reader.setInputLocation(new File("src/test/resources/org/onebusaway/gtfs/bart.zip"));
reader.setEntityStore(_dao);
reader.setDefaultAgencyId(_agencyId);
reader.run();
}
Aggregations