use of ddf.catalog.source.UnsupportedQueryException in project ddf by codice.
the class SolrMetacardClientImpl method query.
@Override
public List<Metacard> query(String queryString) throws UnsupportedQueryException {
SolrQuery query = new SolrQuery();
query.setQuery(queryString);
try {
QueryResponse solrResponse = client.query(query, SolrRequest.METHOD.POST);
SolrDocumentList docs = solrResponse.getResults();
List<Metacard> results = new ArrayList<>();
for (SolrDocument doc : docs) {
try {
results.add(createMetacard(doc));
} catch (MetacardCreationException e) {
throw new UnsupportedQueryException("Could not create metacard(s).", e);
}
}
return results;
} catch (SolrServerException | IOException e) {
throw new UnsupportedQueryException("Could not complete solr query.", e);
}
}
use of ddf.catalog.source.UnsupportedQueryException in project ddf by codice.
the class RegistryStoreImpl method init.
public void init() {
SourceMonitor registrySourceMonitor = new SourceMonitor() {
@Override
public void setAvailable() {
try {
registryInfoQuery();
} catch (UnsupportedQueryException e) {
LOGGER.debug("Unable to query registry configurations, ", e);
}
}
@Override
public void setUnavailable() {
}
};
addSourceMonitor(registrySourceMonitor);
super.init();
}
use of ddf.catalog.source.UnsupportedQueryException in project ddf by codice.
the class RegistryStoreImpl method create.
@Override
public CreateResponse create(CreateRequest request) throws IngestException {
if (request.getMetacards().stream().map(RegistryUtility::getRegistryId).anyMatch(Objects::isNull)) {
throw new IngestException("One or more of the metacards is not a registry metacard");
}
validateOperation();
List<Filter> regIdFilters = request.getMetacards().stream().map(e -> filterBuilder.attribute(RegistryObjectMetacardType.REMOTE_METACARD_ID).is().equalTo().text(e.getId())).collect(Collectors.toList());
Filter tagFilter = filterBuilder.attribute(Metacard.TAGS).is().equalTo().text(RegistryConstants.REGISTRY_TAG_INTERNAL);
Map<String, Serializable> queryProps = new HashMap<>();
queryProps.put(SecurityConstants.SECURITY_SUBJECT, request.getPropertyValue(SecurityConstants.SECURITY_SUBJECT));
QueryImpl query = new QueryImpl(filterBuilder.allOf(tagFilter, filterBuilder.attribute(RegistryObjectMetacardType.REGISTRY_LOCAL_NODE).empty(), filterBuilder.anyOf(regIdFilters)));
QueryRequest queryRequest = new QueryRequestImpl(query, queryProps);
try {
SourceResponse queryResponse = super.query(queryRequest);
Map<String, Metacard> responseMap = queryResponse.getResults().stream().collect(Collectors.toMap(e -> RegistryUtility.getRegistryId(e.getMetacard()), Result::getMetacard));
List<Metacard> metacardsToCreate = request.getMetacards().stream().filter(e -> !responseMap.containsKey(RegistryUtility.getRegistryId(e))).collect(Collectors.toList());
List<Metacard> allMetacards = new ArrayList<>(responseMap.values());
if (CollectionUtils.isNotEmpty(metacardsToCreate)) {
CreateResponse createResponse = super.create(new CreateRequestImpl(metacardsToCreate, request.getProperties()));
allMetacards.addAll(createResponse.getCreatedMetacards());
}
return new CreateResponseImpl(request, request.getProperties(), allMetacards);
} catch (UnsupportedQueryException e) {
LOGGER.warn("Unable to perform pre-create remote query. Proceeding with original query. Error was {}", e.getMessage());
}
return super.create(request);
}
use of ddf.catalog.source.UnsupportedQueryException in project ddf by codice.
the class SearchControllerTest method createFramework.
private CatalogFramework createFramework() {
final long COUNT = 2;
CatalogFramework framework = mock(CatalogFramework.class);
List<Result> results = new ArrayList<Result>();
for (int i = 0; i < COUNT; i++) {
Result result = mock(Result.class);
MetacardImpl metacard = new MetacardImpl();
metacard.setId("Metacard_" + i);
metacard.setTitle("Metacard " + i);
metacard.setLocation("POINT(" + i + " " + i + ")");
metacard.setType(BasicTypes.BASIC_METACARD);
metacard.setCreatedDate(TIMESTAMP);
metacard.setEffectiveDate(TIMESTAMP);
metacard.setExpirationDate(TIMESTAMP);
metacard.setModifiedDate(TIMESTAMP);
metacard.setContentTypeName("TEST");
metacard.setContentTypeVersion("1.0");
metacard.setTargetNamespace(URI.create(getClass().getPackage().getName()));
when(result.getDistanceInMeters()).thenReturn(100.0 * i);
when(result.getRelevanceScore()).thenReturn(100.0 * (COUNT - i) / COUNT);
when(result.getMetacard()).thenReturn(metacard);
results.add(result);
}
QueryResponse response = new QueryResponseImpl(mock(QueryRequest.class), new ArrayList<Result>(), COUNT);
response.getResults().addAll(results);
try {
when(framework.query(any(QueryRequest.class))).thenReturn(response);
} catch (UnsupportedQueryException e) {
LOGGER.debug("Error querying framework", e);
} catch (SourceUnavailableException e) {
LOGGER.debug("Error querying framework", e);
} catch (FederationException e) {
LOGGER.debug("Error querying framework", e);
}
return framework;
}
use of ddf.catalog.source.UnsupportedQueryException 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;
}
Aggregations