Search in sources :

Example 6 with AgencyBean

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

the class RouteBeanServiceImplTest method testGetRouteForId.

@Test
public void testGetRouteForId() {
    AgencyAndId routeId = new AgencyAndId("1", "route");
    RouteCollectionNarrative.Builder routeBuilder = RouteCollectionNarrative.builder();
    routeBuilder.setColor("blue");
    routeBuilder.setDescription("route desc");
    routeBuilder.setLongName("route long name");
    routeBuilder.setShortName("route short name");
    routeBuilder.setTextColor("red");
    routeBuilder.setType(3);
    routeBuilder.setUrl("http://wwww.route.com");
    RouteCollectionNarrative route = routeBuilder.create();
    AgencyBean agency = new AgencyBean();
    Mockito.when(_agencyBeanService.getAgencyForId("1")).thenReturn(agency);
    Mockito.when(_narrativeService.getRouteCollectionForId(routeId)).thenReturn(route);
    RouteBean bean = _service.getRouteForId(routeId);
    assertEquals(route.getColor(), bean.getColor());
    assertEquals(route.getDescription(), bean.getDescription());
    assertEquals(AgencyAndIdLibrary.convertToString(routeId), bean.getId());
    assertEquals(route.getLongName(), bean.getLongName());
    assertEquals(route.getShortName(), bean.getShortName());
    assertEquals(route.getTextColor(), bean.getTextColor());
    assertEquals(route.getType(), bean.getType());
    assertEquals(route.getUrl(), bean.getUrl());
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) RouteCollectionNarrative(org.onebusaway.transit_data_federation.model.narrative.RouteCollectionNarrative) AgencyBean(org.onebusaway.transit_data.model.AgencyBean) Test(org.junit.Test)

Example 7 with AgencyBean

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

the class ArrivalsAndDeparturesTemplate method buildPredictedArrivalsTemplate.

protected void buildPredictedArrivalsTemplate(List<ArrivalAndDepartureBean> arrivals) {
    if (arrivals.isEmpty()) {
        addMessage(Messages.ARRIVAL_INFO_NO_SCHEDULED_ARRIVALS);
    }
    Collections.sort(arrivals, new ArrivalAndDepartureComparator());
    long now = SystemTime.currentTimeMillis();
    for (ArrivalAndDepartureBean adb : arrivals) {
        TripBean trip = adb.getTrip();
        RouteBean route = trip.getRoute();
        addMessage(Messages.ROUTE);
        String routeNumber = RoutePresenter.getNameForRoute(route);
        addText(_routeNumberPronunciation.modify(routeNumber));
        String headsign = trip.getTripHeadsign();
        if (headsign != null) {
            addMessage(Messages.TO);
            String destination = _destinationPronunciation.modify(headsign);
            addText(destination);
        }
        if (TransitDataConstants.STATUS_LEGACY_CANCELLED.equalsIgnoreCase(adb.getStatus())) {
            addText("is currently not in service");
            continue;
        }
        long t = adb.computeBestDepartureTime();
        boolean isPrediction = adb.hasPredictedDepartureTime();
        int min = (int) ((t - now) / 1000 / 60);
        if (min < 0) {
            min = -min;
            if (min > 60) {
                String message = isPrediction ? Messages.PREDICTED_AT_PAST_DATE : Messages.SCHEDULED_AT_PAST_DATE;
                addMessage(message, new Date(t));
            } else {
                String message = isPrediction ? Messages.PREDICTED_IN_PAST : Messages.SCHEDULED_IN_PAST;
                addMessage(message, min);
            }
        } else {
            if (min > 60) {
                String message = isPrediction ? Messages.PREDICTED_AT_FUTURE_DATE : Messages.SCHEDULED_AT_FUTURE_DATE;
                addMessage(message, new Date(t));
            } else {
                String message = isPrediction ? Messages.PREDICTED_IN_FUTURE : Messages.SCHEDULED_IN_FUTURE;
                addMessage(message, min);
            }
        }
        if (TransitDataConstants.STATUS_REROUTE.equals(adb.getStatus()))
            addText("but is currently on adverse weather re-route.");
    }
    addMessage(Messages.ARRIVAL_INFO_DISCLAIMER);
    List<AgencyBean> agencies = AgencyPresenter.getAgenciesForArrivalAndDepartures(arrivals);
    if (!agencies.isEmpty()) {
        addMessage(Messages.ARRIVAL_INFO_DATA_PROVIDED_BY);
        for (int i = 0; i < agencies.size(); i++) {
            AgencyBean agency = agencies.get(i);
            if (i == agencies.size() - 1 && agencies.size() > 1)
                addText(Messages.AND);
            addText(agency.getName());
            addText(",");
        }
    }
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) ArrivalAndDepartureComparator(org.onebusaway.presentation.impl.ArrivalAndDepartureComparator) TripBean(org.onebusaway.transit_data.model.trips.TripBean) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean) Date(java.util.Date) AgencyBean(org.onebusaway.transit_data.model.AgencyBean)

Example 8 with AgencyBean

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

the class PreCacheTask method run.

@Override
public void run() {
    // Clear all existing cache elements
    for (String cacheName : _cacheManager.getCacheNames()) {
        Cache cache = _cacheManager.getCache(cacheName);
        cache.removeAll();
    }
    try {
        List<AgencyWithCoverageBean> agenciesWithCoverage = _service.getAgenciesWithCoverage();
        for (AgencyWithCoverageBean agencyWithCoverage : agenciesWithCoverage) {
            AgencyBean agency = agencyWithCoverage.getAgency();
            System.out.println("agency=" + agency.getId());
            ListBean<String> stopIds = _service.getStopIdsForAgencyId(agency.getId());
            for (String stopId : stopIds.getList()) {
                System.out.println("  stop=" + stopId);
                _service.getStop(stopId);
            }
            ListBean<String> routeIds = _service.getRouteIdsForAgencyId(agency.getId());
            for (String routeId : routeIds.getList()) {
                System.out.println("  route=" + routeId);
                _service.getStopsForRoute(routeId);
            }
        }
        Set<AgencyAndId> shapeIds = new HashSet<AgencyAndId>();
        for (TripEntry trip : _transitGraphDao.getAllTrips()) {
            AgencyAndId shapeId = trip.getShapeId();
            if (shapeId != null && shapeId.hasValues())
                shapeIds.add(shapeId);
        }
        for (AgencyAndId shapeId : shapeIds) {
            System.out.println("shape=" + shapeId);
            _service.getShapeForId(AgencyAndIdLibrary.convertToString(shapeId));
        }
    } catch (ServiceException ex) {
        _log.error("service exception", ex);
    }
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ServiceException(org.onebusaway.exceptions.ServiceException) AgencyWithCoverageBean(org.onebusaway.transit_data.model.AgencyWithCoverageBean) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) Cache(net.sf.ehcache.Cache) AgencyBean(org.onebusaway.transit_data.model.AgencyBean) HashSet(java.util.HashSet)

Example 9 with AgencyBean

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

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

the class StopScheduleServiceImpl method getAllServiceIdsForStop.

private Set<ServiceIdActivation> getAllServiceIdsForStop(StopEntry stop, boolean includePrivateService) {
    Set<ServiceIdActivation> allServiceIds = new HashSet<ServiceIdActivation>();
    List<BlockStopTimeIndex> indices = _blockIndexService.getStopTimeIndicesForStop(stop);
    for (BlockStopTimeIndex index : indices) allServiceIds.add(index.getServiceIds());
    List<FrequencyBlockStopTimeIndex> frequencyIndices = _blockIndexService.getFrequencyStopTimeIndicesForStop(stop);
    for (FrequencyBlockStopTimeIndex index : frequencyIndices) allServiceIds.add(index.getServiceIds());
    for (Iterator<ServiceIdActivation> it = allServiceIds.iterator(); it.hasNext(); ) {
        ServiceIdActivation activation = it.next();
        LocalizedServiceId lsid = activation.getActiveServiceIds().get(0);
        String agencyId = lsid.getId().getAgencyId();
        AgencyBean bean = _agencyBeanService.getAgencyForId(agencyId);
        if (bean.isPrivateService() && !includePrivateService)
            it.remove();
    }
    return allServiceIds;
}
Also used : FrequencyBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex) BlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex) LocalizedServiceId(org.onebusaway.gtfs.model.calendar.LocalizedServiceId) FrequencyBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex) ServiceIdActivation(org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation) HashSet(java.util.HashSet) AgencyBean(org.onebusaway.transit_data.model.AgencyBean)

Aggregations

AgencyBean (org.onebusaway.transit_data.model.AgencyBean)12 RouteBean (org.onebusaway.transit_data.model.RouteBean)6 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)5 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)5 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 ArrivalAndDepartureBean (org.onebusaway.transit_data.model.ArrivalAndDepartureBean)4 HashMap (java.util.HashMap)3 StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)3 StopGroupingBean (org.onebusaway.transit_data.model.StopGroupingBean)3 Date (java.util.Date)2 Before (org.junit.Before)2 Matchers.anyString (org.mockito.Matchers.anyString)2 ArrivalAndDepartureComparator (org.onebusaway.presentation.impl.ArrivalAndDepartureComparator)2 AgencyWithCoverageBean (org.onebusaway.transit_data.model.AgencyWithCoverageBean)2 NameBean (org.onebusaway.transit_data.model.NameBean)2 Builder (org.onebusaway.transit_data.model.RouteBean.Builder)2 StopBean (org.onebusaway.transit_data.model.StopBean)2 TripBean (org.onebusaway.transit_data.model.trips.TripBean)2 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)2