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);
}
}
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;
}
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);
}
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;
}
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);
}
}
Aggregations