use of org.onebusaway.transit_data_federation.bundle.model.GtfsBundle 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.GtfsBundle in project onebusaway-application-modules by camsys.
the class BundleBuildingServiceImpl method createGtfsBundles.
private List<GtfsBundle> createGtfsBundles(BundleBuildResponse response) {
List<String> gtfsList = response.getGtfsList();
final String gtfsMsg = "constructing configuration for bundles=" + gtfsList;
response.addStatusMessage(gtfsMsg);
_log.info(gtfsMsg);
List<GtfsBundle> bundles = new ArrayList<GtfsBundle>(gtfsList.size());
String defaultAgencyId = getDefaultAgencyId();
response.addStatusMessage("default agency configured to be |" + defaultAgencyId + "|");
for (String path : gtfsList) {
GtfsBundle gtfsBundle = new GtfsBundle();
gtfsBundle.setPath(new File(path));
String agencySpecificId = getAgencySpecificId(path);
if (agencySpecificId != null) {
_log.info("using agency specific id=" + agencySpecificId);
gtfsBundle.setDefaultAgencyId(agencySpecificId);
} else {
if (defaultAgencyId != null && defaultAgencyId.length() > 0) {
final String msg = "for bundle " + path + " setting defaultAgencyId='" + defaultAgencyId + "'";
response.addStatusMessage(msg);
_log.info(msg);
gtfsBundle.setDefaultAgencyId(defaultAgencyId);
}
}
Map<String, String> mappings = getAgencyIdMappings(path);
if (mappings != null) {
_log.info("using agency specific mappings=" + mappings);
gtfsBundle.setAgencyIdMappings(mappings);
}
bundles.add(gtfsBundle);
}
return bundles;
}
use of org.onebusaway.transit_data_federation.bundle.model.GtfsBundle 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.GtfsBundle 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.GtfsBundle in project onebusaway-application-modules by camsys.
the class GtfsFullValidationTask method processGtfsBundles.
private void processGtfsBundles(GtfsBundles gtfsBundles) {
List<GtfsFullValidationTaskJobResult> results = new ArrayList<GtfsFullValidationTaskJobResult>();
for (GtfsBundle gtfsBundle : gtfsBundles.getBundles()) {
try {
results.add(submitJob(_validateService, gtfsBundle));
} catch (Exception any) {
_log.error("GtfsFullValidationTask failed for gtfsBundle:" + gtfsBundle.getPath().getName(), any);
}
}
try {
// give the executor a chance to run
Thread.sleep(1 * 1000);
} catch (InterruptedException e1) {
return;
}
// here we wait on the tasks to finish up
int i = 0;
for (GtfsFullValidationTaskJobResult result : results) {
while (!result.isDone()) {
try {
_log.info("waiting on thread[" + i + "/" + results.size() + "] " + result.getCsvFileName());
Thread.sleep(10 * 1000);
} catch (InterruptedException e) {
return;
}
}
i++;
_log.info("result " + result.getCsvFileName() + " completed in " + result.getRunTime() / 1000 + "s");
// process the results in the order they were submitted
processResult(result);
}
}
Aggregations