Search in sources :

Example 6 with NotificationCriteria

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

the class WebNotificationRepositoryFilterIT method testResponderFilter.

@Test
@Transactional
public void testResponderFilter() {
    m_daoNotificationRepo.acknowledgeMatchingNotification("TestUser", new Date(), new NotificationCriteria());
    ResponderFilter filter = new ResponderFilter("TestUser");
    assert1Result(filter);
}
Also used : ResponderFilter(org.opennms.web.notification.filter.ResponderFilter) NotificationCriteria(org.opennms.web.notification.filter.NotificationCriteria) Date(java.util.Date) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with NotificationCriteria

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

the class WebNotificationRepositoryFilterIT method assert1Result.

private void assert1Result(Filter filter) {
    System.out.println(filter.getSql());
    NotificationCriteria criteria = new NotificationCriteria(filter);
    Notification[] notifs = m_daoNotificationRepo.getMatchingNotifications(criteria);
    assertEquals(1, notifs.length);
}
Also used : NotificationCriteria(org.opennms.web.notification.filter.NotificationCriteria)

Example 8 with NotificationCriteria

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

the class WebNotificationRepositoryFilterIT method testAcknowledgeByFilter.

@Test
@Transactional
public void testAcknowledgeByFilter() {
    m_daoNotificationRepo.acknowledgeMatchingNotification("TestUser", new Date(), new NotificationCriteria());
    AcknowledgedByFilter filter = new AcknowledgedByFilter("TestUser");
    assert1Result(filter);
}
Also used : NotificationCriteria(org.opennms.web.notification.filter.NotificationCriteria) AcknowledgedByFilter(org.opennms.web.notification.filter.AcknowledgedByFilter) Date(java.util.Date) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with NotificationCriteria

use of org.opennms.web.notification.filter.NotificationCriteria 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

NotificationCriteria (org.opennms.web.notification.filter.NotificationCriteria)9 Test (org.junit.Test)6 Transactional (org.springframework.transaction.annotation.Transactional)5 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 Filter (org.opennms.web.filter.Filter)4 AcknowledgedByFilter (org.opennms.web.notification.filter.AcknowledgedByFilter)4 Notification (org.opennms.web.notification.Notification)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 HashMap (java.util.HashMap)1 TreeSet (java.util.TreeSet)1 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 Event (org.opennms.web.event.Event)1 EventCriteria (org.opennms.web.event.filter.EventCriteria)1 EventIdListFilter (org.opennms.web.event.filter.EventIdListFilter)1 AcknowledgeType (org.opennms.web.notification.AcknowledgeType)1 NoticeQueryParms (org.opennms.web.notification.NoticeQueryParms)1 SortStyle (org.opennms.web.notification.SortStyle)1 NotificationIdListFilter (org.opennms.web.notification.filter.NotificationIdListFilter)1