Search in sources :

Example 1 with TripUpdateModel

use of org.onebusaway.gtfs_realtime.model.TripUpdateModel in project onebusaway-application-modules by camsys.

the class TripUpdateConvertor method readFeedEntity.

@Override
public TripUpdateModel readFeedEntity(FeedEntity entity, long timestamp) {
    if (entity.hasTripUpdate()) {
        TripUpdateModel tu = new TripUpdateModel();
        TripDescriptor t = entity.getTripUpdate().getTrip();
        if (entity.getTripUpdate().hasTimestamp()) {
            timestamp = entity.getTripUpdate().getTimestamp() * 1000;
        }
        tu.setTimestamp(new Date(timestamp));
        if (entity.getTripUpdate().hasDelay()) {
            tu.setDelay(entity.getTripUpdate().getDelay());
        }
        if (t.hasTripId())
            tu.setTripId(t.getTripId());
        if (t.hasRouteId()) {
            tu.setRouteId(t.getRouteId());
        }
        if (t.hasStartDate() && t.hasStartTime()) {
            tu.setTripStart(GtfsRealtimeConversionLibrary.parseDate(t.getStartDate(), t.getStartTime()));
        }
        tu.setScheduleRelationship(findRelationship(t));
        VehicleDescriptor vehicle = entity.getTripUpdate().getVehicle();
        if (vehicle != null) {
            tu.setVehicleId(vehicle.getId());
            tu.setVehicleLabel(vehicle.getLabel());
            tu.setVehicleLicensePlate(vehicle.getLicensePlate());
        }
        for (StopTimeUpdate stu : entity.getTripUpdate().getStopTimeUpdateList()) {
            StopTimeUpdateModel stopTimeUpdate = readStopTimeUpdate(stu, tu.getScheduleRelationship());
            if (stopTimeUpdate != null) {
                stopTimeUpdate.setTripUpdateModel(tu);
                tu.addStopTimeUpdateModel(stopTimeUpdate);
            }
        }
        return tu;
    }
    return null;
}
Also used : StopTimeUpdateModel(org.onebusaway.gtfs_realtime.model.StopTimeUpdateModel) TripDescriptor(com.google.transit.realtime.GtfsRealtime.TripDescriptor) StopTimeUpdate(com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate) VehicleDescriptor(com.google.transit.realtime.GtfsRealtime.VehicleDescriptor) Date(java.util.Date) TripUpdateModel(org.onebusaway.gtfs_realtime.model.TripUpdateModel)

Example 2 with TripUpdateModel

use of org.onebusaway.gtfs_realtime.model.TripUpdateModel in project onebusaway-application-modules by camsys.

the class FeedServiceImpl method readTripUpdates.

@Override
public List<TripUpdateModel> readTripUpdates(FeedMessage tripUpdates, GtfsRealtimeEntitySource entitySource) {
    List<TripUpdateModel> updates = GtfsRealtimeConversionLibrary.readTripUpdates(tripUpdates);
    for (TripUpdateModel tripUpdate : updates) {
        String agencyId = getAgencyId(entitySource);
        addAgencyIdToTripId(tripUpdate, agencyId, entitySource);
        addAgencyIdToRouteId(tripUpdate, agencyId, entitySource);
        // Check stop id
        for (StopTimeUpdateModel stopTimeUpdate : tripUpdate.getStopTimeUpdates()) {
            addAgencyIdToStopId(stopTimeUpdate, agencyId, entitySource);
        }
        _persistor.persist(tripUpdate);
    }
    return updates;
}
Also used : StopTimeUpdateModel(org.onebusaway.gtfs_realtime.model.StopTimeUpdateModel) TripUpdateModel(org.onebusaway.gtfs_realtime.model.TripUpdateModel)

Aggregations

StopTimeUpdateModel (org.onebusaway.gtfs_realtime.model.StopTimeUpdateModel)2 TripUpdateModel (org.onebusaway.gtfs_realtime.model.TripUpdateModel)2 TripDescriptor (com.google.transit.realtime.GtfsRealtime.TripDescriptor)1 StopTimeUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate)1 VehicleDescriptor (com.google.transit.realtime.GtfsRealtime.VehicleDescriptor)1 Date (java.util.Date)1