Search in sources :

Example 21 with SyndEntry

use of com.rometools.rome.feed.synd.SyndEntry in project onebusaway-application-modules by camsys.

the class ServiceAlertsUpdateAction method execute.

@Override
public String execute() {
    _feed = new SyndFeedImpl();
    StringBuilder title = new StringBuilder();
    title.append("OneBusAway Agency Advisories");
    HttpServletRequest request = ServletActionContext.getRequest();
    StringBuilder b = new StringBuilder();
    b.append("http://");
    b.append(request.getServerName());
    if (request.getServerPort() != 80)
        b.append(":").append(request.getServerPort());
    if (request.getContextPath() != null)
        b.append(request.getContextPath());
    String baseUrl = b.toString();
    _feed.setTitle(title.toString());
    _feed.setLink(baseUrl);
    _feed.setDescription("Service Alerts");
    List<SyndEntry> entries = new ArrayList<SyndEntry>();
    // Add Service Alerts
    SyndEntry serviceAlertEntry = new SyndEntryImpl();
    SyndContent saContent = new SyndContentImpl();
    StatusGroup saGroup = _statusProvider.getAgencyServiceAlertStatus();
    if (saGroup.getItems().size() == 0) {
        serviceAlertEntry = new SyndEntryImpl();
        serviceAlertEntry.setTitle("All systems operational");
        entries.add(serviceAlertEntry);
    } else {
        for (StatusItem saItem : saGroup.getItems()) {
            serviceAlertEntry = new SyndEntryImpl();
            serviceAlertEntry.setTitle(saItem.getTitle());
            saContent = new SyndContentImpl();
            saContent.setValue(saItem.getDescription());
            serviceAlertEntry.setDescription(saContent);
            entries.add(serviceAlertEntry);
        }
    }
    _feed.setEntries(entries);
    return SUCCESS;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) StatusItem(org.onebusaway.enterprise.webapp.actions.status.model.StatusItem) SyndContent(com.rometools.rome.feed.synd.SyndContent) StatusGroup(org.onebusaway.enterprise.webapp.actions.status.model.StatusGroup) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) SyndContentImpl(com.rometools.rome.feed.synd.SyndContentImpl) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) ArrayList(java.util.ArrayList) SyndFeedImpl(com.rometools.rome.feed.synd.SyndFeedImpl)

Example 22 with SyndEntry

use of com.rometools.rome.feed.synd.SyndEntry in project onebusaway-application-modules by camsys.

the class StatusUpdateAction method setAgencyServiceAlerts.

// these are top-level service alerts without a route/stop affects clause
protected void setAgencyServiceAlerts(List<SyndEntry> entries, String baseUrl) {
    // Add Service Alerts
    SyndEntry serviceAlertEntry = new SyndEntryImpl();
    SyndContent saContent = new SyndContentImpl();
    serviceAlertEntry.setTitle("Agency Advisories");
    serviceAlertEntry.setLink(baseUrl + "/rss/service-alerts-update");
    entries.add(serviceAlertEntry);
    StatusGroup saGroup = _statusProvider.getAgencyServiceAlertStatus();
    if (saGroup.getItems().size() == 0) {
        serviceAlertEntry = new SyndEntryImpl();
        serviceAlertEntry.setTitle("All systems operational");
        entries.add(serviceAlertEntry);
    } else {
        for (StatusItem saItem : saGroup.getItems()) {
            serviceAlertEntry = new SyndEntryImpl();
            serviceAlertEntry.setTitle(saItem.getTitle());
            saContent = new SyndContentImpl();
            saContent.setValue(saItem.getDescription());
            serviceAlertEntry.setDescription(saContent);
            entries.add(serviceAlertEntry);
        }
    }
}
Also used : StatusItem(org.onebusaway.enterprise.webapp.actions.status.model.StatusItem) SyndContent(com.rometools.rome.feed.synd.SyndContent) StatusGroup(org.onebusaway.enterprise.webapp.actions.status.model.StatusGroup) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) SyndContentImpl(com.rometools.rome.feed.synd.SyndContentImpl) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl)

Example 23 with SyndEntry

use of com.rometools.rome.feed.synd.SyndEntry in project onebusaway-application-modules by camsys.

the class StatusUpdateAction method setIcingaAlerts.

private void setIcingaAlerts(List<SyndEntry> entries, String baseUrl) {
    // Add Icinga Alerts
    SyndEntry icingaEntry = new SyndEntryImpl();
    SyndContent icingaContent = new SyndContentImpl();
    icingaEntry.setTitle("System Monitoring");
    icingaEntry.setLink(baseUrl + "/rss/monitoring-alerts-update");
    entries.add(icingaEntry);
    StatusGroup icingaGroup = _statusProvider.getIcingaStatus();
    StatusGroup icingaProblems = new StatusGroup();
    icingaProblems.setTitle(icingaGroup.getTitle());
    // Only report items where status is not "OK"
    for (StatusItem icingaItem : icingaGroup.getItems()) {
        if (icingaItem.getStatus() != StatusItem.Status.OK) {
            icingaProblems.addItem(icingaItem);
        }
    }
    if (icingaProblems.getItems().size() == 0) {
        icingaEntry = new SyndEntryImpl();
        icingaEntry.setTitle("All systems operational");
        entries.add(icingaEntry);
    } else {
        for (StatusItem icingaItem : icingaProblems.getItems()) {
            icingaEntry = new SyndEntryImpl();
            icingaEntry.setTitle(icingaItem.getTitle());
            icingaContent = new SyndContentImpl();
            icingaContent.setValue(icingaItem.getStatus() + ": " + icingaItem.getDescription());
            icingaEntry.setDescription(icingaContent);
            entries.add(icingaEntry);
        }
    }
}
Also used : StatusItem(org.onebusaway.enterprise.webapp.actions.status.model.StatusItem) SyndContent(com.rometools.rome.feed.synd.SyndContent) StatusGroup(org.onebusaway.enterprise.webapp.actions.status.model.StatusGroup) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) SyndContentImpl(com.rometools.rome.feed.synd.SyndContentImpl) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl)

Example 24 with SyndEntry

use of com.rometools.rome.feed.synd.SyndEntry in project onebusaway-application-modules by camsys.

the class StatusUpdateAction method execute.

@Override
public String execute() {
    _feed = new SyndFeedImpl();
    StringBuilder title = new StringBuilder();
    title.append("OneBusAway System Status");
    String baseUrl = createBaseUrl(ServletActionContext.getRequest());
    _feed.setTitle(title.toString());
    // _feed.setLink(baseUrl);
    _feed.setLink("");
    _feed.setDescription("System Status");
    List<SyndEntry> entries = new ArrayList<SyndEntry>();
    setIcingaAlerts(entries, baseUrl);
    setAgencyServiceAlerts(entries, baseUrl);
    setAgencyMessages(entries, baseUrl);
    _feed.setEntries(entries);
    return SUCCESS;
}
Also used : SyndEntry(com.rometools.rome.feed.synd.SyndEntry) ArrayList(java.util.ArrayList) SyndFeedImpl(com.rometools.rome.feed.synd.SyndFeedImpl)

Example 25 with SyndEntry

use of com.rometools.rome.feed.synd.SyndEntry in project ddf by codice.

the class OpenSearchSource method processResponse.

private SourceResponseImpl processResponse(InputStream is, QueryRequest queryRequest) throws UnsupportedQueryException {
    List<Result> resultQueue = new ArrayList<>();
    SyndFeedInput syndFeedInput = new SyndFeedInput();
    SyndFeed syndFeed = null;
    try {
        syndFeed = syndFeedInput.build(new InputStreamReader(is, StandardCharsets.UTF_8));
    } catch (FeedException e) {
        LOGGER.debug("Unable to read RSS/Atom feed.", e);
    }
    List<SyndEntry> entries;
    long totalResults = 0;
    List<Element> foreignMarkup = null;
    if (syndFeed != null) {
        entries = syndFeed.getEntries();
        for (SyndEntry entry : entries) {
            resultQueue.addAll(createResponseFromEntry(entry));
        }
        totalResults = entries.size();
        foreignMarkup = syndFeed.getForeignMarkup();
        for (Element element : foreignMarkup) {
            if (element.getName().equals("totalResults")) {
                try {
                    totalResults = Long.parseLong(element.getContent(0).getValue());
                } catch (NumberFormatException | IndexOutOfBoundsException e) {
                    // totalResults is already initialized to the correct value, so don't change it here.
                    LOGGER.debug("Received invalid number of results.", e);
                }
            }
        }
    }
    SourceResponseImpl response = new SourceResponseImpl(queryRequest, resultQueue);
    response.setHits(totalResults);
    if (foreignMarkup != null) {
        this.foreignMarkupBiConsumer.accept(Collections.unmodifiableList(foreignMarkup), response);
    }
    return response;
}
Also used : InputStreamReader(java.io.InputStreamReader) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) FeedException(com.rometools.rome.io.FeedException) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) Result(ddf.catalog.data.Result) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SyndFeedInput(com.rometools.rome.io.SyndFeedInput)

Aggregations

SyndEntry (com.rometools.rome.feed.synd.SyndEntry)45 ArrayList (java.util.ArrayList)23 SyndFeed (com.rometools.rome.feed.synd.SyndFeed)22 SyndEntryImpl (com.rometools.rome.feed.synd.SyndEntryImpl)18 SyndContent (com.rometools.rome.feed.synd.SyndContent)15 SyndFeedImpl (com.rometools.rome.feed.synd.SyndFeedImpl)14 SyndContentImpl (com.rometools.rome.feed.synd.SyndContentImpl)13 SyndFeedInput (com.rometools.rome.io.SyndFeedInput)9 FeedException (com.rometools.rome.io.FeedException)7 Test (org.junit.Test)7 XmlReader (com.rometools.rome.io.XmlReader)6 URL (java.net.URL)6 Date (java.util.Date)5 StatusGroup (org.onebusaway.enterprise.webapp.actions.status.model.StatusGroup)5 StatusItem (org.onebusaway.enterprise.webapp.actions.status.model.StatusItem)5 IOException (java.io.IOException)4 BeanFactory (org.springframework.beans.factory.BeanFactory)4 ClassPathResource (org.springframework.core.io.ClassPathResource)4 SyndFeedOutput (com.rometools.rome.io.SyndFeedOutput)3 Post (it.vige.rubia.model.Post)3