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);
}
}
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;
}
Aggregations