Search in sources :

Example 11 with ContentTypePredicate

use of ddf.catalog.pubsub.predicate.ContentTypePredicate in project ddf by codice.

the class SubscriptionFilterVisitor method visit.

/**
     * PropertyIsLike filter maps to a Contextual search criteria.
     */
@Override
public Object visit(PropertyIsLike filter, Object data) {
    LOGGER.debug("ENTERING: PropertyIsLike filter");
    String wildcard = filter.getWildCard();
    String escape = filter.getEscape();
    String single = filter.getSingleChar();
    boolean isFuzzy = false;
    List<String> textPathList = null;
    LikeFilterImpl likeFilter = (LikeFilterImpl) filter;
    Expression expression = likeFilter.getExpression();
    // ContentTypePredicate
    if (expression instanceof PropertyName) {
        PropertyName propertyName = (PropertyName) expression;
        if (Metacard.CONTENT_TYPE.equals(propertyName.getPropertyName())) {
            LOGGER.debug("Expression is ContentType.");
            String typeValue = likeFilter.getLiteral();
            ContentTypePredicate predicate = new ContentTypePredicate(typeValue, null);
            return predicate;
        } else if (Metacard.CONTENT_TYPE_VERSION.equals(propertyName.getPropertyName())) {
            LOGGER.debug("Expression is ContentTypeVersion.");
            String versionValue = likeFilter.getLiteral();
            ContentTypePredicate predicate = new ContentTypePredicate(null, versionValue);
            return predicate;
        }
    }
    if (expression instanceof AttributeExpressionImpl) {
        AttributeExpressionImpl textPathExpression = (AttributeExpressionImpl) expression;
        textPathList = extractXpathSelectors(textPathExpression);
    } else if (expression instanceof FuzzyFunction) {
        FuzzyFunction fuzzyFunction = (FuzzyFunction) expression;
        LOGGER.debug("fuzzy search");
        isFuzzy = true;
        List<Expression> expressions = fuzzyFunction.getParameters();
        AttributeExpressionImpl firstExpression = (AttributeExpressionImpl) expressions.get(0);
        if (!Metacard.ANY_TEXT.equals(firstExpression.getPropertyName())) {
            LOGGER.debug("fuzzy search has a text path section");
            textPathList = extractXpathSelectors(firstExpression);
        }
    }
    String searchPhrase = likeFilter.getLiteral();
    LOGGER.debug("raw searchPhrase = [{}]", searchPhrase);
    String sterilizedSearchPhrase = sterilize(searchPhrase, wildcard, escape, single);
    LOGGER.debug("sterilizedSearchPhrase = [{}]", sterilizedSearchPhrase);
    ContextualPredicate contextPred = new ContextualPredicate(sterilizedSearchPhrase, isFuzzy, likeFilter.isMatchingCase(), textPathList);
    LOGGER.debug("EXITING: PropertyIsLike filter");
    return contextPred;
}
Also used : PropertyName(org.opengis.filter.expression.PropertyName) FuzzyFunction(ddf.catalog.impl.filter.FuzzyFunction) LikeFilterImpl(org.geotools.filter.LikeFilterImpl) Expression(org.opengis.filter.expression.Expression) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) ContextualPredicate(ddf.catalog.pubsub.predicate.ContextualPredicate) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) ArrayList(java.util.ArrayList) List(java.util.List)

Example 12 with ContentTypePredicate

use of ddf.catalog.pubsub.predicate.ContentTypePredicate in project ddf by codice.

the class ContentTypeEvaluator method evaluate.

public static boolean evaluate(ContentTypeEvaluationCriteriaImpl ctec) {
    String methodName = "evaluate";
    LOGGER.debug("ENTERING: {}", methodName);
    ContentTypePredicate matchContentTypePredicate = ctec.getContentType();
    String matchType = matchContentTypePredicate.getType();
    String matchVersion = matchContentTypePredicate.getVersion();
    // to handle the wildcard.
    if (matchType != null) {
        matchType = matchType.replaceAll("\\*", ".*");
    }
    if (matchVersion != null) {
        matchVersion = matchVersion.replaceAll("\\*", ".*");
    }
    String input = ctec.getInputContentType();
    LOGGER.debug("Match ContentType: {}", matchContentTypePredicate);
    String inputType;
    String inputVersion;
    //Check if both type and version are blank
    if (input == null || input.matches(",")) {
        inputType = "null";
        inputVersion = "null";
    } else {
        String[] inputTypeVersionPair = input.split(",");
        //Check if content type is blank. If yes, set to null.
        if (inputTypeVersionPair[0].isEmpty()) {
            inputType = "null";
        } else {
            inputType = inputTypeVersionPair[0];
        }
        //Check if version is blank. If yes, set to null.
        if (inputTypeVersionPair.length == 1) {
            inputVersion = "null";
        } else {
            inputVersion = inputTypeVersionPair[1];
        }
    }
    LOGGER.debug("inputType = {}, inputVersion = {}", inputType, inputVersion);
    LOGGER.debug("matchType = {}, matchVersion = {}", matchType, matchVersion);
    if (matchType != null && !matchType.isEmpty() && inputType.matches(matchType)) {
        if (matchVersion != null && !matchVersion.isEmpty() && !inputVersion.matches(matchVersion)) {
            LOGGER.debug("EXITING: {} - returning false.  Did not match version.", methodName);
            return false;
        }
        LOGGER.debug("EXITING: {} - returning true.", methodName);
        return true;
    }
    LOGGER.debug("EXITING: {} - returning false.", methodName);
    return false;
}
Also used : ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate)

Example 13 with ContentTypePredicate

use of ddf.catalog.pubsub.predicate.ContentTypePredicate in project ddf by codice.

the class PredicateTest method testContentTypeEvaluatorTypeAndVersionTypeMismatch.

@Test
public void testContentTypeEvaluatorTypeAndVersionTypeMismatch() throws Exception {
    LOGGER.debug("**************************  START: testContentTypeEvaluator_TypeAndVersion_TypeMismatch()  ***********************");
    // Match on "nitf, v20"
    ContentTypePredicate predicate = new ContentTypePredicate("nitf", "v20");
    String inputContentType = "video,v20";
    ContentTypeEvaluationCriteriaImpl ctec = new ContentTypeEvaluationCriteriaImpl(predicate, inputContentType);
    boolean status = ContentTypeEvaluator.evaluate(ctec);
    assertFalse(status);
    LOGGER.debug("**************************  END: testContentTypeEvaluator_TypeAndVersion_TypeMismatch()  ***********************");
}
Also used : ContentTypeEvaluationCriteriaImpl(ddf.catalog.pubsub.criteria.contenttype.ContentTypeEvaluationCriteriaImpl) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) Test(org.junit.Test)

Aggregations

ContentTypePredicate (ddf.catalog.pubsub.predicate.ContentTypePredicate)13 Test (org.junit.Test)9 ContentTypeEvaluationCriteriaImpl (ddf.catalog.pubsub.criteria.contenttype.ContentTypeEvaluationCriteriaImpl)5 HashMap (java.util.HashMap)4 Event (org.osgi.service.event.Event)4 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)3 ContextualPredicate (ddf.catalog.pubsub.predicate.ContextualPredicate)3 ArrayList (java.util.ArrayList)3 EntryPredicate (ddf.catalog.pubsub.predicate.EntryPredicate)2 GeospatialPredicate (ddf.catalog.pubsub.predicate.GeospatialPredicate)2 Predicate (ddf.catalog.pubsub.predicate.Predicate)2 TemporalPredicate (ddf.catalog.pubsub.predicate.TemporalPredicate)2 AttributeExpressionImpl (org.geotools.filter.AttributeExpressionImpl)2 FuzzyFunction (ddf.catalog.impl.filter.FuzzyFunction)1 SubscriptionFilterVisitor (ddf.catalog.pubsub.internal.SubscriptionFilterVisitor)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 List (java.util.List)1 LikeFilterImpl (org.geotools.filter.LikeFilterImpl)1 LiteralExpressionImpl (org.geotools.filter.LiteralExpressionImpl)1