use of ddf.catalog.filter.impl.SortByImpl in project alliance by codice.
the class FindChildrenStreamEndPlugin method handleParentMetacard.
private void handleParentMetacard(Context context, Metacard parentMetacard) {
Handler handler = factory.build();
Filter filter = filterBuilder.attribute(Associations.DERIVED).is().equalTo().text(parentMetacard.getId());
int startIndex = 1;
Long expectedReturnCount = null;
int subsequentErrorCount = 0;
do {
QueryRequest queryRequest = new QueryRequestImpl(new QueryImpl(filter, startIndex, BATCH_SIZE, new SortByImpl(Core.METACARD_CREATED, SortOrder.ASCENDING), true, 0));
try {
QueryResponse queryResponse = context.getUdpStreamProcessor().getCatalogFramework().query(queryRequest);
if (startIndex == 1) {
expectedReturnCount = queryResponse.getHits();
}
List<Metacard> batch = queryResponse.getResults().stream().map(Result::getMetacard).collect(Collectors.toList());
handler.handle(context, parentMetacard, batch);
startIndex += batch.size();
subsequentErrorCount = 0;
} catch (UnsupportedQueryException | SourceUnavailableException | FederationException e) {
LOGGER.debug("unable to find the children for a parent metacard: metacardId={}", parentMetacard.getId(), e);
subsequentErrorCount++;
} catch (RuntimeException e) {
LOGGER.debug("unable to process a batch of children for a parent metacard: metacardId={}", parentMetacard.getId(), e);
subsequentErrorCount++;
}
} while (continueProcessing(startIndex, expectedReturnCount, subsequentErrorCount));
handler.end(context, parentMetacard);
}
use of ddf.catalog.filter.impl.SortByImpl in project alliance by codice.
the class NsiliSourceTest method testQuerySupportedAscendingSorting.
@Test
public void testQuerySupportedAscendingSorting() throws Exception {
QueryImpl propertyIsLikeQuery = new QueryImpl(builder.attribute(Metacard.CONTENT_TYPE).is().equalTo().text(GMTI));
SortBy sortBy = new SortByImpl(Metacard.MODIFIED, SortOrder.ASCENDING);
propertyIsLikeQuery.setSortBy(sortBy);
source.query(new QueryRequestImpl(propertyIsLikeQuery));
ArgumentCaptor<SortAttribute[]> argumentCaptor = ArgumentCaptor.forClass(SortAttribute[].class);
verify(catalogMgr).submit_query(any(Query.class), any(String[].class), argumentCaptor.capture(), any(NameValue[].class));
String sortAttr = NsiliConstants.NSIL_CARD + "." + NsiliConstants.DATE_TIME_MODIFIED;
assertThat(argumentCaptor.getValue()[0].attribute_name, is(sortAttr));
assertThat(argumentCaptor.getValue()[0].sort_polarity, is(Polarity.ASCENDING));
}
use of ddf.catalog.filter.impl.SortByImpl in project alliance by codice.
the class NsiliSourceTest method testQuerySortingNullSortableAttributes.
@Test
public void testQuerySortingNullSortableAttributes() throws Exception {
source.setSortableAttributes(null);
QueryImpl propertyIsLikeQuery = new QueryImpl(builder.attribute(Metacard.CONTENT_TYPE).is().equalTo().text(GMTI));
SortBy sortBy = new SortByImpl(RELEVANCE, SortOrder.DESCENDING);
propertyIsLikeQuery.setSortBy(sortBy);
source.query(new QueryRequestImpl(propertyIsLikeQuery));
ArgumentCaptor<SortAttribute[]> argumentCaptor = ArgumentCaptor.forClass(SortAttribute[].class);
verify(catalogMgr).submit_query(any(Query.class), any(String[].class), argumentCaptor.capture(), any(NameValue[].class));
// Length is 1, as we force a sort attribute if a valid one is not provided.
assertThat(argumentCaptor.getValue().length, is(1));
}
use of ddf.catalog.filter.impl.SortByImpl in project alliance by codice.
the class NsiliSourceTest method testQueryUnsupportedSorting.
@Test
public void testQueryUnsupportedSorting() throws Exception {
QueryImpl propertyIsLikeQuery = new QueryImpl(builder.attribute(Metacard.CONTENT_TYPE).is().equalTo().text(GMTI));
SortBy sortBy = new SortByImpl(RELEVANCE, SortOrder.DESCENDING);
propertyIsLikeQuery.setSortBy(sortBy);
source.query(new QueryRequestImpl(propertyIsLikeQuery));
ArgumentCaptor<SortAttribute[]> argumentCaptor = ArgumentCaptor.forClass(SortAttribute[].class);
verify(catalogMgr).submit_query(any(Query.class), any(String[].class), argumentCaptor.capture(), any(NameValue[].class));
assertThat(argumentCaptor.getValue().length, is(0));
}
use of ddf.catalog.filter.impl.SortByImpl in project ddf by codice.
the class OpenSearchParserImplTest method populateSearchOptionsWithSubject.
@Test
public void populateSearchOptionsWithSubject() {
SortBy sortBy = new SortByImpl(Result.TEMPORAL, SortOrder.DESCENDING);
Filter filter = mock(Filter.class);
Query query = new QueryImpl(filter, 0, 2000, sortBy, true, 30000);
QueryRequest queryRequest = new QueryRequestImpl(query);
String principalName = "principalName";
Subject subject = getMockSubject(principalName);
openSearchParser.populateSearchOptions(webClient, queryRequest, subject, Arrays.asList("q,src,mr,start,count,mt,dn,lat,lon,radius,bbox,polygon,dtstart,dtend,dateName,filter,sort".split(",")));
assertQueryParameterPopulated(OpenSearchConstants.COUNT);
assertQueryParameterPopulated(OpenSearchConstants.MAX_RESULTS, MAX_RESULTS);
assertQueryParameterPopulated(OpenSearchConstants.MAX_TIMEOUT, TIMEOUT);
assertQueryParameterPopulated(OpenSearchParserImpl.USER_DN, principalName);
assertQueryParameterPopulated(OpenSearchConstants.SORT, DESCENDING_TEMPORAL_SORT);
}
Aggregations