use of org.codice.ddf.spatial.geocoding.FeatureExtractor in project ddf by codice.
the class GazetteerUpdateCommandTest method testFeatureIndexing.
@Test
public void testFeatureIndexing() throws Exception {
String resource = "example.geojson";
final FeatureExtractor featureExtractor = spy(new FeatureExtractor() {
@Override
public void pushFeaturesToExtractionCallback(String resource, ExtractionCallback extractionCallback) throws FeatureExtractionException {
/* stub */
}
});
final FeatureIndexer featureIndexer = spy(new FeatureIndexer() {
@Override
public void updateIndex(String resource, FeatureExtractor featureExtractor, boolean create, IndexCallback callback) throws FeatureExtractionException, FeatureIndexingException {
/* stub */
}
});
gazetteerUpdateCommand.setResource(resource);
gazetteerUpdateCommand.setFeatureExtractor(featureExtractor);
gazetteerUpdateCommand.setFeatureIndexer(featureIndexer);
gazetteerUpdateCommand.executeWithSubject();
verify(featureIndexer, times(1)).updateIndex(eq(resource), eq(featureExtractor), eq(false), any(FeatureIndexer.IndexCallback.class));
}
use of org.codice.ddf.spatial.geocoding.FeatureExtractor in project ddf by codice.
the class CatalogFeatureIndexerTest method setUp.
@Before
public void setUp() throws SecurityServiceException, InvocationTargetException, FeatureExtractionException, UnsupportedQueryException, SourceUnavailableException, FederationException {
Security security = mock(Security.class);
doAnswer(invocation -> {
Callable callback = (Callable) invocation.getArguments()[0];
callback.call();
return null;
}).when(security).runWithSubjectOrElevate(any(Callable.class));
featureExtractor = mock(FeatureExtractor.class);
doAnswer(invocation -> {
FeatureExtractor.ExtractionCallback callback = (FeatureExtractor.ExtractionCallback) invocation.getArguments()[1];
callback.extracted(getExampleFeature());
return null;
}).when(featureExtractor).pushFeaturesToExtractionCallback(eq(RESOURCE_PATH), any(FeatureExtractor.ExtractionCallback.class));
catalogFramework = mock(CatalogFramework.class);
CatalogHelper catalogHelper = new CatalogHelper(FILTER_BUILDER);
featureIndexer = new CatalogFeatureIndexer(catalogFramework, catalogHelper, generateMetacardType(), security);
featureIndexer.setSecurity(security);
QueryResponse queryResponse = mock(QueryResponse.class);
Result result = mock(Result.class);
when(result.getMetacard()).thenReturn(getExampleMetacard());
when(queryResponse.getResults()).thenReturn(Collections.singletonList(result));
when(catalogFramework.query(any())).thenReturn(queryResponse);
exampleMetacard = getExampleMetacard();
}
use of org.codice.ddf.spatial.geocoding.FeatureExtractor in project ddf by codice.
the class GazetteerUpdateCommand method executeWithSubject.
@Override
protected Object executeWithSubject() throws Exception {
final PrintStream console = System.out;
final ProgressCallback progressCallback = progress -> {
console.printf("\r%d%%", progress);
console.flush();
};
final FeatureIndexer.IndexCallback featureIndexCallback = count -> {
console.printf("\r%d features indexed", count);
console.flush();
};
console.println("Updating...");
try {
if (isResourceGeoJSON()) {
featureIndexer.updateIndex(resource, featureExtractor, create, featureIndexCallback);
} else {
geoEntryIndexer.updateIndex(resource, geoEntryExtractor, create, progressCallback);
}
console.println("\nDone.");
} catch (GeoEntryExtractionException | FeatureExtractionException e) {
LOGGER.info("Error extracting data from resource {}", resource, e);
console.printf("Could not extract data from resource %s.%n Message: %s%n Check the logs for more details.%n", resource, e.getMessage());
} catch (GeoEntryIndexingException | FeatureIndexingException e) {
LOGGER.info("Error indexing data", e);
console.printf("Could not index the data.%n Message: %s%n Check the logs for more details.%n", e.getMessage());
} catch (GeoNamesRemoteDownloadException e) {
LOGGER.info("Error downloading resource from remote source {}", resource, e);
console.printf("Could not download the GeoNames file %s.%n Message: %s%n Check the logs for more details.%n", resource, e.getMessage());
}
return null;
}
Aggregations