Search in sources :

Example 21 with SortByImpl

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

the class ConfluenceSourceTest method testQuery.

@Test
public void testQuery() throws Exception {
    QueryRequest request = new QueryRequestImpl(new QueryImpl(builder.attribute("anyText").is().like().text("searchValue"), 1, 1, new SortByImpl("title", SortOrder.DESCENDING), false, 1000));
    InputStream entity = new ByteArrayInputStream(JSON_RESPONSE.getBytes(StandardCharsets.UTF_8));
    when(clientResponse.getEntity()).thenReturn(entity);
    when(clientResponse.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
    SourceResponse response = confluence.query(request);
    assertThat(response.getHits(), is(1L));
    assertThat(response.getResults().get(0).getMetacard(), notNullValue());
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponse(ddf.catalog.operation.SourceResponse) SortByImpl(ddf.catalog.filter.impl.SortByImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Test(org.junit.Test)

Example 22 with SortByImpl

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

the class GazetteerQueryCatalog method query.

@Override
public List<GeoEntry> query(String queryString, int maxResults) throws GeoEntryQueryException {
    Filter textFilter = filterBuilder.attribute(Core.TITLE).is().like().text(queryString);
    Filter queryFilter = filterBuilder.allOf(tagFilter, textFilter);
    Map<String, Serializable> properties = new HashMap<>();
    SortBy featureCodeSortBy = new SortByImpl(GeoEntryAttributes.FEATURE_CODE_ATTRIBUTE_NAME, SortOrder.ASCENDING);
    SortBy populationSortBy = new SortByImpl(GeoEntryAttributes.POPULATION_ATTRIBUTE_NAME, SortOrder.DESCENDING);
    SortBy[] sortbys = { populationSortBy };
    properties.put(ADDITIONAL_SORT_BYS, sortbys);
    Query query = new QueryImpl(queryFilter, 1, maxResults, featureCodeSortBy, false, TIMEOUT);
    QueryRequest queryRequest = new QueryRequestImpl(query, properties);
    QueryResponse queryResponse;
    try {
        queryResponse = catalogFramework.query(queryRequest);
    } catch (UnsupportedQueryException | SourceUnavailableException | FederationException e) {
        throw new GeoEntryQueryException(ERROR_MESSAGE, e);
    }
    return queryResponse.getResults().stream().map(Result::getMetacard).map(this::transformMetacardToGeoEntry).filter(Objects::nonNull).collect(Collectors.toList());
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) Serializable(java.io.Serializable) Query(ddf.catalog.operation.Query) QueryRequest(ddf.catalog.operation.QueryRequest) HashMap(java.util.HashMap) SortBy(org.opengis.filter.sort.SortBy) GeoEntryQueryException(org.codice.ddf.spatial.geocoding.GeoEntryQueryException) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) FederationException(ddf.catalog.federation.FederationException) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) SortByImpl(ddf.catalog.filter.impl.SortByImpl) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse)

Example 23 with SortByImpl

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

the class CswSourceTest 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(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().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 : 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)

Example 24 with SortByImpl

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

the class CswSourceTest method testQueryWithSortByRelevance.

@Test
public void testQueryWithSortByRelevance() 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.RELEVANCE, 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().getSortProperty().size(), is(1));
    assertThat(cswQuery.getSortBy().getSortProperty().get(0).getPropertyName().getContent().get(0).toString(), equalTo(Core.TITLE));
    assertThat(cswQuery.getSortBy().getSortProperty().get(0).getSortOrder(), is(SortOrderType.DESC));
}
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)

Example 25 with SortByImpl

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

the class WfsSourceTest method testSortingNoSortProperty.

@Test
public void testSortingNoSortProperty() throws Exception {
    // query is still valid even if sort property is missing
    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(null, "ASC"));
    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)

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