use of ddf.catalog.content.operation.impl.DeleteStorageResponseImpl 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 (Files.exists(contentIdDir)) {
List<Path> paths = new ArrayList<>();
if (Files.isDirectory(contentIdDir)) {
paths = listPaths(contentIdDir);
} else {
paths.add(contentIdDir);
}
for (Path path : paths) {
if (Files.exists(path)) {
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.impl.DeleteStorageResponseImpl 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