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());
}
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());
}
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));
}
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));
}
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));
}
Aggregations