Search in sources :

Example 6 with SituationQueryBean

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

the class ServiceAlertsHelper method handleStopGroupBean.

private void handleStopGroupBean(String stopIdString, SituationQueryBean query, RouteBean route, StopGroupBean stopGroup) {
    List<StopGroupBean> subGroups = stopGroup.getSubGroups();
    if (subGroups != null && !subGroups.isEmpty()) {
        for (StopGroupBean stopSubGroup : subGroups) {
            handleStopGroupBean(stopIdString, query, route, stopSubGroup);
        }
    }
    String direction = stopGroup.getId();
    for (String groupStopId : stopGroup.getStopIds()) {
        if (groupStopId.equals(stopIdString)) {
            SituationQueryBean.AffectsBean affects = new SituationQueryBean.AffectsBean();
            query.getAffects().add(affects);
            affects.setRouteId(route.getId());
            affects.setDirectionId(direction);
        }
    }
}
Also used : SituationAffectsBean(org.onebusaway.transit_data.model.service_alerts.SituationAffectsBean) SituationQueryBean(org.onebusaway.transit_data.model.service_alerts.SituationQueryBean) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean)

Example 7 with SituationQueryBean

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

the class RealtimeServiceImpl method getServiceAlertsForRouteAndDirection.

@Override
public List<ServiceAlertBean> getServiceAlertsForRouteAndDirection(String routeId, String directionId) {
    SituationQueryBean query = new SituationQueryBean();
    SituationQueryBean.AffectsBean affects = new SituationQueryBean.AffectsBean();
    query.getAffects().add(affects);
    affects.setRouteId(routeId);
    if (directionId != null) {
        affects.setDirectionId(directionId);
    } else {
        /*
       * TODO
       * The route index is not currently being populated correctly; query by route and direction,
       * and supply both directions if not present
       */
        SituationQueryBean.AffectsBean affects1 = new SituationQueryBean.AffectsBean();
        query.getAffects().add(affects1);
        affects1.setRouteId(routeId);
        affects1.setDirectionId("0");
        SituationQueryBean.AffectsBean affects2 = new SituationQueryBean.AffectsBean();
        query.getAffects().add(affects2);
        affects2.setRouteId(routeId);
        affects2.setDirectionId("1");
    }
    ListBean<ServiceAlertBean> serviceAlerts = _transitDataService.getServiceAlerts(query);
    return serviceAlerts.getList();
}
Also used : SituationQueryBean(org.onebusaway.transit_data.model.service_alerts.SituationQueryBean) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)

Example 8 with SituationQueryBean

use of org.onebusaway.transit_data.model.service_alerts.SituationQueryBean 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)

Example 9 with SituationQueryBean

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

the class RealtimeServiceImpl method getServiceAlertsGlobal.

@Override
public List<ServiceAlertBean> getServiceAlertsGlobal() {
    SituationQueryBean query = new SituationQueryBean();
    SituationQueryBean.AffectsBean affects = new SituationQueryBean.AffectsBean();
    affects.setAgencyId("__ALL_OPERATORS__");
    query.getAffects().add(affects);
    ListBean<ServiceAlertBean> serviceAlerts = _transitDataService.getServiceAlerts(query);
    return serviceAlerts.getList();
}
Also used : SituationQueryBean(org.onebusaway.transit_data.model.service_alerts.SituationQueryBean) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)

Example 10 with SituationQueryBean

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

the class ServiceAlertsServiceImpl method getServiceAlerts.

@Override
public List<ServiceAlertRecord> getServiceAlerts(SituationQueryBean query) {
    Set<AgencyAndId> serviceAlertIds = new HashSet<AgencyAndId>();
    if (_persister.cachedNeedsSync())
        this.loadServiceAlerts();
    for (SituationQueryBean.AffectsBean affects : query.getAffects()) {
        AgencyAndId routeId = AgencyAndId.convertFromString(affects.getRouteId());
        AgencyAndId tripId = AgencyAndId.convertFromString(affects.getTripId());
        AgencyAndId stopId = AgencyAndId.convertFromString(affects.getStopId());
        AffectsType type = getAffectsType(affects.getAgencyId(), affects.getRouteId(), affects.getDirectionId(), affects.getTripId(), affects.getStopId());
        switch(type) {
            case AGENCY:
                {
                    /**
                     * Note we are treating the query's agency ID as that of what the
                     * service alert affects, not the alert's federated agency ID.
                     */
                    getServiceAlertIdsForKey(_cache.getServiceAlertIdsByAgencyId(), affects.getAgencyId(), serviceAlertIds);
                    break;
                }
            case ROUTE:
                {
                    getServiceAlertIdsForKey(_cache.getServiceAlertIdsByRouteId(), routeId, serviceAlertIds);
                    break;
                }
            case TRIP:
                {
                    getServiceAlertIdsForKey(_cache.getServiceAlertIdsByTripId(), tripId, serviceAlertIds);
                    break;
                }
            case STOP:
                {
                    getServiceAlertIdsForKey(_cache.getServiceAlertIdsByStopId(), stopId, serviceAlertIds);
                    break;
                }
            case ROUTE_DIRECTION:
                {
                    RouteAndDirectionRef routeAndDirectionRef = new RouteAndDirectionRef(routeId, affects.getDirectionId());
                    getServiceAlertIdsForKey(_cache.getServiceAlertIdsByRouteAndDirectionId(), routeAndDirectionRef, serviceAlertIds);
                    break;
                }
            case ROUTE_DIRECTION_STOP:
                {
                    RouteDirectionAndStopCallRef ref = new RouteDirectionAndStopCallRef(routeId, affects.getDirectionId(), stopId);
                    getServiceAlertIdsForKey(_cache.getServiceAlertIdsByRouteDirectionAndStopCall(), ref, serviceAlertIds);
                    break;
                }
            case ROUTE_STOP:
                {
                    RouteAndStopCallRef routeAndStopRef = new RouteAndStopCallRef(routeId, stopId);
                    getServiceAlertIdsForKey(_cache.getServiceAlertIdsByRouteAndStop(), routeAndStopRef, serviceAlertIds);
                    break;
                }
            case TRIP_STOP:
                {
                    TripAndStopCallRef ref = new TripAndStopCallRef(tripId, stopId);
                    getServiceAlertIdsForKey(_cache.getServiceAlertIdsByTripAndStopId(), ref, serviceAlertIds);
                    break;
                }
            default:
                {
                    throw new RuntimeException("Unhandled type " + type);
                }
        }
    }
    List<ServiceAlertRecord> alerts = getServiceAlertIdsAsObjects(serviceAlertIds);
    return alerts;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) SituationQueryBean(org.onebusaway.transit_data.model.service_alerts.SituationQueryBean)

Aggregations

SituationQueryBean (org.onebusaway.transit_data.model.service_alerts.SituationQueryBean)16 ServiceAlertBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)10 SituationAffectsBean (org.onebusaway.transit_data.model.service_alerts.SituationAffectsBean)6 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)4 RouteBean (org.onebusaway.transit_data.model.RouteBean)2 StopBean (org.onebusaway.transit_data.model.StopBean)2 StopGroupingBean (org.onebusaway.transit_data.model.StopGroupingBean)2 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)2 PtSituationElementStructure (uk.org.siri.siri.PtSituationElementStructure)2 PtSituationElementStructure (uk.org.siri.siri_2.PtSituationElementStructure)2 StatusGroup (org.onebusaway.enterprise.webapp.actions.status.model.StatusGroup)1 StatusItem (org.onebusaway.enterprise.webapp.actions.status.model.StatusItem)1 AgencyWithCoverageBean (org.onebusaway.transit_data.model.AgencyWithCoverageBean)1 AffectsBean (org.onebusaway.transit_data.model.service_alerts.SituationQueryBean.AffectsBean)1 MonitoredStopVisitStructure (uk.org.siri.siri.MonitoredStopVisitStructure)1 VehicleActivityStructure (uk.org.siri.siri.VehicleActivityStructure)1 MonitoredStopVisitStructure (uk.org.siri.siri_2.MonitoredStopVisitStructure)1