Search in sources :

Example 11 with AttributeExpressionImpl

use of org.geotools.filter.AttributeExpressionImpl in project ddf by codice.

the class OpenSearchQueryTest method verifyLikeFilter.

private void verifyLikeFilter(Filter filter, String expectedPropertyName, String expectedValue) {
    assertTrue(filter instanceof LikeFilterImpl);
    LikeFilterImpl likeFilter = (LikeFilterImpl) filter;
    AttributeExpressionImpl expression = (AttributeExpressionImpl) likeFilter.getExpression();
    LOGGER.debug("propertyName = {}", expression.getPropertyName());
    assertEquals(expectedPropertyName, expression.getPropertyName());
    String pattern = likeFilter.getLiteral();
    LOGGER.debug("value to search for = {}", pattern);
    assertEquals(expectedValue, pattern);
}
Also used : LikeFilterImpl(org.geotools.filter.LikeFilterImpl) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl)

Example 12 with AttributeExpressionImpl

use of org.geotools.filter.AttributeExpressionImpl in project ddf by codice.

the class OpenSearchQueryTest method verifyEqualsFilter.

private void verifyEqualsFilter(Filter filter, String expectedPropertyName, String expectedValue) {
    assertTrue(filter instanceof IsEqualsToImpl);
    IsEqualsToImpl equalsFilter = (IsEqualsToImpl) filter;
    AttributeExpressionImpl expression1 = (AttributeExpressionImpl) equalsFilter.getExpression1();
    LOGGER.debug("propertyName = {}", expression1.getPropertyName());
    assertEquals(expectedPropertyName, expression1.getPropertyName());
    LiteralExpressionImpl expression2 = (LiteralExpressionImpl) equalsFilter.getExpression2();
    LOGGER.debug("version to search for = {}", expression2.getValue());
    assertEquals(expectedValue, expression2.getValue());
}
Also used : AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl) IsEqualsToImpl(org.geotools.filter.IsEqualsToImpl)

Example 13 with AttributeExpressionImpl

use of org.geotools.filter.AttributeExpressionImpl in project ddf by codice.

the class OpenSearchFilterVisitor method visit.

/**
     * PropertyIsLike filter maps to a Contextual search criteria.
     */
@Override
public Object visit(PropertyIsLike filter, Object data) {
    LOGGER.trace("ENTERING: PropertyIsLike filter");
    if (currentNest != NestedTypes.NOT) {
        LikeFilterImpl likeFilter = (LikeFilterImpl) filter;
        AttributeExpressionImpl expression = (AttributeExpressionImpl) likeFilter.getExpression();
        String selectors = expression.getPropertyName();
        LOGGER.debug("selectors = {}", selectors);
        String searchPhrase = likeFilter.getLiteral();
        LOGGER.debug("searchPhrase = [{}]", searchPhrase);
        if (contextualSearch != null) {
            contextualSearch.setSearchPhrase(contextualSearch.getSearchPhrase() + " " + currentNest.toString() + " " + searchPhrase);
        } else {
            contextualSearch = new ContextualSearch(selectors, searchPhrase, likeFilter.isMatchingCase());
        }
    }
    LOGGER.trace("EXITING: PropertyIsLike filter");
    return super.visit(filter, data);
}
Also used : LikeFilterImpl(org.geotools.filter.LikeFilterImpl) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl)

Example 14 with AttributeExpressionImpl

use of org.geotools.filter.AttributeExpressionImpl in project ddf by codice.

the class TestCswRecordMapperFilterVisitor method testVisitWithBoundingBoxProperty.

@Test
public void testVisitWithBoundingBoxProperty() {
    AttributeExpressionImpl propName = new AttributeExpressionImpl(new NameImpl(new QName(CswConstants.DUBLIN_CORE_SCHEMA, CswConstants.OWS_BOUNDING_BOX, CswConstants.DUBLIN_CORE_NAMESPACE_PREFIX)));
    CswRecordMapperFilterVisitor visitor = new CswRecordMapperFilterVisitor(metacardType, mockMetacardTypeList);
    PropertyName propertyName = (PropertyName) visitor.visit(propName, null);
    assertThat(propertyName.getPropertyName(), is(Metacard.ANY_GEO));
}
Also used : NameImpl(org.geotools.feature.NameImpl) PropertyName(org.opengis.filter.expression.PropertyName) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) QName(javax.xml.namespace.QName) CswQueryFactoryTest(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest) Test(org.junit.Test)

Example 15 with AttributeExpressionImpl

use of org.geotools.filter.AttributeExpressionImpl 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)

Aggregations

AttributeExpressionImpl (org.geotools.filter.AttributeExpressionImpl)15 NameImpl (org.geotools.feature.NameImpl)5 LikeFilterImpl (org.geotools.filter.LikeFilterImpl)5 QName (javax.xml.namespace.QName)4 Expression (org.opengis.filter.expression.Expression)4 PropertyName (org.opengis.filter.expression.PropertyName)4 ContentTypePredicate (ddf.catalog.pubsub.predicate.ContentTypePredicate)3 ContextualPredicate (ddf.catalog.pubsub.predicate.ContextualPredicate)3 ArrayList (java.util.ArrayList)3 CswQueryFactoryTest (org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest)3 LiteralExpressionImpl (org.geotools.filter.LiteralExpressionImpl)3 Test (org.junit.Test)3 SpatialFilter (ddf.catalog.impl.filter.SpatialFilter)2 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 Date (java.util.Date)2 Filter (org.opengis.filter.Filter)2 SortByImpl (ddf.catalog.filter.impl.SortByImpl)1