Search in sources :

Example 11 with CreateStorageResponse

use of ddf.catalog.content.operation.CreateStorageResponse in project ddf by codice.

the class FileSystemStorageProviderTest method testDeleteIdWithMultpleContent.

@Test
public void testDeleteIdWithMultpleContent() throws Exception {
    CreateStorageResponse createResponse = assertContentItem(TEST_INPUT_CONTENTS, NITF_MIME_TYPE, TEST_INPUT_FILENAME);
    createResponse = assertContentItemWithQualifier(TEST_INPUT_CONTENTS, NITF_MIME_TYPE, TEST_INPUT_FILENAME, createResponse.getCreatedContentItems().get(0).getId(), QUALIFIER);
    String id = createResponse.getCreatedContentItems().get(0).getId();
    DeleteStorageRequest deleteRequest = new DeleteStorageRequestImpl(createResponse.getCreatedContentItems().stream().map(ContentItem::getMetacard).collect(Collectors.toList()), null);
    when(deleteRequest.getMetacards().get(0).getId()).thenReturn(id);
    DeleteStorageResponse deleteResponse = provider.delete(deleteRequest);
    provider.commit(deleteRequest);
    List<ContentItem> items = deleteResponse.getDeletedContentItems();
    assertThat(items, hasSize(2));
    for (ContentItem item : items) {
        LOGGER.debug("Item retrieved: {}", item);
        assertThat(item.getId(), is(id));
        assertThat(item.getFilename(), isEmptyString());
    }
}
Also used : DeleteStorageRequest(ddf.catalog.content.operation.DeleteStorageRequest) CreateStorageResponse(ddf.catalog.content.operation.CreateStorageResponse) DeleteStorageRequestImpl(ddf.catalog.content.operation.impl.DeleteStorageRequestImpl) DeleteStorageResponse(ddf.catalog.content.operation.DeleteStorageResponse) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) ContentItem(ddf.catalog.content.data.ContentItem) Test(org.junit.Test)

Example 12 with CreateStorageResponse

use of ddf.catalog.content.operation.CreateStorageResponse in project ddf by codice.

the class FileSystemStorageProviderTest method testDeleteReference.

@Test
public void testDeleteReference() throws Exception {
    String path = baseTmpDir + File.separator + TEST_INPUT_FILENAME;
    FileUtils.writeStringToFile(new File(path), TEST_INPUT_CONTENTS);
    Map<String, Serializable> properties = new HashMap<>();
    properties.put(Constants.STORE_REFERENCE_KEY, path);
    CreateStorageResponse createResponse = assertContentItem(TEST_INPUT_CONTENTS, NITF_MIME_TYPE, TEST_INPUT_FILENAME, properties);
    String id = createResponse.getCreatedContentItems().get(0).getId();
    DeleteStorageRequest deleteRequest = new DeleteStorageRequestImpl(createResponse.getCreatedContentItems().stream().map(ContentItem::getMetacard).collect(Collectors.toList()), null);
    when(deleteRequest.getMetacards().get(0).getId()).thenReturn(id);
    DeleteStorageResponse deleteResponse = provider.delete(deleteRequest);
    List<ContentItem> items = deleteResponse.getDeletedContentItems();
    ContentItem item = items.get(0);
    LOGGER.debug("Item retrieved: {}", item);
    assertEquals(id, item.getId());
    assertThat(item.getFilename(), isEmptyString());
    assertTrue(new File(path).exists());
}
Also used : DeleteStorageRequest(ddf.catalog.content.operation.DeleteStorageRequest) CreateStorageResponse(ddf.catalog.content.operation.CreateStorageResponse) DeleteStorageRequestImpl(ddf.catalog.content.operation.impl.DeleteStorageRequestImpl) Serializable(java.io.Serializable) DeleteStorageResponse(ddf.catalog.content.operation.DeleteStorageResponse) HashMap(java.util.HashMap) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) File(java.io.File) ContentItem(ddf.catalog.content.data.ContentItem) Test(org.junit.Test)

Example 13 with CreateStorageResponse

use of ddf.catalog.content.operation.CreateStorageResponse in project ddf by codice.

the class CreateOperations method create.

public CreateResponse create(CreateStorageRequest streamCreateRequest, List<String> fanoutTagBlacklist) throws IngestException, SourceUnavailableException {
    Map<String, Metacard> metacardMap = new HashMap<>();
    List<ContentItem> contentItems = new ArrayList<>(streamCreateRequest.getContentItems().size());
    HashMap<String, Map<String, Path>> tmpContentPaths = new HashMap<>();
    CreateResponse createResponse = null;
    CreateStorageRequest createStorageRequest = null;
    CreateStorageResponse createStorageResponse;
    streamCreateRequest = opsStorageSupport.prepareStorageRequest(streamCreateRequest, streamCreateRequest::getContentItems);
    // Operation populates the metacardMap, contentItems, and tmpContentPaths
    opsMetacardSupport.generateMetacardAndContentItems(streamCreateRequest.getContentItems(), metacardMap, contentItems, tmpContentPaths);
    if (blockCreateMetacards(metacardMap.values(), fanoutTagBlacklist)) {
        String message = "Fanout proxy does not support create operations with blacklisted metacard tag";
        LOGGER.debug("{}. Tags blacklist: {}", message, fanoutTagBlacklist);
        throw new IngestException(message);
    }
    streamCreateRequest.getProperties().put(CONTENT_PATHS, tmpContentPaths);
    injectAttributes(metacardMap);
    setDefaultValues(metacardMap);
    streamCreateRequest = applyAttributeOverrides(streamCreateRequest, metacardMap);
    try {
        if (!contentItems.isEmpty()) {
            createStorageRequest = new CreateStorageRequestImpl(contentItems, streamCreateRequest.getId(), streamCreateRequest.getProperties());
            createStorageRequest = processPreCreateStoragePlugins(createStorageRequest);
            try {
                createStorageResponse = sourceOperations.getStorage().create(createStorageRequest);
                createStorageResponse.getProperties().put(CONTENT_PATHS, tmpContentPaths);
            } catch (StorageException e) {
                throw new IngestException("Could not store content items.", e);
            }
            createStorageResponse = processPostCreateStoragePlugins(createStorageResponse);
            populateMetacardMap(metacardMap, createStorageResponse);
        }
        CreateRequest createRequest = new CreateRequestImpl(new ArrayList<>(metacardMap.values()), Optional.ofNullable(createStorageRequest).map(StorageRequest::getProperties).orElseGet(HashMap::new));
        createResponse = doCreate(createRequest);
    } catch (IOException | RuntimeException e) {
        if (createStorageRequest != null) {
            try {
                sourceOperations.getStorage().rollback(createStorageRequest);
            } catch (StorageException e1) {
                LOGGER.info("Unable to remove temporary content for id: {}", createStorageRequest.getId(), e1);
            }
        }
        throw new IngestException("Unable to store products for request: " + streamCreateRequest.getId(), e);
    } finally {
        opsStorageSupport.commitAndCleanup(createStorageRequest, tmpContentPaths);
    }
    createResponse = doPostIngest(createResponse);
    return createResponse;
}
Also used : HashMap(java.util.HashMap) CreateResponse(ddf.catalog.operation.CreateResponse) CreateRequest(ddf.catalog.operation.CreateRequest) ArrayList(java.util.ArrayList) IOException(java.io.IOException) CreateStorageResponse(ddf.catalog.content.operation.CreateStorageResponse) Metacard(ddf.catalog.data.Metacard) CreateStorageRequest(ddf.catalog.content.operation.CreateStorageRequest) StorageRequest(ddf.catalog.content.operation.StorageRequest) CreateStorageRequestImpl(ddf.catalog.content.operation.impl.CreateStorageRequestImpl) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) InternalIngestException(ddf.catalog.source.InternalIngestException) IngestException(ddf.catalog.source.IngestException) Map(java.util.Map) HashMap(java.util.HashMap) StorageException(ddf.catalog.content.StorageException) ContentItem(ddf.catalog.content.data.ContentItem) CreateStorageRequest(ddf.catalog.content.operation.CreateStorageRequest)

Example 14 with CreateStorageResponse

use of ddf.catalog.content.operation.CreateStorageResponse in project ddf by codice.

the class TestVideoThumbnailPlugin method testCreatedItemNotVideoFile.

@Test
public void testCreatedItemNotVideoFile() throws Exception {
    mockContentItem = mock(ContentItem.class);
    doReturn(new MimeType("image/jpeg")).when(mockContentItem).getMimeType();
    Metacard mockMetacard = new MetacardImpl();
    doReturn(mockMetacard).when(mockContentItem).getMetacard();
    final CreateStorageResponse mockCreateResponse = mock(CreateStorageResponse.class);
    doReturn(Collections.singletonList(mockContentItem)).when(mockCreateResponse).getCreatedContentItems();
    final CreateStorageResponse processedCreateResponse = videoThumbnailPlugin.process(mockCreateResponse);
    assertThat(processedCreateResponse.getCreatedContentItems().get(0).getMetacard().getAttribute(Metacard.THUMBNAIL), CoreMatchers.is(nullValue()));
}
Also used : CreateStorageResponse(ddf.catalog.content.operation.CreateStorageResponse) Metacard(ddf.catalog.data.Metacard) ContentItem(ddf.catalog.content.data.ContentItem) MimeType(javax.activation.MimeType) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 15 with CreateStorageResponse

use of ddf.catalog.content.operation.CreateStorageResponse in project ddf by codice.

the class TestVideoThumbnailPlugin method getCreatedItemThumbnail.

private byte[] getCreatedItemThumbnail(final String videoFile) throws Exception {
    setUpMockContentItem(videoFile);
    final CreateStorageResponse mockCreateResponse = mock(CreateStorageResponse.class);
    doReturn(Collections.singletonList(mockContentItem)).when(mockCreateResponse).getCreatedContentItems();
    final CreateStorageRequest mockCreateRequest = mock(CreateStorageRequest.class);
    doReturn(mockCreateRequest).when(mockCreateResponse).getRequest();
    doReturn(properties).when(mockCreateResponse).getProperties();
    final CreateStorageResponse processedCreateResponse = videoThumbnailPlugin.process(mockCreateResponse);
    return (byte[]) processedCreateResponse.getCreatedContentItems().get(0).getMetacard().getAttribute(Metacard.THUMBNAIL).getValue();
}
Also used : CreateStorageResponse(ddf.catalog.content.operation.CreateStorageResponse) CreateStorageRequest(ddf.catalog.content.operation.CreateStorageRequest)

Aggregations

CreateStorageResponse (ddf.catalog.content.operation.CreateStorageResponse)24 ContentItem (ddf.catalog.content.data.ContentItem)18 Test (org.junit.Test)17 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)16 Metacard (ddf.catalog.data.Metacard)11 ByteSource (com.google.common.io.ByteSource)9 ContentItemImpl (ddf.catalog.content.data.impl.ContentItemImpl)9 CreateStorageRequestImpl (ddf.catalog.content.operation.impl.CreateStorageRequestImpl)7 StorageException (ddf.catalog.content.StorageException)5 CreateStorageRequest (ddf.catalog.content.operation.CreateStorageRequest)5 DeleteStorageRequest (ddf.catalog.content.operation.DeleteStorageRequest)5 DeleteStorageResponse (ddf.catalog.content.operation.DeleteStorageResponse)5 DeleteStorageRequestImpl (ddf.catalog.content.operation.impl.DeleteStorageRequestImpl)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 ReadStorageResponse (ddf.catalog.content.operation.ReadStorageResponse)4 ReadStorageRequestImpl (ddf.catalog.content.operation.impl.ReadStorageRequestImpl)4 IOException (java.io.IOException)4 URI (java.net.URI)4 ReadStorageRequest (ddf.catalog.content.operation.ReadStorageRequest)3