Search in sources :

Example 6 with ResourceOperations

use of ddf.catalog.impl.operations.ResourceOperations in project ddf by codice.

the class FanoutCatalogFrameworkTest method testBlacklistedTagCreateStorageRequestFails.

@Test(expected = IngestException.class)
public void testBlacklistedTagCreateStorageRequestFails() throws Exception {
    Metacard metacard = new MetacardImpl();
    metacard.setAttribute(new AttributeImpl(Metacard.TAGS, "blacklisted"));
    CatalogProvider catalogProvider = mock(CatalogProvider.class);
    doReturn(true).when(catalogProvider).isAvailable();
    StorageProvider storageProvider = new MockMemoryStorageProvider();
    MimeTypeMapper mimeTypeMapper = mock(MimeTypeMapper.class);
    doReturn("extension").when(mimeTypeMapper).getFileExtensionForMimeType(anyString());
    InputTransformer transformer = mock(InputTransformer.class);
    doReturn(metacard).when(transformer).transform(any(InputStream.class));
    MimeTypeToTransformerMapper mimeTypeToTransformerMapper = mock(MimeTypeToTransformerMapper.class);
    doReturn(Collections.singletonList(transformer)).when(mimeTypeToTransformerMapper).findMatches(any(Class.class), any(MimeType.class));
    frameworkProperties.setCatalogProviders(Collections.singletonList(catalogProvider));
    frameworkProperties.setStorageProviders(Collections.singletonList(storageProvider));
    frameworkProperties.setMimeTypeMapper(mimeTypeMapper);
    frameworkProperties.setMimeTypeToTransformerMapper(mimeTypeToTransformerMapper);
    OperationsSecuritySupport opsSecurity = new OperationsSecuritySupport();
    MetacardFactory metacardFactory = new MetacardFactory(frameworkProperties.getMimeTypeToTransformerMapper(), uuidGenerator);
    OperationsMetacardSupport opsMetacard = new OperationsMetacardSupport(frameworkProperties, metacardFactory);
    SourceOperations sourceOperations = new SourceOperations(frameworkProperties);
    sourceOperations.bind(catalogProvider);
    sourceOperations.bind(storageProvider);
    TransformOperations transformOperations = new TransformOperations(frameworkProperties);
    QueryOperations queryOperations = new QueryOperations(frameworkProperties, sourceOperations, opsSecurity, opsMetacard);
    OperationsCatalogStoreSupport opsCatStore = new OperationsCatalogStoreSupport(frameworkProperties, sourceOperations);
    OperationsStorageSupport opsStorage = new OperationsStorageSupport(sourceOperations, queryOperations);
    ResourceOperations resourceOperations = new ResourceOperations(frameworkProperties, queryOperations, opsSecurity);
    OperationsMetacardSupport opsMetacardSupport = new OperationsMetacardSupport(frameworkProperties, metacardFactory);
    // Need to set these for InputValidation to work
    System.setProperty("bad.files", "none");
    System.setProperty("bad.file.extensions", "none");
    System.setProperty("bad.mime.types", "none");
    CreateOperations createOperations = new CreateOperations(frameworkProperties, queryOperations, sourceOperations, opsSecurity, opsMetacardSupport, opsCatStore, opsStorage);
    framework = new CatalogFrameworkImpl(createOperations, null, null, queryOperations, resourceOperations, sourceOperations, transformOperations);
    framework.setId(NEW_SOURCE_ID);
    framework.setFanoutEnabled(true);
    framework.setFanoutTagBlacklist(Collections.singletonList("blacklisted"));
    ContentItem item = new ContentItemImpl(uuidGenerator.generateUuid(), ByteSource.empty(), "text/xml", "filename.xml", 0L, metacard);
    CreateStorageRequest request = new CreateStorageRequestImpl(Collections.singletonList(item), new HashMap<>());
    framework.create(request);
}
Also used : MimeTypeToTransformerMapper(ddf.mime.MimeTypeToTransformerMapper) OperationsCatalogStoreSupport(ddf.catalog.impl.operations.OperationsCatalogStoreSupport) MimeTypeMapper(ddf.mime.MimeTypeMapper) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) MockMemoryStorageProvider(ddf.catalog.content.impl.MockMemoryStorageProvider) InputTransformer(ddf.catalog.transform.InputTransformer) MimeType(javax.activation.MimeType) MetacardFactory(ddf.catalog.impl.operations.MetacardFactory) OperationsStorageSupport(ddf.catalog.impl.operations.OperationsStorageSupport) CreateStorageRequestImpl(ddf.catalog.content.operation.impl.CreateStorageRequestImpl) SourceOperations(ddf.catalog.impl.operations.SourceOperations) InputStream(java.io.InputStream) ResourceOperations(ddf.catalog.impl.operations.ResourceOperations) StorageProvider(ddf.catalog.content.StorageProvider) MockMemoryStorageProvider(ddf.catalog.content.impl.MockMemoryStorageProvider) TransformOperations(ddf.catalog.impl.operations.TransformOperations) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Metacard(ddf.catalog.data.Metacard) CatalogProvider(ddf.catalog.source.CatalogProvider) QueryOperations(ddf.catalog.impl.operations.QueryOperations) OperationsSecuritySupport(ddf.catalog.impl.operations.OperationsSecuritySupport) CreateOperations(ddf.catalog.impl.operations.CreateOperations) OperationsMetacardSupport(ddf.catalog.impl.operations.OperationsMetacardSupport) ContentItem(ddf.catalog.content.data.ContentItem) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl) CreateStorageRequest(ddf.catalog.content.operation.CreateStorageRequest) Test(org.junit.Test)

Example 7 with ResourceOperations

use of ddf.catalog.impl.operations.ResourceOperations in project ddf by codice.

the class FanoutCatalogFrameworkTest method testBlacklistedTagDeleteRequestFails.

@Test(expected = IngestException.class)
public void testBlacklistedTagDeleteRequestFails() throws Exception {
    Metacard metacard = new MetacardImpl();
    metacard.setAttribute(new AttributeImpl(Metacard.ID, "metacardId"));
    metacard.setAttribute(new AttributeImpl(Metacard.TAGS, "blacklisted"));
    CatalogProvider catalogProvider = mock(CatalogProvider.class);
    doReturn(true).when(catalogProvider).isAvailable();
    StorageProvider storageProvider = new MockMemoryStorageProvider();
    FilterBuilder filterBuilder = new GeotoolsFilterBuilder();
    FilterAdapter filterAdapter = mock(FilterAdapter.class);
    ValidationQueryFactory validationQueryFactory = new ValidationQueryFactory(filterAdapter, filterBuilder);
    QueryRequestImpl queryRequest = new QueryRequestImpl(mock(Query.class));
    ResultImpl result = new ResultImpl(metacard);
    List<Result> results = new ArrayList<>();
    results.add(result);
    QueryResponseImpl queryResponse = new QueryResponseImpl(queryRequest, results, 1);
    FederationStrategy strategy = mock(FederationStrategy.class);
    when(strategy.federate(anyList(), any())).thenReturn(queryResponse);
    QueryResponsePostProcessor queryResponsePostProcessor = mock(QueryResponsePostProcessor.class);
    doNothing().when(queryResponsePostProcessor).processResponse(any());
    frameworkProperties.setCatalogProviders(Collections.singletonList(catalogProvider));
    frameworkProperties.setStorageProviders(Collections.singletonList(storageProvider));
    frameworkProperties.setFilterBuilder(filterBuilder);
    frameworkProperties.setValidationQueryFactory(validationQueryFactory);
    frameworkProperties.setFederationStrategy(strategy);
    frameworkProperties.setQueryResponsePostProcessor(queryResponsePostProcessor);
    OperationsSecuritySupport opsSecurity = new OperationsSecuritySupport();
    MetacardFactory metacardFactory = new MetacardFactory(frameworkProperties.getMimeTypeToTransformerMapper(), uuidGenerator);
    OperationsMetacardSupport opsMetacard = new OperationsMetacardSupport(frameworkProperties, metacardFactory);
    SourceOperations sourceOperations = new SourceOperations(frameworkProperties);
    sourceOperations.bind(catalogProvider);
    sourceOperations.bind(storageProvider);
    TransformOperations transformOperations = new TransformOperations(frameworkProperties);
    QueryOperations queryOperations = new QueryOperations(frameworkProperties, sourceOperations, opsSecurity, opsMetacard);
    OperationsCatalogStoreSupport opsCatStore = new OperationsCatalogStoreSupport(frameworkProperties, sourceOperations);
    ResourceOperations resourceOperations = new ResourceOperations(frameworkProperties, queryOperations, opsSecurity);
    DeleteOperations deleteOperations = new DeleteOperations(frameworkProperties, queryOperations, sourceOperations, opsSecurity, null);
    deleteOperations.setOpsCatStoreSupport(opsCatStore);
    framework = new CatalogFrameworkImpl(null, null, deleteOperations, queryOperations, resourceOperations, sourceOperations, transformOperations);
    framework.setId(NEW_SOURCE_ID);
    framework.setFanoutEnabled(true);
    framework.setFanoutTagBlacklist(Collections.singletonList("blacklisted"));
    DeleteRequest request = new DeleteRequestImpl(metacard.getId());
    framework.delete(request);
}
Also used : OperationsCatalogStoreSupport(ddf.catalog.impl.operations.OperationsCatalogStoreSupport) Query(ddf.catalog.operation.Query) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) MockMemoryStorageProvider(ddf.catalog.content.impl.MockMemoryStorageProvider) ArrayList(java.util.ArrayList) FilterAdapter(ddf.catalog.filter.FilterAdapter) ResultImpl(ddf.catalog.data.impl.ResultImpl) DeleteOperations(ddf.catalog.impl.operations.DeleteOperations) Result(ddf.catalog.data.Result) MetacardFactory(ddf.catalog.impl.operations.MetacardFactory) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) FilterBuilder(ddf.catalog.filter.FilterBuilder) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) SourceOperations(ddf.catalog.impl.operations.SourceOperations) FederationStrategy(ddf.catalog.federation.FederationStrategy) ResourceOperations(ddf.catalog.impl.operations.ResourceOperations) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) ValidationQueryFactory(ddf.catalog.cache.solr.impl.ValidationQueryFactory) StorageProvider(ddf.catalog.content.StorageProvider) MockMemoryStorageProvider(ddf.catalog.content.impl.MockMemoryStorageProvider) TransformOperations(ddf.catalog.impl.operations.TransformOperations) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Metacard(ddf.catalog.data.Metacard) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) CatalogProvider(ddf.catalog.source.CatalogProvider) QueryOperations(ddf.catalog.impl.operations.QueryOperations) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) OperationsSecuritySupport(ddf.catalog.impl.operations.OperationsSecuritySupport) OperationsMetacardSupport(ddf.catalog.impl.operations.OperationsMetacardSupport) DeleteRequest(ddf.catalog.operation.DeleteRequest) Test(org.junit.Test)

Aggregations

QueryOperations (ddf.catalog.impl.operations.QueryOperations)7 ResourceOperations (ddf.catalog.impl.operations.ResourceOperations)7 SourceOperations (ddf.catalog.impl.operations.SourceOperations)7 MetacardFactory (ddf.catalog.impl.operations.MetacardFactory)6 OperationsCatalogStoreSupport (ddf.catalog.impl.operations.OperationsCatalogStoreSupport)6 OperationsMetacardSupport (ddf.catalog.impl.operations.OperationsMetacardSupport)6 OperationsSecuritySupport (ddf.catalog.impl.operations.OperationsSecuritySupport)6 TransformOperations (ddf.catalog.impl.operations.TransformOperations)6 CreateOperations (ddf.catalog.impl.operations.CreateOperations)5 DeleteOperations (ddf.catalog.impl.operations.DeleteOperations)5 OperationsStorageSupport (ddf.catalog.impl.operations.OperationsStorageSupport)5 Metacard (ddf.catalog.data.Metacard)4 UpdateOperations (ddf.catalog.impl.operations.UpdateOperations)4 CatalogProvider (ddf.catalog.source.CatalogProvider)4 ArrayList (java.util.ArrayList)4 MockMemoryStorageProvider (ddf.catalog.content.impl.MockMemoryStorageProvider)3 Result (ddf.catalog.data.Result)3 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)3 FederationStrategy (ddf.catalog.federation.FederationStrategy)3 GeotoolsFilterBuilder (ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder)3