Search in sources :

Example 1 with ServiceAlertRssBean

use of org.onebusaway.rss.model.ServiceAlertRssBean in project onebusaway-application-modules by camsys.

the class AlertsAction method setServiceAlerts.

private void setServiceAlerts(AgencyWithCoverageBean agency, List<ServiceAlertRssBean> beans, String baseUrl) {
    ListBean<ServiceAlertBean> allServiceAlertsForAgencyId = _transitDataService.getAllServiceAlertsForAgencyId(agency.getAgency().getId());
    if (allServiceAlertsForAgencyId == null) {
        _log.info("no service alerts returned for agency " + agency.getAgency().getId());
        return;
    }
    long time = System.currentTimeMillis();
    for (ServiceAlertBean sab : allServiceAlertsForAgencyId.getList()) {
        if (!containsActiveAlert(sab, time)) {
            continue;
        }
        ServiceAlertRssBean bean = new ServiceAlertRssBean();
        bean.setId(sab.getId());
        bean.setReason(sab.getReason());
        if (sab.getSeverity() != null) {
            bean.setSeverity(sab.getSeverity().getTpegCodes()[0]);
        }
        bean.setSummary(ServiceAlertRssBean.getLocalString(sab.getSummaries()));
        bean.setDescription(ServiceAlertRssBean.getLocalString(sab.getDescriptions()));
        bean.setPublicationWindows(toTimeRange(sab.getPublicationWindows()));
        bean.setAffectsClauses(toAffectClause(sab.getAllAffects()));
        beans.add(bean);
    }
}
Also used : ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean) ServiceAlertRssBean(org.onebusaway.rss.model.ServiceAlertRssBean)

Example 2 with ServiceAlertRssBean

use of org.onebusaway.rss.model.ServiceAlertRssBean in project onebusaway-application-modules by camsys.

the class AlertsAction method execute.

@Override
public String execute() {
    try {
        _feed = new SyndFeedImpl();
        List<ServiceAlertRssBean> beans = new ArrayList<>();
        String baseUrl = createBaseUrl(ServletActionContext.getRequest());
        setServiceAlerts(beans, baseUrl);
        for (Object objBean : beans) {
            ServiceAlertRssBean rssBean = (ServiceAlertRssBean) objBean;
            _feed.getModules().add(rssBean);
        }
        _feed.setTitle("OneBusAway Service Alerts");
        _feed.setLink("");
        _feed.setDescription("Service Information - Service Alerts");
        return SUCCESS;
    } catch (Throwable t) {
        _log.error("Exception in execute: ", t);
        return ERROR;
    }
}
Also used : ArrayList(java.util.ArrayList) SyndFeedImpl(com.rometools.rome.feed.synd.SyndFeedImpl) ServiceAlertRssBean(org.onebusaway.rss.model.ServiceAlertRssBean)

Aggregations

ServiceAlertRssBean (org.onebusaway.rss.model.ServiceAlertRssBean)2 SyndFeedImpl (com.rometools.rome.feed.synd.SyndFeedImpl)1 ArrayList (java.util.ArrayList)1 ServiceAlertBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)1