Search in sources :

Example 11 with PersistentItem

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) {
    }
}
Also used : PersistentItem(org.codice.ddf.persistence.PersistentItem) PersistenceException(org.codice.ddf.persistence.PersistenceException)

Example 12 with PersistentItem

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;
}
Also used : PersistentItem(org.codice.ddf.persistence.PersistentItem)

Example 13 with 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);
    }
}
Also used : SubscriptionStoreException(org.codice.ddf.catalog.subscriptionstore.internal.SubscriptionStoreException) PersistentItem(org.codice.ddf.persistence.PersistentItem) PersistenceException(org.codice.ddf.persistence.PersistenceException)

Aggregations

PersistentItem (org.codice.ddf.persistence.PersistentItem)13 PersistenceException (org.codice.ddf.persistence.PersistenceException)9 Map (java.util.Map)6 PersistentStore (org.codice.ddf.persistence.PersistentStore)3 Subject (ddf.security.Subject)2 IOException (java.io.IOException)2 StringReader (java.io.StringReader)2 ParseException (java.text.ParseException)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Listener (org.cometd.annotation.Listener)2 ServerMessage (org.cometd.bayeux.server.ServerMessage)2 JSONContext (org.cometd.common.JSONContext)2 Jackson1JSONContextClient (org.cometd.common.Jackson1JSONContextClient)2 Jackson1JSONContextServer (org.cometd.server.Jackson1JSONContextServer)2 ServerMessageImpl (org.cometd.server.ServerMessageImpl)2 ImmutableMap (com.google.common.collect.ImmutableMap)1