Search in sources :

Example 26 with AttributeExpressionImpl

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

the class MockQuery method addContextualFilter.

public void addContextualFilter(String searchTerm, String selector) {
    Filter filter = null;
    if (selector != null) {
        List<Filter> xpathFilters = new ArrayList<Filter>();
        String[] selectors = selector.split(",");
        for (int i = 0; i < selectors.length; i++) {
            Expression xpathRef = new AttributeExpressionImpl(selectors[i]);
            filter = FILTER_FACTORY.like(xpathRef, searchTerm);
            xpathFilters.add(filter);
        }
        filter = FILTER_FACTORY.or(xpathFilters);
    } else {
        filter = FILTER_FACTORY.like(FILTER_FACTORY.property(Metacard.ANY_TEXT), searchTerm);
    }
    if (filter != null) {
        filters.add(filter);
        this.filter = getFilter();
    }
}
Also used : SpatialFilter(ddf.catalog.impl.filter.SpatialFilter) TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) SpatialDistanceFilter(ddf.catalog.impl.filter.SpatialDistanceFilter) Filter(org.opengis.filter.Filter) Expression(org.opengis.filter.expression.Expression) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) ArrayList(java.util.ArrayList)

Example 27 with AttributeExpressionImpl

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

the class OpenSearchQueryTest method verifyContextualFilter.

// private Document getDocument( String xml ) throws Exception
// {
// DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// factory.setNamespaceAware( true );
// DocumentBuilder builder = factory.newDocumentBuilder();
// StringReader reader = new StringReader( xml );
// InputSource inputSource = new InputSource( reader );
// Document doc = builder.parse( inputSource );
// reader.close();
//
// return doc;
// }
// private String getFilterAsXml( Filter filter ) throws Exception
// {
// FilterTransformer transform = new FilterTransformer();
// transform.setIndentation( 2 );
// String filterXml = transform.transform( filter );
// LOGGER.debug( filterXml );
//
// return filterXml;
// }
private void verifyContextualFilter(Filter filter, String expectedPropertyName, String expectedSearchTerm) throws Exception {
    LikeFilterImpl likeFilter = (LikeFilterImpl) filter;
    AttributeExpressionImpl expression = (AttributeExpressionImpl) likeFilter.getExpression();
    LOGGER.debug("propertyName = {}", expression.getPropertyName());
    assertEquals(expectedPropertyName, expression.getPropertyName());
    String extractedSearchTerm = likeFilter.getLiteral();
    LOGGER.debug("extractedSearchTerm = [{}]", extractedSearchTerm);
    assertEquals(expectedSearchTerm, extractedSearchTerm);
}
Also used : LikeFilterImpl(org.geotools.filter.LikeFilterImpl) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl)

Example 28 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 29 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 30 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)

Aggregations

AttributeExpressionImpl (org.geotools.filter.AttributeExpressionImpl)50 LiteralExpressionImpl (org.geotools.filter.LiteralExpressionImpl)20 Expression (org.opengis.filter.expression.Expression)19 NameImpl (org.geotools.feature.NameImpl)13 Test (org.junit.Test)10 PropertyName (org.opengis.filter.expression.PropertyName)10 LikeFilterImpl (org.geotools.filter.LikeFilterImpl)9 ArrayList (java.util.ArrayList)8 QName (javax.xml.namespace.QName)8 FunctionExpressionImpl (org.geotools.filter.FunctionExpressionImpl)7 MathExpressionImpl (org.geotools.filter.MathExpressionImpl)7 CswQueryFactoryTest (org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest)6 FilterFactoryImpl (org.geotools.filter.FilterFactoryImpl)5 HashMap (java.util.HashMap)4 FieldIdEnum (com.sldeditor.common.xml.ui.FieldIdEnum)3 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)3 ContentTypePredicate (ddf.catalog.pubsub.predicate.ContentTypePredicate)3 ContextualPredicate (ddf.catalog.pubsub.predicate.ContextualPredicate)3 Date (java.util.Date)3 FunctionExpression (org.geotools.filter.FunctionExpression)3