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