use of org.opennms.web.notification.filter.NotificationCriteria in project opennms by OpenNMS.
the class WebNotificationRepositoryFilterIT method testServiceFilter.
@Test
// Relies on specific IDs so we need a fresh database
@JUnitTemporaryDatabase
public void testServiceFilter() {
Notification[] notifs = m_daoNotificationRepo.getMatchingNotifications(new NotificationCriteria());
System.out.println(notifs[0].getServiceId());
ServiceFilter filter = new ServiceFilter(1, null);
assert1Result(filter);
}
use of org.opennms.web.notification.filter.NotificationCriteria in project opennms by OpenNMS.
the class DaoWebNotificationRepositoryIT method testAcknowledgeNotification.
@Test
@Transactional
public void testAcknowledgeNotification() {
m_daoNotificationRepo.acknowledgeMatchingNotification("TestUser", new Date(), new NotificationCriteria());
int notifCount = m_daoNotificationRepo.countMatchingNotifications(new NotificationCriteria(new AcknowledgedByFilter("TestUser")));
assertEquals(1, notifCount);
Notification[] notif = m_daoNotificationRepo.getMatchingNotifications(new NotificationCriteria(new AcknowledgedByFilter("TestUser")));
assertEquals(1, notif.length);
assertEquals("TestUser", notif[0].m_responder);
}
use of org.opennms.web.notification.filter.NotificationCriteria in project opennms by OpenNMS.
the class DaoWebNotificationRepositoryIT method testNotificationCount.
@Test
@Transactional
public void testNotificationCount() {
List<Filter> filterList = new ArrayList<>();
Filter[] filters = filterList.toArray(new Filter[0]);
AcknowledgeType ackType = AcknowledgeType.UNACKNOWLEDGED;
int notificationCount = m_daoNotificationRepo.countMatchingNotifications(new NotificationCriteria(ackType, filters));
assertEquals(1, notificationCount);
}
use of org.opennms.web.notification.filter.NotificationCriteria in project opennms by OpenNMS.
the class DaoWebNotificationRepositoryIT method testGetMatchingNotifications.
@Test
@Transactional
public void testGetMatchingNotifications() {
List<Filter> filterList = new ArrayList<>();
int limit = 10;
int multiple = 0;
AcknowledgeType ackType = AcknowledgeType.UNACKNOWLEDGED;
SortStyle sortStyle = SortStyle.DEFAULT_SORT_STYLE;
Filter[] filters = filterList.toArray(new Filter[0]);
Notification[] notices = m_daoNotificationRepo.getMatchingNotifications(new NotificationCriteria(filters, sortStyle, ackType, limit, limit * multiple));
assertEquals(1, notices.length);
assertEquals("This is a test notification", notices[0].getTextMessage());
}
use of org.opennms.web.notification.filter.NotificationCriteria in project opennms by OpenNMS.
the class NotificationFilterController method handleRequestInternal.
/**
* {@inheritDoc}
*
* Parses the query string to determine what types of notification filters to use
* (for example, what to filter on or sort by), then does the database query
* and then forwards the results to a JSP for display.
*/
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
String display = request.getParameter("display");
// handle the style sort parameter
String sortStyleString = request.getParameter("sortby");
SortStyle sortStyle = m_defaultSortStyle;
if (sortStyleString != null) {
SortStyle temp = SortStyle.getSortStyle(sortStyleString);
if (temp != null) {
sortStyle = temp;
}
}
// handle the acknowledgment type parameter
String ackTypeString = request.getParameter("acktype");
AcknowledgeType ackType = m_defaultAckType;
if (ackTypeString != null) {
AcknowledgeType temp = AcknowledgeType.getAcknowledgeType(ackTypeString);
if (temp != null) {
ackType = temp;
}
}
// handle the filter parameters
String[] filterStrings = request.getParameterValues("filter");
List<Filter> filterList = new ArrayList<>();
if (filterStrings != null) {
for (String filterString : filterStrings) {
Filter filter = NoticeUtil.getFilter(filterString, getServletContext());
if (filter != null) {
filterList.add(filter);
}
}
}
// Check for a username filter (used on notifications/index.jsp)
String username = request.getParameter("user");
if (username != null) {
Filter filter = NoticeUtil.getFilter("user=" + username, getServletContext());
if (filter != null) {
filterList.add(filter);
}
}
// handle the optional limit parameter
String limitString = request.getParameter("limit");
int limit = "long".equals(display) ? m_defaultLongLimit : m_defaultShortLimit;
if (limitString != null) {
try {
int newlimit = WebSecurityUtils.safeParseInt(limitString);
if (newlimit > 0) {
limit = newlimit;
}
} catch (NumberFormatException e) {
// do nothing, the default is already set
}
}
// handle the optional multiple parameter
String multipleString = request.getParameter("multiple");
int multiple = DEFAULT_MULTIPLE;
if (multipleString != null) {
try {
multiple = Math.max(0, WebSecurityUtils.safeParseInt(multipleString));
} catch (NumberFormatException e) {
}
}
// put the parameters in a convenient struct
Filter[] filters = filterList.toArray(new Filter[0]);
NoticeQueryParms parms = new NoticeQueryParms();
parms.ackType = ackType;
parms.display = display;
parms.filters = filterList;
parms.limit = limit;
parms.multiple = multiple;
parms.sortStyle = sortStyle;
NotificationCriteria queryCriteria = new NotificationCriteria(filters, sortStyle, ackType, limit, limit * multiple);
NotificationCriteria countCriteria = new NotificationCriteria(ackType, filters);
Notification[] notices = m_webNotificationRepository.getMatchingNotifications(queryCriteria);
int noticeCount = m_webNotificationRepository.countMatchingNotifications(countCriteria);
final Map<Integer, String[]> nodeLabels = new HashMap<Integer, String[]>();
final Map<Integer, String[]> nodeLocations = new HashMap<Integer, String[]>();
Set<Integer> eventIds = new TreeSet<>();
// really inefficient, is there a better way to do this?
for (Notification notice : notices) {
if (notice.getEventId() > 0) {
eventIds.add(notice.getEventId());
}
if (notice.getNodeId() > 0) {
if (!nodeLabels.containsKey(notice.getNodeId())) {
String[] labels = null;
String[] locations = null;
OnmsNode node = m_nodeDao.get(notice.getNodeId());
if (node != null) {
String longLabel = node.getLabel();
if (longLabel == null) {
labels = new String[] { "<No Node Label>", "<No Node Label>" };
} else {
if (longLabel.length() > 32) {
String shortLabel = longLabel.substring(0, 31) + "…";
labels = new String[] { shortLabel, longLabel };
} else {
labels = new String[] { longLabel, longLabel };
}
}
if (node.getLocation() != null) {
String location = node.getLocation().getLocationName();
if (location == null) {
locations = new String[] { "<No Node Location>", "<No Node Location>" };
} else {
if (location.length() > 32) {
String shortLocation = location.substring(0, 31) + "…";
locations = new String[] { shortLocation, location };
} else {
locations = new String[] { location, location };
}
}
}
}
nodeLabels.put(notice.getNodeId(), labels);
nodeLocations.put(notice.getNodeId(), locations);
}
}
}
Map<Integer, Event> events = new HashMap<Integer, Event>();
if (eventIds.size() > 0) {
for (Event e : m_webEventRepository.getMatchingEvents(new EventCriteria(new EventIdListFilter(eventIds)))) {
events.put(e.getId(), e);
}
}
ModelAndView modelAndView = new ModelAndView(m_successView);
modelAndView.addObject("notices", notices);
modelAndView.addObject("noticeCount", noticeCount);
modelAndView.addObject("nodeLabels", nodeLabels);
modelAndView.addObject("nodeLocations", nodeLocations);
modelAndView.addObject("events", events);
modelAndView.addObject("parms", parms);
return modelAndView;
}
Aggregations