Search in sources :

Example 1 with Cacheable

use of org.onebusaway.container.cache.Cacheable 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 2 with Cacheable

use of org.onebusaway.container.cache.Cacheable in project onebusaway-application-modules by camsys.

the class NearbyStopsBeanServiceImpl method getNearbyStops.

@Cacheable
public List<AgencyAndId> getNearbyStops(@CacheableArgument(keyProperty = "id") StopBean stopBean, double radius) {
    CoordinateBounds bounds = SphericalGeometryLibrary.bounds(stopBean.getLat(), stopBean.getLon(), radius);
    List<AgencyAndId> ids = _geospatialBeanService.getStopsByBounds(bounds);
    List<AgencyAndId> excludingSource = new ArrayList<AgencyAndId>();
    for (AgencyAndId id : ids) {
        if (!ApplicationBeanLibrary.getId(id).equals(stopBean.getId()))
            excludingSource.add(id);
    }
    return excludingSource;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds) Cacheable(org.onebusaway.container.cache.Cacheable)

Example 3 with Cacheable

use of org.onebusaway.container.cache.Cacheable in project onebusaway-application-modules by camsys.

the class RouteBeanServiceImpl method getStopsForRoute.

@Cacheable
public StopsForRouteBean getStopsForRoute(AgencyAndId routeId) {
    RouteCollectionEntry routeCollectionEntry = _transitGraphDao.getRouteCollectionForId(routeId);
    RouteCollectionNarrative narrative = _narrativeService.getRouteCollectionForId(routeId);
    if (routeCollectionEntry == null || narrative == null)
        return null;
    return getStopsForRouteCollectionAndNarrative(routeCollectionEntry, narrative);
}
Also used : RouteCollectionEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry) RouteCollectionNarrative(org.onebusaway.transit_data_federation.model.narrative.RouteCollectionNarrative) Cacheable(org.onebusaway.container.cache.Cacheable)

Example 4 with Cacheable

use of org.onebusaway.container.cache.Cacheable 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 5 with Cacheable

use of org.onebusaway.container.cache.Cacheable in project onebusaway-application-modules by camsys.

the class ShapeBeanServiceImpl method getMergedPolylinesForShapeIds.

@Cacheable
public List<EncodedPolylineBean> getMergedPolylinesForShapeIds(Collection<AgencyAndId> shapeIds) {
    List<EncodedPolylineBean> polylines = new ArrayList<EncodedPolylineBean>();
    if (shapeIds.isEmpty())
        return polylines;
    List<CoordinatePoint> currentLine = new ArrayList<CoordinatePoint>();
    Set<Edge> edges = new HashSet<Edge>();
    for (AgencyAndId shapeId : shapeIds) {
        ShapePoints shapePoints = _shapePointService.getShapePointsForShapeId(shapeId);
        if (shapePoints == null) {
            _log.warn("no shape points for shapeId=" + shapeId);
            continue;
        }
        double[] lats = shapePoints.getLats();
        double[] lons = shapePoints.getLons();
        CoordinatePoint prev = null;
        for (int i = 0; i < shapePoints.getSize(); i++) {
            CoordinatePoint loc = new CoordinatePoint(lats[i], lons[i]);
            if (prev != null && !prev.equals(loc)) {
                Edge edge = new Edge(prev, loc);
                if (!edges.add(edge)) {
                    if (currentLine.size() > 1)
                        polylines.add(PolylineEncoder.createEncodings(currentLine));
                    currentLine.clear();
                }
            }
            if (prev == null || !prev.equals(loc))
                currentLine.add(loc);
            prev = loc;
        }
        if (currentLine.size() > 1)
            polylines.add(PolylineEncoder.createEncodings(currentLine));
        currentLine.clear();
    }
    return polylines;
}
Also used : ShapePoints(org.onebusaway.transit_data_federation.model.ShapePoints) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) EncodedPolylineBean(org.onebusaway.geospatial.model.EncodedPolylineBean) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) HashSet(java.util.HashSet) Cacheable(org.onebusaway.container.cache.Cacheable)

Aggregations

Cacheable (org.onebusaway.container.cache.Cacheable)23 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)10 ArrayList (java.util.ArrayList)8 HashSet (java.util.HashSet)7 RouteCollectionEntry (org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry)6 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)6 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)6 HashMap (java.util.HashMap)4 AgencyEntry (org.onebusaway.transit_data_federation.services.transit_graph.AgencyEntry)4 Date (java.util.Date)3 LocalizedServiceId (org.onebusaway.gtfs.model.calendar.LocalizedServiceId)3 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)3 RouteBean (org.onebusaway.transit_data.model.RouteBean)3 ShapePoints (org.onebusaway.transit_data_federation.model.ShapePoints)3 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)3 BlockEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry)3 FactoryMap (org.onebusaway.collections.FactoryMap)2 NoSuchAgencyServiceException (org.onebusaway.exceptions.NoSuchAgencyServiceException)2 CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)2 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)2