Search in sources :

Example 1 with FeedEntityModel

use of org.onebusaway.gtfs_realtime.interfaces.FeedEntityModel in project onebusaway-application-modules by camsys.

the class GtfsRealtimeRetrieverImpl method getFeedMessage.

@Override
public FeedMessage getFeedMessage(EntityType type, Date startDate, Date endDate) {
    FeedMessage.Builder builder = FeedMessage.newBuilder();
    List<? extends FeedEntityModel> updates = (type == EntityType.VEHICLE) ? _vehiclePositionDao.findByDate(startDate, endDate) : _tripUpdateDao.findByDate(startDate, endDate);
    long timestamp = 0;
    for (FeedEntityModel update : updates) {
        FeedEntity.Builder fe = fillFeedEntity(update);
        // This is not guaranteed to match entityID in source feed.
        fe.setId(Long.toString(update.getId()));
        builder.addEntity(fe);
        timestamp = Math.max(timestamp, update.getTimestamp().getTime());
    }
    FeedHeader.Builder header = FeedHeader.newBuilder();
    header.setTimestamp(timestamp / 1000);
    header.setGtfsRealtimeVersion(GTFS_RT_VERSION);
    builder.setHeader(header);
    return builder.build();
}
Also used : FeedMessage(com.google.transit.realtime.GtfsRealtime.FeedMessage) FeedEntityModel(org.onebusaway.gtfs_realtime.interfaces.FeedEntityModel) FeedEntity(com.google.transit.realtime.GtfsRealtime.FeedEntity) FeedHeader(com.google.transit.realtime.GtfsRealtime.FeedHeader)

Aggregations

FeedEntity (com.google.transit.realtime.GtfsRealtime.FeedEntity)1 FeedHeader (com.google.transit.realtime.GtfsRealtime.FeedHeader)1 FeedMessage (com.google.transit.realtime.GtfsRealtime.FeedMessage)1 FeedEntityModel (org.onebusaway.gtfs_realtime.interfaces.FeedEntityModel)1