Search in sources :

Example 51 with RouteBean

use of org.onebusaway.transit_data.model.RouteBean 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 52 with RouteBean

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

the class BeanFactoryV2 method getStop.

public StopV2Bean getStop(StopBean stop) {
    StopV2Bean bean = new StopV2Bean();
    bean.setCode(stop.getCode());
    bean.setDirection(stop.getDirection());
    bean.setId(stop.getId());
    bean.setLat(stop.getLat());
    bean.setLon(stop.getLon());
    bean.setLocationType(stop.getLocationType());
    bean.setName(stop.getName());
    bean.setWheelchairBoarding(stop.getWheelchairBoarding());
    List<String> routeIds = new ArrayList<String>();
    for (RouteBean route : stop.getRoutes()) {
        routeIds.add(route.getId());
        addToReferences(route);
    }
    bean.setRouteIds(routeIds);
    return bean;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) ArrayList(java.util.ArrayList)

Example 53 with RouteBean

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

the class VehiclePositionsForAgencyAction method fillFeedMessage.

@Override
protected void fillFeedMessage(FeedMessage.Builder feed, String agencyId, long timestamp) {
    ListBean<VehicleStatusBean> vehicles = _service.getAllVehiclesForAgency(agencyId, timestamp);
    for (VehicleStatusBean vehicle : vehicles.getList()) {
        FeedEntity.Builder entity = feed.addEntityBuilder();
        entity.setId(Integer.toString(feed.getEntityCount()));
        VehiclePosition.Builder vehiclePosition = entity.getVehicleBuilder();
        TripStatusBean tripStatus = vehicle.getTripStatus();
        if (tripStatus != null) {
            TripBean activeTrip = tripStatus.getActiveTrip();
            RouteBean route = activeTrip.getRoute();
            TripDescriptor.Builder tripDesc = vehiclePosition.getTripBuilder();
            tripDesc.setTripId(normalizeId(activeTrip.getId()));
            tripDesc.setRouteId(normalizeId(route.getId()));
        }
        VehicleDescriptor.Builder vehicleDesc = vehiclePosition.getVehicleBuilder();
        vehicleDesc.setId(normalizeId(vehicle.getVehicleId()));
        CoordinatePoint location = vehicle.getLocation();
        if (location != null) {
            Position.Builder position = vehiclePosition.getPositionBuilder();
            position.setLatitude((float) location.getLat());
            position.setLongitude((float) location.getLon());
        }
        vehiclePosition.setTimestamp(vehicle.getLastUpdateTime() / 1000);
    }
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) VehiclePosition(com.google.transit.realtime.GtfsRealtime.VehiclePosition) Position(com.google.transit.realtime.GtfsRealtime.Position) TripBean(org.onebusaway.transit_data.model.trips.TripBean) VehicleStatusBean(org.onebusaway.transit_data.model.VehicleStatusBean) RouteBean(org.onebusaway.transit_data.model.RouteBean) VehiclePosition(com.google.transit.realtime.GtfsRealtime.VehiclePosition) TripDescriptor(com.google.transit.realtime.GtfsRealtime.TripDescriptor) TripStatusBean(org.onebusaway.transit_data.model.trips.TripStatusBean) FeedEntity(com.google.transit.realtime.GtfsRealtime.FeedEntity) VehicleDescriptor(com.google.transit.realtime.GtfsRealtime.VehicleDescriptor)

Example 54 with RouteBean

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

the class SearchResultFactoryImplTest method createRouteBean.

private RouteBean createRouteBean() {
    Builder builder = RouteBean.builder();
    builder.setId(ROUTE_ID);
    RouteBean routeBean = builder.create();
    return routeBean;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) Builder(org.onebusaway.transit_data.model.RouteBean.Builder)

Example 55 with RouteBean

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

the class ArrivalsAndDeparturesAction method filterArrivalsAndDeparturesByRoute.

private void filterArrivalsAndDeparturesByRoute(String[] tokens) {
    // Filter by route
    Set<String> routes = new HashSet<String>();
    for (String token : tokens) {
        String[] routeNames = token.split(",");
        for (String routeName : routeNames) routes.add(routeName);
    }
    StopsWithArrivalsAndDeparturesBean result = _model.getResult();
    Iterator<ArrivalAndDepartureBean> it = result.getArrivalsAndDepartures().iterator();
    while (it.hasNext()) {
        ArrivalAndDepartureBean bean = it.next();
        TripBean trip = bean.getTrip();
        RouteBean route = trip.getRoute();
        String routeName = RoutePresenter.getNameForRoute(route);
        if (!routes.contains(routeName))
            it.remove();
    }
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsWithArrivalsAndDeparturesBean(org.onebusaway.transit_data.model.StopsWithArrivalsAndDeparturesBean) TripBean(org.onebusaway.transit_data.model.trips.TripBean) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean) HashSet(java.util.HashSet)

Aggregations

RouteBean (org.onebusaway.transit_data.model.RouteBean)63 ArrayList (java.util.ArrayList)35 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)24 StopBean (org.onebusaway.transit_data.model.StopBean)22 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)18 TripBean (org.onebusaway.transit_data.model.trips.TripBean)14 StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)12 StopGroupingBean (org.onebusaway.transit_data.model.StopGroupingBean)12 List (java.util.List)9 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)7 CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)7 NameBean (org.onebusaway.transit_data.model.NameBean)7 Date (java.util.Date)6 Test (org.junit.Test)6 AgencyBean (org.onebusaway.transit_data.model.AgencyBean)6 ArrivalAndDepartureBean (org.onebusaway.transit_data.model.ArrivalAndDepartureBean)6 IOException (java.io.IOException)5 Matchers.anyString (org.mockito.Matchers.anyString)5 SearchQueryBean (org.onebusaway.transit_data.model.SearchQueryBean)5