Search in sources :

Example 21 with StopGroupBean

use of org.onebusaway.transit_data.model.StopGroupBean 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;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) StopRouteDirection(org.onebusaway.api.actions.siri.model.StopRouteDirection) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) RouteForDirection(org.onebusaway.api.actions.siri.model.RouteForDirection) NameBean(org.onebusaway.transit_data.model.NameBean)

Example 22 with StopGroupBean

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

the class ServiceAlertsHelperV2 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 23 with StopGroupBean

use of org.onebusaway.transit_data.model.StopGroupBean 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);
}
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_2.PtSituationElementStructure) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) MonitoredStopVisitStructure(uk.org.siri.siri_2.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 24 with StopGroupBean

use of org.onebusaway.transit_data.model.StopGroupBean 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;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) ArrayList(java.util.ArrayList) ScheduleStop(org.onebusaway.nextbus.model.nextbus.ScheduleStop) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) StopsWithArrivalsAndDeparturesBean(org.onebusaway.transit_data.model.StopsWithArrivalsAndDeparturesBean) ArrivalsAndDeparturesQueryBean(org.onebusaway.transit_data.model.ArrivalsAndDeparturesQueryBean) ScheduleTableRow(org.onebusaway.nextbus.model.nextbus.ScheduleTableRow) DisplayStop(org.onebusaway.nextbus.model.nextbus.DisplayStop) Body(org.onebusaway.nextbus.model.nextbus.Body) AgencyBean(org.onebusaway.transit_data.model.AgencyBean) HashSet(java.util.HashSet) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) ScheduleRoute(org.onebusaway.nextbus.model.nextbus.ScheduleRoute)

Example 25 with StopGroupBean

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

the class RouteBeanServiceImpl method getStopsForRouteCollectionAndNarrative.

private StopsForRouteBean getStopsForRouteCollectionAndNarrative(RouteCollectionEntry routeCollection, RouteCollectionNarrative narrative) {
    StopsForRouteBean result = new StopsForRouteBean();
    AgencyAndId routeCollectionId = routeCollection.getId();
    result.setRoute(getRouteBeanForRouteCollection(routeCollectionId, narrative));
    result.setStops(getStopBeansForRoute(routeCollectionId));
    result.setPolylines(getEncodedPolylinesForRoute(routeCollection));
    StopGroupingBean directionGrouping = new StopGroupingBean();
    directionGrouping.setType(TransitDataConstants.STOP_GROUPING_TYPE_DIRECTION);
    List<StopGroupBean> directionGroups = new ArrayList<StopGroupBean>();
    directionGrouping.setStopGroups(directionGroups);
    directionGrouping.setOrdered(true);
    result.addGrouping(directionGrouping);
    List<BlockTripIndex> blockIndices = _blockIndexService.getBlockTripIndicesForRouteCollectionId(routeCollectionId);
    List<FrequencyBlockTripIndex> frequencyBlockIndices = _blockIndexService.getFrequencyBlockTripIndicesForRouteCollectionId(routeCollectionId);
    List<BlockTripEntry> blockTrips = new ArrayList<BlockTripEntry>();
    getBlockTripsForIndicesMatchingRouteCollection(blockIndices, routeCollectionId, blockTrips);
    getBlockTripsForIndicesMatchingRouteCollection(frequencyBlockIndices, routeCollectionId, blockTrips);
    List<StopSequence> sequences = _stopSequencesService.getStopSequencesForTrips(blockTrips);
    List<StopSequenceCollection> blocks = _stopSequenceBlocksService.getStopSequencesAsCollections(sequences);
    for (StopSequenceCollection block : blocks) {
        NameBean name = new NameBean(NameBeanTypes.DESTINATION, block.getDescription());
        List<StopEntry> stops = getStopsInOrder(block);
        List<String> groupStopIds = new ArrayList<String>();
        for (StopEntry stop : stops) groupStopIds.add(ApplicationBeanLibrary.getId(stop.getId()));
        Set<AgencyAndId> shapeIds = getShapeIdsForStopSequenceBlock(block);
        List<EncodedPolylineBean> polylines = _shapeBeanService.getMergedPolylinesForShapeIds(shapeIds);
        StopGroupBean group = new StopGroupBean();
        group.setId(block.getPublicId());
        group.setName(name);
        group.setStopIds(groupStopIds);
        group.setPolylines(polylines);
        directionGroups.add(group);
    }
    sortResult(result);
    return result;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) ArrayList(java.util.ArrayList) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) StopSequence(org.onebusaway.transit_data_federation.model.StopSequence) FrequencyBlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) NameBean(org.onebusaway.transit_data.model.NameBean) EncodedPolylineBean(org.onebusaway.geospatial.model.EncodedPolylineBean) BlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.BlockTripIndex) FrequencyBlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex) AbstractBlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.AbstractBlockTripIndex) StopSequenceCollection(org.onebusaway.transit_data_federation.model.StopSequenceCollection)

Aggregations

StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)25 StopGroupingBean (org.onebusaway.transit_data.model.StopGroupingBean)22 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)21 ArrayList (java.util.ArrayList)18 StopBean (org.onebusaway.transit_data.model.StopBean)15 NameBean (org.onebusaway.transit_data.model.NameBean)14 RouteBean (org.onebusaway.transit_data.model.RouteBean)12 HashMap (java.util.HashMap)9 EncodedPolylineBean (org.onebusaway.geospatial.model.EncodedPolylineBean)7 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)7 HashSet (java.util.HashSet)5 List (java.util.List)4 Matchers.anyString (org.mockito.Matchers.anyString)3 RouteDirection (org.onebusaway.enterprise.webapp.actions.api.model.RouteDirection)3 AgencyBean (org.onebusaway.transit_data.model.AgencyBean)3 SituationAffectsBean (org.onebusaway.transit_data.model.service_alerts.SituationAffectsBean)3 SituationQueryBean (org.onebusaway.transit_data.model.service_alerts.SituationQueryBean)3 Map (java.util.Map)2 Before (org.junit.Before)2 StopRouteDirection (org.onebusaway.api.actions.siri.model.StopRouteDirection)2