Search in sources :

Example 1 with DeleteStorageResponseImpl

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;
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) DeleteStorageResponseImpl(ddf.catalog.content.operation.impl.DeleteStorageResponseImpl) Metacard(ddf.catalog.data.Metacard) DeleteStorageResponse(ddf.catalog.content.operation.DeleteStorageResponse) StorageException(ddf.catalog.content.StorageException) ContentItem(ddf.catalog.content.data.ContentItem) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl)

Example 2 with DeleteStorageResponseImpl

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);
}
Also used : CreateStorageRequest(ddf.catalog.content.operation.CreateStorageRequest) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) ReadStorageRequest(ddf.catalog.content.operation.ReadStorageRequest) 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

StorageException (ddf.catalog.content.StorageException)2 ContentItem (ddf.catalog.content.data.ContentItem)2 DeleteStorageResponse (ddf.catalog.content.operation.DeleteStorageResponse)2 DeleteStorageResponseImpl (ddf.catalog.content.operation.impl.DeleteStorageResponseImpl)2 Metacard (ddf.catalog.data.Metacard)2 ArrayList (java.util.ArrayList)2 StorageProvider (ddf.catalog.content.StorageProvider)1 ContentItemImpl (ddf.catalog.content.data.impl.ContentItemImpl)1 CreateStorageRequest (ddf.catalog.content.operation.CreateStorageRequest)1 CreateStorageResponse (ddf.catalog.content.operation.CreateStorageResponse)1 DeleteStorageRequest (ddf.catalog.content.operation.DeleteStorageRequest)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 CreateStorageResponseImpl (ddf.catalog.content.operation.impl.CreateStorageResponseImpl)1 ReadStorageResponseImpl (ddf.catalog.content.operation.impl.ReadStorageResponseImpl)1 UpdateStorageResponseImpl (ddf.catalog.content.operation.impl.UpdateStorageResponseImpl)1 IOException (java.io.IOException)1