Search in sources :

Example 1 with NotificationIdListFilter

use of org.opennms.web.notification.filter.NotificationIdListFilter in project opennms by OpenNMS.

the class WebNotificationRepositoryFilterIT method testNotificationIdListFilter.

@Test
// Relies on specific IDs so we need a fresh database
@JUnitTemporaryDatabase
public void testNotificationIdListFilter() {
    int[] ids = { 1 };
    NotificationIdListFilter filter = new NotificationIdListFilter(ids);
    assert1Result(filter);
}
Also used : NotificationIdListFilter(org.opennms.web.notification.filter.NotificationIdListFilter) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 2 with NotificationIdListFilter

use of org.opennms.web.notification.filter.NotificationIdListFilter in project opennms by OpenNMS.

the class AcknowledgeNotificationController method handleRequestInternal.

/**
 * {@inheritDoc}
 *
 * Acknowledge the notifications specified in the POST and then redirect the client
 * to an appropriate URL for display.
 */
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String[] required = { "notices" };
    String[] noticeIdStrings = request.getParameterValues("notices");
    if (noticeIdStrings == null) {
        throw new MissingParameterException("notices", required);
    }
    String currentUser = request.getParameter("curUser");
    if (currentUser == null) {
        currentUser = request.getRemoteUser();
    }
    List<Integer> noticeIds = new ArrayList<>();
    for (String noticeIdString : noticeIdStrings) {
        noticeIds.add(WebSecurityUtils.safeParseInt(noticeIdString));
    }
    List<Filter> filters = new ArrayList<>();
    filters.add(new NotificationIdListFilter(noticeIds.toArray(new Integer[0])));
    NotificationCriteria criteria = new NotificationCriteria(filters.toArray(new Filter[0]));
    m_webNotificationRepository.acknowledgeMatchingNotification(currentUser, new Date(), criteria);
    Notification[] notices = m_webNotificationRepository.getMatchingNotifications(criteria);
    request.setAttribute("notices", notices);
    String redirectParms = request.getParameter("redirectParms");
    String redirect = request.getParameter("redirect");
    String viewName;
    if (redirect != null) {
        viewName = redirect;
    } else {
        viewName = (redirectParms == null || redirectParms == "" || redirectParms == "null" ? m_redirectView : m_redirectView + "?" + redirectParms);
    }
    RedirectView view = new RedirectView(viewName, true);
    return new ModelAndView(view);
}
Also used : ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) Date(java.util.Date) Notification(org.opennms.web.notification.Notification) NotificationIdListFilter(org.opennms.web.notification.filter.NotificationIdListFilter) Filter(org.opennms.web.filter.Filter) NotificationIdListFilter(org.opennms.web.notification.filter.NotificationIdListFilter) NotificationCriteria(org.opennms.web.notification.filter.NotificationCriteria) RedirectView(org.springframework.web.servlet.view.RedirectView) MissingParameterException(org.opennms.web.servlet.MissingParameterException)

Aggregations

NotificationIdListFilter (org.opennms.web.notification.filter.NotificationIdListFilter)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Test (org.junit.Test)1 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)1 Filter (org.opennms.web.filter.Filter)1 Notification (org.opennms.web.notification.Notification)1 NotificationCriteria (org.opennms.web.notification.filter.NotificationCriteria)1 MissingParameterException (org.opennms.web.servlet.MissingParameterException)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1 RedirectView (org.springframework.web.servlet.view.RedirectView)1