Search in sources :

Example 91 with MetacardImpl

use of ddf.catalog.data.impl.MetacardImpl 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;
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) QueryRequest(ddf.catalog.operation.QueryRequest) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ArrayList(java.util.ArrayList) FederationException(ddf.catalog.federation.FederationException) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) QueryResponse(ddf.catalog.operation.QueryResponse) CatalogFramework(ddf.catalog.CatalogFramework)

Example 92 with MetacardImpl

use of ddf.catalog.data.impl.MetacardImpl 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 93 with MetacardImpl

use of ddf.catalog.data.impl.MetacardImpl 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 94 with MetacardImpl

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

the class TestMetacardValueResolver method testResolveSourceId.

@Test
public void testResolveSourceId() {
    MetacardImpl mc = new MetacardImpl();
    String expected = "src";
    mc.setSourceId(expected);
    MetacardValueResolver mvr = new MetacardValueResolver();
    Object props = mvr.resolve(mc, "properties");
    Object actual = mvr.resolve(props, "source-id");
    assertEquals(expected, actual);
}
Also used : MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 95 with MetacardImpl

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

the class CacheSolrMetacardClient method createMetacard.

@Override
public MetacardImpl createMetacard(SolrDocument doc) throws MetacardCreationException {
    MetacardImpl metacard = super.createMetacard(doc);
    metacard.setSourceId(getMetacardSource(doc));
    metacard.setId(getMetacardId(doc));
    return metacard;
}
Also used : MetacardImpl(ddf.catalog.data.impl.MetacardImpl)

Aggregations

MetacardImpl (ddf.catalog.data.impl.MetacardImpl)384 Test (org.junit.Test)247 Metacard (ddf.catalog.data.Metacard)144 ArrayList (java.util.ArrayList)102 Result (ddf.catalog.data.Result)62 HashMap (java.util.HashMap)59 Date (java.util.Date)52 ResultImpl (ddf.catalog.data.impl.ResultImpl)51 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)49 URI (java.net.URI)38 Matchers.anyString (org.mockito.Matchers.anyString)38 QueryRequest (ddf.catalog.operation.QueryRequest)36 QueryResponse (ddf.catalog.operation.QueryResponse)35 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)35 Serializable (java.io.Serializable)33 HashSet (java.util.HashSet)31 QueryImpl (ddf.catalog.operation.impl.QueryImpl)29 MetacardTypeImpl (ddf.catalog.data.impl.MetacardTypeImpl)28 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)27 List (java.util.List)27