Search in sources :

Example 1 with AffectsClauseRssBean

use of org.onebusaway.rss.model.AffectsClauseRssBean 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 AffectsClauseRssBean

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

the class AlertsAction method toAffectClause.

private List<AffectsClauseRssBean> toAffectClause(List<SituationAffectsBean> clauses) {
    List<AffectsClauseRssBean> beans = new ArrayList<>();
    if (clauses == null)
        return null;
    for (SituationAffectsBean clause : clauses) {
        AffectsClauseRssBean bean = new AffectsClauseRssBean();
        bean.setAgencyId(clause.getAgencyId());
        bean.setRouteId(clause.getRouteId());
        bean.setTripId(clause.getTripId());
        bean.setStopId(clause.getStopId());
        beans.add(bean);
    }
    return beans;
}
Also used : SituationAffectsBean(org.onebusaway.transit_data.model.service_alerts.SituationAffectsBean) ArrayList(java.util.ArrayList) AffectsClauseRssBean(org.onebusaway.rss.model.AffectsClauseRssBean)

Aggregations

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