Search in sources :

Example 11 with SortByImpl

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);
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) QueryRequest(ddf.catalog.operation.QueryRequest) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) FederationException(ddf.catalog.federation.FederationException) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Metacard(ddf.catalog.data.Metacard) Filter(org.opengis.filter.Filter) SortByImpl(ddf.catalog.filter.impl.SortByImpl) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse)

Example 12 with SortByImpl

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));
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) SortAttribute(org.codice.alliance.nsili.common.GIAS.SortAttribute) Query(org.codice.alliance.nsili.common.GIAS.Query) SortByImpl(ddf.catalog.filter.impl.SortByImpl) SortBy(org.opengis.filter.sort.SortBy) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 13 with SortByImpl

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));
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) SortAttribute(org.codice.alliance.nsili.common.GIAS.SortAttribute) Query(org.codice.alliance.nsili.common.GIAS.Query) SortByImpl(ddf.catalog.filter.impl.SortByImpl) SortBy(org.opengis.filter.sort.SortBy) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Test(org.junit.Test)

Example 14 with SortByImpl

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));
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) SortAttribute(org.codice.alliance.nsili.common.GIAS.SortAttribute) Query(org.codice.alliance.nsili.common.GIAS.Query) SortByImpl(ddf.catalog.filter.impl.SortByImpl) SortBy(org.opengis.filter.sort.SortBy) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Test(org.junit.Test)

Example 15 with SortByImpl

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);
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Query(ddf.catalog.operation.Query) QueryRequest(ddf.catalog.operation.QueryRequest) SortByImpl(ddf.catalog.filter.impl.SortByImpl) TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) Filter(org.opengis.filter.Filter) SortBy(org.opengis.filter.sort.SortBy) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Subject(ddf.security.Subject) 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