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");
}
}
Aggregations