Search in sources :

Example 1 with SortByImpl

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

the class TestOpenSearchSiteUtil method populateSearchOptions.

@Test
public void populateSearchOptions() throws UnsupportedEncodingException {
    String maxResults = "2000";
    String timeout = "30000";
    //this wasn't url encoded in the previous test, should have been
    String sort = "date%3Adesc";
    SortBy sortBy = new SortByImpl(Result.TEMPORAL, SortOrder.DESCENDING);
    Filter filter = mock(Filter.class);
    Query query = new QueryImpl(filter, 0, 2000, sortBy, true, 30000);
    WebClient webClient = WebClient.create(url.toString());
    OpenSearchSiteUtil.populateSearchOptions(webClient, query, null, Arrays.asList("q,src,mr,start,count,mt,dn,lat,lon,radius,bbox,polygon,dtstart,dtend,dateName,filter,sort".split(",")));
    String urlStr = webClient.getCurrentURI().toString();
    assertTrue(urlStr.indexOf(maxResults) != -1);
    assertTrue(urlStr.indexOf(timeout) != -1);
    assertThat(urlStr, containsString(sort));
    assertTrue(urlStr.indexOf(OpenSearchSiteUtil.COUNT) != -1);
    assertTrue(urlStr.indexOf(OpenSearchSiteUtil.MAX_RESULTS) != -1);
    //src is handled when the params are added to the url
    //        assertTrue(urlStr.indexOf(OpenSearchSiteUtil.SRC) != -1);
    //        assertTrue(urlStr.indexOf(OpenSearchSiteUtil.USER_DN) != -1);
    assertTrue(urlStr.indexOf(OpenSearchSiteUtil.MAX_TIMEOUT) != -1);
    //filter isn't even used, removed from test
    //        assertTrue(urlStr.indexOf(OpenSearchSiteUtil.FILTER) != -1);
    assertTrue(urlStr.indexOf(OpenSearchSiteUtil.SORT) != -1);
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Query(ddf.catalog.operation.Query) SortByImpl(ddf.catalog.filter.impl.SortByImpl) SpatialFilter(ddf.catalog.impl.filter.SpatialFilter) TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) SpatialDistanceFilter(ddf.catalog.impl.filter.SpatialDistanceFilter) Filter(org.opengis.filter.Filter) SortBy(org.opengis.filter.sort.SortBy) Matchers.containsString(org.hamcrest.Matchers.containsString) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 2 with SortByImpl

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

the class TestWfsSource method testResultNumReturnedNegative.

@Test
public void testResultNumReturnedNegative() throws WfsException, SecurityServiceException, TransformerConfigurationException, UnsupportedQueryException {
    //Setup
    final String TITLE = "title";
    final String searchPhrase = "*";
    final int pageSize = 1;
    WfsSource source = getWfsSource(ONE_TEXT_PROPERTY_SCHEMA, MockWfsServer.getFilterCapabilities(), GeospatialUtil.EPSG_4326_URN, 3, false, true, -1);
    QueryImpl query = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text(searchPhrase));
    query.setPageSize(pageSize);
    SortBy sortBy = new SortByImpl(TITLE, SortOrder.DESCENDING);
    query.setSortBy(sortBy);
    QueryRequestImpl queryReq = new QueryRequestImpl(query);
    // Perform test
    SourceResponse resp = source.query(queryReq);
}
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) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 3 with SortByImpl

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

the class TestWfsSource method testSortingAscendingNoFeaturePropertyMappingSortingSupported.

/**
     * Verify that the SortBy is NOT set.  In this case, there is no mapping for the incoming sort property of TEMPORAL so no SortBy should be set.
     * <p/>
     * <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
     * <ns5:GetFeature startIndex="1" count="1" service="WFS" version="2.0.0" xmlns:ns2="http://www.opengis.net/ows/1.1" xmlns="http://www.opengis.net/fes/2.0" xmlns:ns4="http://www.opengis.net/gml" xmlns:ns3="http://www.w3.org/1999/xlink" xmlns:ns5="http://www.opengis.net/wfs/2.0">
     * <ns5:Query typeNames="SampleFeature0" handle="SampleFeature0">
     * <Filter>
     * <PropertyIsLike wildCard="*" singleChar="?" escapeChar="!">
     * <Literal>*</Literal>
     * <ValueReference>title</ValueReference>
     * </PropertyIsLike>
     * </Filter>
     * </ns5:Query>
     * </ns5:GetFeature>
     */
@Test
public void testSortingAscendingNoFeaturePropertyMappingSortingSupported() throws Exception {
    // Setup
    final String searchPhrase = "*";
    final String mockFeatureType = "{http://example.com}" + SAMPLE_FEATURE_NAME + 0;
    final int pageSize = 1;
    WfsSource source = getWfsSource(ONE_TEXT_PROPERTY_SCHEMA, MockWfsServer.getFilterCapabilities(), GeospatialUtil.EPSG_4326_URN, 1, false, false, 0);
    MetacardMapper mockMetacardMapper = mock(MetacardMapper.class);
    when(mockMetacardMapper.getFeatureType()).thenReturn(mockFeatureType);
    List<MetacardMapper> mappers = new ArrayList<MetacardMapper>(1);
    mappers.add(mockMetacardMapper);
    source.setMetacardToFeatureMapper(mappers);
    QueryImpl query = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text(searchPhrase));
    query.setPageSize(pageSize);
    SortBy sortBy = new SortByImpl(Result.TEMPORAL, SortOrder.ASCENDING);
    query.setSortBy(sortBy);
    // Perform Test
    GetFeatureType featureType = source.buildGetFeatureRequest(query);
    // Verify
    QueryType queryType = (QueryType) featureType.getAbstractQueryExpression().get(0).getValue();
    assertFalse(queryType.isSetAbstractSortingClause());
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) SortByImpl(ddf.catalog.filter.impl.SortByImpl) SortBy(org.opengis.filter.sort.SortBy) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) QueryType(net.opengis.wfs.v_2_0_0.QueryType) MetacardMapper(org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper) GetFeatureType(net.opengis.wfs.v_2_0_0.GetFeatureType) Test(org.junit.Test)

Example 4 with SortByImpl

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

the class TestWfsSource method testSortingAscendingSortingNotSupported.

/**
     * Verify that the SortBy is NOT set.  In this case, sorting is not supported in the capabilities.
     */
@Test
public void testSortingAscendingSortingNotSupported() throws Exception {
    // Setup
    final String searchPhrase = "*";
    final String mockTemporalFeatureProperty = "myTemporalFeatureProperty";
    final String mockFeatureType = "{http://example.com}" + SAMPLE_FEATURE_NAME + 0;
    final int pageSize = 1;
    // Set ImplementsSorting to FALSE (sorting not supported)
    FilterCapabilities mockCapabilitiesSortingNotSupported = MockWfsServer.getFilterCapabilities();
    ConformanceType conformance = mockCapabilitiesSortingNotSupported.getConformance();
    List<DomainType> domainTypes = conformance.getConstraint();
    for (DomainType domainType : domainTypes) {
        if (StringUtils.equals(domainType.getName(), "ImplementsSorting")) {
            ValueType valueType = new ValueType();
            valueType.setValue("FALSE");
            domainType.setDefaultValue(valueType);
            break;
        }
    }
    WfsSource source = getWfsSource(ONE_TEXT_PROPERTY_SCHEMA, mockCapabilitiesSortingNotSupported, GeospatialUtil.EPSG_4326_URN, 1, false, false, 0);
    MetacardMapper mockMetacardMapper = mock(MetacardMapper.class);
    when(mockMetacardMapper.getFeatureType()).thenReturn(mockFeatureType);
    when(mockMetacardMapper.getSortByTemporalFeatureProperty()).thenReturn(mockTemporalFeatureProperty);
    List<MetacardMapper> mappers = new ArrayList<MetacardMapper>(1);
    mappers.add(mockMetacardMapper);
    source.setMetacardToFeatureMapper(mappers);
    QueryImpl query = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text(searchPhrase));
    query.setPageSize(pageSize);
    SortBy sortBy = new SortByImpl(Result.TEMPORAL, SortOrder.ASCENDING);
    query.setSortBy(sortBy);
    // Perform Test
    GetFeatureType featureType = source.buildGetFeatureRequest(query);
    // Verify
    QueryType queryType = (QueryType) featureType.getAbstractQueryExpression().get(0).getValue();
    assertFalse(queryType.isSetAbstractSortingClause());
}
Also used : ValueType(net.opengis.ows.v_1_1_0.ValueType) SortBy(org.opengis.filter.sort.SortBy) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) FilterCapabilities(net.opengis.filter.v_2_0_0.FilterCapabilities) QueryImpl(ddf.catalog.operation.impl.QueryImpl) DomainType(net.opengis.ows.v_1_1_0.DomainType) SortByImpl(ddf.catalog.filter.impl.SortByImpl) ConformanceType(net.opengis.filter.v_2_0_0.ConformanceType) QueryType(net.opengis.wfs.v_2_0_0.QueryType) MetacardMapper(org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper) GetFeatureType(net.opengis.wfs.v_2_0_0.GetFeatureType) Test(org.junit.Test)

Example 5 with SortByImpl

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

the class TestCswSource method testQueryWithSortByTemporal.

@Test
public void testQueryWithSortByTemporal() 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.TEMPORAL, SortOrder.DESCENDING);
    query.setSortBy(sortBy);
    AbstractCswSource cswSource = getCswSource(mockCsw, mockContext);
    cswSource.setCswUrl(URL);
    cswSource.setId(ID);
    // Perform test
    SourceResponse response = cswSource.query(new QueryRequestImpl(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().getSortProperty().size(), is(1));
    assertThat(cswQuery.getSortBy().getSortProperty().get(0).getPropertyName().getContent().get(0).toString(), equalTo(Core.MODIFIED));
    assertThat(cswQuery.getSortBy().getSortProperty().get(0).getSortOrder(), is(SortOrderType.DESC));
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) 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) Matchers.anyString(org.mockito.Matchers.anyString) QueryImpl(ddf.catalog.operation.impl.QueryImpl) SortByImpl(ddf.catalog.filter.impl.SortByImpl) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) 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