use of org.onebusaway.transit_data.model.RouteBean in project onebusaway-application-modules by camsys.
the class NameBasedNotificationStrategyImpl method summarizeRoute.
@Override
public String summarizeRoute(String routeIdStr) {
if (routeIdStr == null)
return null;
// return the route short name for the give routeId
try {
AgencyAndId routeId = AgencyAndIdLibrary.convertFromString(routeIdStr);
RouteBean route = _tds.getRouteForId(routeIdStr);
if (route == null || route.getShortName() == null)
return routeIdStr;
return route.getShortName();
} catch (IllegalStateException ise) {
// invalid id -- return it as is
return routeIdStr;
}
}
use of org.onebusaway.transit_data.model.RouteBean in project onebusaway-application-modules by camsys.
the class RouteDescriptionComponent method end.
@Override
public boolean end(Writer writer, String body) {
if (_value == null)
_value = "top";
Object obj = findValue(_value);
if (obj instanceof RouteBean) {
RouteBean route = (RouteBean) obj;
String value = RoutePresenter.getDescriptionForRoute(route);
try {
if (value != null)
writer.write(value);
} catch (IOException e) {
LOG.error("Could not write out Text tag", e);
}
}
return super.end(writer, "");
}
use of org.onebusaway.transit_data.model.RouteBean in project onebusaway-application-modules by camsys.
the class BeanFactoryV2 method getStopsForRoute.
public StopsForRouteV2Bean getStopsForRoute(StopsForRouteBean stopsForRoute, boolean includePolylines) {
StopsForRouteV2Bean bean = new StopsForRouteV2Bean();
RouteBean route = stopsForRoute.getRoute();
if (route != null) {
addToReferences(route);
bean.setRouteId(route.getId());
}
List<String> stopIds = new ArrayList<String>();
for (StopBean stop : stopsForRoute.getStops()) {
stopIds.add(stop.getId());
addToReferences(stop);
}
bean.setStopIds(stopIds);
bean.setStopGroupings(stopsForRoute.getStopGroupings());
if (!includePolylines) {
for (StopGroupingBean grouping : stopsForRoute.getStopGroupings()) {
for (StopGroupBean group : grouping.getStopGroups()) group.setPolylines(null);
}
}
if (includePolylines)
bean.setPolylines(stopsForRoute.getPolylines());
return bean;
}
use of org.onebusaway.transit_data.model.RouteBean in project onebusaway-application-modules by camsys.
the class BeanFactoryV2 method getArrivalAndDeparture.
public ArrivalAndDepartureV2Bean getArrivalAndDeparture(ArrivalAndDepartureBean ad) {
TripBean trip = ad.getTrip();
RouteBean route = trip.getRoute();
StopBean stop = ad.getStop();
ArrivalAndDepartureV2Bean bean = new ArrivalAndDepartureV2Bean();
bean.setTripId(trip.getId());
addToReferences(trip);
bean.setServiceDate(ad.getServiceDate());
bean.setVehicleId(ad.getVehicleId());
bean.setStopId(stop.getId());
addToReferences(stop);
bean.setStopSequence(ad.getStopSequence());
bean.setBlockTripSequence(ad.getBlockTripSequence());
bean.setTotalStopsInTrip(ad.getTotalStopsInTrip());
bean.setRouteId(route.getId());
addToReferences(route);
String routeShortName = ad.getRouteShortName();
if (routeShortName == null || routeShortName.isEmpty())
routeShortName = trip.getRouteShortName();
if (routeShortName == null || routeShortName.isEmpty())
routeShortName = route.getShortName();
bean.setRouteShortName(routeShortName);
bean.setRouteLongName(route.getLongName());
String tripHeadsign = ad.getTripHeadsign();
if (tripHeadsign == null || tripHeadsign.isEmpty())
tripHeadsign = trip.getTripHeadsign();
bean.setTripHeadsign(tripHeadsign);
bean.setArrivalEnabled(ad.isArrivalEnabled());
bean.setDepartureEnabled(ad.isDepartureEnabled());
bean.setScheduledArrivalTime(ad.getScheduledArrivalTime());
bean.setScheduledDepartureTime(ad.getScheduledDepartureTime());
bean.setPredictedArrivalTime(ad.getPredictedArrivalTime());
bean.setPredictedDepartureTime(ad.getPredictedDepartureTime());
bean.setScheduledArrivalInterval(getTimeInterval(ad.getScheduledArrivalInterval()));
bean.setScheduledDepartureInterval(getTimeInterval(ad.getScheduledDepartureInterval()));
bean.setPredictedArrivalInterval(getTimeInterval(ad.getPredictedArrivalInterval()));
bean.setPredictedDepartureInterval(getTimeInterval(ad.getPredictedDepartureInterval()));
if (ad.getFrequency() != null)
bean.setFrequency(getFrequency(ad.getFrequency()));
bean.setStatus(ad.getStatus());
if (ad.isDistanceFromStopSet())
bean.setDistanceFromStop(ad.getDistanceFromStop());
bean.setNumberOfStopsAway(ad.getNumberOfStopsAway());
TripStatusBean tripStatus = ad.getTripStatus();
if (tripStatus != null)
bean.setTripStatus(getTripStatus(tripStatus));
bean.setPredicted(ad.isPredicted());
bean.setLastUpdateTime(ad.getLastUpdateTime());
List<ServiceAlertBean> situations = ad.getSituations();
if (situations != null && !situations.isEmpty()) {
List<String> situationIds = new ArrayList<String>();
for (ServiceAlertBean situation : situations) {
situationIds.add(situation.getId());
addToReferences(situation);
}
bean.setSituationIds(situationIds);
}
return bean;
}
use of org.onebusaway.transit_data.model.RouteBean in project onebusaway-application-modules by camsys.
the class TripUpdatesForAgencyAction method fillFeedMessage.
@Override
protected void fillFeedMessage(FeedMessage.Builder feed, String agencyId, long timestamp) {
ListBean<VehicleStatusBean> vehicles = _service.getAllVehiclesForAgency(agencyId, timestamp);
for (VehicleStatusBean vehicle : vehicles.getList()) {
TripStatusBean tripStatus = vehicle.getTripStatus();
if (tripStatus == null) {
continue;
}
TripBean activeTrip = tripStatus.getActiveTrip();
RouteBean route = activeTrip.getRoute();
FeedEntity.Builder entity = feed.addEntityBuilder();
entity.setId(Integer.toString(feed.getEntityCount()));
TripUpdate.Builder tripUpdate = entity.getTripUpdateBuilder();
TripDescriptor.Builder tripDesc = tripUpdate.getTripBuilder();
tripDesc.setTripId(normalizeId(activeTrip.getId()));
tripDesc.setRouteId(normalizeId(route.getId()));
VehicleDescriptor.Builder vehicleDesc = tripUpdate.getVehicleBuilder();
vehicleDesc.setId(normalizeId(vehicle.getVehicleId()));
if (tripStatus.getTimepointPredictions() != null && tripStatus.getTimepointPredictions().size() > 0) {
for (TimepointPredictionBean timepointPrediction : tripStatus.getTimepointPredictions()) {
AgencyAndId stopId = modifiedStopId(agencyId, timepointPrediction.getTimepointId());
if (!stopId.getAgencyId().equals(agencyId))
continue;
TripUpdate.StopTimeUpdate.Builder stopTimeUpdate = tripUpdate.addStopTimeUpdateBuilder();
stopTimeUpdate.setStopId(normalizeId(stopId.toString()));
TripUpdate.StopTimeEvent.Builder arrival = stopTimeUpdate.getArrivalBuilder();
if (timepointPrediction.getTimepointPredictedArrivalTime() != -1) {
arrival.setTime(timepointPrediction.getTimepointPredictedArrivalTime() / 1000L);
}
TripUpdate.StopTimeEvent.Builder departure = stopTimeUpdate.getDepartureBuilder();
if (timepointPrediction.getTimepointPredictedDepartureTime() != -1) {
departure.setTime(timepointPrediction.getTimepointPredictedDepartureTime() / 1000L);
}
}
tripUpdate.setTimestamp(vehicle.getLastUpdateTime() / 1000);
} else {
StopBean nextStop = tripStatus.getNextStop();
if (nextStop != null) {
AgencyAndId stopId = modifiedStopId(agencyId, nextStop.getId());
if (stopId.getAgencyId().equals(agencyId)) {
TripUpdate.StopTimeUpdate.Builder stopTimeUpdate = tripUpdate.addStopTimeUpdateBuilder();
stopTimeUpdate.setStopId(normalizeId(stopId.toString()));
TripUpdate.StopTimeEvent.Builder departure = stopTimeUpdate.getDepartureBuilder();
departure.setTime(timestamp / 1000 + tripStatus.getNextStopTimeOffset());
}
}
}
tripUpdate.setDelay((int) tripStatus.getScheduleDeviation());
tripUpdate.setTimestamp(vehicle.getLastUpdateTime() / 1000);
}
}
Aggregations