Search in sources :

Example 41 with UnsupportedQueryException

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;
}
Also used : QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) CatalogFramework(ddf.catalog.CatalogFramework) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) HashMap(java.util.HashMap) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) MetacardVersion(ddf.catalog.core.versioning.MetacardVersion) SortBy(org.opengis.filter.sort.SortBy) EndpointUtil(org.codice.ddf.catalog.ui.util.EndpointUtil) Metacard(ddf.catalog.data.Metacard) Map(java.util.Map) HashCodeBuilder(org.apache.commons.lang3.builder.HashCodeBuilder) Result(ddf.catalog.data.Result) EqualsBuilder(org.apache.commons.lang3.builder.EqualsBuilder) QueryImpl(ddf.catalog.operation.impl.QueryImpl) ImmutableSet(com.google.common.collect.ImmutableSet) Collection(java.util.Collection) IngestException(ddf.catalog.source.IngestException) DeletedMetacard(ddf.catalog.core.versioning.DeletedMetacard) Set(java.util.Set) FederationException(ddf.catalog.federation.FederationException) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) QueryResponse(ddf.catalog.operation.QueryResponse) List(java.util.List) Stream(java.util.stream.Stream) Attribute(ddf.catalog.data.Attribute) Optional(java.util.Optional) Filter(org.opengis.filter.Filter) Collections(java.util.Collections) Metacard(ddf.catalog.data.Metacard) DeletedMetacard(ddf.catalog.core.versioning.DeletedMetacard)

Example 42 with UnsupportedQueryException

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;
}
Also used : Shape(org.locationtech.spatial4j.shape.Shape) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) IOException(java.io.IOException) ParseException(java.text.ParseException)

Example 43 with UnsupportedQueryException

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;
}
Also used : UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException) SolrException(org.apache.solr.common.SolrException)

Example 44 with UnsupportedQueryException

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;
}
Also used : MetacardCreationException(ddf.catalog.data.MetacardCreationException) SourceResponse(ddf.catalog.operation.SourceResponse) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) SolrDocumentList(org.apache.solr.common.SolrDocumentList) IOException(java.io.IOException) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Result(ddf.catalog.data.Result) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) SolrDocument(org.apache.solr.common.SolrDocument) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrException(org.apache.solr.common.SolrException)

Example 45 with UnsupportedQueryException

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);
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) Test(org.junit.Test)

Aggregations

UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)85 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)34 FederationException (ddf.catalog.federation.FederationException)31 QueryRequest (ddf.catalog.operation.QueryRequest)31 Metacard (ddf.catalog.data.Metacard)28 QueryImpl (ddf.catalog.operation.impl.QueryImpl)27 Filter (org.opengis.filter.Filter)27 ArrayList (java.util.ArrayList)26 Result (ddf.catalog.data.Result)25 QueryResponse (ddf.catalog.operation.QueryResponse)25 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)25 Test (org.junit.Test)21 SourceResponse (ddf.catalog.operation.SourceResponse)16 IngestException (ddf.catalog.source.IngestException)15 IOException (java.io.IOException)15 Query (ddf.catalog.operation.Query)12 CreateResponse (ddf.catalog.operation.CreateResponse)10 GeotoolsFilterAdapterImpl (ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl)9 ResourceNotFoundException (ddf.catalog.resource.ResourceNotFoundException)9 Subject (ddf.security.Subject)9