use of org.onebusaway.transit_data_federation.bundle.services.EntityReplacementStrategy in project onebusaway-application-modules by camsys.
the class GtfsReadingSupport method readGtfsIntoStore.
/**
* Read gtfs, as defined by {@link GtfsBundles} entries in the application
* context, into the specified data store. Gtfs will be read in quasi-paralle
* mode using {@link GtfsMultiReaderImpl}. Any
* {@link EntityReplacementStrategy} strategies defined in the application
* context will be applied as well.
*
* @param context
* @param store
* @param factory
* @param disableStopConsolidation
* @throws IOException
*/
public static void readGtfsIntoStore(ApplicationContext context, GenericMutableDao store, DefaultEntitySchemaFactory factory, boolean disableStopConsolidation) throws IOException {
GtfsMultiReaderImpl multiReader = new GtfsMultiReaderImpl();
multiReader.setStore(store);
if (!disableStopConsolidation && context.containsBean("entityReplacementStrategy")) {
EntityReplacementStrategy strategy = (EntityReplacementStrategy) context.getBean("entityReplacementStrategy");
multiReader.setEntityReplacementStrategy(strategy);
if (context.containsBean("multiCSVLogger")) {
MultiCSVLogger csvLogger = (MultiCSVLogger) context.getBean("multiCSVLogger");
if (context.containsBean("entityReplacementLogger")) {
EntityReplacementLogger entityLogger = (EntityReplacementLogger) context.getBean("entityReplacementLogger");
entityLogger.setMultiCSVLogger(csvLogger);
csvLogger.addListener(entityLogger.getListener());
multiReader.setEntityReplacementLogger(entityLogger);
}
}
}
GtfsBundles gtfsBundles = getGtfsBundles(context);
for (GtfsBundle gtfsBundle : gtfsBundles.getBundles()) {
System.out.println("gtfs=" + gtfsBundle.getPath());
GtfsReader reader = new GtfsReader();
reader.setEntitySchemaFactory(factory);
reader.setInputLocation(gtfsBundle.getPath());
if (gtfsBundle.getDefaultAgencyId() != null)
reader.setDefaultAgencyId(gtfsBundle.getDefaultAgencyId());
for (Map.Entry<String, String> entry : gtfsBundle.getAgencyIdMappings().entrySet()) reader.addAgencyIdMapping(entry.getKey(), entry.getValue());
multiReader.addGtfsReader(reader);
}
multiReader.run();
}
Aggregations