Search in sources :

Example 6 with DeleteStorageResponse

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

the class FileSystemStorageProviderTest method testDeleteReference.

@Test
public void testDeleteReference() throws Exception {
    String path = baseTmpDir + File.separator + TEST_INPUT_FILENAME;
    File tempFile = new File(path);
    FileUtils.writeStringToFile(tempFile, TEST_INPUT_CONTENTS);
    Map<String, Serializable> properties = new HashMap<>();
    properties.put(Constants.STORE_REFERENCE_KEY, tempFile.toURI().toASCIIString());
    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(tempFile.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 7 with DeleteStorageResponse

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

the class FileSystemStorageProviderTest method testDeleteWithSimilarIds.

@Test
public void testDeleteWithSimilarIds() throws Exception {
    CreateStorageResponse createResponse = assertContentItem(TEST_INPUT_CONTENTS, NITF_MIME_TYPE, TEST_INPUT_FILENAME);
    String id = createResponse.getCreatedContentItems().get(0).getId();
    String uuid = UUID.randomUUID().toString().replaceAll("-", "");
    String badId = id.substring(0, 6) + uuid.substring(6, uuid.length() - 1);
    boolean hadError = false;
    try {
        CreateStorageResponse badCreateResponse = assertContentItemWithQualifier(TEST_INPUT_CONTENTS, NITF_MIME_TYPE, TEST_INPUT_FILENAME, badId, "");
    } catch (AssertionError e) {
        // bad id is not a valid ID
        hadError = true;
    } finally {
        if (!hadError) {
            fail("Create succeeded when it should not have! " + badId + "Should not be valid!");
        }
        hadError = false;
    }
    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(), is(""));
    provider.commit(deleteRequest);
    try {
        assertReadRequest(createResponse.getCreatedContentItems().get(0).getUri(), NITF_MIME_TYPE);
    } catch (StorageException e) {
        // The item was deleted so it shouldn't have found it
        hadError = true;
    } finally {
        if (!hadError) {
            fail("read succeeded when it should not have! ");
        }
    }
}
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) StorageException(ddf.catalog.content.StorageException) ContentItem(ddf.catalog.content.data.ContentItem) Test(org.junit.Test)

Example 8 with DeleteStorageResponse

use of ddf.catalog.content.operation.DeleteStorageResponse 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)

Aggregations

ContentItem (ddf.catalog.content.data.ContentItem)8 DeleteStorageResponse (ddf.catalog.content.operation.DeleteStorageResponse)8 DeleteStorageRequest (ddf.catalog.content.operation.DeleteStorageRequest)7 CreateStorageResponse (ddf.catalog.content.operation.CreateStorageResponse)6 DeleteStorageRequestImpl (ddf.catalog.content.operation.impl.DeleteStorageRequestImpl)6 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)6 Test (org.junit.Test)6 StorageException (ddf.catalog.content.StorageException)3 Metacard (ddf.catalog.data.Metacard)3 ContentItemImpl (ddf.catalog.content.data.impl.ContentItemImpl)2 DeleteStorageResponseImpl (ddf.catalog.content.operation.impl.DeleteStorageResponseImpl)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 StorageProvider (ddf.catalog.content.StorageProvider)1 CreateStorageRequest (ddf.catalog.content.operation.CreateStorageRequest)1 ReadStorageRequest (ddf.catalog.content.operation.ReadStorageRequest)1 ReadStorageResponse (ddf.catalog.content.operation.ReadStorageResponse)1 StorageRequest (ddf.catalog.content.operation.StorageRequest)1 UpdateStorageRequest (ddf.catalog.content.operation.UpdateStorageRequest)1 UpdateStorageResponse (ddf.catalog.content.operation.UpdateStorageResponse)1