use of org.onebusaway.transit_data.model.StopsForRouteBean in project onebusaway-application-modules by camsys.
the class RealtimeServiceV2Impl method getStopRouteDirection.
private StopRouteDirection getStopRouteDirection(StopBean stop, List<StopsForRouteBean> stopsForRouteList, Map<Filters, String> filters) {
// Filter Values
String upcomingScheduledServiceFilter = filters.get(Filters.UPCOMING_SCHEDULED_SERVICE);
String directionIdFilter = filters.get(Filters.DIRECTION_REF);
StopRouteDirection stopRouteDirection = new StopRouteDirection(stop);
for (StopsForRouteBean stopsForRoute : stopsForRouteList) // Check to see which stop group the specified stop exists in (usually 2 stop groups)
for (StopGroupingBean stopGrouping : stopsForRoute.getStopGroupings()) {
for (StopGroupBean stopGroup : stopGrouping.getStopGroups()) {
NameBean name = stopGroup.getName();
String type = name.getType();
String directionId = stopGroup.getId();
RouteBean route = stopsForRoute.getRoute();
// Destination and DirectionId Filter
if (!type.equals("destination") || !SiriSupportV2.passFilter(directionId, directionIdFilter))
continue;
// filter out route directions that don't stop at this stop
if (!stopGroup.getStopIds().contains(stop.getId()))
continue;
// filter hasUpcomingScheduledService
Boolean hasUpcomingScheduledService = _transitDataService.stopHasUpcomingScheduledService((route.getAgency() != null ? route.getAgency().getId() : null), SystemTime.currentTimeMillis(), stop.getId(), stopsForRoute.getRoute().getId(), directionId);
String hasUpcomingScheduledServiceVal = String.valueOf(hasUpcomingScheduledService);
if (!hasUpcomingScheduledServiceVal.trim().equals("false")) {
hasUpcomingScheduledServiceVal = "true";
}
if (!SiriSupportV2.passFilter(hasUpcomingScheduledServiceVal, upcomingScheduledServiceFilter))
continue;
stopRouteDirection.addRouteDirection(new RouteForDirection(route.getId(), directionId, hasUpcomingScheduledService));
}
}
return stopRouteDirection;
}
use of org.onebusaway.transit_data.model.StopsForRouteBean in project onebusaway-application-modules by camsys.
the class ServiceAlertsHelperV2 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.StopsForRouteBean in project onebusaway-application-modules by camsys.
the class SearchResultFactoryImplTest method runGetRouteResult.
private RouteResult runGetRouteResult(List<ServiceAlertBean> serviceAlerts) {
StopsForRouteBean stopsForRouteBean = mock(StopsForRouteBean.class);
when(_transitDataService.getStopsForRoute(anyString())).thenReturn(stopsForRouteBean);
when(_realtimeService.getServiceAlertsForRoute(ROUTE_ID)).thenReturn(serviceAlerts);
SearchResultFactoryImpl srf = new SearchResultFactoryImpl(_transitDataService, _realtimeService, _configurationService);
RouteResult result = (RouteResult) srf.getRouteResult(createRouteBean());
return result;
}
use of org.onebusaway.transit_data.model.StopsForRouteBean in project onebusaway-application-modules by camsys.
the class ScheduleAction method getModel.
@Override
public Body<ScheduleRoute> getModel() {
Body<ScheduleRoute> body = new Body<ScheduleRoute>();
List<AgencyAndId> routeIds = new ArrayList<AgencyAndId>();
if (this.isValid(body, routeIds)) {
AgencyBean agency = _transitDataService.getAgency(agencyId);
List<HashMap<String, HashSet<ScheduleStop>>> blockStopsMapList = new ArrayList<HashMap<String, HashSet<ScheduleStop>>>();
blockStopsMapList.add(new HashMap<String, HashSet<ScheduleStop>>());
blockStopsMapList.add(new HashMap<String, HashSet<ScheduleStop>>());
blockStopsMapList.add(new HashMap<String, HashSet<ScheduleStop>>());
blockStopsMapList.add(new HashMap<String, HashSet<ScheduleStop>>());
// Get All the Stops for a specific route
for (AgencyAndId routeId : routeIds) {
String route = AgencyAndId.convertToString(routeId);
StopsForRouteBean stopsForRoute = _service.getStopsForRoute(route);
for (StopGroupingBean stopGroupingBean : stopsForRoute.getStopGroupings()) {
for (StopGroupBean stopGroupBean : stopGroupingBean.getStopGroups()) {
// Weekday Trips
for (Long weekdayTime : DateUtil.getWeekdayDateTimes(agency.getTimezone())) {
ArrivalsAndDeparturesQueryBean query = new ArrivalsAndDeparturesQueryBean();
query.setTime(weekdayTime);
query.setMinutesBefore(0);
query.setMinutesAfter(MINUTES_IN_DAY);
StopsWithArrivalsAndDeparturesBean stopsWithArrivals = _service.getStopsWithArrivalsAndDepartures(stopGroupBean.getStopIds(), query);
for (ArrivalAndDepartureBean arrivalsAndDeparture : stopsWithArrivals.getArrivalsAndDepartures()) {
// Filter Arrivals and Departures By Route
if (arrivalsAndDeparture.getTrip().getRoute().getId().equals(route)) {
ScheduleStop scheduleStop = new ScheduleStop();
scheduleStop.setTag(getIdNoAgency(arrivalsAndDeparture.getStop().getId()));
scheduleStop.setEpochTime(arrivalsAndDeparture.getScheduledArrivalTime());
scheduleStop.setStopName(arrivalsAndDeparture.getStop().getName());
if (arrivalsAndDeparture.getTrip().getDirectionId().equals("0")) {
addStopByBlockId(blockStopsMapList.get(0), arrivalsAndDeparture.getTrip().getBlockId(), scheduleStop);
} else if (arrivalsAndDeparture.getTrip().getDirectionId().equals("1")) {
addStopByBlockId(blockStopsMapList.get(1), arrivalsAndDeparture.getTrip().getBlockId(), scheduleStop);
}
}
}
}
// Weekend Trips
for (Long weekendTime : DateUtil.getWeekendDateTimes(agency.getTimezone())) {
ArrivalsAndDeparturesQueryBean query = new ArrivalsAndDeparturesQueryBean();
query.setTime(weekendTime);
query.setMinutesBefore(0);
query.setMinutesAfter(MINUTES_IN_DAY);
StopsWithArrivalsAndDeparturesBean stopsWithArrivals = _service.getStopsWithArrivalsAndDepartures(stopGroupBean.getStopIds(), query);
for (ArrivalAndDepartureBean arrivalsAndDeparture : stopsWithArrivals.getArrivalsAndDepartures()) {
// Filter Arrivals and Departures By Route
if (arrivalsAndDeparture.getTrip().getRoute().getId().equals(route)) {
ScheduleStop scheduleStop = new ScheduleStop();
scheduleStop.setTag(getIdNoAgency(arrivalsAndDeparture.getStop().getId()));
scheduleStop.setEpochTime(arrivalsAndDeparture.getScheduledArrivalTime());
scheduleStop.setStopName(arrivalsAndDeparture.getStop().getName());
if (arrivalsAndDeparture.getTrip().getDirectionId().equals("0")) {
addStopByBlockId(blockStopsMapList.get(2), arrivalsAndDeparture.getTrip().getBlockId(), scheduleStop);
} else if (arrivalsAndDeparture.getTrip().getDirectionId().equals("1")) {
addStopByBlockId(blockStopsMapList.get(3), arrivalsAndDeparture.getTrip().getBlockId(), scheduleStop);
}
}
}
}
}
}
// Routes
for (int n = 0; n < blockStopsMapList.size(); n++) {
HashMap<String, HashSet<ScheduleStop>> blockStopsMap = blockStopsMapList.get(n);
ScheduleRoute scheduleRoute = new ScheduleRoute();
scheduleRoute.setTitle(stopsForRoute.getRoute().getLongName());
scheduleRoute.setDirection(Integer.toString(n % 2));
scheduleRoute.setTag(getIdNoAgency(stopsForRoute.getRoute().getId()));
scheduleRoute.setServiceClass(n < 3 ? "wkd" : "wkend");
// Blocks
for (Entry<String, HashSet<ScheduleStop>> entry : blockStopsMap.entrySet()) {
int tripStopTimeCounter = 0;
String blockId = entry.getKey();
HashSet<ScheduleStop> blockStops = entry.getValue();
ScheduleTableRow scheduleTr = new ScheduleTableRow(getIdNoAgency(blockId));
// Stop Times
for (ScheduleStop stop : blockStops) {
if (tripStopTimeCounter == 0) {
DisplayStop displayStop = new DisplayStop();
displayStop.setTag(stop.getTag());
displayStop.setValue(stop.getStopName());
scheduleRoute.getStops().add(displayStop);
}
// scheduleStop.setValue(value);
scheduleTr.getStops().add(stop);
}
scheduleRoute.getScheduleTableRow().add(scheduleTr);
}
body.getResponse().add(scheduleRoute);
}
}
}
return body;
}
use of org.onebusaway.transit_data.model.StopsForRouteBean in project onebusaway-application-modules by camsys.
the class StopsForRouteAction method execute.
@Override
public String execute() throws Exception {
StopsForRouteBean stopsForRoute = _transitDataService.getStopsForRoute(_route.getId());
List<Integer> selectionIndices = Collections.emptyList();
StopSelectionBean selection = _stopSelectionService.getSelectedStops(stopsForRoute, selectionIndices);
List<NameBean> names = new ArrayList<NameBean>(selection.getNames());
_navigation = new NavigationBean();
_navigation.setRoute(_route);
_navigation.setStopsForRoute(stopsForRoute);
_navigation.setSelectionIndices(selectionIndices);
_navigation.setCurrentIndex(0);
_navigation.setSelection(selection);
_navigation.setNames(names);
if (selection.hasStop()) {
_stop = selection.getStop();
return "stopFound";
}
return SUCCESS;
}
Aggregations