Search in sources :

Example 6 with AgencyWithCoverageBean

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

the class ServiceAlertsAction method execute.

@SkipValidation
@Override
public String execute() {
    _log.info("ServiceAlerts.execute()");
    /*
    if (submit) {
        _log.info("Service Alert submitted");
        //doSubmit();
        //return "submitResult";
     }
     if (clear) {
       _log.info("Service Alert cleared");
        //doClear();
        //return "clearResult";
     }
     */
    // Check that we have permission:
    super.execute();
    try {
        _agencies = _transitDataService.getAgenciesWithCoverage();
        _situationsByAgency = new List[_agencies.size()];
        // for (AgencyWithCoverageBean agency : _agencies) {
        for (int i = 0; i < _agencies.size(); ++i) {
            AgencyWithCoverageBean agency = _agencies.get(i);
            String agencyId = agency.getAgency().getId();
            ListBean<ServiceAlertRecordBean> result = _transitDataService.getAllServiceAlertRecordsForAgencyId(agencyId);
            List<ServiceAlertRecordBean> serviceAlerts = result.getList();
            _situationsByAgency[i] = serviceAlerts;
        }
        for (int i = 0; i < _agencies.size(); ++i) {
            _log.info("Agency " + _agencies.get(i).getAgency().getId());
            List<ServiceAlertRecordBean> serviceAlerts = _situationsByAgency[i];
            for (ServiceAlertRecordBean serviceAlert : serviceAlerts) {
                _log.info("   Alert: " + serviceAlert.getServiceAlertBean().getSummaries().get(0));
            }
        }
    } catch (Throwable t) {
        _log.error("unable to retrieve agencies with coverage", t);
        _log.error("issue connecting to TDS -- check your configuration in data-sources.xml");
        throw new RuntimeException("Check your onebusaway-nyc-transit-data-federation-webapp configuration", t);
    }
    return SUCCESS;
}
Also used : ServiceAlertRecordBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertRecordBean) AgencyWithCoverageBean(org.onebusaway.transit_data.model.AgencyWithCoverageBean) SkipValidation(org.apache.struts2.interceptor.validation.SkipValidation)

Example 7 with AgencyWithCoverageBean

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

the class RemoteConfigAction method getMapBounds.

public String getMapBounds() {
    List<AgencyWithCoverageBean> agencyWithCoverageBeans = _transitDataService.getAgenciesWithCoverage();
    Double minLat = 999d;
    Double minLon = 999d;
    Double maxLat = -999d;
    Double maxLon = -999d;
    for (AgencyWithCoverageBean agencyWithCoverageBean : agencyWithCoverageBeans) {
        if (agencyWithCoverageBean.getLat() != 0 && agencyWithCoverageBean.getLon() != 0) {
            minLat = Math.min(minLat, agencyWithCoverageBean.getLat() - agencyWithCoverageBean.getLatSpan() / 2);
            minLon = Math.min(minLon, agencyWithCoverageBean.getLon() - agencyWithCoverageBean.getLonSpan() / 2);
            maxLat = Math.max(maxLat, agencyWithCoverageBean.getLat() + agencyWithCoverageBean.getLatSpan() / 2);
            maxLon = Math.max(maxLon, agencyWithCoverageBean.getLon() + agencyWithCoverageBean.getLonSpan() / 2);
        }
    }
    return "{ swLat: " + minLat + ", swLon: " + minLon + ", neLat: " + maxLat + ", neLon: " + maxLon + " }";
}
Also used : AgencyWithCoverageBean(org.onebusaway.transit_data.model.AgencyWithCoverageBean)

Example 8 with AgencyWithCoverageBean

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

the class ConfigAction method getMapBounds.

public String getMapBounds() {
    List<AgencyWithCoverageBean> agencyWithCoverageBeans = _transitDataService.getAgenciesWithCoverage();
    Double minLat = 999d;
    Double minLon = 999d;
    Double maxLat = -999d;
    Double maxLon = -999d;
    for (AgencyWithCoverageBean agencyWithCoverageBean : agencyWithCoverageBeans) {
        if (agencyWithCoverageBean.getLat() != 0 && agencyWithCoverageBean.getLon() != 0) {
            minLat = Math.min(minLat, agencyWithCoverageBean.getLat() - agencyWithCoverageBean.getLatSpan() / 2);
            minLon = Math.min(minLon, agencyWithCoverageBean.getLon() - agencyWithCoverageBean.getLonSpan() / 2);
            maxLat = Math.max(maxLat, agencyWithCoverageBean.getLat() + agencyWithCoverageBean.getLatSpan() / 2);
            maxLon = Math.max(maxLon, agencyWithCoverageBean.getLon() + agencyWithCoverageBean.getLonSpan() / 2);
        }
    }
    return "{ swLat: " + minLat + ", swLon: " + minLon + ", neLat: " + maxLat + ", neLon: " + maxLon + " }";
}
Also used : AgencyWithCoverageBean(org.onebusaway.transit_data.model.AgencyWithCoverageBean)

Example 9 with AgencyWithCoverageBean

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

the class SearchServiceImpl method refreshCachesIfNecessary.

// we keep an internal cache of route short/long names because if we moved
// this into the
// transit data federation, we'd also have to move the model factory and
// some other agency-specific
// conventions, which wouldn't be pretty.
// 
// long-term FIXME: figure out how to split apart the model creation a bit
// more from the actual
// search process.
public void refreshCachesIfNecessary() {
    String currentBundleId = _transitDataService.getActiveBundleId();
    if ((_bundleIdForCaches != null && _bundleIdForCaches.equals(currentBundleId)) || currentBundleId == null) {
        return;
    }
    _routeShortNameToRouteBeanMap.clear();
    _routeIdToRouteBeanMap.clear();
    _routeLongNameToRouteBeanMap.clear();
    _stopCodeToStopIdMap.clear();
    for (AgencyWithCoverageBean agency : _transitDataService.getAgenciesWithCoverage()) {
        for (RouteBean routeBean : _transitDataService.getRoutesForAgencyId(agency.getAgency().getId()).getList()) {
            if (routeBean.getShortName() != null)
                if (_routeShortNameToRouteBeanMap.containsKey(routeBean.getShortName().toUpperCase())) {
                    _routeShortNameToRouteBeanMap.get(routeBean.getShortName().toUpperCase()).add(routeBean);
                } else {
                    _routeShortNameToRouteBeanMap.put(routeBean.getShortName().toUpperCase(), new ArrayList<RouteBean>(Arrays.asList(routeBean)));
                }
            if (routeBean.getLongName() != null)
                if (_routeLongNameToRouteBeanMap.containsKey(routeBean.getLongName())) {
                    _routeLongNameToRouteBeanMap.get(routeBean.getLongName()).add(routeBean);
                } else {
                    _routeLongNameToRouteBeanMap.put(routeBean.getLongName(), new ArrayList<RouteBean>(Arrays.asList(routeBean)));
                }
            _routeIdToRouteBeanMap.put(routeBean.getId(), routeBean);
        }
        List<StopBean> stopsList = _transitDataService.getAllRevenueStops(agency);
        for (StopBean stop : stopsList) {
            _stopCodeToStopIdMap.put(agency.getAgency().getId() + "_" + stop.getCode().toUpperCase(), stop.getId());
        }
    }
    _bundleIdForCaches = currentBundleId;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) AgencyWithCoverageBean(org.onebusaway.transit_data.model.AgencyWithCoverageBean) ArrayList(java.util.ArrayList) StopBean(org.onebusaway.transit_data.model.StopBean)

Example 10 with AgencyWithCoverageBean

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

the class DefaultWebappConfigurationSource method getConfiguration.

@Override
public Map<String, Object> getConfiguration(String contextPath) {
    Map<String, Object> config = new HashMap<String, Object>();
    config.put("apiKey", "web");
    config.put("baseUrl", contextPath);
    config.put("apiUrl", contextPath + "/api");
    List<AgencyWithCoverageBean> agenciesWithCoverage = _transitDataService.getAgenciesWithCoverage();
    CoordinateBounds bounds = new CoordinateBounds();
    for (AgencyWithCoverageBean awc : agenciesWithCoverage) {
        if (awc.getLatSpan() <= 0 || awc.getLonSpan() <= 0)
            continue;
        bounds.addPoint(awc.getLat() + awc.getLatSpan() / 2, awc.getLon() + awc.getLonSpan() / 2);
        bounds.addPoint(awc.getLat() - awc.getLatSpan() / 2, awc.getLon() - awc.getLonSpan() / 2);
    }
    if (bounds.isEmpty()) {
        config.put("centerLat", 0.0);
        config.put("centerLon", 0.0);
        config.put("spanLat", 180.0);
        config.put("spanLon", 180.0);
    } else {
        config.put("centerLat", (bounds.getMinLat() + bounds.getMaxLat()) / 2);
        config.put("centerLon", (bounds.getMinLon() + bounds.getMaxLon()) / 2);
        config.put("spanLat", bounds.getMaxLat() - bounds.getMinLat());
        config.put("spanLon", bounds.getMaxLon() - bounds.getMinLon());
    }
    config.put("hasDefaultServiceArea", _serviceAreaService.hasDefaultServiceArea());
    config.put("googleMapsApiKey", _googleMapsApiKey);
    config.put("tracker", _googleAnalyticsAnalyticsKey);
    return config;
}
Also used : HashMap(java.util.HashMap) AgencyWithCoverageBean(org.onebusaway.transit_data.model.AgencyWithCoverageBean) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

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