Search in sources :

Example 46 with UnsupportedQueryException

use of ddf.catalog.source.UnsupportedQueryException in project ddf by codice.

the class TagsFilterQueryPlugin method process.

@Override
public QueryRequest process(Source source, QueryRequest input) throws PluginExecutionException, StopProcessingException {
    if (!isLocalSource(source)) {
        return input;
    }
    QueryRequest request = input;
    try {
        Query query = request.getQuery();
        if (filterAdapter.adapt(query, new TagsFilterDelegate())) {
            return request;
        }
        List<Filter> filters = new ArrayList<>();
        //no tags filter given in props or in query. Add the default ones.
        filters.add(filterBuilder.attribute(Metacard.TAGS).is().like().text(Metacard.DEFAULT_TAG));
        filters.add(filterBuilder.attribute(Metacard.TAGS).empty());
        Filter newFilter = filterBuilder.allOf(filterBuilder.anyOf(filters), query);
        QueryImpl newQuery = new QueryImpl(newFilter, query.getStartIndex(), query.getPageSize(), query.getSortBy(), query.requestsTotalResultsCount(), query.getTimeoutMillis());
        request = new QueryRequestImpl(newQuery, request.isEnterprise(), request.getSourceIds(), request.getProperties());
    } catch (UnsupportedQueryException uqe) {
        LOGGER.debug("Unable to update query with default tags filter", uqe);
    }
    return request;
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) TagsFilterDelegate(ddf.catalog.filter.delegate.TagsFilterDelegate) QueryRequest(ddf.catalog.operation.QueryRequest) Query(ddf.catalog.operation.Query) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ArrayList(java.util.ArrayList)

Example 47 with UnsupportedQueryException

use of ddf.catalog.source.UnsupportedQueryException in project ddf by codice.

the class WfsSource method query.

@Override
public SourceResponse query(QueryRequest request) throws UnsupportedQueryException {
    Wfs wfs = factory.getClient();
    Query query = request.getQuery();
    LOGGER.debug("WFS Source {}: Received query: \n{}", getId(), query);
    if (query.getStartIndex() < 1) {
        throw new UnsupportedQueryException("Start Index is one-based and must be an integer greater than 0; should not be [" + query.getStartIndex() + "]");
    }
    SourceResponseImpl simpleResponse = null;
    // WFS v1.0 specification does not support response indicating total
    // number
    // of features satisfying query constraints.
    // Hence, we save off the original
    // page size from the query request and create a copy of the query,
    // changing
    // the page size by a multiplier and the current page number of results
    // so that
    // more features are returned as the user pages through the results,
    // getting
    // a better sense of how many total features exist that satisfy the
    // query.
    int origPageSize = query.getPageSize();
    if (origPageSize <= 0 || origPageSize > WFS_MAX_FEATURES_RETURNED) {
        origPageSize = WFS_MAX_FEATURES_RETURNED;
    }
    QueryImpl modifiedQuery = new QueryImpl(query);
    // Determine current page number of results being requested.
    // Example: startIndex = 21 and origPageSize=10, then requesting to go
    // to page number 3.
    // Note: Integer division will truncate remainders so 4 / 2 will return 0 and not .5.  Also,
    // pages are numbered 1 - N so we add 1 to the result
    int pageNumber = query.getStartIndex() / origPageSize + 1;
    // Modified page size is based on current page number and a constant
    // multiplier,
    // but limited to a max value to prevent time consuming queries just to
    // get an
    // approximation of total number of features.
    // So as page number increases the pageSize increases.
    // Example:
    // pageNumber=2, modifiedPageSize=60
    // pageNumber=3, modifiedPageSize=90
    int modifiedPageSize = Math.min(pageNumber * origPageSize * WFS_QUERY_PAGE_SIZE_MULTIPLIER, WFS_MAX_FEATURES_RETURNED);
    LOGGER.debug("WFS Source {}: modified page size = {}", getId(), modifiedPageSize);
    modifiedQuery.setPageSize(modifiedPageSize);
    GetFeatureType getFeature = buildGetFeatureRequest(modifiedQuery);
    try {
        LOGGER.debug("WFS Source {}: Sending query ...", getId());
        WfsFeatureCollection featureCollection = wfs.getFeature(getFeature);
        if (featureCollection == null) {
            throw new UnsupportedQueryException("Invalid results returned from server");
        }
        availabilityTask.updateLastAvailableTimestamp(System.currentTimeMillis());
        LOGGER.debug("WFS Source {}: Received featureCollection with {} metacards.", getId(), featureCollection.getFeatureMembers().size());
        // Only return the number of results originally asked for in the
        // query, or the entire list of results if it is smaller than the
        // original page size.
        int numberOfResultsToReturn = Math.min(origPageSize, featureCollection.getFeatureMembers().size());
        List<Result> results = new ArrayList<Result>(numberOfResultsToReturn);
        int stopIndex = Math.min((origPageSize * pageNumber) + query.getStartIndex(), featureCollection.getFeatureMembers().size() + 1);
        LOGGER.debug("WFS Source {}: startIndex = {}, stopIndex = {}, origPageSize = {}, pageNumber = {}", getId(), query.getStartIndex(), stopIndex, origPageSize, pageNumber);
        for (int i = query.getStartIndex(); i < stopIndex; i++) {
            Metacard mc = featureCollection.getFeatureMembers().get(i - 1);
            mc = transform(mc, DEFAULT_WFS_TRANSFORMER_ID);
            Result result = new ResultImpl(mc);
            results.add(result);
            debugResult(result);
        }
        Long totalHits = (long) featureCollection.getFeatureMembers().size();
        simpleResponse = new SourceResponseImpl(request, results, totalHits);
    } catch (WfsException wfse) {
        LOGGER.debug(WFS_ERROR_MESSAGE, wfse);
        throw new UnsupportedQueryException("Error received from WFS Server", wfse);
    } catch (Exception ce) {
        String msg = handleClientException(ce);
        throw new UnsupportedQueryException(msg, ce);
    }
    return simpleResponse;
}
Also used : Query(ddf.catalog.operation.Query) Wfs(org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.common.Wfs) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) WfsException(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) JAXBException(javax.xml.bind.JAXBException) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) WebApplicationException(javax.ws.rs.WebApplicationException) SecurityServiceException(ddf.security.service.SecurityServiceException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException) Result(ddf.catalog.data.Result) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Metacard(ddf.catalog.data.Metacard) WfsException(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException) WfsFeatureCollection(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsFeatureCollection) GetFeatureType(ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType)

Example 48 with UnsupportedQueryException

use of ddf.catalog.source.UnsupportedQueryException in project ddf by codice.

the class WfsSource method buildGetFeatureRequest.

private GetFeatureType buildGetFeatureRequest(Query query) throws UnsupportedQueryException {
    List<ContentType> contentTypes = getContentTypesFromQuery(query);
    List<QueryType> queries = new ArrayList<QueryType>();
    for (Entry<QName, WfsFilterDelegate> filterDelegateEntry : featureTypeFilters.entrySet()) {
        if (contentTypes.isEmpty() || isFeatureTypeInQuery(contentTypes, filterDelegateEntry.getKey().getLocalPart())) {
            QueryType wfsQuery = new QueryType();
            wfsQuery.setTypeName(filterDelegateEntry.getKey());
            FilterType filter = filterAdapter.adapt(query, filterDelegateEntry.getValue());
            if (filter != null) {
                if (areAnyFiltersSet(filter)) {
                    wfsQuery.setFilter(filter);
                }
                queries.add(wfsQuery);
            } else {
                LOGGER.debug("WFS Source {}: {} has an invalid filter.", getId(), filterDelegateEntry.getKey());
            }
        }
    }
    if (queries != null && !queries.isEmpty()) {
        GetFeatureType getFeatureType = new GetFeatureType();
        getFeatureType.setMaxFeatures(BigInteger.valueOf(query.getPageSize()));
        getFeatureType.getQuery().addAll(queries);
        getFeatureType.setService(Wfs10Constants.WFS);
        getFeatureType.setVersion(Wfs10Constants.VERSION_1_0_0);
        logMessage(getFeatureType);
        return getFeatureType;
    } else {
        throw new UnsupportedQueryException("Unable to build query. No filters could be created from query criteria.");
    }
}
Also used : FilterType(ogc.schema.opengis.filter.v_1_0_0.FilterType) ContentType(ddf.catalog.data.ContentType) QName(javax.xml.namespace.QName) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ArrayList(java.util.ArrayList) QueryType(ogc.schema.opengis.wfs.v_1_0_0.QueryType) GetFeatureType(ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType)

Example 49 with UnsupportedQueryException

use of ddf.catalog.source.UnsupportedQueryException in project ddf by codice.

the class DummyPreQueryPlugin method process.

@Override
public QueryRequest process(QueryRequest input) throws PluginExecutionException, StopProcessingException {
    String methodName = "process";
    LOGGER.trace(ENTERING, methodName);
    QueryRequest newQueryRequest = input;
    if (input != null) {
        Query query = input.getQuery();
        if (query != null) {
            FilterDelegate<Filter> delegate = new CopyFilterDelegate(filterBuilder);
            try {
                // Make a defensive copy of the original filter (just in case anyone else
                // expects
                // it to remain unmodified)
                Filter copiedFilter = filterAdapter.adapt(query, delegate);
                // Define the extra query clause(s) to add to the copied filter
                // This will create a filter with a search phrase of:
                // ((("schematypesearch") and ("test" and ("ISAF" or "CAN"))))
                Filter contextualFilter = filterBuilder.attribute(Metacard.ANY_TEXT).like().text("test");
                Filter releasableToFilter1 = filterBuilder.attribute(Metacard.ANY_TEXT).like().text("ISAF");
                Filter releasableToFilter2 = filterBuilder.attribute(Metacard.ANY_TEXT).like().text("CAN");
                Filter orFilter = filterBuilder.anyOf(releasableToFilter1, releasableToFilter2);
                Filter extraFilter = filterBuilder.allOf(contextualFilter, orFilter);
                // AND this PreQueryPlugin's extra query clause(s) to the copied filter
                Filter modifiedFilter = filterBuilder.allOf(copiedFilter, extraFilter);
                // Create a new QueryRequest using the modified filter and the attributes from
                // the original query
                QueryImpl newQuery = new QueryImpl(modifiedFilter, query.getStartIndex(), query.getPageSize(), query.getSortBy(), query.requestsTotalResultsCount(), query.getTimeoutMillis());
                newQueryRequest = new QueryRequestImpl(newQuery, input.isEnterprise(), input.getSourceIds(), input.getProperties());
            } catch (UnsupportedQueryException e) {
                throw new PluginExecutionException(e);
            }
        }
    }
    LOGGER.trace(EXITING, methodName);
    return newQueryRequest;
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryRequest(ddf.catalog.operation.QueryRequest) Query(ddf.catalog.operation.Query) Filter(org.opengis.filter.Filter) CopyFilterDelegate(ddf.catalog.filter.delegate.CopyFilterDelegate) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException)

Example 50 with UnsupportedQueryException

use of ddf.catalog.source.UnsupportedQueryException in project ddf by codice.

the class DummyPreSubscriptionPlugin method process.

public Subscription process(Subscription input) throws PluginExecutionException {
    String methodName = "process";
    LOGGER.trace(ENTERING, methodName);
    Subscription newSubscription = input;
    if (input != null) {
        FilterDelegate<Filter> delegate = new CopyFilterDelegate(filterBuilder);
        try {
            // Make a defensive copy of the original filter (just in case anyone else expects
            // it to remain unmodified)
            Filter copiedFilter = filterAdapter.adapt(input, delegate);
            // Define the extra query clause(s) to add to the copied filter
            Filter extraFilter = filterBuilder.attribute(Metacard.ANY_TEXT).like().text("CAN");
            // AND the extra query clause(s) to the copied filter
            Filter modifiedFilter = filterBuilder.allOf(copiedFilter, extraFilter);
            // Create a new subscription with the modified filter
            newSubscription = new SubscriptionImpl(modifiedFilter, input.getDeliveryMethod(), input.getSourceIds(), input.isEnterprise());
        } catch (UnsupportedQueryException e) {
            throw new PluginExecutionException(e);
        }
    }
    LOGGER.trace(EXITING, methodName);
    return newSubscription;
}
Also used : Filter(org.opengis.filter.Filter) CopyFilterDelegate(ddf.catalog.filter.delegate.CopyFilterDelegate) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) Subscription(ddf.catalog.event.Subscription) SubscriptionImpl(ddf.catalog.event.impl.SubscriptionImpl) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException)

Aggregations

UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)85 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)34 FederationException (ddf.catalog.federation.FederationException)31 QueryRequest (ddf.catalog.operation.QueryRequest)31 Metacard (ddf.catalog.data.Metacard)28 QueryImpl (ddf.catalog.operation.impl.QueryImpl)27 Filter (org.opengis.filter.Filter)27 ArrayList (java.util.ArrayList)26 Result (ddf.catalog.data.Result)25 QueryResponse (ddf.catalog.operation.QueryResponse)25 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)25 Test (org.junit.Test)21 SourceResponse (ddf.catalog.operation.SourceResponse)16 IngestException (ddf.catalog.source.IngestException)15 IOException (java.io.IOException)15 Query (ddf.catalog.operation.Query)12 CreateResponse (ddf.catalog.operation.CreateResponse)10 GeotoolsFilterAdapterImpl (ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl)9 ResourceNotFoundException (ddf.catalog.resource.ResourceNotFoundException)9 Subject (ddf.security.Subject)9