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