use of org.onebusaway.transit_data_federation.bundle.model.GtfsBundles 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();
}
use of org.onebusaway.transit_data_federation.bundle.model.GtfsBundles in project onebusaway-application-modules by camsys.
the class GtfsReadingSupport method getGtfsBundles.
/**
* Looks for instances of {@link GtfsBundles} or {@link GtfsBundle} in the
* application context.
*
* @param context
* @return
*/
public static GtfsBundles getGtfsBundles(ApplicationContext context) {
GtfsBundles bundles = (GtfsBundles) context.getBean("gtfs-bundles");
if (bundles != null)
return bundles;
GtfsBundle bundle = (GtfsBundle) context.getBean("gtfs-bundle");
if (bundle != null) {
bundles = new GtfsBundles();
bundles.getBundles().add(bundle);
return bundles;
}
throw new IllegalStateException("must define either \"gtfs-bundles\" or \"gtfs-bundle\" in config");
}
use of org.onebusaway.transit_data_federation.bundle.model.GtfsBundles in project onebusaway-application-modules by camsys.
the class GtfsArchiveTask method run.
@Override
public void run() {
if (!requestResponse.getRequest().getArchiveFlag()) {
_log.info("archive flag not set, exiting");
return;
}
long start = SystemTime.currentTimeMillis();
_log.info("archiving gtfs");
Configuration config = getConfiguration();
if (config == null) {
_log.error("missing configuration, GTFS will not be archived");
return;
}
SessionFactory sessionFactory = config.buildSessionFactory();
Session session = sessionFactory.openSession();
Transaction transaction = session.beginTransaction();
HibernateGtfsFactory factory = new HibernateGtfsFactory(sessionFactory);
GtfsBundles gtfsBundles = getGtfsBundles(_applicationContext);
Integer gtfsBundleInfoId = createMetaData(session, requestResponse);
for (GtfsBundle gtfsBundle : gtfsBundles.getBundles()) {
GtfsReader reader = new GtfsReader();
reader.getEntityClasses().add(PatternPair.class);
try {
cleanTempTables(session);
reader.setInputLocation(gtfsBundle.getPath());
GtfsMutableRelationalDao dao = factory.getDao();
reader.setEntityStore(dao);
_log.info("running for gtfs=" + gtfsBundle.getPath());
reader.run();
reader.close();
archiveData(session, gtfsBundleInfoId);
} catch (IOException e) {
_log.error("gtfs archive failure:", e);
}
}
cleanTempTables(session);
transaction.commit();
session.flush();
session.close();
long stop = SystemTime.currentTimeMillis();
_log.info("archiving gtfs complete in " + (stop - start) / 1000 + "s");
}
use of org.onebusaway.transit_data_federation.bundle.model.GtfsBundles in project onebusaway-application-modules by camsys.
the class GtfsFullValidationTask method getGtfsBundles.
protected GtfsBundles getGtfsBundles(ApplicationContext context) {
GtfsBundles bundles = (GtfsBundles) context.getBean("gtfs-bundles");
if (bundles != null)
return bundles;
GtfsBundle bundle = (GtfsBundle) context.getBean("gtfs-bundle");
if (bundle != null) {
bundles = new GtfsBundles();
bundles.getBundles().add(bundle);
return bundles;
}
throw new IllegalStateException("must define either \"gtfs-bundles\" or \"gtfs-bundle\" in config");
}
use of org.onebusaway.transit_data_federation.bundle.model.GtfsBundles in project onebusaway-application-modules by camsys.
the class HastusTranslateTask method updateGtfsBundle.
private void updateGtfsBundle(BundleRequestResponse requestResponse, String zipFilename, HastusData hd) {
GtfsBundles bundles = getGtfsBundles(_applicationContext);
GtfsBundle bundle = new GtfsBundle();
bundle.setDefaultAgencyId(hd.getAgencyId());
bundle.setPath(new File(zipFilename));
bundles.getBundles().add(bundle);
}
Aggregations