Search in sources :

Example 1 with NotificationModel

use of org.opennms.web.notification.NotificationModel in project opennms by OpenNMS.

the class NotificationFeed method getFeed.

/**
     * <p>getFeed</p>
     *
     * @return a {@link com.sun.syndication.feed.synd.SyndFeed} object.
     */
@Override
public SyndFeed getFeed() {
    SyndFeed feed = new SyndFeedImpl();
    feed.setTitle("Notifications");
    feed.setDescription("Notifications");
    feed.setLink(getUrlBase() + "notification/browse");
    List<SyndEntry> entries = new ArrayList<SyndEntry>();
    try {
        NotificationModel model = new NotificationModel();
        Notification[] notifications = model.allNotifications("desc");
        SyndEntry entry;
        int count = 0;
        for (Notification notification : notifications) {
            if (count++ == this.getMaxEntries()) {
                break;
            }
            entry = new SyndEntryImpl();
            entry.setPublishedDate(notification.getTimeSent());
            if (notification.getTimeReplied() == null) {
                entry.setTitle(sanitizeTitle(notification.getTextMessage()));
                entry.setUpdatedDate(notification.getTimeSent());
            } else {
                entry.setTitle(sanitizeTitle(notification.getTextMessage()) + " (acknowledged)");
                entry.setUpdatedDate(notification.getTimeReplied());
            }
            entry.setLink(getUrlBase() + "notification/detail.jsp?notice=" + notification.getId());
            entry.setAuthor("OpenNMS");
            entries.add(entry);
        }
    } catch (SQLException e) {
        LOG.warn("unable to get outstanding notifications", e);
    }
    feed.setEntries(entries);
    return feed;
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SQLException(java.sql.SQLException) SyndEntry(com.sun.syndication.feed.synd.SyndEntry) SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl) ArrayList(java.util.ArrayList) SyndFeedImpl(com.sun.syndication.feed.synd.SyndFeedImpl) NotificationModel(org.opennms.web.notification.NotificationModel) Notification(org.opennms.web.notification.Notification)

Aggregations

SyndEntry (com.sun.syndication.feed.synd.SyndEntry)1 SyndEntryImpl (com.sun.syndication.feed.synd.SyndEntryImpl)1 SyndFeed (com.sun.syndication.feed.synd.SyndFeed)1 SyndFeedImpl (com.sun.syndication.feed.synd.SyndFeedImpl)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 Notification (org.opennms.web.notification.Notification)1 NotificationModel (org.opennms.web.notification.NotificationModel)1