Search in sources :

Example 1 with TimeRangeRssBean

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

the class ServiceAlertRssModuleGenerator method generate.

@Override
public void generate(Module module, Element element) {
    // this is not necessary, it is done to avoid the namespace definition in every item.
    Element root = element;
    while (root.getParent() != null && root.getParent() instanceof Element) {
        root = (Element) element.getParent();
    }
    root.addNamespaceDeclaration(SERVICE_ALERT_NS);
    Element sas = null;
    Element channel = getElement(root, "channel");
    if (channel == null) {
        throw new RuntimeException("missing channel from element=" + root);
    }
    sas = getElement(channel, "ServiceAlerts");
    if (sas == null) {
        sas = generateSimpleElement("ServiceAlerts", "");
        sas.setName("ServiceAlerts");
        channel.addContent(sas);
    }
    if (module instanceof IServiceAlert) {
        IServiceAlert isa = (IServiceAlert) module;
        if (isa.getId() != null) {
            Element sa = generateSimpleElement("ServiceAlert", "");
            sa.setName("ServiceAlert");
            sa.addContent(generateSimpleElement("id", isa.getId()));
            sa.addContent(generateSimpleElement("summary", isa.getSummary()));
            sa.addContent(generateSimpleElement("description", isa.getDescription()));
            sa.addContent(generateSimpleElement("reason", isa.getReason()));
            sa.addContent(generateSimpleElement("severity", isa.getSeverity()));
            if (isa.getPublicationWindows() != null && !isa.getPublicationWindows().isEmpty()) {
                Element publicationWindows = generateSimpleElement("PublicationWindows", "");
                publicationWindows.setName("PublicationWindows");
                sa.addContent(publicationWindows);
                for (TimeRangeRssBean trb : isa.getPublicationWindows()) {
                    Element timeRange = generateSimpleElement("TimeRange", "");
                    timeRange.addContent(generateSimpleElement("from", "" + trb.getFrom()));
                    timeRange.addContent(generateSimpleElement("to", "" + trb.getTo()));
                    publicationWindows.addContent(timeRange);
                }
            }
            if (isa.getAffectsClauses() != null && !isa.getAffectsClauses().isEmpty()) {
                Element affectsClauses = generateSimpleElement("AffectsClauses", "");
                affectsClauses.setName("AffectsClauses");
                sa.addContent(affectsClauses);
                for (AffectsClauseRssBean acrb : isa.getAffectsClauses()) {
                    Element affect = generateSimpleElement("Affect", "");
                    if (acrb.getAgencyId() != null && acrb.getRouteId() == null && acrb.getStopId() == null && acrb.getTripId() == null)
                        affect.addContent(generateAgencyElement("agencyId", acrb.getAgencyId()));
                    if (acrb.getRouteId() != null)
                        affect.addContent(generateAgencyElement("routeId", acrb.getRouteId()));
                    if (acrb.getStopId() != null)
                        affect.addContent(generateAgencyElement("stopId", acrb.getStopId()));
                    if (acrb.getTripId() != null)
                        affect.addContent(generateAgencyElement("tripId", acrb.getTripId()));
                    affectsClauses.addContent(affect);
                }
            }
            sas.addContent(sa);
        }
    } else {
        _log.error("unknown type=" + module);
    }
}
Also used : IServiceAlert(org.onebusaway.rss.model.IServiceAlert) Element(org.jdom2.Element) TimeRangeRssBean(org.onebusaway.rss.model.TimeRangeRssBean) AffectsClauseRssBean(org.onebusaway.rss.model.AffectsClauseRssBean)

Example 2 with TimeRangeRssBean

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

the class AlertsAction method toTimeRange.

private List<TimeRangeRssBean> toTimeRange(List<TimeRangeBean> beans) {
    List<TimeRangeRssBean> trrbs = new ArrayList<>();
    if (beans == null)
        return trrbs;
    for (TimeRangeBean trb : beans) {
        TimeRangeRssBean trrb = new TimeRangeRssBean();
        trrb.setFrom(trb.getFrom());
        trrb.setTo(trb.getTo());
        trrbs.add(trrb);
    }
    return trrbs;
}
Also used : TimeRangeBean(org.onebusaway.transit_data.model.service_alerts.TimeRangeBean) ArrayList(java.util.ArrayList) TimeRangeRssBean(org.onebusaway.rss.model.TimeRangeRssBean)

Aggregations

TimeRangeRssBean (org.onebusaway.rss.model.TimeRangeRssBean)2 ArrayList (java.util.ArrayList)1 Element (org.jdom2.Element)1 AffectsClauseRssBean (org.onebusaway.rss.model.AffectsClauseRssBean)1 IServiceAlert (org.onebusaway.rss.model.IServiceAlert)1 TimeRangeBean (org.onebusaway.transit_data.model.service_alerts.TimeRangeBean)1