Search in sources :

Example 1 with BundleMetadata

use of org.onebusaway.transit_data.model.config.BundleMetadata in project onebusaway-application-modules by camsys.

the class BundleConfigDao method setup.

@PostConstruct
@Refreshable(dependsOn = RefreshableResources.TRANSIT_GRAPH)
public void setup() throws IOException, ClassNotFoundException {
    _meta = null;
    File path = _bundle.getBundleMetadataPath();
    _log.info("looking for metadata file " + path);
    if (path.exists()) {
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        BundleMetadata meta = null;
        try {
            meta = mapper.readValue(path, BundleMetadata.class);
        } catch (Exception any) {
            _log.error("reading metadata failed:", any);
        }
        if (meta != null) {
            _meta = meta;
        }
    } else {
        _log.error(" did not find metadata file " + path);
    }
}
Also used : File(java.io.File) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) IOException(java.io.IOException) BundleMetadata(org.onebusaway.transit_data.model.config.BundleMetadata) Refreshable(org.onebusaway.container.refresh.Refreshable) PostConstruct(javax.annotation.PostConstruct)

Example 2 with BundleMetadata

use of org.onebusaway.transit_data.model.config.BundleMetadata in project onebusaway-application-modules by camsys.

the class ConfigAction method index.

public DefaultHttpHeaders index() throws IOException, ServiceException {
    if (hasErrors())
        return setValidationErrorsResponse();
    BundleMetadata meta = _service.getBundleMetadata();
    BeanFactoryV2 factory = getBeanFactoryV2();
    return setOkResponse(factory.getResponse(meta));
}
Also used : BundleMetadata(org.onebusaway.transit_data.model.config.BundleMetadata) BeanFactoryV2(org.onebusaway.api.model.transit.BeanFactoryV2)

Example 3 with BundleMetadata

use of org.onebusaway.transit_data.model.config.BundleMetadata 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;
}
Also used : ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) BundleItem(org.onebusaway.transit_data_federation.model.bundle.BundleItem) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) Date(java.util.Date) DateTime(org.joda.time.DateTime) BundleMetadata(org.onebusaway.transit_data.model.config.BundleMetadata)

Aggregations

BundleMetadata (org.onebusaway.transit_data.model.config.BundleMetadata)3 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2 File (java.io.File)1 IOException (java.io.IOException)1 Date (java.util.Date)1 PostConstruct (javax.annotation.PostConstruct)1 DateTime (org.joda.time.DateTime)1 BeanFactoryV2 (org.onebusaway.api.model.transit.BeanFactoryV2)1 Refreshable (org.onebusaway.container.refresh.Refreshable)1 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)1 BundleItem (org.onebusaway.transit_data_federation.model.bundle.BundleItem)1