Search in sources :

Example 76 with QueryImpl

use of ddf.catalog.operation.impl.QueryImpl in project ddf by codice.

the class TestWfsSource method testPagingPageSizeNegative.

/**
     * Verify that, per DDF Query API Javadoc, if the startIndex is negative, the WfsSource throws
     * an UnsupportedQueryException.
     *
     * @throws WfsException,                     SecurityServiceException
     * @throws TransformerConfigurationException
     * @throws UnsupportedQueryException
     */
@Test(expected = UnsupportedQueryException.class)
public void testPagingPageSizeNegative() throws WfsException, SecurityServiceException, TransformerConfigurationException, UnsupportedQueryException {
    //Setup
    int pageSize = -4;
    int startIndex = 0;
    WfsSource source = getWfsSource(ONE_TEXT_PROPERTY_SCHEMA, MockWfsServer.getFilterCapabilities(), GeospatialUtil.EPSG_4326_URN, 10, false);
    Filter filter = builder.attribute(Metacard.ANY_TEXT).is().like().text(LITERAL);
    Query query = new QueryImpl(filter, startIndex, pageSize, null, false, 0);
    //Execute
    GetFeatureType featureType = source.buildGetFeatureRequest(query);
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Query(ddf.catalog.operation.Query) Filter(org.opengis.filter.Filter) GetFeatureType(net.opengis.wfs.v_2_0_0.GetFeatureType) Test(org.junit.Test)

Example 77 with QueryImpl

use of ddf.catalog.operation.impl.QueryImpl in project ddf by codice.

the class SolrCache method query.

@Override
public List<Metacard> query(Filter filter) throws UnsupportedQueryException {
    QueryRequest queryRequest = new QueryRequestImpl(new QueryImpl(filter), true);
    SourceResponse response = solrClientAdaptor.getSolrMetacardClient().query(queryRequest);
    return getMetacardsFromResponse(response);
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponse(ddf.catalog.operation.SourceResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl)

Example 78 with QueryImpl

use of ddf.catalog.operation.impl.QueryImpl in project ddf by codice.

the class CacheQueryFactory method getQueryRequestWithSourcesFilter.

QueryRequest getQueryRequestWithSourcesFilter(QueryRequest input) {
    QueryRequest queryWithSources = input;
    if (input.getSourceIds() != null) {
        List<Filter> sourceFilters = new ArrayList<>();
        for (String sourceId : input.getSourceIds()) {
            sourceFilters.add(builder.attribute(StringUtils.removeEnd(SolrCache.METACARD_SOURCE_NAME, SchemaFields.TEXT_SUFFIX)).is().equalTo().text(sourceId));
        }
        QueryImpl sourceQuery = new QueryImpl(builder.allOf(input.getQuery(), builder.anyOf(sourceFilters)));
        sourceQuery.setPageSize(input.getQuery().getPageSize());
        sourceQuery.setStartIndex(input.getQuery().getStartIndex());
        sourceQuery.setSortBy(input.getQuery().getSortBy());
        sourceQuery.setTimeoutMillis(input.getQuery().getTimeoutMillis());
        queryWithSources = new QueryRequestImpl(sourceQuery, input.isEnterprise(), input.getSourceIds(), input.getProperties());
    }
    return queryWithSources;
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryRequest(ddf.catalog.operation.QueryRequest) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) ArrayList(java.util.ArrayList)

Example 79 with QueryImpl

use of ddf.catalog.operation.impl.QueryImpl in project ddf by codice.

the class CachingFederationStrategy method getModifiedQuery.

private Query getModifiedQuery(Query originalQuery, int numberOfSources, int offset, int pageSize) {
    Query query;
    // If offset is not specified, our offset is 1
    if (offset > 1 && numberOfSources > 1) {
        final int modifiedOffset = 1;
        int modifiedPageSize = computeModifiedPageSize(offset, pageSize);
        LOGGER.debug("Creating new query for federated sources to query each source from {} " + "to {}.", modifiedOffset, modifiedPageSize);
        LOGGER.debug("original offset: {}", offset);
        LOGGER.debug("original page size: {}", pageSize);
        LOGGER.debug("modified offset: {}", modifiedOffset);
        LOGGER.debug("modified page size: {}", modifiedPageSize);
        /**
             * Federated sources always query from offset of 1. When all query results are received
             * from all federated sources and merged together - then the offset is applied.
             *
             */
        query = new QueryImpl(originalQuery, modifiedOffset, modifiedPageSize, originalQuery.getSortBy(), originalQuery.requestsTotalResultsCount(), originalQuery.getTimeoutMillis());
    } else {
        query = originalQuery;
    }
    return query;
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Query(ddf.catalog.operation.Query)

Example 80 with QueryImpl

use of ddf.catalog.operation.impl.QueryImpl in project ddf by codice.

the class DuplicationValidator method query.

private SourceResponse query(Set<Attribute> attributes, String originalId) {
    final Filter filter = filterBuilder.allOf(filterBuilder.anyOf(buildFilters(attributes)), filterBuilder.not(filterBuilder.attribute(Metacard.ID).is().equalTo().text(originalId)));
    LOGGER.debug("filter {}", filter);
    QueryImpl query = new QueryImpl(filter);
    query.setRequestsTotalResultsCount(false);
    QueryRequest request = new QueryRequestImpl(query);
    SourceResponse response = null;
    try {
        response = catalogFramework.query(request);
    } catch (FederationException | SourceUnavailableException | UnsupportedQueryException e) {
        LOGGER.debug("Query failed ", e);
    }
    return response;
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponse(ddf.catalog.operation.SourceResponse) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) FederationException(ddf.catalog.federation.FederationException)

Aggregations

QueryImpl (ddf.catalog.operation.impl.QueryImpl)232 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)186 Test (org.junit.Test)149 Filter (org.opengis.filter.Filter)117 SourceResponse (ddf.catalog.operation.SourceResponse)95 QueryRequest (ddf.catalog.operation.QueryRequest)66 Metacard (ddf.catalog.data.Metacard)61 ArrayList (java.util.ArrayList)50 Result (ddf.catalog.data.Result)49 Matchers.containsString (org.hamcrest.Matchers.containsString)30 Query (ddf.catalog.operation.Query)29 QueryResponse (ddf.catalog.operation.QueryResponse)28 SortByImpl (ddf.catalog.filter.impl.SortByImpl)27 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)25 SortBy (org.opengis.filter.sort.SortBy)25 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)24 Serializable (java.io.Serializable)23 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)22 HashMap (java.util.HashMap)20 Matchers.anyString (org.mockito.Matchers.anyString)20