Search in sources :

Example 11 with AgencyWithCoverageBean

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

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

the class LongTermAveragesResource method getAgencyList.

private List<String> getAgencyList() {
    try {
        List<AgencyWithCoverageBean> agencyBeans = getTDS().getAgenciesWithCoverage();
        agencyIds = new ArrayList<String>();
        for (AgencyWithCoverageBean agency : agencyBeans) {
            agencyIds.add(agency.getAgency().getId());
        }
    } catch (Exception e) {
        _log.error("getAgencyList broke", e);
    }
    return agencyIds;
}
Also used : AgencyWithCoverageBean(org.onebusaway.transit_data.model.AgencyWithCoverageBean) IOException(java.io.IOException)

Example 13 with AgencyWithCoverageBean

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

the class RootResource method listAgencies.

@Path("list-agencies")
@GET
@Produces("application/json")
public Response listAgencies() {
    List<AgencyWithCoverageBean> agenciesWithCoverage = getTDS().getAgenciesWithCoverage();
    List<String> agencyIds = new ArrayList<String>();
    for (AgencyWithCoverageBean bean : agenciesWithCoverage) {
        agencyIds.add(bean.getAgency().getId());
    }
    Collections.sort(agencyIds);
    StringBuffer json = new StringBuffer();
    json.append("[");
    for (String agency : agencyIds) {
        json.append("\"");
        json.append(agency);
        json.append("\"");
        json.append(",");
    }
    json.deleteCharAt(json.length() - 1);
    json.append("]");
    return Response.ok(json.toString()).build();
}
Also used : AgencyWithCoverageBean(org.onebusaway.transit_data.model.AgencyWithCoverageBean) ArrayList(java.util.ArrayList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 14 with AgencyWithCoverageBean

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

the class AgencyResource method getAgencyIdList.

@Path("id-list")
@GET
@Produces("application/json")
public Response getAgencyIdList() {
    try {
        List<AgencyWithCoverageBean> agencyBeans = getTDS().getAgenciesWithCoverage();
        List<String> agencyIds = new ArrayList<String>();
        for (AgencyWithCoverageBean agency : agencyBeans) {
            agencyIds.add(agency.getAgency().getId());
        }
        return Response.ok(ok("agency-id-list", agencyIds)).build();
    } catch (Exception e) {
        _log.error("getAgencyIdList broke", e);
        return Response.ok(error("agency-id-list", e)).build();
    }
}
Also used : AgencyWithCoverageBean(org.onebusaway.transit_data.model.AgencyWithCoverageBean) ArrayList(java.util.ArrayList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 15 with AgencyWithCoverageBean

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

the class BundleManagementServiceImpl method removeAndRebuildCache.

/**
 ***********************
 * Private Helper Methods
 ************************
 */
private void removeAndRebuildCache() {
    // give subclasses a chance to do work
    timingHook();
    _log.info("Clearing all caches...");
    for (CacheManager cacheManager : CacheManager.ALL_CACHE_MANAGERS) {
        _log.info("Found " + cacheManager.getName());
        for (String cacheName : cacheManager.getCacheNames()) {
            _log.info(" > Cache: " + cacheName);
            cacheManager.getCache(cacheName).flush();
            cacheManager.clearAllStartingWith(cacheName);
        }
        // why not?
        cacheManager.clearAll();
    }
    // Rebuild cache
    try {
        List<AgencyWithCoverageBean> agenciesWithCoverage = _transitDataService.getAgenciesWithCoverage();
        for (AgencyWithCoverageBean agencyWithCoverage : agenciesWithCoverage) {
            AgencyBean agency = agencyWithCoverage.getAgency();
            ListBean<String> stopIds = _transitDataService.getStopIdsForAgencyId(agency.getId());
            for (String stopId : stopIds.getList()) {
                _transitDataService.getStop(stopId);
            }
            ListBean<String> routeIds = _transitDataService.getRouteIdsForAgencyId(agency.getId());
            for (String routeId : routeIds.getList()) {
                _transitDataService.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) {
            _transitDataService.getShapeForId(AgencyAndIdLibrary.convertToString(shapeId));
        }
        _log.info("cache clearing complete!");
    } catch (Exception e) {
        _log.error("Exception during cache rebuild: ", e.getMessage());
    }
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) AgencyWithCoverageBean(org.onebusaway.transit_data.model.AgencyWithCoverageBean) CacheManager(net.sf.ehcache.CacheManager) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) AgencyBean(org.onebusaway.transit_data.model.AgencyBean) HashSet(java.util.HashSet)

Aggregations

AgencyWithCoverageBean (org.onebusaway.transit_data.model.AgencyWithCoverageBean)15 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 ServiceException (org.onebusaway.exceptions.ServiceException)2 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)2 AgencyBean (org.onebusaway.transit_data.model.AgencyBean)2 RouteBean (org.onebusaway.transit_data.model.RouteBean)2 ServiceAlertBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)2 ServiceAlertRecordBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertRecordBean)2 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Cache (net.sf.ehcache.Cache)1 CacheManager (net.sf.ehcache.CacheManager)1 SkipValidation (org.apache.struts2.interceptor.validation.SkipValidation)1 StatusGroup (org.onebusaway.enterprise.webapp.actions.status.model.StatusGroup)1 StatusItem (org.onebusaway.enterprise.webapp.actions.status.model.StatusItem)1