use of ddf.catalog.content.StorageException in project ddf by codice.
the class FileSystemStorageProvider method getContentFilePath.
private Path getContentFilePath(URI uri) throws StorageException {
Path contentIdDir = getContentItemDir(uri);
List<Path> contentFiles;
if (contentIdDir != null && contentIdDir.toFile().exists()) {
try {
contentFiles = listPaths(contentIdDir);
} catch (IOException e) {
throw new StorageException(e);
}
contentFiles.removeIf(Files::isDirectory);
if (contentFiles.size() != 1) {
throw new StorageException("Content ID: " + uri.getSchemeSpecificPart() + " storage folder is corrupted.");
}
// there should only be one file
return contentFiles.get(0);
}
return null;
}
use of ddf.catalog.content.StorageException 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.StorageException in project ddf by codice.
the class FileSystemStorageProvider method rollback.
@Override
public void rollback(StorageRequest request) throws StorageException {
String id = request.getId();
Path requestIdDir = Paths.get(baseContentTmpDirectory.toAbsolutePath().toString(), id);
deletionMap.remove(id);
updateMap.remove(id);
try {
FileUtils.deleteDirectory(requestIdDir.toFile());
} catch (IOException e) {
throw new StorageException("Unable to remove temporary content storage for request: " + id, e);
}
}
use of ddf.catalog.content.StorageException in project ddf by codice.
the class FileSystemStorageProvider method decryptStream.
private ByteSource decryptStream(InputStream contentInputStream) throws StorageException {
ByteSource output = null;
try (InputStream decryptedInputStream = crypter.decrypt(contentInputStream);
FileBackedOutputStream decryptedOutputStream = new FileBackedOutputStream(128)) {
// do not use try with resources in order to have these InputStreams in the finally block
IOUtils.copy(decryptedInputStream, decryptedOutputStream);
output = decryptedOutputStream.asByteSource();
} catch (CrypterException | IOException e) {
LOGGER.debug("Error decrypting InputStream {}. Failing StorageProvider read.", contentInputStream, e);
throw new StorageException(String.format("Cannot decrypt InputStream %s.", contentInputStream), e);
}
return output;
}
use of ddf.catalog.content.StorageException in project ddf by codice.
the class FileSystemStorageProvider method create.
@Override
public CreateStorageResponse create(CreateStorageRequest createRequest) throws StorageException {
LOGGER.trace("ENTERING: create");
List<ContentItem> contentItems = createRequest.getContentItems();
List<ContentItem> createdContentItems = new ArrayList<>(createRequest.getContentItems().size());
for (ContentItem contentItem : contentItems) {
try {
if (!ContentItemValidator.validate(contentItem)) {
LOGGER.warn("Item is not valid: {}", contentItem);
continue;
}
Path contentIdDir = getTempContentItemDir(createRequest.getId(), new URI(contentItem.getUri()));
Path contentDirectory = Files.createDirectories(contentIdDir);
createdContentItems.add(generateContentFile(contentItem, contentDirectory, (String) createRequest.getPropertyValue(Constants.STORE_REFERENCE_KEY)));
} catch (IOException | URISyntaxException | IllegalArgumentException e) {
throw new StorageException(e);
}
}
CreateStorageResponse response = new CreateStorageResponseImpl(createRequest, createdContentItems);
updateMap.put(createRequest.getId(), createdContentItems.stream().map(ContentItem::getUri).collect(Collectors.toSet()));
LOGGER.trace("EXITING: create");
return response;
}
Aggregations