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));
}
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));
}
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));
}
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));
}
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);
}
Aggregations