use of org.codice.ddf.persistence.PersistentItem in project ddf by codice.
the class NotificationListener method handleEvent.
@Override
public void handleEvent(Event event) throws IllegalArgumentException {
LOGGER.debug("Received notification on topic {}", event.getTopic());
String id = (String) event.getProperty(Notification.NOTIFICATION_KEY_ID);
String application = (String) event.getProperty(Notification.NOTIFICATION_KEY_APPLICATION);
String message = (String) event.getProperty(Notification.NOTIFICATION_KEY_MESSAGE);
String timestamp = (String) event.getProperty(Notification.NOTIFICATION_KEY_TIMESTAMP);
String title = (String) event.getProperty(Notification.NOTIFICATION_KEY_TITLE);
String userId = (String) event.getProperty(Notification.NOTIFICATION_KEY_USER_ID);
if (StringUtils.isEmpty(userId)) {
throw new IllegalArgumentException("Event \"" + Notification.NOTIFICATION_KEY_USER_ID + "\" property is blank");
}
//TODO: Do we need to get extra properties out of event for Notification, i.e., STATUS and BYTES?
PersistentItem item = new PersistentItem();
item.addIdProperty(id);
item.addProperty(Notification.NOTIFICATION_KEY_USER_ID, userId);
item.addProperty(Notification.NOTIFICATION_KEY_TIMESTAMP, timestamp);
item.addProperty(Notification.NOTIFICATION_KEY_APPLICATION, application);
item.addProperty(Notification.NOTIFICATION_KEY_TITLE, title);
item.addProperty(Notification.NOTIFICATION_KEY_MESSAGE, message);
try {
persistentStore.add(PersistentStore.NOTIFICATION_TYPE, item);
} catch (PersistenceException e) {
}
}
use of org.codice.ddf.persistence.PersistentItem in project ddf by codice.
the class SubscriptionPersistor method metadataToPersistentItem.
/**
* Given subscription metadata, transform it into a persistent item for storage.
*/
private PersistentItem metadataToPersistentItem(SubscriptionMetadata metadata) {
notNull(metadata, "subscription metadata cannot be null");
PersistentItem persistentItem = new PersistentItem();
persistentItem.addProperty(VERSION_LABEL, VERSION);
persistentItem.addProperty(SUBSCRIPTION_ID_SOLR, metadata.getId());
persistentItem.addProperty(SUBSCRIPTION_TYPE, metadata.getTypeName());
persistentItem.addProperty(SUBSCRIPTION_FILTER, metadata.getFilter());
persistentItem.addProperty(SUBSCRIPTION_CALLBACK, metadata.getCallbackAddress());
return persistentItem;
}
use of org.codice.ddf.persistence.PersistentItem in project ddf by codice.
the class SubscriptionPersistor method insert.
/**
* Add the subscription metadata to the persistent store using its id for the document key.
* <p>
* Insertion operations with the same key overwrite the previous value, which means a duplicate
* being added is a no-op, minus the network overhead.
*
* @param metadata the subscription metadata to add to the persistent store.
* @throws SubscriptionStoreException if a problem occurs during insert.
*/
public void insert(SubscriptionMetadata metadata) {
LOGGER.debug("Adding [{}] to persistence store. ", metadata.getId());
PersistentItem persistentSubscription = metadataToPersistentItem(metadata);
try {
persistentStore.add(PersistentStore.EVENT_SUBSCRIPTIONS_TYPE, persistentSubscription);
} catch (PersistenceException e) {
throw new SubscriptionStoreException("Exception while persisting subscription: ", e);
}
}
Aggregations