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());
}
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! ");
}
}
}
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);
}
Aggregations