Search in sources :

Example 1 with DefaultFilterVisitor

use of org.geotools.filter.visitor.DefaultFilterVisitor in project ddf by codice.

the class FilterBuilderTest method withinGeoTest.

/**
     *
     */
@Test
public void withinGeoTest() {
    FilterBuilder builder = new GeotoolsFilterBuilder();
    Filter filter = builder.attribute(Metacard.GEOGRAPHY).within().wkt(POINT_WKT);
    filter.accept(new DefaultFilterVisitor() {

        @Override
        public Object visit(Within filter, Object data) {
            Literal literalWrapper = (Literal) filter.getExpression2();
            Geometry geometry = (Geometry) literalWrapper.evaluate(null);
            geometry.getCentroid().getCoordinate();
            return super.visit(filter, data);
        }
    }, null);
}
Also used : Geometry(org.opengis.geometry.Geometry) DefaultFilterVisitor(org.geotools.filter.visitor.DefaultFilterVisitor) Filter(org.opengis.filter.Filter) FilterBuilder(ddf.catalog.filter.FilterBuilder) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) Literal(org.opengis.filter.expression.Literal) DWithin(org.opengis.filter.spatial.DWithin) Within(org.opengis.filter.spatial.Within) Matchers.anyObject(org.mockito.Matchers.anyObject) Test(org.junit.Test)

Example 2 with DefaultFilterVisitor

use of org.geotools.filter.visitor.DefaultFilterVisitor in project ddf by codice.

the class FilterBuilderTest method propertyIsEqual.

@Test
public void propertyIsEqual() {
    FilterVisitor visitor = spy(new DefaultFilterVisitor() {
    });
    FilterBuilder builder = new GeotoolsFilterBuilder();
    Filter filter = builder.attribute(FOO_ATTRIBUTE).equalTo().text("bar");
    filter.accept(visitor, null);
    filter = builder.attribute(FOO_ATTRIBUTE).is().equalTo().text("bar");
    filter.accept(visitor, null);
    filter = builder.attribute(FOO_ATTRIBUTE).is().text("bar");
    filter.accept(visitor, null);
    filter = builder.attribute(FOO_ATTRIBUTE).equalTo().bool(true);
    filter.accept(visitor, null);
    filter = builder.attribute(FOO_ATTRIBUTE).equalTo().bytes(new byte[] {});
    filter.accept(visitor, null);
    filter = builder.attribute(FOO_ATTRIBUTE).equalTo().date(new Date());
    filter.accept(visitor, null);
    filter = builder.attribute(FOO_ATTRIBUTE).equalTo().number((short) 5);
    filter.accept(visitor, null);
    filter = builder.attribute(FOO_ATTRIBUTE).equalTo().number(new Integer(5));
    filter.accept(visitor, null);
    filter = builder.attribute(FOO_ATTRIBUTE).equalTo().number(new Long(5));
    filter.accept(visitor, null);
    filter = builder.attribute(FOO_ATTRIBUTE).equalTo().number(new Float(5));
    filter.accept(visitor, null);
    filter = builder.attribute(FOO_ATTRIBUTE).equalTo().number(new Double(5));
    filter.accept(visitor, null);
    filter = builder.attribute(FOO_ATTRIBUTE).equalTo().wkt("POINT (10, 30)");
    filter.accept(visitor, null);
    filter = builder.attribute(null).is().text(null);
    filter.accept(visitor, null);
    filter = builder.attribute(FOO_ATTRIBUTE).equalTo().dateRange(new Date(1), new Date(2));
    filter.accept(visitor, null);
    InOrder inOrder = inOrder(visitor);
    inOrder.verify(visitor, times(13)).visit(isA(PropertyIsEqualTo.class), anyObject());
    inOrder.verify(visitor, times(1)).visit(isA(During.class), anyObject());
}
Also used : InOrder(org.mockito.InOrder) DefaultFilterVisitor(org.geotools.filter.visitor.DefaultFilterVisitor) Date(java.util.Date) During(org.opengis.filter.temporal.During) PropertyIsEqualTo(org.opengis.filter.PropertyIsEqualTo) DefaultFilterVisitor(org.geotools.filter.visitor.DefaultFilterVisitor) FilterVisitor(org.opengis.filter.FilterVisitor) Filter(org.opengis.filter.Filter) FilterBuilder(ddf.catalog.filter.FilterBuilder) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) Test(org.junit.Test)

Example 3 with DefaultFilterVisitor

use of org.geotools.filter.visitor.DefaultFilterVisitor in project ddf by codice.

the class FilterBuilderTest method likeXPathNull.

@Test(expected = IllegalArgumentException.class)
public void likeXPathNull() {
    FilterVisitor visitor = spy(new DefaultFilterVisitor() {
    });
    FilterBuilder builder = new GeotoolsFilterBuilder();
    Filter filter = builder.xpath("//foo").is().like().text(null);
    filter.accept(visitor, null);
    InOrder inOrder = inOrder(visitor);
    inOrder.verify(visitor, times(1)).visit(isA(PropertyIsLike.class), anyObject());
    filter = builder.xpath(null).is().like().text(null);
}
Also used : PropertyIsLike(org.opengis.filter.PropertyIsLike) InOrder(org.mockito.InOrder) DefaultFilterVisitor(org.geotools.filter.visitor.DefaultFilterVisitor) DefaultFilterVisitor(org.geotools.filter.visitor.DefaultFilterVisitor) FilterVisitor(org.opengis.filter.FilterVisitor) Filter(org.opengis.filter.Filter) FilterBuilder(ddf.catalog.filter.FilterBuilder) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) Test(org.junit.Test)

Example 4 with DefaultFilterVisitor

use of org.geotools.filter.visitor.DefaultFilterVisitor in project ddf by codice.

the class FilterBuilderTest method likeXPath.

@Test
public void likeXPath() {
    FilterVisitor visitor = spy(new DefaultFilterVisitor() {
    });
    FilterBuilder builder = new GeotoolsFilterBuilder();
    Filter filter = builder.xpath("//foo").like().text("bar");
    filter.accept(visitor, null);
    filter = builder.xpath("//foo").is().like().text("bar");
    filter.accept(visitor, null);
    InOrder inOrder = inOrder(visitor);
    inOrder.verify(visitor, times(2)).visit(isA(PropertyIsLike.class), anyObject());
}
Also used : PropertyIsLike(org.opengis.filter.PropertyIsLike) InOrder(org.mockito.InOrder) DefaultFilterVisitor(org.geotools.filter.visitor.DefaultFilterVisitor) DefaultFilterVisitor(org.geotools.filter.visitor.DefaultFilterVisitor) FilterVisitor(org.opengis.filter.FilterVisitor) Filter(org.opengis.filter.Filter) FilterBuilder(ddf.catalog.filter.FilterBuilder) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) Test(org.junit.Test)

Example 5 with DefaultFilterVisitor

use of org.geotools.filter.visitor.DefaultFilterVisitor in project ddf by codice.

the class FilterBuilderTest method andNull.

@Test
public void andNull() {
    FilterVisitor visitor = spy(new DefaultFilterVisitor() {
    });
    FilterBuilder builder = new GeotoolsFilterBuilder();
    Filter filter = builder.allOf(builder.attribute(FOO_ATTRIBUTE).is().empty());
    filter.accept(visitor, null);
    InOrder inOrder = inOrder(visitor);
    inOrder.verify(visitor, times(1)).visit(isA(And.class), anyObject());
    inOrder.verify(visitor).visit(isA(PropertyIsNull.class), anyObject());
}
Also used : InOrder(org.mockito.InOrder) PropertyIsNull(org.opengis.filter.PropertyIsNull) DefaultFilterVisitor(org.geotools.filter.visitor.DefaultFilterVisitor) DefaultFilterVisitor(org.geotools.filter.visitor.DefaultFilterVisitor) FilterVisitor(org.opengis.filter.FilterVisitor) Filter(org.opengis.filter.Filter) FilterBuilder(ddf.catalog.filter.FilterBuilder) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) And(org.opengis.filter.And) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) Test(org.junit.Test)

Aggregations

FilterBuilder (ddf.catalog.filter.FilterBuilder)24 GeotoolsFilterBuilder (ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder)24 DefaultFilterVisitor (org.geotools.filter.visitor.DefaultFilterVisitor)24 Test (org.junit.Test)24 Filter (org.opengis.filter.Filter)24 FilterVisitor (org.opengis.filter.FilterVisitor)23 InOrder (org.mockito.InOrder)21 Date (java.util.Date)6 PropertyIsLike (org.opengis.filter.PropertyIsLike)6 PropertyIsNull (org.opengis.filter.PropertyIsNull)4 DWithin (org.opengis.filter.spatial.DWithin)3 DefaultExpressionVisitor (org.geotools.filter.visitor.DefaultExpressionVisitor)2 And (org.opengis.filter.And)2 Or (org.opengis.filter.Or)2 PropertyIsEqualTo (org.opengis.filter.PropertyIsEqualTo)2 ExpressionVisitor (org.opengis.filter.expression.ExpressionVisitor)2 Literal (org.opengis.filter.expression.Literal)2 PropertyName (org.opengis.filter.expression.PropertyName)2 Within (org.opengis.filter.spatial.Within)2 After (org.opengis.filter.temporal.After)2