Search in sources :

Example 46 with SortByImpl

use of ddf.catalog.filter.impl.SortByImpl in project ddf by codice.

the class WfsSourceTest method testSortingNoSortMapping.

@Test
public void testSortingNoSortMapping() throws Exception {
    // if sorting is enabled but there is no sort mapping, throw an UnsupportedQueryException
    expectedEx.expect(UnsupportedQueryException.class);
    expectedEx.expectMessage("Source WFS_ID does not support specified sort property title");
    mapSchemaToFeatures(ONE_TEXT_PROPERTY_SCHEMA_PERSON, ONE_FEATURE);
    setUpMocks(null, null, ONE_FEATURE, ONE_FEATURE);
    final QueryImpl propertyIsLikeQuery = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text("literal"));
    setupMapper(null, null, null);
    source.setMetacardMappers(metacardMappers);
    source.setDisableSorting(false);
    propertyIsLikeQuery.setSortBy(new SortByImpl("title", SortOrder.ASCENDING));
    source.query(new QueryRequestImpl(propertyIsLikeQuery));
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) SortByImpl(ddf.catalog.filter.impl.SortByImpl) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Test(org.junit.Test)

Example 47 with SortByImpl

use of ddf.catalog.filter.impl.SortByImpl in project ddf by codice.

the class WfsSourceTest method testSortingSortOrderDescending.

@Test
public void testSortingSortOrderDescending() throws Exception {
    mapSchemaToFeatures(ONE_TEXT_PROPERTY_SCHEMA_PERSON, ONE_FEATURE);
    setUpMocks(null, null, ONE_FEATURE, ONE_FEATURE);
    final QueryImpl propertyIsLikeQuery = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text("literal"));
    setupMapper(MOCK_TEMPORAL_SORT_PROPERTY, MOCK_RELEVANCE_SORT_PROPERTY, MOCK_DISTANCE_SORT_PROPERTY);
    source.setMetacardMappers(metacardMappers);
    propertyIsLikeQuery.setSortBy(new SortByImpl(Result.TEMPORAL, SortOrder.DESCENDING));
    final ArgumentCaptor<ExtendedGetFeatureType> captor = ArgumentCaptor.forClass(ExtendedGetFeatureType.class);
    source.query(new QueryRequestImpl(propertyIsLikeQuery));
    verify(mockWfs, times(2)).getFeature(captor.capture());
    for (final ExtendedGetFeatureType getFeatureType : captor.getAllValues()) {
        assertFeature(getFeatureType, true, MOCK_TEMPORAL_SORT_PROPERTY, "DESC");
    }
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) SortByImpl(ddf.catalog.filter.impl.SortByImpl) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Test(org.junit.Test)

Example 48 with SortByImpl

use of ddf.catalog.filter.impl.SortByImpl in project ddf by codice.

the class WfsSourceTest method testSortingSortOrderAscending.

/**
 * WFS 1.1.0 Sorting uses the following format: Valid sort orders are "ASC" and "DESC". Ref:
 * http://schemas.opengis.net/filter/1.1.0/sort.xsd <wfs:Query typeName="QName QName">
 * <wfs:PropertyName>QName</wfs:PropertyName> <ogc:Filter> <ogc:Equals> <ogc:PropertyName/>
 * <gml:Point>... </gml:Point> </ogc:Equals> </ogc:Filter> <ogc:SortBy> <ogc:SortProperty>
 * <ogc:PropertyName>property</ogc:PropertyName> <ogc:SortOrder>ASC</ogc:SortOrder>
 * </ogc:SortProperty> </ogc:SortBy> </wfs:Query>
 */
@Test
public void testSortingSortOrderAscending() throws Exception {
    // Setup
    mapSchemaToFeatures(ONE_TEXT_PROPERTY_SCHEMA_PERSON, ONE_FEATURE);
    setUpMocks(null, null, ONE_FEATURE, ONE_FEATURE);
    final QueryImpl propertyIsLikeQuery = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text("literal"));
    setupMapper(MOCK_TEMPORAL_SORT_PROPERTY, MOCK_RELEVANCE_SORT_PROPERTY, MOCK_DISTANCE_SORT_PROPERTY);
    source.setMetacardMappers(metacardMappers);
    propertyIsLikeQuery.setSortBy(new SortByImpl(Result.TEMPORAL, SortOrder.ASCENDING));
    final ArgumentCaptor<ExtendedGetFeatureType> captor = ArgumentCaptor.forClass(ExtendedGetFeatureType.class);
    source.query(new QueryRequestImpl(propertyIsLikeQuery));
    verify(mockWfs, times(2)).getFeature(captor.capture());
    for (final ExtendedGetFeatureType getFeatureType : captor.getAllValues()) {
        assertFeature(getFeatureType, true, MOCK_TEMPORAL_SORT_PROPERTY, "ASC");
    }
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) SortByImpl(ddf.catalog.filter.impl.SortByImpl) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Test(org.junit.Test)

Example 49 with SortByImpl

use of ddf.catalog.filter.impl.SortByImpl in project ddf by codice.

the class WfsSourceTest method testNullSortProperty.

@Test
public void testNullSortProperty() throws Exception {
    mapSchemaToFeatures(ONE_TEXT_PROPERTY_SCHEMA_PERSON, ONE_FEATURE);
    setUpMocks(null, null, ONE_FEATURE, ONE_FEATURE);
    final QueryImpl propertyIsLikeQuery = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text("literal"));
    setupMapper(MOCK_TEMPORAL_SORT_PROPERTY, MOCK_RELEVANCE_SORT_PROPERTY, MOCK_DISTANCE_SORT_PROPERTY);
    source.setMetacardMappers(metacardMappers);
    propertyIsLikeQuery.setSortBy(new SortByImpl(new PropertyNameImpl(null), null));
    source.query(new QueryRequestImpl(propertyIsLikeQuery));
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) SortByImpl(ddf.catalog.filter.impl.SortByImpl) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) PropertyNameImpl(ddf.catalog.filter.impl.PropertyNameImpl) Test(org.junit.Test)

Example 50 with SortByImpl

use of ddf.catalog.filter.impl.SortByImpl in project ddf by codice.

the class CswSourceTest method testQueryWithSortByDistance.

@Test
public void testQueryWithSortByDistance() throws JAXBException, UnsupportedQueryException, DatatypeConfigurationException, SAXException, IOException, SecurityServiceException {
    // Setup
    final String searchPhrase = "*";
    final int pageSize = 1;
    final int numRecordsReturned = 1;
    final long numRecordsMatched = 1;
    setupMockContextForMetacardTypeRegistrationAndUnregistration(getDefaultContentTypes());
    try {
        configureMockCsw(numRecordsReturned, numRecordsMatched, CswConstants.VERSION_2_0_2);
    } catch (CswException e) {
        fail("Could not configure Mock Remote CSW: " + e.getMessage());
    }
    QueryImpl query = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text(searchPhrase));
    query.setPageSize(pageSize);
    SortBy sortBy = new SortByImpl(Result.DISTANCE, SortOrder.DESCENDING);
    query.setSortBy(sortBy);
    AbstractCswSource cswSource = getCswSource(mockCsw, mockContext);
    cswSource.setCswUrl(URL);
    cswSource.setId(ID);
    // Perform test
    SourceResponse response = cswSource.query(getQueryRequestWithSubject(query));
    // Verify
    Assert.assertNotNull(response);
    assertThat(response.getResults().size(), is(numRecordsReturned));
    assertThat(response.getHits(), is(numRecordsMatched));
    ArgumentCaptor<GetRecordsType> captor = ArgumentCaptor.forClass(GetRecordsType.class);
    try {
        verify(mockCsw, atLeastOnce()).getRecords(captor.capture());
    } catch (CswException e) {
        fail("Could not verify mock CSW record count: " + e.getMessage());
    }
    GetRecordsType getRecordsType = captor.getValue();
    QueryType cswQuery = (QueryType) getRecordsType.getAbstractQuery().getValue();
    assertThat(cswQuery.getSortBy(), nullValue());
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) SourceResponse(ddf.catalog.operation.SourceResponse) SortByImpl(ddf.catalog.filter.impl.SortByImpl) SortBy(org.opengis.filter.sort.SortBy) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) Test(org.junit.Test)

Aggregations

SortByImpl (ddf.catalog.filter.impl.SortByImpl)68 QueryImpl (ddf.catalog.operation.impl.QueryImpl)65 Test (org.junit.Test)56 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)47 SortBy (org.opengis.filter.sort.SortBy)45 SourceResponse (ddf.catalog.operation.SourceResponse)28 QueryRequest (ddf.catalog.operation.QueryRequest)23 Matchers.containsString (org.hamcrest.Matchers.containsString)21 Filter (org.opengis.filter.Filter)13 ArrayList (java.util.ArrayList)12 GetFeatureType (net.opengis.wfs.v_2_0_0.GetFeatureType)12 QueryType (net.opengis.wfs.v_2_0_0.QueryType)12 Query (ddf.catalog.operation.Query)9 TemporalFilter (ddf.catalog.impl.filter.TemporalFilter)8 InputStream (java.io.InputStream)8 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)8 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)8 CswException (org.codice.ddf.spatial.ogc.csw.catalog.common.CswException)8 MetacardMapper (org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7