Search in sources :

Example 11 with ServiceAlertBean

use of org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean in project onebusaway-application-modules by camsys.

the class ArrivalsAndDeparturesAction method processServiceAlertMessages.

private void processServiceAlertMessages(Map<StopRouteKey, List<ServiceAlertBean>> stopRouteAlertsMap) {
    List<String> routeIds = new ArrayList<String>();
    List<String> stopIds = new ArrayList<String>();
    if (!stopRouteAlertsMap.isEmpty()) {
        for (Map.Entry<StopRouteKey, List<ServiceAlertBean>> entry : stopRouteAlertsMap.entrySet()) {
            List<ServiceAlertBean> alerts = entry.getValue();
            for (ServiceAlertBean alert : alerts) {
                if (containsActiveAlert(alert, System.currentTimeMillis())) {
                    if (entry.getKey().hasRoute()) {
                        routeIds.add(entry.getKey().getRoute());
                        break;
                    } else {
                        stopIds.add(entry.getKey().getStop());
                        break;
                    }
                }
            }
        }
    }
    addServiceAlertRouteText(routeIds);
    addServiceAlertStopText(stopIds);
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 12 with ServiceAlertBean

use of org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean in project onebusaway-application-modules by camsys.

the class SearchResultFactoryImpl method getRouteResult.

@Override
public SearchResult getRouteResult(RouteBean routeBean) {
    List<RouteDirection> directions = new ArrayList<RouteDirection>();
    StopsForRouteBean stopsForRoute = _transitDataService.getStopsForRoute(routeBean.getId());
    // create stop ID->stop bean map
    Map<String, StopBean> stopIdToStopBeanMap = new HashMap<String, StopBean>();
    for (StopBean stopBean : stopsForRoute.getStops()) {
        stopIdToStopBeanMap.put(stopBean.getId(), stopBean);
    }
    // add stops in both directions
    List<VehicleActivityStructure> journeyList = _realtimeService.getVehicleActivityForRoute(routeBean.getId(), null, 0, SystemTime.currentTimeMillis(), false);
    Map<String, List<String>> stopIdToDistanceAwayStringMap = new HashMap<String, List<String>>();
    Map<String, List<String>> stopIdToVehicleIdMap = new HashMap<String, List<String>>();
    Map<String, Boolean> stopIdToRealtimeDataMap = new HashMap<String, Boolean>();
    // build map of stop IDs to list of distance strings
    for (VehicleActivityStructure journey : journeyList) {
        // on detour?
        MonitoredCallStructure monitoredCall = journey.getMonitoredVehicleJourney().getMonitoredCall();
        if (monitoredCall == null) {
            continue;
        }
        String stopId = monitoredCall.getStopPointRef().getValue();
        fillDistanceAwayStringsList(journey.getMonitoredVehicleJourney(), journey.getRecordedAtTime(), stopId, stopIdToDistanceAwayStringMap);
        fillVehicleIdsStringList(journey.getMonitoredVehicleJourney(), journey.getRecordedAtTime(), stopId, stopIdToVehicleIdMap);
        fillRealtimeData(journey.getMonitoredVehicleJourney(), stopId, stopIdToRealtimeDataMap);
    }
    List<StopGroupingBean> stopGroupings = stopsForRoute.getStopGroupings();
    for (StopGroupingBean stopGroupingBean : stopGroupings) {
        for (StopGroupBean stopGroupBean : stopGroupingBean.getStopGroups()) {
            NameBean name = stopGroupBean.getName();
            String type = name.getType();
            if (!type.equals("destination"))
                continue;
            // service in this direction
            Boolean hasUpcomingScheduledService = _transitDataService.routeHasUpcomingScheduledService((routeBean.getAgency() != null ? routeBean.getAgency().getId() : null), SystemTime.currentTimeMillis(), routeBean.getId(), stopGroupBean.getId());
            // if there are buses on route, always have "scheduled service"
            Boolean routeHasVehiclesInService = _realtimeService.getVehiclesInServiceForRoute(routeBean.getId(), stopGroupBean.getId(), SystemTime.currentTimeMillis());
            if (routeHasVehiclesInService) {
                hasUpcomingScheduledService = true;
            }
            // stops in this direction
            List<StopOnRoute> stopsOnRoute = null;
            if (!stopGroupBean.getStopIds().isEmpty()) {
                stopsOnRoute = new ArrayList<StopOnRoute>();
                for (String stopId : stopGroupBean.getStopIds()) {
                    if (_transitDataService.stopHasRevenueServiceOnRoute((routeBean.getAgency() != null ? routeBean.getAgency().getId() : null), stopId, routeBean.getId(), stopGroupBean.getId())) {
                        stopsOnRoute.add(new StopOnRoute(stopIdToStopBeanMap.get(stopId), stopIdToDistanceAwayStringMap.get(stopId), stopIdToRealtimeDataMap.get(stopId), stopIdToVehicleIdMap.get(stopId)));
                    }
                }
            }
            directions.add(new RouteDirection(stopGroupBean.getName().getName(), stopGroupBean, stopsOnRoute, hasUpcomingScheduledService, null));
        }
    }
    // service alerts in this direction
    Set<String> serviceAlertDescriptions = new HashSet<String>();
    List<ServiceAlertBean> serviceAlertBeans = _realtimeService.getServiceAlertsForRoute(routeBean.getId());
    populateServiceAlerts(serviceAlertDescriptions, serviceAlertBeans);
    return new RouteResult(routeBean, directions, serviceAlertDescriptions);
}
Also used : HashMap(java.util.HashMap) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) ArrayList(java.util.ArrayList) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) RouteResult(org.onebusaway.enterprise.webapp.actions.m.model.RouteResult) ArrayList(java.util.ArrayList) List(java.util.List) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean) MonitoredCallStructure(uk.org.siri.siri.MonitoredCallStructure) HashSet(java.util.HashSet) RouteDirection(org.onebusaway.enterprise.webapp.actions.m.model.RouteDirection) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) StopBean(org.onebusaway.transit_data.model.StopBean) VehicleActivityStructure(uk.org.siri.siri.VehicleActivityStructure) NameBean(org.onebusaway.transit_data.model.NameBean) StopOnRoute(org.onebusaway.enterprise.webapp.actions.m.model.StopOnRoute)

Example 13 with ServiceAlertBean

use of org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean in project onebusaway-application-modules by camsys.

the class SearchResultFactoryImpl method getStopResult.

@Override
public SearchResult getStopResult(StopBean stopBean, Set<RouteBean> routeFilter) {
    List<RouteAtStop> routesWithArrivals = new ArrayList<RouteAtStop>();
    List<RouteAtStop> routesWithNoVehiclesEnRoute = new ArrayList<RouteAtStop>();
    List<RouteAtStop> routesWithNoScheduledService = new ArrayList<RouteAtStop>();
    List<RouteBean> filteredRoutes = new ArrayList<RouteBean>();
    Set<String> serviceAlertDescriptions = new HashSet<String>();
    for (RouteBean routeBean : stopBean.getRoutes()) {
        if (routeFilter != null && !routeFilter.isEmpty() && !routeFilter.contains(routeBean)) {
            filteredRoutes.add(routeBean);
            continue;
        }
        StopsForRouteBean stopsForRoute = _transitDataService.getStopsForRoute(routeBean.getId());
        List<RouteDirection> directions = new ArrayList<RouteDirection>();
        List<StopGroupingBean> stopGroupings = stopsForRoute.getStopGroupings();
        for (StopGroupingBean stopGroupingBean : stopGroupings) {
            for (StopGroupBean stopGroupBean : stopGroupingBean.getStopGroups()) {
                NameBean name = stopGroupBean.getName();
                String type = name.getType();
                if (!type.equals("destination"))
                    continue;
                // filter out route directions that don't stop at this stop
                if (!stopGroupBean.getStopIds().contains(stopBean.getId()))
                    continue;
                // arrivals in this direction
                Map<String, List<StopOnRoute>> arrivalsForRouteAndDirection = getDisplayStringsByHeadsignForStopAndRouteAndDirection(stopBean, routeBean, stopGroupBean);
                // service alerts for this route + direction
                List<ServiceAlertBean> serviceAlertBeans = _realtimeService.getServiceAlertsForRouteAndDirection(routeBean.getId(), stopGroupBean.getId());
                populateServiceAlerts(serviceAlertDescriptions, serviceAlertBeans);
                // service in this direction
                Boolean hasUpcomingScheduledService = _transitDataService.stopHasUpcomingScheduledService((routeBean.getAgency() != null ? routeBean.getAgency().getId() : null), SystemTime.currentTimeMillis(), stopBean.getId(), routeBean.getId(), stopGroupBean.getId());
                // if there are buses on route, always have "scheduled service"
                if (!arrivalsForRouteAndDirection.isEmpty()) {
                    hasUpcomingScheduledService = true;
                }
                if (arrivalsForRouteAndDirection.isEmpty()) {
                    directions.add(new RouteDirection(stopGroupBean.getName().getName(), stopGroupBean, Collections.<StopOnRoute>emptyList(), hasUpcomingScheduledService, Collections.<String>emptyList()));
                } else {
                    for (Map.Entry<String, List<StopOnRoute>> entry : arrivalsForRouteAndDirection.entrySet()) {
                        directions.add(new RouteDirection(entry.getKey(), stopGroupBean, entry.getValue(), hasUpcomingScheduledService, Collections.<String>emptyList()));
                    }
                }
            }
        }
        // Now one RouteAtStop object exists for each direction for each route.
        for (RouteDirection direction : directions) {
            List<RouteDirection> directionList = Collections.<RouteDirection>singletonList(direction);
            RouteAtStop routeAtStop = new RouteAtStop(routeBean, directionList, serviceAlertDescriptions);
            if (!direction.getStops().isEmpty())
                routesWithArrivals.add(routeAtStop);
            else if (Boolean.FALSE.equals(direction.getHasUpcomingScheduledService()))
                routesWithNoScheduledService.add(routeAtStop);
            else
                routesWithNoVehiclesEnRoute.add(routeAtStop);
        }
    }
    return new StopResult(stopBean, routesWithArrivals, routesWithNoVehiclesEnRoute, routesWithNoScheduledService, filteredRoutes, serviceAlertDescriptions);
}
Also used : RouteDirection(org.onebusaway.enterprise.webapp.actions.m.model.RouteDirection) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) ArrayList(java.util.ArrayList) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) RouteAtStop(org.onebusaway.enterprise.webapp.actions.m.model.RouteAtStop) RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) ArrayList(java.util.ArrayList) List(java.util.List) NameBean(org.onebusaway.transit_data.model.NameBean) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean) HashMap(java.util.HashMap) Map(java.util.Map) StopOnRoute(org.onebusaway.enterprise.webapp.actions.m.model.StopOnRoute) StopResult(org.onebusaway.enterprise.webapp.actions.m.model.StopResult) HashSet(java.util.HashSet)

Example 14 with ServiceAlertBean

use of org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean in project onebusaway-application-modules by camsys.

the class AlertsAction method setServiceAlerts.

private void setServiceAlerts(AgencyWithCoverageBean agency, List<ServiceAlertRssBean> beans, String baseUrl) {
    ListBean<ServiceAlertBean> allServiceAlertsForAgencyId = _transitDataService.getAllServiceAlertsForAgencyId(agency.getAgency().getId());
    if (allServiceAlertsForAgencyId == null) {
        _log.info("no service alerts returned for agency " + agency.getAgency().getId());
        return;
    }
    long time = System.currentTimeMillis();
    for (ServiceAlertBean sab : allServiceAlertsForAgencyId.getList()) {
        if (!containsActiveAlert(sab, time)) {
            continue;
        }
        ServiceAlertRssBean bean = new ServiceAlertRssBean();
        bean.setId(sab.getId());
        bean.setReason(sab.getReason());
        if (sab.getSeverity() != null) {
            bean.setSeverity(sab.getSeverity().getTpegCodes()[0]);
        }
        bean.setSummary(ServiceAlertRssBean.getLocalString(sab.getSummaries()));
        bean.setDescription(ServiceAlertRssBean.getLocalString(sab.getDescriptions()));
        bean.setPublicationWindows(toTimeRange(sab.getPublicationWindows()));
        bean.setAffectsClauses(toAffectClause(sab.getAllAffects()));
        beans.add(bean);
    }
}
Also used : ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean) ServiceAlertRssBean(org.onebusaway.rss.model.ServiceAlertRssBean)

Example 15 with ServiceAlertBean

use of org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean in project onebusaway-application-modules by camsys.

the class StatusProviderImpl method getAgencyServiceAlertStatus.

@Override
public StatusGroup getAgencyServiceAlertStatus() {
    StatusGroup group = new StatusGroup();
    group.setTitle("Agency Advisories");
    group.setScope("Schedule and real-time availability at the agency level");
    group.setSource("Sound Transit administrators -- manual entry");
    List<AgencyWithCoverageBean> agencies = _transitDataService.getAgenciesWithCoverage();
    for (AgencyWithCoverageBean agency : agencies) {
        String agencyId = agency.getAgency().getId();
        String agencyName = agency.getAgency().getName();
        // Use query to limit to agency and no other parameters
        SituationQueryBean query = new SituationQueryBean();
        AffectsBean ab = new AffectsBean();
        ab.setAgencyId(agencyId);
        query.setAffects(Collections.singletonList(ab));
        ListBean<ServiceAlertBean> alerts = _transitDataService.getServiceAlerts(query);
        List<ServiceAlertBean> beans = filterByTime(alerts.getList(), System.currentTimeMillis());
        for (ServiceAlertBean bean : beans) {
            StatusItem item = new StatusItem();
            item.setDescription(bean.getDescriptions().get(0).getValue());
            item.setTitle(agencyName + ": " + bean.getSummaries().get(0).getValue());
            item.setStatus(StatusItem.Status.ALERT);
            group.addItem(item);
        }
    }
    return group;
}
Also used : AffectsBean(org.onebusaway.transit_data.model.service_alerts.SituationQueryBean.AffectsBean) StatusItem(org.onebusaway.enterprise.webapp.actions.status.model.StatusItem) StatusGroup(org.onebusaway.enterprise.webapp.actions.status.model.StatusGroup) SituationQueryBean(org.onebusaway.transit_data.model.service_alerts.SituationQueryBean) AgencyWithCoverageBean(org.onebusaway.transit_data.model.AgencyWithCoverageBean) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)

Aggregations

ServiceAlertBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)54 ArrayList (java.util.ArrayList)22 SituationQueryBean (org.onebusaway.transit_data.model.service_alerts.SituationQueryBean)11 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)8 StopBean (org.onebusaway.transit_data.model.StopBean)8 SituationAffectsBean (org.onebusaway.transit_data.model.service_alerts.SituationAffectsBean)8 HashMap (java.util.HashMap)7 List (java.util.List)5 RouteBean (org.onebusaway.transit_data.model.RouteBean)5 TripBean (org.onebusaway.transit_data.model.trips.TripBean)5 Test (org.junit.Test)4 NaturalLanguageStringBean (org.onebusaway.transit_data.model.service_alerts.NaturalLanguageStringBean)4 TripStatusBean (org.onebusaway.transit_data.model.trips.TripStatusBean)4 PtSituationElementStructure (uk.org.siri.siri.PtSituationElementStructure)4 PtSituationElementStructure (uk.org.siri.siri_2.PtSituationElementStructure)4 HashSet (java.util.HashSet)3 ArrivalAndDepartureBean (org.onebusaway.transit_data.model.ArrivalAndDepartureBean)3 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)3 BlockTripBean (org.onebusaway.transit_data.model.blocks.BlockTripBean)3 TimeRangeBean (org.onebusaway.transit_data.model.service_alerts.TimeRangeBean)3