Search in sources :

Example 1 with Expression

use of org.opengis.filter.expression.Expression in project ddf by codice.

the class GeoToolsFunctionFactoryTest method testFuzzyFunction.

@Test
public void testFuzzyFunction() {
    List<Expression> expr = new ArrayList<>();
    expr.add(Expression.NIL);
    Function result = toTest.function(FuzzyFunction.NAME.getName(), expr, null);
    assertThat(result.getName(), is(FuzzyFunction.NAME.getName()));
}
Also used : Function(org.opengis.filter.expression.Function) Expression(org.opengis.filter.expression.Expression) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with Expression

use of org.opengis.filter.expression.Expression in project ddf by codice.

the class GeoToolsFunctionFactoryTest method testFunctionForValidNameWithTooManyExpressions.

@Test(expected = IllegalArgumentException.class)
public void testFunctionForValidNameWithTooManyExpressions() {
    List<Expression> expr = new ArrayList<>();
    expr.add(Expression.NIL);
    expr.add(Expression.NIL);
    Function result = toTest.function(FuzzyFunction.NAME.getName(), expr, null);
    assertThat(result.getName(), is(FuzzyFunction.NAME.getName()));
}
Also used : Function(org.opengis.filter.expression.Function) Expression(org.opengis.filter.expression.Expression) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with Expression

use of org.opengis.filter.expression.Expression in project ddf by codice.

the class MockQuery method addTypeFilter.

public void addTypeFilter(List<MockTypeVersionsExtension> extensionList) {
    List<Filter> runningFilterList = new ArrayList<Filter>();
    for (MockTypeVersionsExtension e : extensionList) {
        String type = e.getExtensionTypeName();
        List<String> versions = e.getVersions();
        Filter oneTypeFilter = null;
        Expression expressionType = FILTER_FACTORY.property(Metacard.CONTENT_TYPE);
        Expression expressionVersion = FILTER_FACTORY.property(Metacard.CONTENT_TYPE_VERSION);
        // Logically 'AND' the type and versions together
        if (versions != null && !versions.isEmpty()) {
            List<Filter> andedTypeVersionPairs = new ArrayList<Filter>();
            for (String v : versions) {
                if (v != null) {
                    PropertyIsLike typeFilter = FILTER_FACTORY.like(expressionType, type, "*", "?", "\\", false);
                    PropertyIsLike versionFilter = FILTER_FACTORY.like(expressionVersion, v, "*", "?", "\\", false);
                    andedTypeVersionPairs.add(FILTER_FACTORY.and(typeFilter, versionFilter));
                }
            }
            // Check if we had any pairs and logically 'OR' them together.
            if (!andedTypeVersionPairs.isEmpty()) {
                oneTypeFilter = FILTER_FACTORY.or(andedTypeVersionPairs);
            } else {
                // if we don't have any pairs, means we don't have versions, handle single type
                oneTypeFilter = FILTER_FACTORY.like(expressionType, type, "*", "?", "\\", false);
            }
        } else {
            // we do not have versions, handle single type case
            oneTypeFilter = FILTER_FACTORY.like(expressionType, type, "*", "?", "\\", false);
        }
        runningFilterList.add(oneTypeFilter);
    }
    if (!runningFilterList.isEmpty()) {
        Filter filter = FILTER_FACTORY.or(runningFilterList);
        filters.add(filter);
    }
}
Also used : PropertyIsLike(org.opengis.filter.PropertyIsLike) SpatialFilter(ddf.catalog.impl.filter.SpatialFilter) Filter(org.opengis.filter.Filter) Expression(org.opengis.filter.expression.Expression) ArrayList(java.util.ArrayList)

Example 4 with Expression

use of org.opengis.filter.expression.Expression in project ddf by codice.

the class MockQuery method addContextualFilter.

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

Example 5 with Expression

use of org.opengis.filter.expression.Expression in project ddf by codice.

the class TestCswRecordMapperFilterVisitor method testVisitPropertyIsEqualTo.

@Test
public void testVisitPropertyIsEqualTo() {
    Expression val = factory.literal("foo");
    PropertyIsEqualTo filter = factory.equals(attrExpr, val);
    PropertyIsEqualTo duplicate = (PropertyIsEqualTo) visitor.visit(filter, null);
    assertThat(duplicate.getExpression1(), is(attrExpr));
    assertThat(duplicate.getExpression2(), is(val));
    assertThat(duplicate.isMatchingCase(), is(true));
}
Also used : PropertyIsEqualTo(org.opengis.filter.PropertyIsEqualTo) Expression(org.opengis.filter.expression.Expression) CswQueryFactoryTest(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest) Test(org.junit.Test)

Aggregations

Expression (org.opengis.filter.expression.Expression)38 Test (org.junit.Test)20 CswQueryFactoryTest (org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest)17 ArrayList (java.util.ArrayList)9 Date (java.util.Date)8 AttributeType (ddf.catalog.data.AttributeType)7 LiteralExpressionImpl (org.geotools.filter.LiteralExpressionImpl)7 Filter (org.opengis.filter.Filter)7 Literal (org.opengis.filter.expression.Literal)5 AttributeExpressionImpl (org.geotools.filter.AttributeExpressionImpl)4 Coordinate (com.vividsolutions.jts.geom.Coordinate)3 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)3 FuzzyFunction (ddf.catalog.impl.filter.FuzzyFunction)3 SpatialFilter (ddf.catalog.impl.filter.SpatialFilter)3 DefaultInstant (org.geotools.temporal.object.DefaultInstant)3 DefaultPeriod (org.geotools.temporal.object.DefaultPeriod)3 DefaultPosition (org.geotools.temporal.object.DefaultPosition)3 PropertyIsEqualTo (org.opengis.filter.PropertyIsEqualTo)3 PropertyIsLike (org.opengis.filter.PropertyIsLike)3 Function (org.opengis.filter.expression.Function)3