Search in sources :

Example 1 with GtfsBundles

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();
}
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)

Example 2 with GtfsBundles

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");
}
Also used : GtfsBundle(org.onebusaway.transit_data_federation.bundle.model.GtfsBundle) GtfsBundles(org.onebusaway.transit_data_federation.bundle.model.GtfsBundles)

Example 3 with GtfsBundles

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");
}
Also used : SessionFactory(org.hibernate.SessionFactory) GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) GtfsReader(org.onebusaway.gtfs.serialization.GtfsReader) Configuration(org.hibernate.cfg.Configuration) Transaction(org.hibernate.Transaction) GtfsBundle(org.onebusaway.transit_data_federation.bundle.model.GtfsBundle) GtfsBundles(org.onebusaway.transit_data_federation.bundle.model.GtfsBundles) IOException(java.io.IOException) HibernateGtfsFactory(org.onebusaway.gtfs.services.HibernateGtfsFactory) Session(org.hibernate.classic.Session)

Example 4 with GtfsBundles

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");
}
Also used : GtfsBundle(org.onebusaway.transit_data_federation.bundle.model.GtfsBundle) GtfsBundles(org.onebusaway.transit_data_federation.bundle.model.GtfsBundles)

Example 5 with GtfsBundles

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);
}
Also used : GtfsBundle(org.onebusaway.transit_data_federation.bundle.model.GtfsBundle) GtfsBundles(org.onebusaway.transit_data_federation.bundle.model.GtfsBundles) File(java.io.File)

Aggregations

GtfsBundle (org.onebusaway.transit_data_federation.bundle.model.GtfsBundle)13 GtfsBundles (org.onebusaway.transit_data_federation.bundle.model.GtfsBundles)13 File (java.io.File)3 ArrayList (java.util.ArrayList)2 GtfsReader (org.onebusaway.gtfs.serialization.GtfsReader)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 SessionFactory (org.hibernate.SessionFactory)1 Transaction (org.hibernate.Transaction)1 Configuration (org.hibernate.cfg.Configuration)1 Session (org.hibernate.classic.Session)1 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)1 HibernateGtfsFactory (org.onebusaway.gtfs.services.HibernateGtfsFactory)1 GtfsMerger (org.onebusaway.gtfs_merge.GtfsMerger)1 AgencyMergeStrategy (org.onebusaway.gtfs_merge.strategies.AgencyMergeStrategy)1 RouteMergeStrategy (org.onebusaway.gtfs_merge.strategies.RouteMergeStrategy)1 ServiceCalendarMergeStrategy (org.onebusaway.gtfs_merge.strategies.ServiceCalendarMergeStrategy)1 StopMergeStrategy (org.onebusaway.gtfs_merge.strategies.StopMergeStrategy)1