Search in sources :

Example 1 with GeoEntryExtractor

use of org.codice.ddf.spatial.geocoding.GeoEntryExtractor in project ddf by codice.

the class TestGeocodingMbean method setUp.

@Before
public void setUp() {
    geocoding = new Geocoding();
    geoEntryExtractor = Mockito.mock(GeoEntryExtractor.class);
    geoEntryIndexer = Mockito.mock(GeoEntryIndexer.class);
    geocoding.setGeoEntryIndexer(geoEntryIndexer);
    geocoding.setGeoEntryExtractor(geoEntryExtractor);
}
Also used : GeoEntryIndexer(org.codice.ddf.spatial.geocoding.GeoEntryIndexer) Geocoding(org.codice.ddf.spatial.admin.module.service.Geocoding) GeoEntryExtractor(org.codice.ddf.spatial.geocoding.GeoEntryExtractor) Before(org.junit.Before)

Example 2 with GeoEntryExtractor

use of org.codice.ddf.spatial.geocoding.GeoEntryExtractor in project ddf by codice.

the class TestGeoNamesUpdateCommand method testExceptionDuringIndexing.

@Test
public void testExceptionDuringIndexing() throws GeoNamesRemoteDownloadException, GeoEntryExtractionException, GeoEntryIndexingException {
    final String errorText = "Indexing error text";
    final GeoEntryExtractor geoEntryExtractor = mock(GeoEntryExtractor.class);
    final GeoEntryIndexer geoEntryIndexer = mock(GeoEntryIndexer.class);
    final GeoEntryIndexingException geoEntryIndexingException = new GeoEntryIndexingException(errorText);
    doThrow(geoEntryIndexingException).when(geoEntryIndexer).updateIndex(anyString(), any(GeoEntryExtractor.class), anyBoolean(), any(ProgressCallback.class));
    geoNamesUpdateCommand.setGeoEntryIndexer(geoEntryIndexer);
    geoNamesUpdateCommand.setGeoEntryExtractor(geoEntryExtractor);
    geoNamesUpdateCommand.setResource("temp");
    geoNamesUpdateCommand.execute();
    assertThat(consoleInterceptor.getOutput(), containsString(errorText));
    consoleInterceptor.resetSystemOut();
}
Also used : GeoEntryIndexer(org.codice.ddf.spatial.geocoding.GeoEntryIndexer) ProgressCallback(org.codice.ddf.spatial.geocoding.ProgressCallback) Matchers.anyString(org.mockito.Matchers.anyString) Matchers.containsString(org.hamcrest.Matchers.containsString) GeoEntryExtractor(org.codice.ddf.spatial.geocoding.GeoEntryExtractor) GeoEntryIndexingException(org.codice.ddf.spatial.geocoding.GeoEntryIndexingException) Test(org.junit.Test)

Example 3 with GeoEntryExtractor

use of org.codice.ddf.spatial.geocoding.GeoEntryExtractor in project ddf by codice.

the class TestGeoNamesLuceneIndexerExceptions method testExceptionWhenAddingDocumentByExtractor.

@Test
public void testExceptionWhenAddingDocumentByExtractor() throws GeoEntryIndexingException, GeoEntryExtractionException, GeoNamesRemoteDownloadException, IOException {
    configureMocks();
    geoNamesLuceneIndexer.setIndexLocation(ABSOLUTE_PATH + TEST_PATH + "index");
    try {
        final GeoEntryExtractor geoEntryExtractor = new GeoEntryExtractor() {

            @Override
            public List<GeoEntry> getGeoEntries(final String resource, final ProgressCallback progressCallback) {
                return null;
            }

            @Override
            public void pushGeoEntriesToExtractionCallback(final String resource, final ExtractionCallback extractionCallback) throws GeoEntryExtractionException {
                extractionCallback.updateProgress(0);
                try {
                    extractionCallback.extracted(GEO_ENTRY);
                } catch (GeoEntryIndexingException e) {
                    throw new GeoEntryExtractionException("Unable to add entry.", e);
                }
            }

            @Override
            public void setUrl(String url) {
                return;
            }
        };
        geoNamesLuceneIndexer.updateIndex("", geoEntryExtractor, true, null);
        fail("Should have thrown a GeoEntryExtractionException; extractionCallback.extract() threw " + "a GeoEntryIndexingException because addDocument() threw an " + "IOException.");
    } catch (GeoEntryExtractionException e) {
        assertThat(e.getCause(), instanceOf(GeoEntryIndexingException.class));
    }
}
Also used : GeoEntry(org.codice.ddf.spatial.geocoding.GeoEntry) GeoEntryExtractionException(org.codice.ddf.spatial.geocoding.GeoEntryExtractionException) ProgressCallback(org.codice.ddf.spatial.geocoding.ProgressCallback) GeoEntryExtractor(org.codice.ddf.spatial.geocoding.GeoEntryExtractor) GeoEntryIndexingException(org.codice.ddf.spatial.geocoding.GeoEntryIndexingException) Test(org.junit.Test)

Example 4 with GeoEntryExtractor

use of org.codice.ddf.spatial.geocoding.GeoEntryExtractor in project ddf by codice.

the class GeoNamesCatalogIndexer method updateIndex.

@Override
public void updateIndex(String resource, GeoEntryExtractor geoEntryExtractor, boolean create, ProgressCallback progressCallback) throws GeoEntryIndexingException, GeoEntryExtractionException, GeoNamesRemoteDownloadException {
    if (StringUtils.isBlank(resource)) {
        LOGGER.debug("The resource was null or empty.");
        return;
    }
    List<Metacard> metacardList = new ArrayList<>();
    final GeoEntryExtractor.ExtractionCallback extractionCallback = new GeoEntryExtractor.ExtractionCallback() {

        @Override
        public void extracted(final GeoEntry newEntry) throws GeoEntryIndexingException {
            Metacard metacard = transformGeoEntryToMetacard(newEntry);
            if (metacard != null) {
                metacardList.add(metacard);
            }
        }

        @Override
        public void updateProgress(final int progress) {
            if (progressCallback != null) {
                progressCallback.updateProgress(progress);
            }
        }
    };
    if (create) {
        RetryPolicy retryPolicy = new RetryPolicy().withDelay(10, TimeUnit.SECONDS).withMaxDuration(5, TimeUnit.MINUTES).retryOn(Exception.class);
        Failsafe.with(retryPolicy).run(() -> removeGeoNamesMetacardsFromCatalog(resource, extractionCallback));
    }
    geoEntryExtractor.pushGeoEntriesToExtractionCallback(resource, extractionCallback);
    if (CollectionUtils.isEmpty(metacardList)) {
        LOGGER.debug("No Metacards were created from the resource.");
        return;
    }
    executeCreateMetacardRequest(metacardList);
    LOGGER.trace("All data created for: {}", resource);
}
Also used : Metacard(ddf.catalog.data.Metacard) GeoEntry(org.codice.ddf.spatial.geocoding.GeoEntry) ArrayList(java.util.ArrayList) RetryPolicy(net.jodah.failsafe.RetryPolicy) GeoEntryExtractor(org.codice.ddf.spatial.geocoding.GeoEntryExtractor)

Example 5 with GeoEntryExtractor

use of org.codice.ddf.spatial.geocoding.GeoEntryExtractor in project ddf by codice.

the class GazetteerUpdateCommandTest method testExceptionDuringExtraction.

@Test
public void testExceptionDuringExtraction() throws Exception {
    final String errorText = "Extraction error text";
    final GeoEntryExtractor geoEntryExtractor = mock(GeoEntryExtractor.class);
    final GeoEntryExtractionException geoEntryExtractionException = new GeoEntryExtractionException(errorText);
    doThrow(geoEntryExtractionException).when(geoEntryExtractor).pushGeoEntriesToExtractionCallback(anyString(), any(ExtractionCallback.class));
    final GeoEntryIndexer geoEntryIndexer = new GeoEntryIndexer() {

        @Override
        public void updateIndex(final List<GeoEntry> newEntries, final boolean create, final ProgressCallback progressCallback, final String entrySource) {
        /* stub */
        }

        @Override
        public void updateIndex(final String resource, final GeoEntryExtractor geoEntryExtractor, final boolean create, final ProgressCallback progressCallback) throws GeoNamesRemoteDownloadException, GeoEntryExtractionException, GeoEntryIndexingException {
            geoEntryExtractor.pushGeoEntriesToExtractionCallback(resource, mock(ExtractionCallback.class));
        }
    };
    gazetteerUpdateCommand.setGeoEntryIndexer(geoEntryIndexer);
    gazetteerUpdateCommand.setGeoEntryExtractor(geoEntryExtractor);
    gazetteerUpdateCommand.setResource("temp.txt");
    gazetteerUpdateCommand.executeWithSubject();
    assertThat(consoleInterceptor.getOutput(), containsString(errorText));
    consoleInterceptor.resetSystemOut();
    consoleInterceptor.closeBuffer();
}
Also used : GeoEntryIndexer(org.codice.ddf.spatial.geocoding.GeoEntryIndexer) GeoEntryExtractionException(org.codice.ddf.spatial.geocoding.GeoEntryExtractionException) ProgressCallback(org.codice.ddf.spatial.geocoding.ProgressCallback) ArrayList(java.util.ArrayList) List(java.util.List) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ExtractionCallback(org.codice.ddf.spatial.geocoding.GeoEntryExtractor.ExtractionCallback) GeoEntryExtractor(org.codice.ddf.spatial.geocoding.GeoEntryExtractor) Test(org.junit.Test)

Aggregations

GeoEntryExtractor (org.codice.ddf.spatial.geocoding.GeoEntryExtractor)11 GeoEntryIndexer (org.codice.ddf.spatial.geocoding.GeoEntryIndexer)8 ProgressCallback (org.codice.ddf.spatial.geocoding.ProgressCallback)8 GeoEntryExtractionException (org.codice.ddf.spatial.geocoding.GeoEntryExtractionException)7 Test (org.junit.Test)7 GeoEntryIndexingException (org.codice.ddf.spatial.geocoding.GeoEntryIndexingException)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 GeoEntry (org.codice.ddf.spatial.geocoding.GeoEntry)4 ExtractionCallback (org.codice.ddf.spatial.geocoding.GeoEntryExtractor.ExtractionCallback)4 GeoNamesRemoteDownloadException (org.codice.ddf.spatial.geocoding.GeoNamesRemoteDownloadException)3 Matchers.anyString (org.mockito.Matchers.anyString)3 Before (org.junit.Before)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Metacard (ddf.catalog.data.Metacard)1 File (java.io.File)1 PrintStream (java.io.PrintStream)1 Locale (java.util.Locale)1 ExecutorService (java.util.concurrent.ExecutorService)1