Search in sources :

Example 1 with EntityReplacementLogger

use of org.onebusaway.transit_data_federation.bundle.services.EntityReplacementLogger 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();
}
Also used : GtfsReader(org.onebusaway.gtfs.serialization.GtfsReader) EntityReplacementLogger(org.onebusaway.transit_data_federation.bundle.services.EntityReplacementLogger) GtfsBundle(org.onebusaway.transit_data_federation.bundle.model.GtfsBundle) GtfsBundles(org.onebusaway.transit_data_federation.bundle.model.GtfsBundles) EntityReplacementStrategy(org.onebusaway.transit_data_federation.bundle.services.EntityReplacementStrategy) Map(java.util.Map)

Aggregations

Map (java.util.Map)1 GtfsReader (org.onebusaway.gtfs.serialization.GtfsReader)1 GtfsBundle (org.onebusaway.transit_data_federation.bundle.model.GtfsBundle)1 GtfsBundles (org.onebusaway.transit_data_federation.bundle.model.GtfsBundles)1 EntityReplacementLogger (org.onebusaway.transit_data_federation.bundle.services.EntityReplacementLogger)1 EntityReplacementStrategy (org.onebusaway.transit_data_federation.bundle.services.EntityReplacementStrategy)1