Search in sources :

Example 1 with ContextualEvaluationCriteriaImpl

use of ddf.catalog.pubsub.criteria.contextual.ContextualEvaluationCriteriaImpl in project ddf by codice.

the class ContextualPredicate method matches.

@Override
public boolean matches(Event properties) {
    String methodName = "matches";
    LOGGER.debug("ENTERING: {}", methodName);
    LOGGER.debug("Headers: {}", properties);
    ContextualEvaluationCriteria cec = null;
    Map<String, Object> contextualMap = (Map<String, Object>) properties.getProperty(PubSubConstants.HEADER_CONTEXTUAL_KEY);
    if (contextualMap == null) {
        LOGGER.debug("No contextual metadata to search against.");
        return false;
    }
    String operation = (String) properties.getProperty(PubSubConstants.HEADER_OPERATION_KEY);
    LOGGER.debug("operation = {}", operation);
    String metadata = (String) contextualMap.get("METADATA");
    LOGGER.debug("metadata = [{}]", metadata);
    // cannot apply any contextual filtering - just send the event on to the subscriber
    if (operation.equals(PubSubConstants.DELETE) && metadata.equals(PubSubConstants.METADATA_DELETED)) {
        LOGGER.debug("Detected a DELETE operation where metadata is just the word 'deleted', so send event on to subscriber");
        return true;
    }
    // text paths)
    if (this.textPaths != null && !this.textPaths.isEmpty()) {
        LOGGER.debug("creating criteria with textPaths and metadata document");
        try {
            cec = new ContextualEvaluationCriteriaImpl(searchPhrase, fuzzy, caseSensitiveSearch, this.textPaths.toArray(new String[this.textPaths.size()]), (String) contextualMap.get("METADATA"));
        } catch (IOException e) {
            LOGGER.debug("IO exception during context evaluation", e);
            return false;
        }
    // This predicate has no text paths specified, so can use default Lucene search index, which
    // indexed the entry's entire metadata
    // per the default XPath expressions in ContextualEvaluator, from the event's properties
    // data
    } else {
        LOGGER.debug("using default Lucene search index for metadata");
        cec = new ContextualEvaluationCriteriaImpl(searchPhrase, fuzzy, caseSensitiveSearch, (Directory) contextualMap.get("DEFAULT_INDEX"));
    }
    try {
        return ContextualEvaluator.evaluate(cec);
    } catch (IOException e) {
        LOGGER.debug("IO Exception evaluating context criteria", e);
    } catch (ParseException e) {
        LOGGER.debug("Parse Exception evaluating context criteria", e);
    }
    LOGGER.debug("EXITING: {}", methodName);
    return false;
}
Also used : ContextualEvaluationCriteria(ddf.catalog.pubsub.criteria.contextual.ContextualEvaluationCriteria) IOException(java.io.IOException) ParseException(org.apache.lucene.queryParser.ParseException) ContextualEvaluationCriteriaImpl(ddf.catalog.pubsub.criteria.contextual.ContextualEvaluationCriteriaImpl) Map(java.util.Map) Directory(org.apache.lucene.store.Directory)

Aggregations

ContextualEvaluationCriteria (ddf.catalog.pubsub.criteria.contextual.ContextualEvaluationCriteria)1 ContextualEvaluationCriteriaImpl (ddf.catalog.pubsub.criteria.contextual.ContextualEvaluationCriteriaImpl)1 IOException (java.io.IOException)1 Map (java.util.Map)1 ParseException (org.apache.lucene.queryParser.ParseException)1 Directory (org.apache.lucene.store.Directory)1