use of org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean in project onebusaway-application-modules by camsys.
the class MessagesAction method getMessagesForRoute.
private List<Message> getMessagesForRoute(String agencyId, String routeId) {
List<Message> messageList = new ArrayList<Message>();
ListBean<ServiceAlertBean> serviceAlertBeans = getAllSituations(agencyId, routeId);
serviceAlerts: for (ServiceAlertBean serviceAlert : serviceAlertBeans.getList()) {
if (serviceAlert.getActiveWindows() != null) {
long currentTime = SystemTime.currentTimeMillis();
for (TimeRangeBean timerange : serviceAlert.getActiveWindows()) {
if (timerange.getFrom() < currentTime || timerange.getTo() < currentTime) {
continue serviceAlerts;
}
}
}
Message message = new Message();
message.setId(serviceAlert.getId());
message.setCreator(serviceAlert.getSource());
// message.setEndBoundaryStr(serviceAlert.getPublicationWindows().toString());
String messageText = "";
for (NaturalLanguageStringBean description : serviceAlert.getDescriptions()) {
messageText += description.getValue();
}
message.setMessageText(new MessageText(messageText));
messageList.add(message);
}
return messageList;
}
use of org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean in project onebusaway-application-modules by camsys.
the class StopWithArrivalsAndDeparturesBeanServiceImpl method getArrivalsAndDeparturesForStopIds.
public StopsWithArrivalsAndDeparturesBean getArrivalsAndDeparturesForStopIds(Set<AgencyAndId> ids, ArrivalsAndDeparturesQueryBean query) throws NoSuchStopServiceException {
List<StopBean> stops = new ArrayList<StopBean>();
List<ArrivalAndDepartureBean> allArrivalsAndDepartures = new ArrayList<ArrivalAndDepartureBean>();
Set<AgencyAndId> allNearbyStopIds = new HashSet<AgencyAndId>();
Map<String, ServiceAlertBean> situationsById = new HashMap<String, ServiceAlertBean>();
Counter<TimeZone> timeZones = new Counter<TimeZone>();
for (AgencyAndId id : ids) {
StopBean stopBean = _stopBeanService.getStopForId(id);
stops.add(stopBean);
List<ArrivalAndDepartureBean> arrivalsAndDepartures = _arrivalsAndDeparturesBeanService.getArrivalsAndDeparturesByStopId(id, query);
allArrivalsAndDepartures.addAll(arrivalsAndDepartures);
List<AgencyAndId> nearbyStopIds = _nearbyStopsBeanService.getNearbyStops(stopBean, 100);
allNearbyStopIds.addAll(nearbyStopIds);
TimeZone timeZone = _agencyService.getTimeZoneForAgencyId(id.getAgencyId());
timeZones.increment(timeZone);
List<ServiceAlertBean> situations = _serviceAlertsBeanService.getServiceAlertsForStopId(query.getTime(), id);
for (ServiceAlertBean situation : situations) situationsById.put(situation.getId(), situation);
}
allNearbyStopIds.removeAll(ids);
List<StopBean> nearbyStops = new ArrayList<StopBean>();
for (AgencyAndId id : allNearbyStopIds) {
StopBean stop = _stopBeanService.getStopForId(id);
nearbyStops.add(stop);
}
TimeZone timeZone = timeZones.getMax();
if (timeZone == null)
timeZone = TimeZone.getDefault();
StopsWithArrivalsAndDeparturesBean result = new StopsWithArrivalsAndDeparturesBean();
result.setStops(stops);
result.setArrivalsAndDepartures(allArrivalsAndDepartures);
result.setNearbyStops(nearbyStops);
result.setSituations(new ArrayList<ServiceAlertBean>(situationsById.values()));
result.setTimeZone(timeZone.getID());
return result;
}
use of org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean in project onebusaway-application-modules by camsys.
the class TripStatusBeanServiceImpl method getTripEntryAndBlockLocationAsTripDetails.
private TripDetailsBean getTripEntryAndBlockLocationAsTripDetails(BlockTripInstance blockTripInstance, BlockLocation blockLocation, TripDetailsInclusionBean inclusion, long time) {
TripBean trip = null;
long serviceDate = blockTripInstance.getServiceDate();
FrequencyBean frequency = null;
TripStopTimesBean stopTimes = null;
TripStatusBean status = null;
AgencyAndId vehicleId = null;
boolean missing = false;
FrequencyEntry frequencyLabel = blockTripInstance.getFrequencyLabel();
if (frequencyLabel != null) {
frequency = FrequencyBeanLibrary.getBeanForFrequency(serviceDate, frequencyLabel);
}
BlockTripEntry blockTrip = blockTripInstance.getBlockTrip();
TripEntry tripEntry = blockTrip.getTrip();
if (inclusion.isIncludeTripBean()) {
trip = _tripBeanService.getTripForId(tripEntry.getId());
if (trip == null)
missing = true;
}
if (inclusion.isIncludeTripSchedule()) {
stopTimes = _tripStopTimesBeanService.getStopTimesForBlockTrip(blockTripInstance);
if (stopTimes == null)
missing = true;
}
if (inclusion.isIncludeTripStatus() && blockLocation != null) {
status = getBlockLocationAsStatusBean(blockLocation, time);
if (status == null)
missing = true;
else
vehicleId = AgencyAndIdLibrary.convertFromString(status.getVehicleId());
}
List<ServiceAlertBean> situations = _serviceAlertBeanService.getServiceAlertsForVehicleJourney(time, blockTripInstance, vehicleId);
if (missing)
return null;
String tripId = AgencyAndIdLibrary.convertToString(tripEntry.getId());
TripDetailsBean bean = new TripDetailsBean();
bean.setTripId(tripId);
bean.setServiceDate(serviceDate);
bean.setFrequency(frequency);
bean.setTrip(trip);
bean.setSchedule(stopTimes);
bean.setStatus(status);
bean.setSituations(situations);
return bean;
}
use of org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean in project onebusaway-application-modules by camsys.
the class ArrivalsAndDeparturesBeanServiceImpl method applySituationsToBean.
private void applySituationsToBean(long time, ArrivalAndDepartureInstance instance, ArrivalAndDepartureBean bean) {
BlockInstance blockInstance = instance.getBlockInstance();
AgencyAndId vehicleId = null;
BlockLocation blockLocation = instance.getBlockLocation();
if (blockLocation != null)
vehicleId = blockLocation.getVehicleId();
List<ServiceAlertBean> situations = _serviceAlertsBeanService.getServiceAlertsForStopCall(time, blockInstance, instance.getBlockStopTime(), vehicleId);
if (!situations.isEmpty())
bean.setSituations(situations);
}
use of org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean in project onebusaway-application-modules by camsys.
the class ServiceAlertsHelperV2 method addGlobalServiceAlertsToServiceDelivery.
public void addGlobalServiceAlertsToServiceDelivery(ServiceDelivery serviceDelivery, RealtimeServiceV2 realtimeService) {
List<ServiceAlertBean> serviceAlertBeans = realtimeService.getServiceAlertsGlobal();
if (serviceAlertBeans == null)
return;
Map<String, PtSituationElementStructure> ptSituationElements = new HashMap<String, PtSituationElementStructure>();
for (ServiceAlertBean serviceAlertBean : serviceAlertBeans) {
ptSituationElements.put(serviceAlertBean.getId(), getServiceAlertBeanAsPtSituationElementStructure(serviceAlertBean));
}
addPtSituationElementsToServiceDelivery(serviceDelivery, ptSituationElements);
}
Aggregations