use of ddf.catalog.content.operation.DeleteStorageResponse in project ddf by codice.
the class FileSystemStorageProvider method delete.
@Override
public DeleteStorageResponse delete(DeleteStorageRequest deleteRequest) throws StorageException {
LOGGER.trace("ENTERING: delete");
List<Metacard> itemsToBeDeleted = new ArrayList<>();
List<ContentItem> deletedContentItems = new ArrayList<>(deleteRequest.getMetacards().size());
for (Metacard metacard : deleteRequest.getMetacards()) {
LOGGER.debug("File to be deleted: {}", metacard.getId());
ContentItem deletedContentItem = new ContentItemImpl(metacard.getId(), "", null, "", "", 0, metacard);
if (!ContentItemValidator.validate(deletedContentItem)) {
LOGGER.warn("Cannot delete invalid content item ({})", deletedContentItem);
continue;
}
try {
// For deletion we can ignore the qualifier and assume everything under a given ID is
// to be removed.
Path contentIdDir = getContentItemDir(new URI(deletedContentItem.getUri()));
if (contentIdDir != null && contentIdDir.toFile().exists()) {
List<Path> paths = new ArrayList<>();
if (contentIdDir.toFile().isDirectory()) {
paths = listPaths(contentIdDir);
} else {
paths.add(contentIdDir);
}
for (Path path : paths) {
if (path.toFile().exists()) {
deletedContentItems.add(deletedContentItem);
}
}
itemsToBeDeleted.add(metacard);
}
} catch (IOException | URISyntaxException e) {
throw new StorageException("Could not delete file: " + metacard.getId(), e);
}
}
deletionMap.put(deleteRequest.getId(), itemsToBeDeleted);
DeleteStorageResponse response = new DeleteStorageResponseImpl(deleteRequest, deletedContentItems);
LOGGER.trace("EXITING: delete");
return response;
}
use of ddf.catalog.content.operation.DeleteStorageResponse in project ddf by codice.
the class FileSystemStorageProviderTest method testDeleteWithQualifier.
@Test
public void testDeleteWithQualifier() throws Exception {
CreateStorageResponse createResponse = assertContentItemWithQualifier(TEST_INPUT_CONTENTS, NITF_MIME_TYPE, TEST_INPUT_FILENAME, "", 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();
ContentItem item = items.get(0);
LOGGER.debug("Item retrieved: {}", item);
assertEquals(id, item.getId());
assertThat(item.getFilename(), is(""));
}
use of ddf.catalog.content.operation.DeleteStorageResponse in project ddf by codice.
the class FileSystemStorageProviderTest method testDelete.
@Test
public void testDelete() throws Exception {
CreateStorageResponse createResponse = assertContentItem(TEST_INPUT_CONTENTS, NITF_MIME_TYPE, TEST_INPUT_FILENAME);
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());
}
use of ddf.catalog.content.operation.DeleteStorageResponse 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());
}
}
use of ddf.catalog.content.operation.DeleteStorageResponse in project ddf by codice.
the class FileSystemStorageProviderTest method testInvalidDelete.
@Test
public void testInvalidDelete() throws Exception {
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
Metacard metacard = mock(Metacard.class);
when(metacard.getId()).thenReturn(uuid);
ContentItem contentItem = new ContentItemImpl(uuid, null, null, "application/text", "datadatadata", 0, metacard);
DeleteStorageRequest deleteRequest = new DeleteStorageRequestImpl(Lists.newArrayList(metacard), null);
DeleteStorageResponse deleteResponse = provider.delete(deleteRequest);
assertThat(deleteResponse.getDeletedContentItems().size(), is(0));
}
Aggregations