use of org.onebusaway.gtfs_realtime.model.VehiclePositionModel in project onebusaway-application-modules by camsys.
the class VehiclePositionConvertor method readFeedEntity.
@Override
public VehiclePositionModel readFeedEntity(FeedEntity entity, long timestamp) {
if (entity == null)
return null;
VehiclePositionModel vpm = new VehiclePositionModel();
if (entity.hasVehicle()) {
if (entity.getVehicle().hasTimestamp()) {
timestamp = entity.getVehicle().getTimestamp() * 1000;
}
if (entity.getVehicle().hasTrip()) {
TripDescriptor td = entity.getVehicle().getTrip();
if (td.hasTripId()) {
vpm.setTripId(td.getTripId());
}
if (td.hasRouteId()) {
vpm.setRouteId(td.getRouteId());
}
if (td.hasStartDate() && td.hasStartTime()) {
vpm.setTripStart(GtfsRealtimeConversionLibrary.parseDate(td.getStartDate(), td.getStartTime()));
}
}
if (entity.getVehicle().hasVehicle()) {
VehicleDescriptor vd = entity.getVehicle().getVehicle();
if (vd.hasId()) {
vpm.setVehicleId(vd.getId());
}
if (vd.hasLabel()) {
vpm.setVehicleLabel(vd.getLabel());
}
if (vd.hasLicensePlate()) {
vpm.setVehicleLicensePlate(vd.getLicensePlate());
}
}
if (entity.getVehicle().hasPosition()) {
Position p = entity.getVehicle().getPosition();
vpm.setLat(p.getLatitude());
vpm.setLon(p.getLongitude());
if (p.hasBearing()) {
vpm.setBearing(p.getBearing());
}
if (p.hasSpeed()) {
vpm.setSpeed(p.getSpeed());
}
}
if (entity.getVehicle().hasTrip()) {
if (vpm.getTripId() == null) {
if (entity.getVehicle().getTrip().hasTripId()) {
vpm.setTripId(entity.getVehicle().getTrip().getTripId());
}
}
if (vpm.getRouteId() == null) {
if (entity.getVehicle().getTrip().hasRouteId()) {
vpm.setRouteId(entity.getVehicle().getTrip().getRouteId());
}
}
}
}
if (entity.getVehicle().hasStopId()) {
vpm.setStopId(entity.getVehicle().getStopId());
}
vpm.setTimestamp(new Date(timestamp));
return vpm;
}
use of org.onebusaway.gtfs_realtime.model.VehiclePositionModel in project onebusaway-application-modules by camsys.
the class VehiclePositionDaoImpl method getAllVehicleIds.
@Override
public List<String> getAllVehicleIds() {
// select distinct vehicleId from VehiclePositionModel
Projection prop = Projections.distinct(Projections.property("vehicleId"));
DetachedCriteria criteria = DetachedCriteria.forClass(VehiclePositionModel.class).setProjection(prop);
return _template.findByCriteria(criteria);
}
use of org.onebusaway.gtfs_realtime.model.VehiclePositionModel in project onebusaway-application-modules by camsys.
the class FeedServiceImpl method readVehiclePositions.
@Override
public List<VehiclePositionModel> readVehiclePositions(FeedMessage vehiclePositions, GtfsRealtimeEntitySource entitySource) {
_log.debug("reading VehiclePosition");
List<VehiclePositionModel> models = GtfsRealtimeConversionLibrary.readVehiclePositions(vehiclePositions);
for (VehiclePositionModel vehiclePosition : models) {
String agencyId = getAgencyId(entitySource);
addAgencyIdToTripId(vehiclePosition, agencyId, entitySource);
addAgencyIdToRouteId(vehiclePosition, agencyId, entitySource);
_persistor.persist(vehiclePosition);
}
return models;
}
Aggregations