Search in sources :

Example 1 with AndImpl

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

the class OpenSearchQueryTest method testTypeFilterWildcardTypeAndMultipleVersions.

@Test
public void testTypeFilterWildcardTypeAndMultipleVersions() throws Exception {
    String type = "*";
    String versions = "v20,invalid_version,*";
    OpenSearchQuery query = new OpenSearchQuery(null, 0, 10, "relevance", "desc", 30000, FILTER_BUILDER);
    query.addTypeFilter(type, versions);
    Filter filter = query.getFilter();
    // String filterXml = getFilterAsXml( filter );
    VerificationVisitor verificationVisitor = new VerificationVisitor();
    filter.accept(verificationVisitor, null);
    HashMap<String, FilterStatus> map = (HashMap<String, FilterStatus>) verificationVisitor.getMap();
    printFilterStatusMap(map);
    String[] expectedVersions = versions.split(",");
    List<Filter> orFilters = getFilters(map, OrImpl.class.getName());
    assertEquals(1, orFilters.size());
    List<Filter> andFilters = getFilters(map, AndImpl.class.getName());
    assertEquals(expectedVersions.length, andFilters.size());
    List<Filter> equalsFilters = getFilters(map, IsEqualsToImpl.class.getName());
    assertEquals(2, equalsFilters.size());
    List<Filter> likeFilters = getFilters(map, LikeFilterImpl.class.getName());
    assertEquals(4, likeFilters.size());
    int i = 0;
    for (Filter f : andFilters) {
        List<Filter> childFilters = ((AndImpl) f).getChildren();
        verifyTypeVersionFilter(childFilters, type, expectedVersions[i]);
        i++;
    }
// Requires gt-jdbc.jar dependency in POM, but whn that JAR is loaded it causes
// IncompatibleClassChangeError class loader issues in OpenSearchQuery.addTemporalFilter()
// HUGH filter.accept( new FilterToSQL( new PrintWriter( System.out, true ) ), null );
}
Also used : LikeFilterImpl(org.geotools.filter.LikeFilterImpl) HashMap(java.util.HashMap) IsEqualsToImpl(org.geotools.filter.IsEqualsToImpl) TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) BBoxSpatialFilter(org.codice.ddf.opensearch.query.filter.BBoxSpatialFilter) PolygonSpatialFilter(org.codice.ddf.opensearch.query.filter.PolygonSpatialFilter) Filter(org.opengis.filter.Filter) AndImpl(org.geotools.filter.AndImpl) OrImpl(org.geotools.filter.OrImpl) Test(org.junit.Test)

Example 2 with AndImpl

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

the class OpenSearchQueryTest method testTypeFilterWildcardTypeAndVersion.

@Test
public void testTypeFilterWildcardTypeAndVersion() throws Exception {
    String type = "*";
    String versions = "collectorPosition";
    OpenSearchQuery query = new OpenSearchQuery(null, 0, 10, "relevance", "desc", 30000, FILTER_BUILDER);
    query.addTypeFilter(type, versions);
    Filter filter = query.getFilter();
    // String filterXml = getFilterAsXml( filter );
    VerificationVisitor verificationVisitor = new VerificationVisitor();
    filter.accept(verificationVisitor, null);
    HashMap<String, FilterStatus> map = (HashMap<String, FilterStatus>) verificationVisitor.getMap();
    printFilterStatusMap(map);
    String[] expectedVersions = versions.split(",");
    List<Filter> andFilters = getFilters(map, AndImpl.class.getName());
    assertEquals(expectedVersions.length, andFilters.size());
    List<Filter> equalsFilters = getFilters(map, IsEqualsToImpl.class.getName());
    assertEquals((expectedVersions.length), equalsFilters.size());
    List<Filter> likeFilters = getFilters(map, LikeFilterImpl.class.getName());
    assertEquals((expectedVersions.length), likeFilters.size());
    int i = 0;
    for (Filter f : andFilters) {
        List<Filter> childFilters = ((AndImpl) f).getChildren();
        verifyTypeVersionFilter(childFilters, type, expectedVersions[i]);
        i++;
    }
}
Also used : LikeFilterImpl(org.geotools.filter.LikeFilterImpl) HashMap(java.util.HashMap) IsEqualsToImpl(org.geotools.filter.IsEqualsToImpl) TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) BBoxSpatialFilter(org.codice.ddf.opensearch.query.filter.BBoxSpatialFilter) PolygonSpatialFilter(org.codice.ddf.opensearch.query.filter.PolygonSpatialFilter) Filter(org.opengis.filter.Filter) AndImpl(org.geotools.filter.AndImpl) Test(org.junit.Test)

Example 3 with AndImpl

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

the class OpenSearchQueryTest method testContextualTemporalFilter.

@Test
public void testContextualTemporalFilter() throws Exception {
    String searchTerm = "cat";
    String selector = null;
    OpenSearchQuery query = new OpenSearchQuery(null, 0, 10, "relevance", "desc", 30000, FILTER_BUILDER);
    query.addContextualFilter(searchTerm, selector);
    String startDate = "2011-10-4T05:48:27.891-07:00";
    String endDate = "2011-10-4T06:18:27.581-07:00";
    String dateOffset = null;
    TemporalFilter temporalFilter = new TemporalFilter(startDate, endDate);
    LOGGER.debug(temporalFilter.toString());
    query.addTemporalFilter(startDate, endDate, dateOffset);
    Filter filter = query.getFilter();
    // String filterXml = getFilterAsXml( filter );
    VerificationVisitor verificationVisitor = new VerificationVisitor();
    filter.accept(verificationVisitor, null);
    HashMap<String, FilterStatus> map = (HashMap<String, FilterStatus>) verificationVisitor.getMap();
    List<Filter> andFilters = getFilters(map, AndImpl.class.getName());
    assertEquals(1, andFilters.size());
    AndImpl andFilter = (AndImpl) andFilters.get(0);
    List<Filter> childFilters = andFilter.getChildren();
    assertTrue(childFilters.size() == 2);
    verifyContextualFilter(childFilters.get(0), "anyText", searchTerm);
    verifyTemporalFilter(childFilters.get(1), startDate, endDate);
}
Also used : TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) BBoxSpatialFilter(org.codice.ddf.opensearch.query.filter.BBoxSpatialFilter) PolygonSpatialFilter(org.codice.ddf.opensearch.query.filter.PolygonSpatialFilter) Filter(org.opengis.filter.Filter) HashMap(java.util.HashMap) AndImpl(org.geotools.filter.AndImpl) Test(org.junit.Test)

Aggregations

TemporalFilter (ddf.catalog.impl.filter.TemporalFilter)3 HashMap (java.util.HashMap)3 BBoxSpatialFilter (org.codice.ddf.opensearch.query.filter.BBoxSpatialFilter)3 PolygonSpatialFilter (org.codice.ddf.opensearch.query.filter.PolygonSpatialFilter)3 AndImpl (org.geotools.filter.AndImpl)3 Test (org.junit.Test)3 Filter (org.opengis.filter.Filter)3 IsEqualsToImpl (org.geotools.filter.IsEqualsToImpl)2 LikeFilterImpl (org.geotools.filter.LikeFilterImpl)2 OrImpl (org.geotools.filter.OrImpl)1