Search in sources :

Example 16 with UnsupportedQueryException

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

the class ResourceOperations method getEnterpriseResourceOptions.

public Map<String, Set<String>> getEnterpriseResourceOptions(String metacardId, boolean fanoutEnabled) throws ResourceNotFoundException {
    LOGGER.trace("ENTERING: getEnterpriseResourceOptions");
    Set<String> supportedOptions = Collections.emptySet();
    try {
        QueryRequest queryRequest = new QueryRequestImpl(createMetacardIdQuery(metacardId), true, null, null);
        QueryResponse queryResponse = queryOperations.query(queryRequest, null, false, fanoutEnabled);
        List<Result> results = queryResponse.getResults();
        if (!results.isEmpty()) {
            Metacard metacard = results.get(0).getMetacard();
            String sourceIdOfResult = metacard.getSourceId();
            if (sourceIdOfResult != null && sourceIdOfResult.equals(getId())) {
                // found entry on local source
                supportedOptions = getOptionsFromLocalProvider(metacard);
            } else if (sourceIdOfResult != null && !sourceIdOfResult.equals(getId())) {
                // found entry on federated source
                supportedOptions = getOptionsFromFederatedSource(metacard, sourceIdOfResult);
            }
        } else {
            String message = "Unable to find metacard " + metacardId + " on enterprise.";
            LOGGER.debug(message);
            LOGGER.trace("EXITING: getEnterpriseResourceOptions");
            throw new ResourceNotFoundException(message);
        }
    } catch (UnsupportedQueryException e) {
        LOGGER.debug("Error finding metacard {}", metacardId, e);
        LOGGER.trace("EXITING: getEnterpriseResourceOptions");
        throw new ResourceNotFoundException("Error finding metacard due to Unsuppported Query", e);
    } catch (FederationException e) {
        LOGGER.debug("Error federating query for metacard {}", metacardId, e);
        LOGGER.trace("EXITING: getEnterpriseResourceOptions");
        throw new ResourceNotFoundException("Error finding metacard due to Federation issue", e);
    } catch (IllegalArgumentException e) {
        LOGGER.debug("Metacard couldn't be found {}", metacardId, e);
        LOGGER.trace("EXITING: getEnterpriseResourceOptions");
        throw new ResourceNotFoundException("Query returned null metacard", e);
    }
    LOGGER.trace("EXITING: getEnterpriseResourceOptions");
    return Collections.singletonMap(ResourceRequest.OPTION_ARGUMENT, supportedOptions);
}
Also used : Metacard(ddf.catalog.data.Metacard) QueryRequest(ddf.catalog.operation.QueryRequest) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) FederationException(ddf.catalog.federation.FederationException) Result(ddf.catalog.data.Result)

Example 17 with UnsupportedQueryException

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

the class ResourceOperations method getResourceOptions.

public Map<String, Set<String>> getResourceOptions(String metacardId, String sourceId, boolean fanoutEnabled) throws ResourceNotFoundException {
    LOGGER.trace("ENTERING: getResourceOptions");
    Map<String, Set<String>> optionsMap;
    try {
        LOGGER.debug("source id to get options from: {}", sourceId);
        QueryRequest queryRequest = new QueryRequestImpl(createMetacardIdQuery(metacardId), false, Collections.singletonList(sourceId == null ? this.getId() : sourceId), null);
        QueryResponse queryResponse = queryOperations.query(queryRequest, null, false, fanoutEnabled);
        List<Result> results = queryResponse.getResults();
        if (!results.isEmpty()) {
            Metacard metacard = results.get(0).getMetacard();
            // or the local provider.
            if (StringUtils.isEmpty(sourceId) || sourceId.equals(getId())) {
                optionsMap = Collections.singletonMap(ResourceRequest.OPTION_ARGUMENT, getOptionsFromLocalProvider(metacard));
            } else {
                optionsMap = Collections.singletonMap(ResourceRequest.OPTION_ARGUMENT, getOptionsFromFederatedSource(metacard, sourceId));
            }
        } else {
            String message = "Could not find metacard " + metacardId + " on source " + sourceId;
            throw new ResourceNotFoundException(message);
        }
    } catch (UnsupportedQueryException e) {
        LOGGER.debug("Error finding metacard {}", metacardId, e);
        throw new ResourceNotFoundException("Error finding metacard due to Unsuppported Query", e);
    } catch (FederationException e) {
        LOGGER.debug("Error federating query for metacard {}", metacardId, e);
        throw new ResourceNotFoundException("Error finding metacard due to Federation issue", e);
    } catch (IllegalArgumentException e) {
        LOGGER.debug("Metacard couldn't be found {}", metacardId, e);
        throw new ResourceNotFoundException("Query returned null metacard", e);
    } finally {
        LOGGER.trace("EXITING: getResourceOptions");
    }
    return optionsMap;
}
Also used : Set(java.util.Set) QueryRequest(ddf.catalog.operation.QueryRequest) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) FederationException(ddf.catalog.federation.FederationException) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException)

Example 18 with UnsupportedQueryException

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

the class ResourceOperations method getLocalResourceOptions.

public Map<String, Set<String>> getLocalResourceOptions(String metacardId, boolean fanoutEnabled) throws ResourceNotFoundException {
    LOGGER.trace("ENTERING: getLocalResourceOptions");
    Map<String, Set<String>> optionsMap;
    try {
        QueryRequest queryRequest = new QueryRequestImpl(createMetacardIdQuery(metacardId), false, Collections.singletonList(getId()), null);
        QueryResponse queryResponse = queryOperations.query(queryRequest, null, false, fanoutEnabled);
        List<Result> results = queryResponse.getResults();
        if (!results.isEmpty()) {
            Metacard metacard = results.get(0).getMetacard();
            optionsMap = Collections.singletonMap(ResourceRequest.OPTION_ARGUMENT, getOptionsFromLocalProvider(metacard));
        } else {
            String message = "Could not find metacard " + metacardId + " on local source";
            ResourceNotFoundException resourceNotFoundException = new ResourceNotFoundException(message);
            LOGGER.trace("EXITING: getLocalResourceOptions");
            throw resourceNotFoundException;
        }
    } catch (UnsupportedQueryException e) {
        LOGGER.debug("Error finding metacard {}", metacardId, e);
        LOGGER.trace("EXITING: getLocalResourceOptions");
        throw new ResourceNotFoundException("Error finding metacard due to Unsuppported Query", e);
    } catch (FederationException e) {
        LOGGER.debug("Error federating query for metacard {}", metacardId, e);
        LOGGER.trace("EXITING: getLocalResourceOptions");
        throw new ResourceNotFoundException("Error finding metacard due to Federation issue", e);
    } catch (IllegalArgumentException e) {
        LOGGER.debug("Metacard couldn't be found {}", metacardId, e);
        LOGGER.trace("EXITING: getLocalResourceOptions");
        throw new ResourceNotFoundException("Query returned null metacard", e);
    }
    LOGGER.trace("EXITING: getLocalResourceOptions");
    return optionsMap;
}
Also used : Set(java.util.Set) QueryRequest(ddf.catalog.operation.QueryRequest) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) FederationException(ddf.catalog.federation.FederationException) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException)

Example 19 with UnsupportedQueryException

use of ddf.catalog.source.UnsupportedQueryException 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)

Example 20 with UnsupportedQueryException

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

the class WfsSource method buildGetFeatureRequest.

protected 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();
            String typeName = null;
            if (StringUtils.isEmpty(filterDelegateEntry.getKey().getPrefix())) {
                typeName = filterDelegateEntry.getKey().getLocalPart();
            } else {
                typeName = filterDelegateEntry.getKey().getPrefix() + ":" + filterDelegateEntry.getKey().getLocalPart();
            }
            if (StringUtils.isNotBlank(srsName)) {
                wfsQuery.setSrsName(srsName);
            }
            wfsQuery.setTypeNames(Arrays.asList(typeName));
            wfsQuery.setHandle(filterDelegateEntry.getKey().getLocalPart());
            FilterType filter = filterAdapter.adapt(query, filterDelegateEntry.getValue());
            if (filter != null) {
                if (areAnyFiltersSet(filter)) {
                    wfsQuery.setAbstractSelectionClause(new net.opengis.filter.v_2_0_0.ObjectFactory().createFilter(filter));
                }
                if (!this.disableSorting) {
                    if (query.getSortBy() != null) {
                        SortOrder sortOrder = query.getSortBy().getSortOrder();
                        if (filterDelegateEntry.getValue().isSortingSupported() && filterDelegateEntry.getValue().getAllowedSortOrders().contains(sortOrder)) {
                            JAXBElement<SortByType> sortBy = buildSortBy(filterDelegateEntry.getKey(), query.getSortBy());
                            if (sortBy != null) {
                                LOGGER.debug("Sorting using sort order of [{}].", sortOrder.identifier());
                                wfsQuery.setAbstractSortingClause(sortBy);
                            }
                        } else if (filterDelegateEntry.getValue().isSortingSupported() && CollectionUtils.isEmpty(filterDelegateEntry.getValue().getAllowedSortOrders())) {
                            JAXBElement<SortByType> sortBy = buildSortBy(filterDelegateEntry.getKey(), query.getSortBy());
                            if (sortBy != null) {
                                LOGGER.debug("No sort orders defined in getCapabilities.  Attempting to sort using sort order of [{}].", sortOrder.identifier());
                                wfsQuery.setAbstractSortingClause(sortBy);
                            }
                        } else if (filterDelegateEntry.getValue().isSortingSupported() && !filterDelegateEntry.getValue().getAllowedSortOrders().contains(sortOrder)) {
                            LOGGER.debug("Unsupported sort order of [{}]. Supported sort orders are {}.", sortOrder, filterDelegateEntry.getValue().getAllowedSortOrders());
                        } else if (!filterDelegateEntry.getValue().isSortingSupported()) {
                            LOGGER.debug("Sorting is not supported.");
                        }
                    }
                } else {
                    LOGGER.debug("Sorting is disabled.");
                }
                queries.add(wfsQuery);
            } else {
                LOGGER.debug("WFS Source {}: {} has an invalid filter.", getId(), filterDelegateEntry.getKey());
            }
        }
    }
    if (queries != null && !queries.isEmpty()) {
        GetFeatureType getFeatureType = new GetFeatureType();
        int pageSize = query.getPageSize();
        if (pageSize < 0) {
            LOGGER.debug("Page size has a negative value");
            throw new UnsupportedQueryException("Unable to build query. Page size has a negative value.");
        }
        int startIndex = query.getStartIndex();
        if (startIndex < 0) {
            LOGGER.debug("Start index has a negative value");
            throw new UnsupportedQueryException("Unable to build query. Start index has a negative value.");
        } else if (startIndex != 0) {
            //Convert DDF index of 1 back to index of 0 for WFS 2.0
            startIndex = query.getStartIndex() - 1;
        } else {
            LOGGER.debug("Query already has a start index of 0");
        }
        getFeatureType.setCount(BigInteger.valueOf(query.getPageSize()));
        getFeatureType.setStartIndex(BigInteger.valueOf(startIndex));
        List<JAXBElement<?>> incomingQueries = getFeatureType.getAbstractQueryExpression();
        for (QueryType queryType : queries) {
            incomingQueries.add(new net.opengis.wfs.v_2_0_0.ObjectFactory().createQuery(queryType));
        }
        logMessage(getFeatureType);
        return getFeatureType;
    } else {
        throw new UnsupportedQueryException("Unable to build query. No filters could be created from query criteria.");
    }
}
Also used : ContentType(ddf.catalog.data.ContentType) QName(javax.xml.namespace.QName) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ArrayList(java.util.ArrayList) SortOrder(org.opengis.filter.sort.SortOrder) SortByType(net.opengis.filter.v_2_0_0.SortByType) JAXBElement(javax.xml.bind.JAXBElement) FilterType(net.opengis.filter.v_2_0_0.FilterType) QueryType(net.opengis.wfs.v_2_0_0.QueryType) GetFeatureType(net.opengis.wfs.v_2_0_0.GetFeatureType)

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