Search in sources :

Example 6 with RouteBean

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

the class TripBeanServiceImpl method getTripForId.

@Cacheable
public TripBean getTripForId(AgencyAndId tripId) {
    TripEntry tripEntry = _graph.getTripEntryForId(tripId);
    if (tripEntry == null)
        return null;
    AgencyAndId routeId = tripEntry.getRouteCollection().getId();
    RouteBean routeBean = _routeBeanService.getRouteForId(routeId);
    TripNarrative tripNarrative = _narrativeService.getTripForId(tripId);
    TripBean tripBean = new TripBean();
    tripBean.setId(ApplicationBeanLibrary.getId(tripId));
    tripBean.setTripShortName(tripNarrative.getTripShortName());
    tripBean.setTripHeadsign(tripNarrative.getTripHeadsign());
    tripBean.setRoute(routeBean);
    tripBean.setRouteShortName(tripNarrative.getRouteShortName());
    tripBean.setServiceId(ApplicationBeanLibrary.getId(tripEntry.getServiceId().getId()));
    AgencyAndId shapeId = tripEntry.getShapeId();
    if (shapeId != null && shapeId.hasValues())
        tripBean.setShapeId(ApplicationBeanLibrary.getId(shapeId));
    tripBean.setDirectionId(tripEntry.getDirectionId());
    tripBean.setTotalTripDistance(tripEntry.getTotalTripDistance());
    BlockEntry block = tripEntry.getBlock();
    tripBean.setBlockId(ApplicationBeanLibrary.getId(block.getId()));
    return tripBean;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) TripBean(org.onebusaway.transit_data.model.trips.TripBean) TripNarrative(org.onebusaway.transit_data_federation.model.narrative.TripNarrative) Cacheable(org.onebusaway.container.cache.Cacheable)

Example 7 with RouteBean

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

the class RoutesBeanServiceImpl method getRoutesForAgencyId.

@Cacheable
@Override
public ListBean<RouteBean> getRoutesForAgencyId(String agencyId) {
    AgencyEntry agency = _graphDao.getAgencyForId(agencyId);
    if (agency == null)
        throw new NoSuchAgencyServiceException(agencyId);
    List<RouteBean> routes = new ArrayList<RouteBean>();
    for (RouteCollectionEntry routeCollection : agency.getRouteCollections()) {
        AgencyAndId routeId = routeCollection.getId();
        RouteBean route = _routeBeanService.getRouteForId(routeId);
        routes.add(route);
    }
    return new ListBean<RouteBean>(routes, false);
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) NoSuchAgencyServiceException(org.onebusaway.exceptions.NoSuchAgencyServiceException) ArrayList(java.util.ArrayList) ListBean(org.onebusaway.transit_data.model.ListBean) RouteCollectionEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry) AgencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.AgencyEntry) Cacheable(org.onebusaway.container.cache.Cacheable)

Example 8 with RouteBean

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

the class RoutesBeanServiceImpl method getRoutesWithRouteNameQuery.

private RoutesBean getRoutesWithRouteNameQuery(SearchQueryBean query) throws ServiceException {
    SearchResult<AgencyAndId> result = searchForRoutes(query);
    List<RouteBean> routeBeans = new ArrayList<RouteBean>();
    CoordinateBounds bounds = query.getBounds();
    for (AgencyAndId id : result.getResults()) {
        STRtree tree = _stopTreesByRouteId.get(id);
        if (tree == null) {
            _log.warn("stop tree not found for routeId=" + id);
            continue;
        }
        Envelope env = new Envelope(bounds.getMinLon(), bounds.getMaxLon(), bounds.getMinLat(), bounds.getMaxLat());
        HasItemsVisitor v = new HasItemsVisitor();
        tree.query(env, v);
        if (v.hasItems()) {
            RouteBean routeBean = _routeBeanService.getRouteForId(id);
            routeBeans.add(routeBean);
        }
    }
    boolean limitExceeded = BeanServiceSupport.checkLimitExceeded(routeBeans, query.getMaxCount());
    return constructResult(routeBeans, limitExceeded);
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) STRtree(com.vividsolutions.jts.index.strtree.STRtree) Envelope(com.vividsolutions.jts.geom.Envelope) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Example 9 with RouteBean

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

the class StopBeanServiceImpl method fillRoutesForStopBean.

private void fillRoutesForStopBean(StopEntry stop, StopBean sb) {
    Set<AgencyAndId> routeCollectionIds = _routeService.getRouteCollectionIdsForStop(stop.getId());
    List<RouteBean> routeBeans = new ArrayList<RouteBean>(routeCollectionIds.size());
    for (AgencyAndId routeCollectionId : routeCollectionIds) {
        RouteBean bean = _routeBeanService.getRouteForId(routeCollectionId);
        routeBeans.add(bean);
    }
    Collections.sort(routeBeans, _routeBeanComparator);
    sb.setRoutes(routeBeans);
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList)

Example 10 with RouteBean

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

the class BundleSearchServiceImpl method init.

@PostConstruct
@Refreshable(dependsOn = { RefreshableResources.ROUTE_COLLECTIONS_DATA, RefreshableResources.TRANSIT_GRAPH })
public void init() {
    Runnable initThread = new Runnable() {

        @Override
        public void run() {
            while (!_initialized) {
                try {
                    Thread.sleep(1 * 1000);
                } catch (InterruptedException e) {
                    return;
                }
            }
            _log.info("building cache");
            Map<String, List<String>> tmpSuggestions = Collections.synchronizedMap(new HashMap<String, List<String>>());
            Map<String, List<CoordinateBounds>> agencies = _transitDataService.getAgencyIdsWithCoverageArea();
            for (String agency : agencies.keySet()) {
                ListBean<RouteBean> routes = _transitDataService.getRoutesForAgencyId(agency);
                for (RouteBean route : routes.getList()) {
                    String shortName = route.getShortName();
                    generateInputsForString(tmpSuggestions, shortName, "\\s+");
                }
                ListBean<String> stopIds = _transitDataService.getStopIdsForAgencyId(agency);
                for (String stopId : stopIds.getList()) {
                    if (_transitDataService.stopHasRevenueService(agency, stopId)) {
                        AgencyAndId agencyAndId = AgencyAndIdLibrary.convertFromString(stopId);
                        generateInputsForString(tmpSuggestions, agencyAndId.getId(), null);
                    }
                }
            }
            suggestions = tmpSuggestions;
            _log.info("complete");
        }
    };
    new Thread(initThread).start();
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) List(java.util.List) Refreshable(org.onebusaway.container.refresh.Refreshable) PostConstruct(javax.annotation.PostConstruct)

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