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);
}
}
}
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();
}
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);
}
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();
}
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;
}
Aggregations