Search in sources :

Example 26 with QueryRequest

use of ddf.catalog.operation.QueryRequest in project ddf by codice.

the class RegistryIdPostIngestPlugin method init.

/**
     * Init method initializes the id sets from the catalog. If the catalog is not available it
     * will retry later.
     */
public void init() {
    try {
        List<Metacard> registryMetacards;
        Filter registryFilter = filterBuilder.anyOf(filterBuilder.attribute(Metacard.TAGS).is().equalTo().text(RegistryConstants.REGISTRY_TAG), filterBuilder.attribute(Metacard.TAGS).is().equalTo().text(RegistryConstants.REGISTRY_TAG_INTERNAL));
        QueryImpl query = new QueryImpl(registryFilter);
        query.setPageSize(PAGE_SIZE);
        QueryRequest request = new QueryRequestImpl(query);
        QueryResponse response = security.runAsAdminWithException(() -> security.runWithSubjectOrElevate(() -> catalogFramework.query(request)));
        if (response == null) {
            throw new PluginExecutionException("Failed to initialize RegistryIdPostIngestPlugin. Query for registry metacards came back null");
        }
        registryMetacards = response.getResults().stream().map(Result::getMetacard).collect(Collectors.toList());
        addIdsFromMetacards(registryMetacards);
    } catch (PrivilegedActionException | PluginExecutionException e) {
        LOGGER.debug("Error getting registry metacards. Will try again later");
        executorService.schedule(this::init, RETRY_INTERVAL, TimeUnit.SECONDS);
    }
}
Also used : Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryRequest(ddf.catalog.operation.QueryRequest) Filter(org.opengis.filter.Filter) PrivilegedActionException(java.security.PrivilegedActionException) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException) Result(ddf.catalog.data.Result)

Example 27 with QueryRequest

use of ddf.catalog.operation.QueryRequest in project ddf by codice.

the class QueryRunnable method queryCatalog.

protected QueryResponse queryCatalog(String sourceId, SearchRequest searchRequest, Subject subject, Map<String, Serializable> properties) {
    Query query = searchRequest.getQuery();
    QueryResponse response = getEmptyResponse(sourceId);
    long startTime = System.currentTimeMillis();
    try {
        if (query != null) {
            List<String> sourceIds;
            if (sourceId == null) {
                sourceIds = new ArrayList<>(searchRequest.getSourceIds());
            } else {
                sourceIds = Collections.singletonList(sourceId);
            }
            QueryRequest request = new QueryRequestImpl(query, false, sourceIds, properties);
            if (subject != null) {
                LOGGER.debug("Adding {} property with value {} to request.", SecurityConstants.SECURITY_SUBJECT, subject);
                request.getProperties().put(SecurityConstants.SECURITY_SUBJECT, subject);
            }
            LOGGER.debug("Sending query: {}", query);
            response = searchController.getFramework().query(request);
        }
    } catch (UnsupportedQueryException | FederationException e) {
        LOGGER.info("Error executing query. {}. Set log level to DEBUG for more information", e.getMessage());
        LOGGER.debug("Error executing query", e);
        response.getProcessingDetails().add(new ProcessingDetailsImpl(sourceId, e));
    } catch (SourceUnavailableException e) {
        LOGGER.info("Error executing query because the underlying source was unavailable. {}. Set log level to DEBUG for more information", e.getMessage());
        LOGGER.debug("Error executing query because the underlying source was unavailable.", e);
        response.getProcessingDetails().add(new ProcessingDetailsImpl(sourceId, e));
    } catch (RuntimeException e) {
        // Account for any runtime exceptions and send back a server error
        // this prevents full stacktraces returning to the client
        // this allows for a graceful server error to be returned
        LOGGER.info("RuntimeException on executing query. {}. Set log level to DEBUG for more information", e.getMessage());
        LOGGER.debug("RuntimeException on executing query", e);
        response.getProcessingDetails().add(new ProcessingDetailsImpl(sourceId, e));
    }
    long estimatedTime = System.currentTimeMillis() - startTime;
    response.getProperties().put("elapsed", estimatedTime);
    return response;
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) Query(ddf.catalog.operation.Query) QueryRequest(ddf.catalog.operation.QueryRequest) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) FederationException(ddf.catalog.federation.FederationException) ProcessingDetailsImpl(ddf.catalog.operation.impl.ProcessingDetailsImpl) QueryResponse(ddf.catalog.operation.QueryResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl)

Example 28 with QueryRequest

use of ddf.catalog.operation.QueryRequest 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 29 with QueryRequest

use of ddf.catalog.operation.QueryRequest 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 30 with QueryRequest

use of ddf.catalog.operation.QueryRequest 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)

Aggregations

QueryRequest (ddf.catalog.operation.QueryRequest)153 Test (org.junit.Test)98 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)86 QueryImpl (ddf.catalog.operation.impl.QueryImpl)66 QueryResponse (ddf.catalog.operation.QueryResponse)57 ArrayList (java.util.ArrayList)41 SourceResponse (ddf.catalog.operation.SourceResponse)39 Metacard (ddf.catalog.data.Metacard)33 Result (ddf.catalog.data.Result)31 Filter (org.opengis.filter.Filter)31 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)30 Query (ddf.catalog.operation.Query)29 Source (ddf.catalog.source.Source)24 FederationException (ddf.catalog.federation.FederationException)20 QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)15 InputStream (java.io.InputStream)15 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)14 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)13 SortByImpl (ddf.catalog.filter.impl.SortByImpl)11 HashMap (java.util.HashMap)11