Search in sources :

Example 56 with Event

use of org.osgi.service.event.Event in project ddf by codice.

the class SourceConfigurationHandlerTest method testIdentityNode.

@Test
public void testIdentityNode() {
    MetacardImpl mcard = new MetacardImpl();
    mcard.setAttribute(Metacard.TAGS, RegistryConstants.REGISTRY_TAG);
    mcard.setAttribute(RegistryObjectMetacardType.REGISTRY_ID, "myRegId");
    mcard.setAttribute(RegistryObjectMetacardType.REGISTRY_IDENTITY_NODE, true);
    Dictionary<String, Object> eventProperties = new Hashtable<>();
    eventProperties.put("ddf.catalog.event.metacard", mcard);
    Event event = new Event("ddf/catalog/event/CREATED", eventProperties);
    sch.handleEvent(event);
    event = new Event("ddf/catalog/event/UPDATED", eventProperties);
    sch.handleEvent(event);
    event = new Event("ddf/catalog/event/DELETED", eventProperties);
    sch.handleEvent(event);
    verify(executorService, never()).execute(any(Runnable.class));
}
Also used : Hashtable(java.util.Hashtable) Event(org.osgi.service.event.Event) Matchers.anyString(org.mockito.Matchers.anyString) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 57 with Event

use of org.osgi.service.event.Event in project ddf by codice.

the class SourceConfigurationHandlerTest method testNonRegistryMetacard.

@Test
public void testNonRegistryMetacard() {
    MetacardImpl metacard = new MetacardImpl();
    metacard.setAttribute(Metacard.TAGS, Metacard.DEFAULT_TAG);
    Dictionary<String, Object> eventProperties = new Hashtable<>();
    eventProperties.put("ddf.catalog.event.metacard", metacard);
    Event event = new Event("ddf/catalog/event/CREATED", eventProperties);
    sch.handleEvent(event);
    verify(executorService, never()).execute(any(Runnable.class));
}
Also used : Hashtable(java.util.Hashtable) Event(org.osgi.service.event.Event) Matchers.anyString(org.mockito.Matchers.anyString) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 58 with Event

use of org.osgi.service.event.Event in project ddf by codice.

the class SourceConfigurationHandlerTest method testRegistryMetacardExecutorCall.

@Test
public void testRegistryMetacardExecutorCall() {
    MetacardImpl mcard = new MetacardImpl();
    mcard.setAttribute(Metacard.TAGS, RegistryConstants.REGISTRY_TAG);
    mcard.setAttribute(RegistryObjectMetacardType.REGISTRY_ID, "urn:uuid:2014ca7f59ac46f495e32b4a67a51276");
    Dictionary<String, Object> eventProperties = new Hashtable<>();
    eventProperties.put("ddf.catalog.event.metacard", mcard);
    Event event = new Event("ddf/catalog/event/CREATED", eventProperties);
    sch.handleEvent(event);
    event = new Event("ddf/catalog/event/UPDATED", eventProperties);
    sch.handleEvent(event);
    event = new Event("ddf/catalog/event/DELETED", eventProperties);
    sch.handleEvent(event);
    verify(executorService, times(3)).execute(any(Runnable.class));
}
Also used : Hashtable(java.util.Hashtable) Event(org.osgi.service.event.Event) Matchers.anyString(org.mockito.Matchers.anyString) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 59 with Event

use of org.osgi.service.event.Event in project ddf by codice.

the class SourceConfigurationHandlerTest method testNullMetacard.

@Test
public void testNullMetacard() {
    Dictionary<String, Object> eventProperties = new Hashtable<>();
    Event event = new Event("ddf/catalog/event/CREATED", eventProperties);
    sch.handleEvent(event);
    verify(executorService, never()).execute(any(Runnable.class));
}
Also used : Hashtable(java.util.Hashtable) Event(org.osgi.service.event.Event) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 60 with Event

use of org.osgi.service.event.Event in project ddf by codice.

the class EventProcessorImpl method processEntry.

/**
     * Processes an entry by adding properties from the metacard to the event. Then the eventAdmin
     * is used to post the metacard properties as a single event.
     *
     * @param metacard   - the metacard to process
     * @param operation  - The type of event {@link ddf.catalog.pubsub.internal.PubSubConstants}
     * @param eventAdmin - OSGi EventAdmin service used post events
     */
public static void processEntry(Metacard metacard, String operation, EventAdmin eventAdmin) {
    String methodName = "processEntry";
    LOGGER.debug("ENTERING: " + methodName);
    if (metacard != null) {
        LOGGER.debug("Input Metacard:{}\n", metacard.toString());
        LOGGER.debug("catalog ID = {}", metacard.getId());
        LOGGER.debug("operation = {}", operation);
        HashMap<String, Object> properties = new HashMap<>(3, 1);
        // Common headers
        properties.put(PubSubConstants.HEADER_OPERATION_KEY, operation);
        properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
        // ENTRY ID INFORMATION
        // TODO: probably don't need to pass this through since they can get the metacard
        properties.put(PubSubConstants.HEADER_ID_KEY, metacard.getId());
        try {
            URI uri = metacard.getResourceURI();
            if (uri != null) {
                String productUri = uri.toString();
                LOGGER.debug("Processing incoming entry.  Adding DAD URI to event properties: {}", productUri);
                // TODO: probably just get this info from the Metacard, Probably don't need to
                // create new property for this
                properties.put(PubSubConstants.HEADER_DAD_KEY, productUri);
            }
        } catch (Exception e) {
            LOGGER.debug("Unable to obtain resource URL, will not be considered in subscription", e);
        }
        // CONTENT TYPE INFORMATION
        String type = metacard.getContentTypeName();
        String contentType = "UNKNOWN";
        if (type != null) {
            contentType = type;
        } else {
            LOGGER.debug("contentType is null");
        }
        String version = metacard.getContentTypeVersion();
        contentType = contentType + "," + (version == null ? "" : version);
        LOGGER.debug("contentType = {}", contentType);
        properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, contentType);
        // CONTEXTUAL INFORMATION
        if (metacard.getMetadata() != null) {
            try {
                // Build Lucene search index on entry's entire metadata using
                // default XPaths (specified
                // in ContextualEvaluator) - this index will be used by all
                // contextual predicates that do
                // *NOT* specify any textPaths. (Building index here optimizes
                // code so that this index is
                // not built for every contextual subscription that has no
                // textPaths.)
                Directory index = ContextualEvaluator.buildIndex(metacard.getMetadata());
                // Build contextual info to be sent in event for this entry.
                // Include the default Lucene search
                // index and the entry's metadata (in case subscription has
                // textPaths, then it can create Lucene
                // search indices on the metadata using its textPaths)
                Map<String, Object> contextualMap = new HashMap<>(2, 1);
                contextualMap.put("DEFAULT_INDEX", index);
                contextualMap.put("METADATA", metacard.getMetadata());
                properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
            } catch (Exception e) {
                LOGGER.info("Exception updating context map", e);
            }
        }
        if (eventAdmin != null) {
            eventAdmin.postEvent(new Event(PubSubConstants.PUBLISHED_EVENT_TOPIC_NAME, properties));
        } else {
            LOGGER.debug("Unable to post event since eventAdmin is null.");
        }
    } else {
        LOGGER.debug("Unable to post null metacard.");
    }
    LOGGER.debug("EXITING: {}", methodName);
}
Also used : HashMap(java.util.HashMap) Event(org.osgi.service.event.Event) URI(java.net.URI) SubscriptionNotFoundException(ddf.catalog.event.SubscriptionNotFoundException) SubscriptionExistsException(ddf.catalog.event.SubscriptionExistsException) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException) InvalidSubscriptionException(ddf.catalog.event.InvalidSubscriptionException) Directory(org.apache.lucene.store.Directory)

Aggregations

Event (org.osgi.service.event.Event)142 Test (org.junit.Test)79 HashMap (java.util.HashMap)48 Hashtable (java.util.Hashtable)44 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)23 ContentTypePredicate (ddf.catalog.pubsub.predicate.ContentTypePredicate)20 EventAdmin (org.osgi.service.event.EventAdmin)19 GeospatialPredicate (ddf.catalog.pubsub.predicate.GeospatialPredicate)18 Predicate (ddf.catalog.pubsub.predicate.Predicate)16 ArrayList (java.util.ArrayList)16 ActivityEvent (org.codice.ddf.activities.ActivityEvent)13 EventHandler (org.osgi.service.event.EventHandler)13 SubscriptionFilterVisitor (ddf.catalog.pubsub.internal.SubscriptionFilterVisitor)11 Date (java.util.Date)11 Job (org.apache.sling.event.jobs.Job)9 Map (java.util.Map)8 List (java.util.List)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 JobManager (org.apache.sling.event.jobs.JobManager)7 JobConsumer (org.apache.sling.event.jobs.consumer.JobConsumer)7