Search in sources :

Example 1 with AgencyWithCoverageBean

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

the class AgencyListAction method getModel.

@Override
public Body<Agency> getModel() {
    Body<Agency> body = new Body<Agency>();
    try {
        List<AgencyWithCoverageBean> agencies = _service.getAgenciesWithCoverage();
        for (AgencyWithCoverageBean agencyBean : agencies) {
            Agency agency = new Agency();
            agency.setTag(agencyBean.getAgency().getId());
            agency.setTitle(agencyBean.getAgency().getName());
            agency.setRegionTitle(agencyBean.getAgency().getName());
            body.getResponse().add(agency);
        }
    } catch (ServiceException e) {
        body.getErrors().add(new BodyError(ErrorMsg.SERVICE_ERROR.getDescription()));
    }
    return body;
}
Also used : Agency(org.onebusaway.nextbus.model.nextbus.Agency) ServiceException(org.onebusaway.exceptions.ServiceException) BodyError(org.onebusaway.nextbus.model.nextbus.BodyError) AgencyWithCoverageBean(org.onebusaway.transit_data.model.AgencyWithCoverageBean) Body(org.onebusaway.nextbus.model.nextbus.Body)

Example 2 with AgencyWithCoverageBean

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

the class AlertsAction method setServiceAlerts.

private void setServiceAlerts(List<ServiceAlertRssBean> beans, String baseUrl) {
    List<AgencyWithCoverageBean> agencies = _transitDataService.getAgenciesWithCoverage();
    for (AgencyWithCoverageBean agency : agencies) {
        String agencyId = agency.getAgency().getId();
        String agencyName = agency.getAgency().getName();
        if (StringUtils.isNotBlank(_agencyId)) {
            // we have a filter, only return service alerts for that agency
            if (_agencyId.equals(agencyId)) {
                setServiceAlerts(agency, beans, baseUrl);
            } else {
            // here we reject the agency and its alerts
            }
        } else {
            // we don't have a filter, render all agencies
            setServiceAlerts(agency, beans, baseUrl);
        }
    }
}
Also used : AgencyWithCoverageBean(org.onebusaway.transit_data.model.AgencyWithCoverageBean)

Example 3 with AgencyWithCoverageBean

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

the class StatusProviderImpl method getAgencyServiceAlertStatus.

@Override
public StatusGroup getAgencyServiceAlertStatus() {
    StatusGroup group = new StatusGroup();
    group.setTitle("Agency Advisories");
    group.setScope("Schedule and real-time availability at the agency level");
    group.setSource("Sound Transit administrators -- manual entry");
    List<AgencyWithCoverageBean> agencies = _transitDataService.getAgenciesWithCoverage();
    for (AgencyWithCoverageBean agency : agencies) {
        String agencyId = agency.getAgency().getId();
        String agencyName = agency.getAgency().getName();
        // Use query to limit to agency and no other parameters
        SituationQueryBean query = new SituationQueryBean();
        AffectsBean ab = new AffectsBean();
        ab.setAgencyId(agencyId);
        query.setAffects(Collections.singletonList(ab));
        ListBean<ServiceAlertBean> alerts = _transitDataService.getServiceAlerts(query);
        List<ServiceAlertBean> beans = filterByTime(alerts.getList(), System.currentTimeMillis());
        for (ServiceAlertBean bean : beans) {
            StatusItem item = new StatusItem();
            item.setDescription(bean.getDescriptions().get(0).getValue());
            item.setTitle(agencyName + ": " + bean.getSummaries().get(0).getValue());
            item.setStatus(StatusItem.Status.ALERT);
            group.addItem(item);
        }
    }
    return group;
}
Also used : AffectsBean(org.onebusaway.transit_data.model.service_alerts.SituationQueryBean.AffectsBean) StatusItem(org.onebusaway.enterprise.webapp.actions.status.model.StatusItem) StatusGroup(org.onebusaway.enterprise.webapp.actions.status.model.StatusGroup) SituationQueryBean(org.onebusaway.transit_data.model.service_alerts.SituationQueryBean) AgencyWithCoverageBean(org.onebusaway.transit_data.model.AgencyWithCoverageBean) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)

Example 4 with AgencyWithCoverageBean

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

the class RouteListServiceImpl method getRoutes.

@Override
public List<RouteBean> getRoutes() {
    List<RouteBean> allRoutes = new ArrayList<RouteBean>();
    List<AgencyWithCoverageBean> agencies = _transitDataService.getAgenciesWithCoverage();
    for (AgencyWithCoverageBean agency : agencies) {
        allRoutes.addAll(_transitDataService.getRoutesForAgencyId(agency.getAgency().getId()).getList());
    }
    Collections.sort(allRoutes, (getShowAgencyNames() ? new AgencyAndRouteComparator() : new RouteComparator()));
    return allRoutes;
}
Also used : AgencyAndRouteComparator(org.onebusaway.presentation.impl.AgencyAndRouteComparator) RouteBean(org.onebusaway.transit_data.model.RouteBean) AgencyWithCoverageBean(org.onebusaway.transit_data.model.AgencyWithCoverageBean) ArrayList(java.util.ArrayList) AgencyAndRouteComparator(org.onebusaway.presentation.impl.AgencyAndRouteComparator) RouteComparator(org.onebusaway.presentation.impl.RouteComparator)

Example 5 with AgencyWithCoverageBean

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

the class ServiceAlertEditAction method execute.

@Override
public String execute() {
    try {
        if (_alertId != null && !_alertId.trim().isEmpty()) {
            _model = _transitDataService.getServiceAlertForId(_alertId);
            if (_agencyId == null) {
                _agencyId = ServiceAlertsUtil.getAgencyFromAlertId(_alertId);
            }
        }
    } catch (RuntimeException e) {
        _log.error("Unable to retrieve Service Alert", e);
        throw e;
    }
    try {
        _agencies = _transitDataService.getAgenciesWithCoverage();
        _situationTemplatesByAgency = new ArrayList<ServiceAlertBean>();
        for (int i = 0; i < _agencies.size(); ++i) {
            AgencyWithCoverageBean agency = _agencies.get(i);
            String agencyId = agency.getAgency().getId();
            ListBean<ServiceAlertRecordBean> result = _transitDataService.getAllServiceAlertRecordsForAgencyId(agencyId);
            for (ServiceAlertRecordBean serviceAlertRecord : result.getList()) {
                if (Boolean.TRUE.equals(serviceAlertRecord.isCopy())) {
                    _situationTemplatesByAgency.add(serviceAlertRecord.getServiceAlertBean());
                }
            }
        }
    } 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);
    }
    if (isFromFavorite()) {
        setStartDate(null);
        setEndDate(null);
    }
    return "SUCCESS";
}
Also used : ServiceAlertRecordBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertRecordBean) AgencyWithCoverageBean(org.onebusaway.transit_data.model.AgencyWithCoverageBean) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)

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