Search in sources :

Example 6 with And

use of org.opengis.filter.And in project ddf by codice.

the class CatalogFeatureQueryableTest method testQuery.

@Test
public void testQuery() throws UnsupportedQueryException, SourceUnavailableException, FederationException, FeatureQueryException {
    final ArgumentCaptor<QueryRequest> requestArgument = ArgumentCaptor.forClass(QueryRequest.class);
    QueryResponse queryResponse = getMockQueryResponse();
    when(catalogFramework.query(any())).thenReturn(queryResponse);
    List<SimpleFeature> results = catalogFeatureQueryable.query(COUNTRY_CODE, "PCL1", 1);
    verify(catalogFramework, atLeastOnce()).query(requestArgument.capture());
    SimpleFeature result = results.get(0);
    Geometry geometry = (Geometry) result.getDefaultGeometry();
    assertThat(geometry.getNumPoints(), is(WKT_NUM_POINTS));
    assertThat(geometry.getGeometryType(), is(WKT_TYPE));
    QueryImpl query = (QueryImpl) requestArgument.getValue().getQuery();
    Filter filter = query.getFilter();
    And and = (And) filter;
    List<Filter> filters = and.getChildren();
    assertThat(filters, hasSize(3));
    List<String> attributes = new ArrayList<>();
    List<String> values = new ArrayList<>();
    for (Filter compFilter : filters) {
        String attribute;
        String value;
        if (compFilter instanceof IsEqualsToImpl) {
            IsEqualsToImpl equals = (IsEqualsToImpl) compFilter;
            AttributeExpressionImpl attributeExpression = (AttributeExpressionImpl) equals.getExpression1();
            attribute = attributeExpression.getPropertyName();
            LiteralExpressionImpl literalExpression = (LiteralExpressionImpl) equals.getExpression2();
            value = (String) literalExpression.getValue();
        } else {
            LikeFilterImpl likeFilter = (LikeFilterImpl) compFilter;
            AttributeExpressionImpl literalExpression = (AttributeExpressionImpl) likeFilter.getExpression();
            attribute = literalExpression.getPropertyName();
            value = likeFilter.getLiteral();
        }
        attributes.add(attribute);
        values.add(value);
    }
    assertThat(attributes, hasSize(3));
    assertThat(attributes, hasItems(Location.COUNTRY_CODE, Core.METACARD_TAGS, Core.METACARD_TAGS));
    assertThat(values, hasSize(3));
    assertThat(values, hasItems(COUNTRY_CODE, GAZETTEER_METACARD_TAG, GeoCodingConstants.COUNTRY_TAG));
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) LikeFilterImpl(org.geotools.filter.LikeFilterImpl) ArrayList(java.util.ArrayList) IsEqualsToImpl(org.geotools.filter.IsEqualsToImpl) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Geometry(org.locationtech.jts.geom.Geometry) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) And(org.opengis.filter.And) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl) QueryResponse(ddf.catalog.operation.QueryResponse) Test(org.junit.Test)

Example 7 with And

use of org.opengis.filter.And in project ddf by codice.

the class TestWorkspaceServiceImpl method testGetWorkspaceMetacardsByWorkspaceIdWithException.

@SuppressWarnings("unchecked")
@Test
public void testGetWorkspaceMetacardsByWorkspaceIdWithException() throws UnsupportedQueryException, SourceUnavailableException, FederationException {
    String id = "123";
    when(catalogFramework.query(any())).thenThrow(UnsupportedQueryException.class);
    Filter workspaceTagFilter = mockWorkspaceTagFilter();
    Filter metacardIdFilter = mock(Filter.class);
    when(filterService.buildMetacardIdFilter(id)).thenReturn(metacardIdFilter);
    And andFilter = mock(And.class);
    when(filterBuilder.allOf(metacardIdFilter, workspaceTagFilter)).thenReturn(andFilter);
    Or orFilter = mock(Or.class);
    when(filterBuilder.anyOf(Collections.singletonList(andFilter))).thenReturn(orFilter);
    List<WorkspaceMetacardImpl> workspaceMetacards = workspaceService.getWorkspaceMetacards(Collections.singleton(id));
    assertThat(workspaceMetacards, hasSize(0));
}
Also used : Or(org.opengis.filter.Or) WorkspaceMetacardFilter(org.codice.ddf.catalog.ui.query.monitor.api.WorkspaceMetacardFilter) Filter(org.opengis.filter.Filter) And(org.opengis.filter.And) WorkspaceMetacardImpl(org.codice.ddf.catalog.ui.metacard.workspace.WorkspaceMetacardImpl) Test(org.junit.Test)

Example 8 with And

use of org.opengis.filter.And in project ddf by codice.

the class OpenSearchFilterVisitorTest method testAndFilter.

@Test
public void testAndFilter() {
    Filter textLikeFilter = geotoolsFilterBuilder.attribute(SOME_ATTRIBUTE_NAME).is().like().text(TEST_STRING);
    And andFilter = geotoolsFilterBuilder.allOf(textLikeFilter, textLikeFilter);
    OpenSearchFilterVisitorObject openSearchFilterVisitorObject = new OpenSearchFilterVisitorObject();
    OpenSearchFilterVisitorObject result = (OpenSearchFilterVisitorObject) openSearchFilterVisitor.visit(andFilter, openSearchFilterVisitorObject);
    assertThat(openSearchFilterVisitorObject, is(result));
}
Also used : TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) Filter(org.opengis.filter.Filter) And(org.opengis.filter.And) Test(org.junit.Test)

Example 9 with And

use of org.opengis.filter.And in project ddf by codice.

the class OpenSearchFilterVisitorTest method testMultipleFilters.

/**
 * Test that the {@link OpenSearchFilterVisitorObject} is populated with multiple filters.
 * Combines the {@link Filter}s from {@link #testDuringDates} and {@link #testContains()}.
 */
@Test
public void testMultipleFilters() {
    During duringFilter = (During) geotoolsFilterBuilder.attribute(TEMPORAL_ATTRIBUTE_NAME).during().dates(START_DATE, END_DATE);
    Contains containsFilter = (Contains) geotoolsFilterBuilder.attribute(SPATIAL_ATTRIBUTE_NAME).containing().wkt(WKT_POLYGON);
    And andFilter = geotoolsFilterBuilder.allOf(duringFilter, containsFilter);
    OpenSearchFilterVisitorObject openSearchFilterVisitorObject = new OpenSearchFilterVisitorObject();
    openSearchFilterVisitorObject.setCurrentNest(NestedTypes.AND);
    OpenSearchFilterVisitorObject result = (OpenSearchFilterVisitorObject) openSearchFilterVisitor.visit(andFilter, openSearchFilterVisitorObject);
    assertThat(result.getTemporalSearch(), allOf(is(notNullValue()), hasProperty("startDate", is(START_DATE)), hasProperty("endDate", is(END_DATE))));
    assertThat(result.getGeometrySearches(), contains(hasToString(is(WKT_POLYGON))));
}
Also used : And(org.opengis.filter.And) Contains(org.opengis.filter.spatial.Contains) During(org.opengis.filter.temporal.During) Test(org.junit.Test)

Aggregations

And (org.opengis.filter.And)9 Test (org.junit.Test)7 Filter (org.opengis.filter.Filter)5 WorkspaceMetacardImpl (org.codice.ddf.catalog.ui.metacard.workspace.WorkspaceMetacardImpl)3 Or (org.opengis.filter.Or)3 QueryResponse (ddf.catalog.operation.QueryResponse)2 WorkspaceMetacardFilter (org.codice.ddf.catalog.ui.query.monitor.api.WorkspaceMetacardFilter)2 BinaryComparisonOperator (org.opengis.filter.BinaryComparisonOperator)2 Literal (org.opengis.filter.expression.Literal)2 Mapped (org.polymap.core.style.model.feature.MappedValues.Mapped)2 CatalogFramework (ddf.catalog.CatalogFramework)1 Attribute (ddf.catalog.data.Attribute)1 FederationException (ddf.catalog.federation.FederationException)1 FilterBuilder (ddf.catalog.filter.FilterBuilder)1 TemporalFilter (ddf.catalog.impl.filter.TemporalFilter)1 QueryRequest (ddf.catalog.operation.QueryRequest)1 QueryImpl (ddf.catalog.operation.impl.QueryImpl)1 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)1 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)1 Subject (ddf.security.Subject)1