Search in sources :

Example 6 with MonitoredStopVisitStructure

use of uk.org.siri.siri.MonitoredStopVisitStructure in project onebusaway-application-modules by camsys.

the class ServiceAlertsHelper method addSituationExchangeToSiriForStops.

public void addSituationExchangeToSiriForStops(ServiceDelivery serviceDelivery, List<MonitoredStopVisitStructure> visits, TransitDataService transitDataService, List<AgencyAndId> stopIds) {
    Map<String, PtSituationElementStructure> ptSituationElements = new HashMap<String, PtSituationElementStructure>();
    for (MonitoredStopVisitStructure visit : visits) {
        if (visit.getMonitoredVehicleJourney() != null)
            addSituationElement(transitDataService, ptSituationElements, visit.getMonitoredVehicleJourney().getSituationRef());
    }
    if (stopIds != null && stopIds.size() > 0) {
        for (AgencyAndId stopId : stopIds) {
            String stopIdString = stopId.toString();
            // First get service alerts for the stop
            SituationQueryBean query = new SituationQueryBean();
            List<String> stopIdStrings = new ArrayList<String>();
            stopIdStrings.add(stopIdString);
            SituationQueryBean.AffectsBean affects = new SituationQueryBean.AffectsBean();
            query.getAffects().add(affects);
            affects.setStopId(stopIdString);
            addFromQuery(transitDataService, ptSituationElements, query);
            // Now also add service alerts for (route+direction)s of the stop
            query = new SituationQueryBean();
            StopBean stopBean = transitDataService.getStop(stopIdString);
            List<RouteBean> routes = stopBean.getRoutes();
            for (RouteBean route : routes) {
                StopsForRouteBean stopsForRoute = transitDataService.getStopsForRoute(route.getId());
                List<StopGroupingBean> stopGroupings = stopsForRoute.getStopGroupings();
                for (StopGroupingBean stopGrouping : stopGroupings) {
                    if (!stopGrouping.getType().equalsIgnoreCase("direction"))
                        continue;
                    for (StopGroupBean stopGroup : stopGrouping.getStopGroups()) {
                        handleStopGroupBean(stopIdString, query, route, stopGroup);
                    }
                }
            }
            addFromQuery(transitDataService, ptSituationElements, query);
        }
    }
    addPtSituationElementsToServiceDelivery(serviceDelivery, ptSituationElements);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) ArrayList(java.util.ArrayList) PtSituationElementStructure(uk.org.siri.siri.PtSituationElementStructure) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) MonitoredStopVisitStructure(uk.org.siri.siri.MonitoredStopVisitStructure) SituationAffectsBean(org.onebusaway.transit_data.model.service_alerts.SituationAffectsBean) RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) SituationQueryBean(org.onebusaway.transit_data.model.service_alerts.SituationQueryBean) StopBean(org.onebusaway.transit_data.model.StopBean)

Aggregations

ArrayList (java.util.ArrayList)6 MonitoredStopVisitStructure (uk.org.siri.siri.MonitoredStopVisitStructure)6 RouteBean (org.onebusaway.transit_data.model.RouteBean)4 HashMap (java.util.HashMap)3 StopBean (org.onebusaway.transit_data.model.StopBean)3 StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)3 StopGroupingBean (org.onebusaway.transit_data.model.StopGroupingBean)3 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)3 MonitoredVehicleJourneyStructure (uk.org.siri.siri.MonitoredVehicleJourneyStructure)3 Date (java.util.Date)2 List (java.util.List)2 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)2 NameBean (org.onebusaway.transit_data.model.NameBean)2 MonitoredCallStructure (uk.org.siri.siri.MonitoredCallStructure)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Matchers.anyString (org.mockito.Matchers.anyString)1 RouteAtStop (org.onebusaway.enterprise.webapp.actions.api.model.RouteAtStop)1 RouteDirection (org.onebusaway.enterprise.webapp.actions.api.model.RouteDirection)1 StopResult (org.onebusaway.enterprise.webapp.actions.api.model.StopResult)1