use of org.codice.ddf.system.alerts.Alert in project ddf by codice.
the class AdminAlertImpl method getAlerts.
@Override
public List<Map<String, Object>> getAlerts() {
List<Map<String, Object>> alerts = new ArrayList<>();
try {
List<Map<String, Object>> results = persistentStore.get("alerts", activeAlertQuery);
if (!results.isEmpty()) {
for (Map<String, Object> item : results) {
item = PersistentItem.stripSuffixes(item);
// strings/sets of strings. Single value sets will come back as strings.
if (item.get(SystemNotice.SYSTEM_NOTICE_DETAILS_KEY) instanceof String) {
item.put(SystemNotice.SYSTEM_NOTICE_DETAILS_KEY, Collections.singleton(item.get(SystemNotice.SYSTEM_NOTICE_DETAILS_KEY)));
}
escapeStrings(item);
alerts.add(item);
}
}
} catch (PersistenceException pe) {
LOGGER.debug("Error retrieving system alert.", pe);
return Collections.singletonList(new Alert("unable_to_retrieve_alerts", NoticePriority.CRITICAL, "Persistent Storage Not Responding. Could Not Retrieve Alerts.", Collections.singleton("Critical alerts may be present, but not displayed because the persistent storage is not responding.")).getProperties());
}
alerts.sort((map1, map2) -> new Alert(map1).getPriority().value() >= new Alert(map2).getPriority().value() ? -1 : 1);
return alerts;
}
use of org.codice.ddf.system.alerts.Alert in project ddf by codice.
the class AlertListenerTest method testHandleEventExistingAlert.
@Test
public void testHandleEventExistingAlert() throws Exception {
SystemNotice notice = new SystemNotice("test-source", NoticePriority.IMPORTANT, "title", new HashSet());
Map<String, Object> props = notice.getProperties();
props.put("event.topics", "decanter/alert/test");
Alert alert = new Alert(props);
ArgumentCaptor<PersistentItem> captor = ArgumentCaptor.forClass(PersistentItem.class);
Event event = new Event("decanter/alert/test", alert.getProperties());
when(persistentStore.get(any(), any())).thenReturn(Collections.singletonList(toSolr(alert)));
alertListener.handleEvent(event);
verify(persistentStore).add(eq("alerts"), captor.capture());
PersistentItem item = captor.getValue();
assertThat(item.getLongProperty(Alert.ALERT_COUNT), equalTo(2L));
}
use of org.codice.ddf.system.alerts.Alert in project ddf by codice.
the class AlertListenerTest method testHandleEventDismiss.
@Test
public void testHandleEventDismiss() throws Exception {
Alert alert = new Alert("test-source", NoticePriority.IMPORTANT, "title", new HashSet());
ArgumentCaptor<PersistentItem> captor = ArgumentCaptor.forClass(PersistentItem.class);
Map<String, String> dismissEvent = new HashMap<>();
dismissEvent.put(Alert.SYSTEM_NOTICE_ID_KEY, alert.getId());
dismissEvent.put(Alert.ALERT_DISMISSED_BY, "test-user");
Event event = new Event(Alert.ALERT_DISMISS_TOPIC, dismissEvent);
when(persistentStore.get(any(), any())).thenReturn(Collections.singletonList(toSolr(alert)));
alertListener.handleEvent(event);
verify(persistentStore).add(eq("alerts"), captor.capture());
PersistentItem item = captor.getValue();
assertThat(item.getTextProperty(Alert.ALERT_DISMISSED_BY), equalTo("test-user"));
assertThat(item.getTextProperty(Alert.ALERT_STATUS), equalTo(Alert.ALERT_DISMISSED_STATUS));
}
use of org.codice.ddf.system.alerts.Alert in project ddf by codice.
the class AlertListenerTest method testHandleEventFirstAlert.
@Test
public void testHandleEventFirstAlert() throws Exception {
SystemNotice notice = new SystemNotice("test-source", NoticePriority.IMPORTANT, "title", new HashSet());
Map<String, Object> props = notice.getProperties();
props.put("event.topics", "decanter/alert/test");
Alert alert = new Alert(props);
ArgumentCaptor<Event> captor = ArgumentCaptor.forClass(Event.class);
Event event = new Event("decanter/alert/test", notice.getProperties());
when(persistentStore.get(any(), any())).thenReturn(new ArrayList<>());
alertListener.handleEvent(event);
verify(persistentStore).add(eq("alerts"), any(PersistentItem.class));
}
use of org.codice.ddf.system.alerts.Alert in project ddf by codice.
the class AlertListener method dismissAlert.
private void dismissAlert(Event dismissEvent) {
String id = (String) dismissEvent.getProperty(Alert.SYSTEM_NOTICE_ID_KEY);
if (id == null) {
return;
}
Alert alert = getAlertById(id);
if (alert == null) {
LOGGER.debug("Could not find alert {} for dismissal.", id);
return;
}
String dismissedBy = (String) dismissEvent.getProperty(Alert.ALERT_DISMISSED_BY);
if (dismissedBy == null) {
LOGGER.debug("Could not dismiss alert {} because the {} property was not provided.", id, Alert.ALERT_DISMISSED_BY);
return;
}
addAlertToStore(alert.getDismissedAlert(dismissedBy));
}
Aggregations