use of org.codice.ddf.system.alerts.Alert in project ddf by codice.
the class AlertListener method handleEvent.
/**
* Processes alert events and stores them in the persistent store. Because this handler 'squashes'
* alerts into one entry it needs to be synchronized to be thread safe.
*
* @param event The osgi alert event
* @throws IllegalArgumentException
*/
@Override
public synchronized void handleEvent(Event event) throws IllegalArgumentException {
if (Alert.ALERT_DISMISS_TOPIC.equals(event.getTopic())) {
dismissAlert(event);
return;
}
// need source to lookup previous alerts
if (event.getProperty(Alert.SYSTEM_NOTICE_SOURCE_KEY) == null) {
return;
}
LOGGER.debug("Received alert event on topic {}", event.getTopic());
Alert alert = getAlertFromEvent(event);
Alert existingAlert = getAlertBySource(alert.getSource());
if (existingAlert != null) {
Map<String, Object> properties = alert.getProperties();
properties.put(Alert.SYSTEM_NOTICE_ID_KEY, existingAlert.getId());
properties.put(Alert.ALERT_COUNT, existingAlert.getCount() + 1);
properties.put(Alert.SYSTEM_NOTICE_TIME_KEY, existingAlert.getTime());
alert = new Alert(properties);
}
addAlertToStore(alert);
}
Aggregations