use of org.onebusaway.transit_data_federation.model.bundle.BundleItem in project onebusaway-application-modules by camsys.
the class LocalBundleStoreImpl method getBundles.
@Override
public List<BundleItem> getBundles() {
ArrayList<BundleItem> output = new ArrayList<BundleItem>();
File bundleRoot = new File(_bundleRootPath);
if (!bundleRoot.isDirectory()) {
return output;
}
for (String filename : bundleRoot.list()) {
File possibleBundle = new File(bundleRoot, filename);
if (possibleBundle.isDirectory()) {
File calendarServiceObjectFile = new File(possibleBundle, CALENDAR_DATA);
File metadataFile = new File(possibleBundle, METADATA);
if (!calendarServiceObjectFile.exists()) {
_log.warn("Could not find " + CALENDAR_DATA + " in local bundle '" + filename + "'; skipping. Not a bundle?");
continue;
}
if (!metadataFile.exists()) {
_log.warn("Could not find " + METADATA + " in local bundle '" + filename + "'; skipping. Not a bundle?");
continue;
}
try {
BundleItem validLocalBundle = createBundleItem(calendarServiceObjectFile, metadataFile, filename);
output.add(validLocalBundle);
} catch (Exception e) {
continue;
}
} else if (possibleBundle.isFile() && possibleBundle.getName().equalsIgnoreCase(CALENDAR_DATA)) {
try {
String parentFilename = bundleRoot.getName();
BundleItem validLocalBundle = createBundleItem(possibleBundle, parentFilename);
output.add(validLocalBundle);
setLegacyBundle(true);
break;
} catch (Exception e) {
continue;
}
}
}
return output;
}
use of org.onebusaway.transit_data_federation.model.bundle.BundleItem in project onebusaway-application-modules by camsys.
the class LocalBundleStoreImpl method createBundleItem.
private BundleItem createBundleItem(File calendarServiceObjectFile, File metadataFile, String filename) throws Exception {
// get data to fill in the BundleItem for this bundle.
ServiceDate minServiceDate = null;
ServiceDate maxServiceDate = null;
try {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
BundleMetadata meta = null;
meta = mapper.readValue(metadataFile, BundleMetadata.class);
// Convert metadata String Dates to Date Objects
Date fromDate = new Date(Long.parseLong(meta.getServiceDateFrom()));
Date toDate = new Date(Long.parseLong(meta.getServiceDateTo()));
// Convert Date Objects to ServiceDate Objects
minServiceDate = new ServiceDate(fromDate);
maxServiceDate = new ServiceDate(toDate);
} catch (Exception e) {
_log.error(e.getMessage());
_log.error("Deserialization of metadata.json in local bundle " + filename + "; skipping.");
throw new Exception(e);
}
_log.info("Found local bundle " + filename + " with service range " + minServiceDate + " => " + maxServiceDate);
BundleItem bundleItem = new BundleItem();
bundleItem.setId(filename);
bundleItem.setName(filename);
bundleItem.setServiceDateFrom(minServiceDate);
bundleItem.setServiceDateTo(maxServiceDate);
DateTime lastModified = new DateTime(calendarServiceObjectFile.lastModified());
bundleItem.setCreated(lastModified);
bundleItem.setUpdated(lastModified);
return bundleItem;
}
Aggregations