Search in sources :

Example 71 with QueryRequestImpl

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

the class CachingFederationStrategy method federate.

@Override
public QueryResponse federate(List<Source> sources, QueryRequest queryRequest) {
    Validate.noNullElements(sources, "Cannot federate with null sources.");
    Validate.notNull(queryRequest, "Cannot federate with null QueryRequest.");
    Set<String> sourceIds = new HashSet<>();
    for (Source source : sources) {
        sourceIds.add(source.getId());
    }
    QueryRequest modifiedQueryRequest = new QueryRequestImpl(queryRequest.getQuery(), queryRequest.isEnterprise(), sourceIds, queryRequest.getProperties());
    if (CACHE_QUERY_MODE.equals(queryRequest.getProperties().get(QUERY_MODE))) {
        return queryCache(modifiedQueryRequest);
    } else {
        return sourceFederate(sources, modifiedQueryRequest);
    }
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Source(ddf.catalog.source.Source) HashSet(java.util.HashSet)

Example 72 with QueryRequestImpl

use of ddf.catalog.operation.impl.QueryRequestImpl 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 73 with QueryRequestImpl

use of ddf.catalog.operation.impl.QueryRequestImpl 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 74 with QueryRequestImpl

use of ddf.catalog.operation.impl.QueryRequestImpl 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 75 with QueryRequestImpl

use of ddf.catalog.operation.impl.QueryRequestImpl 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

QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)216 QueryImpl (ddf.catalog.operation.impl.QueryImpl)187 Test (org.junit.Test)142 Filter (org.opengis.filter.Filter)103 SourceResponse (ddf.catalog.operation.SourceResponse)100 QueryRequest (ddf.catalog.operation.QueryRequest)86 Metacard (ddf.catalog.data.Metacard)72 Result (ddf.catalog.data.Result)60 QueryResponse (ddf.catalog.operation.QueryResponse)46 ArrayList (java.util.ArrayList)46 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)32 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)29 Query (ddf.catalog.operation.Query)28 HashMap (java.util.HashMap)28 FederationException (ddf.catalog.federation.FederationException)27 Serializable (java.io.Serializable)27 Matchers.containsString (org.hamcrest.Matchers.containsString)22 Matchers.anyString (org.mockito.Matchers.anyString)20 SortByImpl (ddf.catalog.filter.impl.SortByImpl)19 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)18