Search in sources :

Example 26 with ResultImpl

use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.

the class RefreshRegistryEntriesTest method testCreateRemoteEntriesSourceUnavailable.

@Test
public void testCreateRemoteEntriesSourceUnavailable() throws Exception {
    Metacard remoteMetacard = getPopulatedTestRegistryMetacard();
    when(federationAdminService.getInternalRegistryMetacards()).thenReturn(Collections.emptyList());
    SourceResponse response = new SourceResponseImpl(null, Collections.singletonList(new ResultImpl(remoteMetacard)));
    when(registryStore.query(any(QueryRequest.class))).thenReturn(response);
    refreshRegistryEntries.setRegistryStores(Collections.singletonList(registryStore));
    when(registryStore.isPullAllowed()).thenReturn(true);
    when(registryStore.isAvailable()).thenReturn(false);
    refreshRegistryEntries.refreshRegistryEntries();
    verify(federationAdminService, never()).addRegistryEntries(Collections.singletonList(remoteMetacard), null);
}
Also used : Metacard(ddf.catalog.data.Metacard) SourceResponse(ddf.catalog.operation.SourceResponse) QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) ResultImpl(ddf.catalog.data.impl.ResultImpl) Test(org.junit.Test)

Example 27 with ResultImpl

use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.

the class QueryRunnable method normalizeRelevance.

protected void normalizeRelevance(List<Result> indexResults, Map<String, Result> results) {
    for (Result indexResult : indexResults) {
        String resultKey = indexResult.getMetacard().getAttribute(FilteringDynamicSchemaResolver.SOURCE_ID).getValue() + indexResult.getMetacard().getId();
        if (results.containsKey(resultKey)) {
            MetacardImpl metacard = new MetacardImpl(results.get(resultKey).getMetacard());
            metacard.setAttribute(Search.CACHED, null);
            ResultImpl result = new ResultImpl(metacard);
            result.setRelevanceScore(indexResult.getRelevanceScore());
            results.put(resultKey, result);
        }
    }
}
Also used : ResultImpl(ddf.catalog.data.impl.ResultImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result)

Example 28 with ResultImpl

use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.

the class QueryRunnable method normalizeDistances.

protected void normalizeDistances(Filter query, Map<String, Result> results) {
    String wkt = extractQueryWkt(query);
    if (StringUtils.isNotBlank(wkt)) {
        Shape queryShape;
        try {
            queryShape = getShape(wkt);
        } catch (ParseException e) {
            LOGGER.debug("Unable to parse query WKT to calculate distance", e);
            return;
        }
        for (Map.Entry<String, Result> entry : results.entrySet()) {
            Result result = entry.getValue();
            if (result.getMetacard() != null && StringUtils.isNotBlank(result.getMetacard().getLocation())) {
                try {
                    Shape locationShape = getShape(result.getMetacard().getLocation());
                    double distance = DistanceUtils.degrees2Dist(SPATIAL_CONTEXT.calcDistance(locationShape.getCenter(), queryShape.getCenter()), DistanceUtils.EARTH_MEAN_RADIUS_KM) * METERS_IN_KILOMETERS;
                    ResultImpl updatedResult = new ResultImpl(new MetacardImpl(result.getMetacard()));
                    updatedResult.setDistanceInMeters(distance);
                    results.put(entry.getKey(), updatedResult);
                } catch (ParseException e) {
                    LOGGER.debug("Unable to parse metacard WKT to calculate distance", e);
                }
            }
        }
    }
}
Also used : Shape(org.locationtech.spatial4j.shape.Shape) ResultImpl(ddf.catalog.data.impl.ResultImpl) ParseException(java.text.ParseException) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result)

Example 29 with ResultImpl

use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.

the class TestGeoJsonQueryResponseTransformer method setupResult.

private Result setupResult() {
    MetacardImpl metacard = new MetacardImpl();
    metacard.setCreatedDate(NOW);
    metacard.setModifiedDate(NOW);
    metacard.setMetadata(DEFAULT_XML);
    metacard.setContentTypeName(DEFAULT_TYPE);
    metacard.setContentTypeVersion(DEFAULT_VERSION);
    metacard.setLocation(DEFAULT_LOCATION);
    byte[] buffer = { 8 };
    metacard.setThumbnail(buffer);
    metacard.setTitle(DEFAULT_TITLE);
    metacard.setSourceId(DEFAULT_SOURCE_ID);
    try {
        metacard.setResourceURI(new URI(DEFAULT_URI));
    } catch (URISyntaxException e) {
        LOGGER.warn("Exception during testing", e);
    }
    ResultImpl result = new ResultImpl(metacard);
    result.setRelevanceScore(DEFAULT_RELEVANCE);
    return result;
}
Also used : ResultImpl(ddf.catalog.data.impl.ResultImpl) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) MetacardImpl(ddf.catalog.data.impl.MetacardImpl)

Example 30 with ResultImpl

use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.

the class TestGeoJsonQueryResponseTransformer method testNullMetacard.

@Test(expected = CatalogTransformerException.class)
public void testNullMetacard() throws CatalogTransformerException {
    List<Result> results = new LinkedList<Result>();
    Result result = new ResultImpl(null);
    results.add(result);
    SourceResponse sourceResponse = new SourceResponseImpl(null, results, 1L);
    new GeoJsonQueryResponseTransformer().transform(sourceResponse, null);
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) ResultImpl(ddf.catalog.data.impl.ResultImpl) LinkedList(java.util.LinkedList) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Aggregations

ResultImpl (ddf.catalog.data.impl.ResultImpl)114 Result (ddf.catalog.data.Result)74 Test (org.junit.Test)73 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)61 Metacard (ddf.catalog.data.Metacard)47 ArrayList (java.util.ArrayList)45 QueryRequest (ddf.catalog.operation.QueryRequest)33 SourceResponse (ddf.catalog.operation.SourceResponse)30 QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)23 SourceResponseImpl (ddf.catalog.operation.impl.SourceResponseImpl)21 QueryResponse (ddf.catalog.operation.QueryResponse)20 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)18 DAG (org.codice.alliance.nsili.common.UCO.DAG)17 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)15 BinaryContent (ddf.catalog.data.BinaryContent)10 MetacardTransformer (ddf.catalog.transform.MetacardTransformer)10 QueryImpl (ddf.catalog.operation.impl.QueryImpl)9 Product (org.codice.alliance.nsili.common.UID.Product)9 Query (ddf.catalog.operation.Query)7 PolicyResponse (ddf.catalog.plugin.PolicyResponse)7