Search in sources :

Example 1 with GtfsMerger

use of org.onebusaway.gtfs_merge.GtfsMerger 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

File (java.io.File)1 ArrayList (java.util.ArrayList)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 TripMergeStrategy (org.onebusaway.gtfs_merge.strategies.TripMergeStrategy)1 GtfsBundle (org.onebusaway.transit_data_federation.bundle.model.GtfsBundle)1 GtfsBundles (org.onebusaway.transit_data_federation.bundle.model.GtfsBundles)1