Search in sources :

Example 11 with CatalogProvider

use of ddf.catalog.source.CatalogProvider in project ddf by codice.

the class HistorianTest method setup.

@Before
public void setup() {
    historian = new Historian();
    uuidGenerator = mock(UuidGenerator.class);
    when(uuidGenerator.generateUuid()).thenReturn(UUID.randomUUID().toString());
    historian.setUuidGenerator(uuidGenerator);
    catalogProvider = mock(CatalogProvider.class);
    historian.setCatalogProviders(Collections.singletonList(catalogProvider));
    storageProvider = new InMemoryStorageProvider();
    historian.setStorageProviders(Collections.singletonList(storageProvider));
    historian.setMetacardTypes(Collections.singletonList(MetacardImpl.BASIC_METACARD));
    SubjectIdentity subjectIdentity = mock(SubjectIdentity.class);
    when(subjectIdentity.getUniqueIdentifier(any())).thenReturn("test");
    historian.setSubjectIdentity(subjectIdentity);
    SubjectOperations subjectOperations = mock(SubjectOperations.class);
    when(subjectOperations.getEmailAddress(any(Subject.class))).thenReturn("test@test.com");
    when(subjectOperations.getName(any(Subject.class))).thenReturn("test");
    historian.setSubjectOperations(subjectOperations);
    historian.setSecurityLogger(mock(SecurityLogger.class));
    Security security = mock(Security.class);
    Subject subject = mock(MockSubject.class);
    when(subject.execute(any(Callable.class))).thenCallRealMethod();
    when(security.runAsAdmin(any(PrivilegedAction.class))).thenReturn(subject);
    historian.setSecurity(security);
}
Also used : SubjectOperations(ddf.security.SubjectOperations) UuidGenerator(org.codice.ddf.platform.util.uuidgenerator.UuidGenerator) CatalogProvider(ddf.catalog.source.CatalogProvider) PrivilegedAction(java.security.PrivilegedAction) SubjectIdentity(ddf.security.SubjectIdentity) Security(org.codice.ddf.security.Security) Subject(ddf.security.Subject) Callable(java.util.concurrent.Callable) SecurityLogger(ddf.security.audit.SecurityLogger) Before(org.junit.Before)

Example 12 with CatalogProvider

use of ddf.catalog.source.CatalogProvider in project ddf by codice.

the class GeoNamesCatalogIndexer method removeGeoNamesMetacardsFromCatalog.

private void removeGeoNamesMetacardsFromCatalog(String resource, ProgressCallback extractionCallback) throws UnsupportedQueryException, SourceUnavailableException, FederationException, IngestException {
    extractionCallback.updateProgress(0);
    Optional<CatalogProvider> catalogProviderOptional = catalogProviders.stream().findFirst();
    if (catalogProviderOptional.isPresent()) {
        CatalogProvider catalogProvider = catalogProviderOptional.get();
        if (StringUtils.isNotBlank(resource)) {
            filter = filterBuilder.allOf(filterBuilder.attribute(GeoEntryAttributes.IMPORT_LOCATION).is().equalTo().text(resource), filter);
        }
        while (true) {
            Query query = new QueryImpl(filter, 1, BATCH_SIZE, SortBy.NATURAL_ORDER, false, TimeUnit.SECONDS.toMillis(90));
            QueryRequest queryRequest = new QueryRequestImpl(query);
            LOGGER.trace("Removing existing geonames data with filter: {}", filter);
            QueryResponse response = catalogFramework.query(queryRequest);
            List<Serializable> metacardsToDelete = response.getResults().stream().map(Result::getMetacard).map(Metacard::getId).collect(Collectors.toList());
            if (CollectionUtils.isEmpty(metacardsToDelete)) {
                break;
            }
            LOGGER.trace("Deleting {} GeoNames metacards", metacardsToDelete.size());
            removeMetacards(catalogProvider, extractionCallback, metacardsToDelete);
        }
    }
    extractionCallback.updateProgress(50);
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Serializable(java.io.Serializable) Query(ddf.catalog.operation.Query) QueryRequest(ddf.catalog.operation.QueryRequest) CatalogProvider(ddf.catalog.source.CatalogProvider) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) Result(ddf.catalog.data.Result)

Example 13 with CatalogProvider

use of ddf.catalog.source.CatalogProvider in project ddf by codice.

the class GeoNamesCatalogIndexerTest method setUp.

@Before
public void setUp() throws Exception {
    geoEntryCreator = mock(GeoEntryCreator.class);
    when(geoEntryCreator.createGeoEntry(anyString(), anyString())).thenReturn(GEO_ENTRY);
    geoEntryExtractor = new GeoNamesFileExtractor();
    geoEntryExtractor.setGeoEntryCreator(geoEntryCreator);
    catalogFramework = mock(CatalogFramework.class);
    uuidGenerator = mock(UuidGenerator.class);
    createResponse = mock(CreateResponse.class);
    when(createResponse.getCreatedMetacards()).thenReturn(Collections.singletonList(METACARD));
    when(catalogFramework.create(any(CreateRequest.class))).thenReturn(createResponse);
    when(uuidGenerator.generateUuid()).thenReturn(UUID.randomUUID().toString());
    catalogProvider = mock(CatalogProvider.class);
    DeleteResponse deleteResponse = mock(DeleteResponse.class);
    when(deleteResponse.getDeletedMetacards()).thenReturn(Collections.singletonList(METACARD));
    when(catalogProvider.delete(any(DeleteRequest.class))).thenReturn(deleteResponse);
    queryResponse = mock(QueryResponse.class);
    when(queryResponse.getResults()).thenReturn(Collections.singletonList(new ResultImpl(new MetacardImpl())));
    when(catalogFramework.query(any(QueryRequest.class))).thenReturn(queryResponse);
    progressCallback = progress -> {
    };
    geoNamesCatalogIndexer = new GeoNamesCatalogIndexer(catalogFramework, uuidGenerator, new GeoEntryAttributes(), new GeotoolsFilterBuilder(), Collections.singletonList(catalogProvider));
}
Also used : UuidGenerator(org.codice.ddf.platform.util.uuidgenerator.UuidGenerator) QueryRequest(ddf.catalog.operation.QueryRequest) GeoEntryAttributes(org.codice.ddf.spatial.geocoding.GeoEntryAttributes) CreateResponse(ddf.catalog.operation.CreateResponse) CreateRequest(ddf.catalog.operation.CreateRequest) ResultImpl(ddf.catalog.data.impl.ResultImpl) GeoEntryCreator(org.codice.ddf.spatial.geocoding.GeoEntryCreator) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) DeleteResponse(ddf.catalog.operation.DeleteResponse) CatalogProvider(ddf.catalog.source.CatalogProvider) QueryResponse(ddf.catalog.operation.QueryResponse) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) GeoNamesFileExtractor(org.codice.ddf.spatial.geocoding.extract.GeoNamesFileExtractor) CatalogFramework(ddf.catalog.CatalogFramework) DeleteRequest(ddf.catalog.operation.DeleteRequest) Before(org.junit.Before)

Example 14 with CatalogProvider

use of ddf.catalog.source.CatalogProvider in project ddf by codice.

the class DescribeCommandTest method setUp.

@Before
public void setUp() throws Exception {
    describeCommand = new DescribeCommand();
    CatalogProvider catalogProvider = mock(CatalogProvider.class);
    doReturn(TEST_CATALOG_PROVIDER_TITLE).when(catalogProvider).getTitle();
    doReturn(TEST_CATALOG_PROVIDER_DESCRIPTION).when(catalogProvider).getDescription();
    doReturn(TEST_CATALOG_PROVIDER_ID).when(catalogProvider).getId();
    doReturn(TEST_CATALOG_PROVIDER_VERSION).when(catalogProvider).getVersion();
    describeCommand.catalogProvider = catalogProvider;
    CatalogFramework catalogFramework = mock(CatalogFramework.class);
    doReturn(TEST_CATALOG_FRAMEWORK_TITLE).when(catalogFramework).getTitle();
    doReturn(TEST_CATALOG_FRAMEWORK_DESCRIPTION).when(catalogFramework).getDescription();
    doReturn(TEST_CATALOG_FRAMEWORK_ID).when(catalogFramework).getId();
    doReturn(TEST_CATALOG_FRAMEWORK_VERSION).when(catalogFramework).getVersion();
    describeCommand.catalogFramework = catalogFramework;
}
Also used : CatalogProvider(ddf.catalog.source.CatalogProvider) CatalogFramework(ddf.catalog.CatalogFramework) Before(org.junit.Before)

Example 15 with CatalogProvider

use of ddf.catalog.source.CatalogProvider in project ddf by codice.

the class TestQueryMonitor method testActiveSearchConstructorValidInputs.

@Test
public void testActiveSearchConstructorValidInputs() {
    CatalogProvider mockSource = mock(CatalogProvider.class);
    uuid = UUID.randomUUID();
    as = new ActiveSearch(CQL_TEXT, mockSource, uuid, CLIENT_TEXT);
    assertThat(as.getCQL(), is(CQL_TEXT));
    assertThat(as.getSource(), is(mockSource));
    assertThat(as.getUniqueID(), is(uuid));
    assertThat(as.getClientInfo(), is(CLIENT_TEXT));
}
Also used : CatalogProvider(ddf.catalog.source.CatalogProvider) Test(org.junit.Test)

Aggregations

CatalogProvider (ddf.catalog.source.CatalogProvider)41 Test (org.junit.Test)26 QueryRequest (ddf.catalog.operation.QueryRequest)13 ArrayList (java.util.ArrayList)9 Result (ddf.catalog.data.Result)8 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)8 FederatedSource (ddf.catalog.source.FederatedSource)8 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)8 Metacard (ddf.catalog.data.Metacard)7 QueryResponse (ddf.catalog.operation.QueryResponse)7 CatalogFramework (ddf.catalog.CatalogFramework)6 GeotoolsFilterBuilder (ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder)6 Source (ddf.catalog.source.Source)6 ByteSource (com.google.common.io.ByteSource)5 FederationStrategy (ddf.catalog.federation.FederationStrategy)5 Query (ddf.catalog.operation.Query)5 QueryImpl (ddf.catalog.operation.impl.QueryImpl)5 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)4 FederationException (ddf.catalog.federation.FederationException)4 QueryOperations (ddf.catalog.impl.operations.QueryOperations)4