use of ddf.catalog.source.UnsupportedQueryException in project ddf by codice.
the class Associated method getAssociations.
public Collection<Edge> getAssociations(String metacardId) throws UnsupportedQueryException, SourceUnavailableException, FederationException {
Map<String, Metacard> metacardMap = query(withNonrestrictedTags(forRootAndParents(metacardId)));
if (metacardMap.isEmpty()) {
return Collections.emptyList();
}
Metacard root = metacardMap.get(metacardId);
Collection<Metacard> parents = metacardMap.values().stream().filter(m -> !m.getId().equals(metacardId)).collect(Collectors.toList());
Map<String, Metacard> childMetacardMap = query(withNonrestrictedTags(forChildAssociations(root)));
Collection<Edge> parentEdges = createParentEdges(parents, root);
Collection<Edge> childrenEdges = createChildEdges(childMetacardMap.values(), root);
Collection<Edge> edges = Stream.of(parentEdges, childrenEdges).flatMap(Collection::stream).collect(Collectors.toList());
return edges;
}
use of ddf.catalog.source.UnsupportedQueryException in project ddf by codice.
the class CqlResult method normalizeDistance.
private Double normalizeDistance(Result result, Query query, FilterAdapter filterAdapter) {
Double distance = result.getDistanceInMeters();
try {
String queryWkt = filterAdapter.adapt(query, WKT_QUERY_DELEGATE);
if (StringUtils.isNotBlank(queryWkt)) {
Shape queryShape = WKT_READER.read(queryWkt);
if (result.getMetacard() != null && StringUtils.isNotBlank(result.getMetacard().getLocation())) {
Shape locationShape = WKT_READER.read(result.getMetacard().getLocation());
distance = DistanceUtils.degrees2Dist(SPATIAL_CONTEXT.calcDistance(locationShape.getCenter(), queryShape.getCenter()), DistanceUtils.EARTH_MEAN_RADIUS_KM) * 1000;
}
}
} catch (IOException | ParseException | UnsupportedQueryException e) {
LOGGER.debug("Unable to parse query wkt", e);
}
if (distance != null && (distance < 0 || distance > Double.MAX_VALUE)) {
distance = null;
}
return distance;
}
use of ddf.catalog.source.UnsupportedQueryException in project ddf by codice.
the class SolrMetacardClientImpl method postAdapt.
protected SolrQuery postAdapt(QueryRequest request, SolrFilterDelegate filterDelegate, SolrQuery query) throws UnsupportedQueryException {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Prepared Query: {}", query.getQuery());
if (query.getFilterQueries() != null && query.getFilterQueries().length > 0) {
LOGGER.debug("Filter Queries: {}", Arrays.toString(query.getFilterQueries()));
}
}
/* Start Index */
if (request.getQuery().getStartIndex() < 1) {
throw new UnsupportedQueryException("Start index must be greater than 0");
}
// Solr is 0-based
query.setStart(request.getQuery().getStartIndex() - 1);
if (queryingForAllRecords(request)) {
try {
query.setRows(queryForNumberOfRows(query));
} catch (SolrServerException | IOException | SolrException | ArithmeticException exception) {
throw new UnsupportedQueryException("Could not retrieve number of records.", exception);
}
} else {
query.setRows(request.getQuery().getPageSize());
}
setSortProperty(request, query, filterDelegate);
return query;
}
use of ddf.catalog.source.UnsupportedQueryException in project ddf by codice.
the class SolrMetacardClientImpl method query.
@Override
public SourceResponse query(QueryRequest request) throws UnsupportedQueryException {
if (request == null || request.getQuery() == null) {
return new QueryResponseImpl(request, new ArrayList<Result>(), true, 0L);
}
SolrQuery query = getSolrQuery(request, filterDelegateFactory.newInstance(resolver));
long totalHits;
List<Result> results = new ArrayList<>();
try {
QueryResponse solrResponse = client.query(query, SolrRequest.METHOD.POST);
totalHits = solrResponse.getResults().getNumFound();
SolrDocumentList docs = solrResponse.getResults();
for (SolrDocument doc : docs) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("SOLR DOC: {}", doc.getFieldValue(Metacard.ID + SchemaFields.TEXT_SUFFIX));
}
ResultImpl tmpResult;
try {
tmpResult = createResult(doc);
} catch (MetacardCreationException e) {
throw new UnsupportedQueryException("Could not create metacard(s).", e);
}
results.add(tmpResult);
}
} catch (SolrServerException | IOException | SolrException e) {
throw new UnsupportedQueryException("Could not complete solr query.", e);
}
SourceResponse sourceResponse = new SourceResponseImpl(request, results, totalHits);
return sourceResponse;
}
use of ddf.catalog.source.UnsupportedQueryException in project ddf by codice.
the class SolrCacheTest method queryThrowsUnsupportedQueryException.
@Test(expected = UnsupportedQueryException.class)
public void queryThrowsUnsupportedQueryException() throws UnsupportedQueryException {
QueryRequest mockQuery = mock(QueryRequest.class);
doThrow(new UnsupportedQueryException()).when(mockCacheSolrMetacardClient).query(mockQuery);
solrCache.query(mockQuery);
}
Aggregations