Search in sources :

Example 86 with ContentItem

use of ddf.catalog.content.data.ContentItem in project ddf by codice.

the class FanoutCatalogFrameworkTest method testBlacklistedTagUpdateStorageRequestFails.

@Test(expected = IngestException.class)
public void testBlacklistedTagUpdateStorageRequestFails() throws Exception {
    Metacard metacard = new MetacardImpl();
    metacard.setAttribute(new AttributeImpl(Metacard.ID, "metacardId"));
    metacard.setAttribute(new AttributeImpl(Metacard.TAGS, "blacklisted"));
    ContentItem item = new ContentItemImpl(uuidGenerator.generateUuid(), ByteSource.empty(), "text/xml", "filename.xml", 0L, metacard);
    UpdateStorageRequest request = new UpdateStorageRequestImpl(Collections.singletonList(item), new HashMap<>());
    framework.setFanoutTagBlacklist(Collections.singletonList("blacklisted"));
    framework.update(request);
}
Also used : Metacard(ddf.catalog.data.Metacard) UpdateStorageRequestImpl(ddf.catalog.content.operation.impl.UpdateStorageRequestImpl) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) ContentItem(ddf.catalog.content.data.ContentItem) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl) Test(org.junit.Test)

Example 87 with ContentItem

use of ddf.catalog.content.data.ContentItem 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);
    final SourcePoller<SourceStatus> mockStatusSourcePoller = mock(SourcePoller.class);
    doAnswer(invocationOnMock -> Optional.of(((Source) invocationOnMock.getArguments()[0]).isAvailable() ? SourceStatus.AVAILABLE : SourceStatus.UNAVAILABLE)).when(mockStatusSourcePoller).getCachedValueForSource(any(Source.class));
    SourceOperations sourceOperations = new SourceOperations(frameworkProperties, sourceActionRegistry, mockStatusSourcePoller, mock(SourcePoller.class));
    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");
    System.setProperty("ignore.files", "");
    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) FederatedSource(ddf.catalog.source.FederatedSource) Source(ddf.catalog.source.Source) ConnectedSource(ddf.catalog.source.ConnectedSource) ByteSource(com.google.common.io.ByteSource) SourcePoller(org.codice.ddf.catalog.sourcepoller.SourcePoller) 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) SourceStatus(org.codice.ddf.catalog.sourcepoller.SourceStatus) 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 88 with ContentItem

use of ddf.catalog.content.data.ContentItem in project ddf by codice.

the class InMemoryStorageProvider method delete.

@Override
public DeleteStorageResponse delete(DeleteStorageRequest deleteRequest) throws StorageException {
    if (deleteRequest == null) {
        throw new StorageException("delete request can't be null");
    }
    List<ContentItem> itemsToDelete = new ArrayList<>();
    for (Metacard metacard : deleteRequest.getMetacards()) {
        List<ContentItem> tmp = storageMap.values().stream().filter(item -> item.getMetacard().getId().equals(metacard.getId())).collect(Collectors.toList());
        if (tmp.isEmpty()) {
            throw new StorageException("can't delete a metacard that isn't stored");
        }
        itemsToDelete.addAll(tmp);
    }
    for (ContentItem item : itemsToDelete) {
        deleteMap.put(item.getUri(), item);
    }
    return new DeleteStorageResponseImpl(deleteRequest, itemsToDelete);
}
Also used : CreateStorageRequest(ddf.catalog.content.operation.CreateStorageRequest) HashMap(java.util.HashMap) ReadStorageRequest(ddf.catalog.content.operation.ReadStorageRequest) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) StorageRequest(ddf.catalog.content.operation.StorageRequest) CreateStorageResponseImpl(ddf.catalog.content.operation.impl.CreateStorageResponseImpl) StorageException(ddf.catalog.content.StorageException) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) ReadStorageResponseImpl(ddf.catalog.content.operation.impl.ReadStorageResponseImpl) List(java.util.List) ContentItem(ddf.catalog.content.data.ContentItem) CreateStorageResponse(ddf.catalog.content.operation.CreateStorageResponse) DeleteStorageRequest(ddf.catalog.content.operation.DeleteStorageRequest) DeleteStorageResponseImpl(ddf.catalog.content.operation.impl.DeleteStorageResponseImpl) UpdateStorageResponseImpl(ddf.catalog.content.operation.impl.UpdateStorageResponseImpl) Metacard(ddf.catalog.data.Metacard) Map(java.util.Map) StorageProvider(ddf.catalog.content.StorageProvider) DeleteStorageResponse(ddf.catalog.content.operation.DeleteStorageResponse) UpdateStorageResponse(ddf.catalog.content.operation.UpdateStorageResponse) ReadStorageResponse(ddf.catalog.content.operation.ReadStorageResponse) Metacard(ddf.catalog.data.Metacard) ArrayList(java.util.ArrayList) StorageException(ddf.catalog.content.StorageException) ContentItem(ddf.catalog.content.data.ContentItem) DeleteStorageResponseImpl(ddf.catalog.content.operation.impl.DeleteStorageResponseImpl)

Example 89 with ContentItem

use of ddf.catalog.content.data.ContentItem in project ddf by codice.

the class OverrideAttributesSupportTest method testNoContentItems.

@Test
public void testNoContentItems() throws URISyntaxException {
    List<ContentItem> contentItems = new ArrayList<>();
    Map<String, Metacard> metacardMap = new HashMap<>();
    MetacardImpl metacard = new MetacardImpl();
    metacard.setMetadata("original");
    metacard.setTitle("original");
    metacard.setId("original");
    metacard.setResourceURI(new URI("content:stuff"));
    metacardMap.put(metacard.getId(), metacard);
    OverrideAttributesSupport.overrideAttributes(contentItems, metacardMap);
    assertNotNull(metacardMap.get("original"));
    assertThat(metacardMap.get("original").getMetadata(), is("original"));
    assertThat(metacardMap.get("original").getTitle(), is("original"));
    assertThat(metacardMap.get("original").getResourceURI().toString(), is("content:stuff"));
    assertThat(metacardMap.get("original").getId(), is("original"));
}
Also used : Metacard(ddf.catalog.data.Metacard) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URI(java.net.URI) ContentItem(ddf.catalog.content.data.ContentItem) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 90 with ContentItem

use of ddf.catalog.content.data.ContentItem in project ddf by codice.

the class HistorianTest method testRollbackFailed.

@Test(expected = IngestException.class)
public void testRollbackFailed() throws StorageException, UnsupportedQueryException, SourceUnavailableException, IngestException {
    List<Metacard> metacards = getMetacardUpdatePair();
    // Mock out a bad storage provider
    StorageProvider exceptionStorageProvider = mock(StorageProvider.class);
    doThrow(StorageException.class).when(exceptionStorageProvider).commit(any());
    doThrow(StorageException.class).when(exceptionStorageProvider).rollback(any());
    ContentItem item = mock(ContentItem.class);
    when(item.getId()).thenReturn(METACARD_ID);
    when(item.getUri()).thenReturn(RESOURCE_URI);
    when(item.getMetacard()).thenReturn(metacards.get(0));
    ReadStorageResponse readStorageResponse = mock(ReadStorageResponse.class);
    when(readStorageResponse.getContentItem()).thenReturn(item);
    when(exceptionStorageProvider.read(any())).thenReturn(readStorageResponse);
    when(exceptionStorageProvider.create(any())).thenReturn(mock(CreateStorageResponse.class));
    historian.setStorageProviders(Collections.singletonList(exceptionStorageProvider));
    // Parameters for historian
    UpdateStorageRequest storageRequest = mock(UpdateStorageRequest.class);
    UpdateStorageResponse storageResponse = mock(UpdateStorageResponse.class);
    UpdateResponse updateResponse = mock(UpdateResponse.class);
    Update update1 = mock(Update.class);
    when(update1.getOldMetacard()).thenReturn(metacards.get(0));
    when(updateResponse.getUpdatedMetacards()).thenReturn(ImmutableList.of(update1));
    // send a request to update the metacard
    updateMetacard(storageRequest, storageResponse, metacards.get(1));
    mockQuery(metacards.get(1));
    historian.version(storageRequest, storageResponse, updateResponse);
    verify(exceptionStorageProvider).rollback(any(StorageRequest.class));
}
Also used : CreateStorageResponse(ddf.catalog.content.operation.CreateStorageResponse) UpdateResponse(ddf.catalog.operation.UpdateResponse) DeletedMetacard(ddf.catalog.core.versioning.DeletedMetacard) Metacard(ddf.catalog.data.Metacard) ReadStorageRequest(ddf.catalog.content.operation.ReadStorageRequest) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) DeleteStorageRequest(ddf.catalog.content.operation.DeleteStorageRequest) StorageRequest(ddf.catalog.content.operation.StorageRequest) UpdateStorageResponse(ddf.catalog.content.operation.UpdateStorageResponse) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) ReadStorageResponse(ddf.catalog.content.operation.ReadStorageResponse) StorageProvider(ddf.catalog.content.StorageProvider) Update(ddf.catalog.operation.Update) ContentItem(ddf.catalog.content.data.ContentItem) Test(org.junit.Test)

Aggregations

ContentItem (ddf.catalog.content.data.ContentItem)92 Test (org.junit.Test)51 Metacard (ddf.catalog.data.Metacard)44 ContentItemImpl (ddf.catalog.content.data.impl.ContentItemImpl)31 CreateStorageResponse (ddf.catalog.content.operation.CreateStorageResponse)30 ArrayList (java.util.ArrayList)29 IOException (java.io.IOException)21 HashMap (java.util.HashMap)21 ByteSource (com.google.common.io.ByteSource)20 URI (java.net.URI)20 UpdateStorageRequest (ddf.catalog.content.operation.UpdateStorageRequest)17 CreateStorageRequestImpl (ddf.catalog.content.operation.impl.CreateStorageRequestImpl)16 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)16 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)15 InputStream (java.io.InputStream)14 StorageException (ddf.catalog.content.StorageException)13 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)13 UpdateStorageResponse (ddf.catalog.content.operation.UpdateStorageResponse)12 Map (java.util.Map)12 StorageProvider (ddf.catalog.content.StorageProvider)11