Search in sources :

Example 6 with GtfsBundles

use of org.onebusaway.transit_data_federation.bundle.model.GtfsBundles in project onebusaway-application-modules by camsys.

the class MultiAgencyModTask method run.

@Override
public void run() {
    try {
        _log.info("GtfsModTask Starting");
        GtfsBundles gtfsBundles = getGtfsBundles(_applicationContext);
        for (GtfsBundle gtfsBundle : gtfsBundles.getBundles()) {
            String agencyId = parseAgencyDir(gtfsBundle.getPath().getPath());
            // _log.info("no modUrl found for agency " + agencyId + " and bundle " + gtfsBundle.getPath());
            String oldFilename = gtfsBundle.getPath().getPath();
            String newFilename = runModifications(gtfsBundle, agencyId, getEmptyModUrl(), null);
            logger.changelog("Transformed " + oldFilename + " to " + newFilename + " to add multi-agency support");
        }
    } catch (Throwable ex) {
        _log.error("error modifying gtfs:", ex);
    } finally {
        _log.info("GtfsModTask Exiting");
    }
}
Also used : GtfsBundle(org.onebusaway.transit_data_federation.bundle.model.GtfsBundle) GtfsBundles(org.onebusaway.transit_data_federation.bundle.model.GtfsBundles)

Example 7 with GtfsBundles

use of org.onebusaway.transit_data_federation.bundle.model.GtfsBundles in project onebusaway-application-modules by camsys.

the class UtilityLibrary method getGtfsBundlesForArguments.

public static List<GtfsBundle> getGtfsBundlesForArguments(List<String> args) {
    List<GtfsBundle> allBundles = new ArrayList<GtfsBundle>();
    List<String> contextPaths = new ArrayList<String>();
    int defaultAgencyIdOffset = 99990;
    for (String arg : args) {
        if (arg.endsWith(".xml"))
            contextPaths.add("file:" + arg);
        else {
            String defaultAgencyId = null;
            int index = arg.indexOf(':');
            if (index != -1) {
                defaultAgencyId = arg.substring(index + 1);
                arg = arg.substring(0, index);
            } else {
                defaultAgencyId = Integer.toString(defaultAgencyIdOffset++);
            }
            GtfsBundle bundle = new GtfsBundle();
            bundle.setPath(new File(arg));
            bundle.setDefaultAgencyId(defaultAgencyId);
            allBundles.add(bundle);
        }
    }
    if (!contextPaths.isEmpty()) {
        // This will get us basic behavior like property expansion
        contextPaths.add(0, "classpath:org/onebusaway/container/application-context-common.xml");
        ConfigurableApplicationContext context = ContainerLibrary.createContext(contextPaths);
        GtfsBundles bundles = (GtfsBundles) context.getBean("gtfs-bundles");
        allBundles.addAll(bundles.getBundles());
    }
    return allBundles;
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) GtfsBundle(org.onebusaway.transit_data_federation.bundle.model.GtfsBundle) ArrayList(java.util.ArrayList) GtfsBundles(org.onebusaway.transit_data_federation.bundle.model.GtfsBundles) File(java.io.File)

Example 8 with GtfsBundles

use of org.onebusaway.transit_data_federation.bundle.model.GtfsBundles in project onebusaway-application-modules by camsys.

the class BaseModTask 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 9 with GtfsBundles

use of org.onebusaway.transit_data_federation.bundle.model.GtfsBundles in project onebusaway-application-modules by camsys.

the class GtfsArchiveTask 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 10 with GtfsBundles

use of org.onebusaway.transit_data_federation.bundle.model.GtfsBundles in project onebusaway-application-modules by camsys.

the class GtfsMergeTask method run.

public void run() {
    if (!requestResponse.getRequest().getConsolidateFlag()) {
        _log.info("consolidate flag not set, extiting");
        return;
    }
    _log.info("GtfsMergeTask Starting with outputDirectory=" + getOutputDirectory());
    try {
        _log.info("Started merging modified GTFS feeds.");
        GtfsBundles gtfsBundles = getGtfsBundles(_applicationContext);
        List<File> inputPaths = new ArrayList<File>();
        // note this will be overridden if properly configured
        String outputLocation = System.getProperty("java.io.tmpdir") + File.separator + "gtfs_puget_sound_consolidated.zip";
        if (getOutputDirectory() != null) {
            String consolidatedPath = getOutputDirectory() + File.separator + CONSOLIDATED_DIR;
            File consolidatedDir = new File(consolidatedPath);
            consolidatedDir.mkdirs();
            outputLocation = consolidatedPath + File.separator + "gtfs_puget_sound_consolidated.zip";
        }
        _log.info("Consolidated file output location: " + outputLocation);
        int i = 0;
        for (GtfsBundle gtfsBundle : gtfsBundles.getBundles()) {
            if (gtfsBundle.getPath() != null) {
                _log.info("addiing agency data file path for agency[" + i + "]=" + gtfsBundle.getPath());
                inputPaths.add(gtfsBundle.getPath());
            } else {
                _log.info("null file path for agency.");
            }
        }
        // Now call GTFS merger
        GtfsMerger feedMerger = new GtfsMerger();
        AgencyMergeStrategy agencyStrategy = new AgencyMergeStrategy();
        // agencies aren't duplicates, its by design
        agencyStrategy.setDuplicateDetectionStrategy(EDuplicateDetectionStrategy.FUZZY);
        feedMerger.setAgencyStrategy(agencyStrategy);
        StopMergeStrategy stopStrategy = new StopMergeStrategy();
        stopStrategy.setDuplicateRenamingStrategy(EDuplicateRenamingStrategy.AGENCY);
        feedMerger.setStopStrategy(stopStrategy);
        RouteMergeStrategy routeStrategy = new RouteMergeStrategy();
        routeStrategy.setDuplicateRenamingStrategy(EDuplicateRenamingStrategy.AGENCY);
        feedMerger.setRouteStrategy(routeStrategy);
        ServiceCalendarMergeStrategy serviceCalendarStrategy = new ServiceCalendarMergeStrategy();
        serviceCalendarStrategy.setDuplicateRenamingStrategy(EDuplicateRenamingStrategy.AGENCY);
        feedMerger.setServiceCalendarStrategy(serviceCalendarStrategy);
        TripMergeStrategy tripStrategy = new TripMergeStrategy();
        tripStrategy.setDuplicateRenamingStrategy(EDuplicateRenamingStrategy.AGENCY);
        feedMerger.setTripStrategy(tripStrategy);
        File outputFile = new File(outputLocation);
        outputFile.createNewFile();
        feedMerger.run(inputPaths, new File(outputLocation));
    } catch (Throwable ex) {
        _log.error("Error merging gtfs:", ex);
    } finally {
        _log.info("GtfsMergeTask Exiting");
    }
}
Also used : TripMergeStrategy(org.onebusaway.gtfs_merge.strategies.TripMergeStrategy) AgencyMergeStrategy(org.onebusaway.gtfs_merge.strategies.AgencyMergeStrategy) RouteMergeStrategy(org.onebusaway.gtfs_merge.strategies.RouteMergeStrategy) GtfsBundles(org.onebusaway.transit_data_federation.bundle.model.GtfsBundles) ArrayList(java.util.ArrayList) StopMergeStrategy(org.onebusaway.gtfs_merge.strategies.StopMergeStrategy) ServiceCalendarMergeStrategy(org.onebusaway.gtfs_merge.strategies.ServiceCalendarMergeStrategy) GtfsBundle(org.onebusaway.transit_data_federation.bundle.model.GtfsBundle) GtfsMerger(org.onebusaway.gtfs_merge.GtfsMerger) 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