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);
}
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);
}
}
}
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);
}
}
}
}
}
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;
}
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);
}
Aggregations