use of org.onebusaway.transit_data_federation.services.realtime.VehicleStatus in project onebusaway-application-modules by camsys.
the class VehicleStatusBeanServiceImpl method getAllVehiclesForAgency.
@Override
public ListBean<VehicleStatusBean> getAllVehiclesForAgency(String agencyId, long time) {
List<VehicleStatus> statuses = _vehicleStatusService.getAllVehicleStatuses();
List<VehicleStatusBean> beans = new ArrayList<VehicleStatusBean>();
for (VehicleStatus status : statuses) {
AgencyAndId vid = status.getVehicleId();
if (!vid.getAgencyId().equals(agencyId))
continue;
VehicleStatusBean bean = getStatusAsBean(status, time);
beans.add(bean);
}
return new ListBean<VehicleStatusBean>(beans, false);
}
use of org.onebusaway.transit_data_federation.services.realtime.VehicleStatus in project onebusaway-application-modules by camsys.
the class GtfsRealtimeServiceImpl method getVehiclePositions.
@Override
public FeedMessage getVehiclePositions() {
FeedMessage.Builder feedMessage = createFeedWithDefaultHeader();
List<VehicleStatus> statuses = _vehicleStatusService.getAllVehicleStatuses();
for (VehicleStatus status : statuses) {
VehicleLocationRecord record = status.getRecord();
VehiclePosition.Builder vehiclePosition = VehiclePosition.newBuilder();
if (record.isCurrentLocationSet()) {
Position.Builder position = Position.newBuilder();
position.setLatitude((float) record.getCurrentLocationLat());
position.setLongitude((float) record.getCurrentLocationLon());
vehiclePosition.setPosition(position);
}
VehicleDescriptor.Builder vehicleDescriptor = VehicleDescriptor.newBuilder();
vehicleDescriptor.setId(AgencyAndId.convertToString(record.getVehicleId()));
vehiclePosition.setVehicle(vehicleDescriptor);
if (record.getTimeOfLocationUpdate() != 0)
vehiclePosition.setTimestamp(record.getTimeOfLocationUpdate() / 1000);
else
vehiclePosition.setTimestamp(record.getTimeOfRecord() / 1000);
/**
* TODO: Block? Trip?
*/
FeedEntity.Builder feedEntity = FeedEntity.newBuilder();
feedEntity.setVehicle(vehiclePosition);
feedEntity.setId(vehicleDescriptor.getId());
feedMessage.addEntity(feedEntity);
}
return feedMessage.build();
}
use of org.onebusaway.transit_data_federation.services.realtime.VehicleStatus in project onebusaway-application-modules by camsys.
the class VehicleStatusServiceImpl method getAllVehicleStatuses.
@Override
public List<VehicleStatus> getAllVehicleStatuses() {
ArrayList<VehicleStatus> statuses = new ArrayList<VehicleStatus>();
for (VehicleLocationRecord record : _vehicleRecordsById.values()) {
VehicleStatus status = new VehicleStatus();
status.setRecord(record);
statuses.add(status);
}
return statuses;
}
use of org.onebusaway.transit_data_federation.services.realtime.VehicleStatus in project onebusaway-application-modules by camsys.
the class VehicleStatusServiceImpl method getVehicleStatusForId.
/**
**
* {@link VehicleStatusService} Interface
***
*/
@Override
public VehicleStatus getVehicleStatusForId(AgencyAndId vehicleId) {
VehicleLocationRecord record = _vehicleRecordsById.get(vehicleId);
if (record == null)
return null;
List<VehicleLocationRecord> records = new ArrayList<VehicleLocationRecord>();
VehicleLocationCacheElements elements = _vehicleLocationRecordCache.getRecordForVehicleId(vehicleId);
if (elements != null) {
for (VehicleLocationCacheElement element : elements.getElements()) records.add(element.getRecord());
}
VehicleStatus status = new VehicleStatus();
status.setRecord(record);
status.setAllRecords(records);
return status;
}
Aggregations