From 38c684bb6a9d0b136413af944381be2bff317b69 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Thu, 8 Aug 2024 17:07:49 +0200 Subject: [PATCH] Reorganized code --- CHANGELOG.md | 4 ++-- .../storagehub/StorageHubManagement.java | 21 ++++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9720fe1..86b53bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## [v3.4.0-SNAPSHOT] -- To ensure persistence of file already stored in the workspace is now used the facility provided by storage-hub #27736 - +- The persistence of file already stored in the workspace can be ensured by using the copy provided by storage-hub #27736 +- The removal of a file persited is resolved using the public link #27952 ## [v3.3.0] diff --git a/src/main/java/org/gcube/storagehub/StorageHubManagement.java b/src/main/java/org/gcube/storagehub/StorageHubManagement.java index 24b8310..4f8b8dd 100644 --- a/src/main/java/org/gcube/storagehub/StorageHubManagement.java +++ b/src/main/java/org/gcube/storagehub/StorageHubManagement.java @@ -194,9 +194,17 @@ public class StorageHubManagement { encId = encId.replace(enchriptedPrefix, ""); String decodeURL = new String(Base64.getUrlDecoder().decode(encId)); String decodedId = StringEncrypter.getEncrypter().decrypt(decodeURL); + logger.trace("From public link URL {} has been extraced the file id={}", url.toString(), decodedId); return decodedId; } + public FileContainer getFileContainer(URL shubPublicLink) throws Exception { + String id = getFileId(shubPublicLink); + OpenResolver openResolver = storageHubClient.open(id); + FileContainer fileContainer = openResolver.asFile(); + return fileContainer; + } + /** * This method can be used only if the caller has the right to access * the file already stored in the workspace @@ -222,13 +230,6 @@ public class StorageHubManagement { logger.debug("File persistence has been ensured. The file is available at {}", finalURL); return finalURL; } - - public FileContainer getFileContainer(URL shubPublicLink) throws Exception { - String id = getFileId(shubPublicLink); - OpenResolver openResolver = storageHubClient.open(id); - FileContainer fileContainer = openResolver.asFile(); - return fileContainer; - } public URL persistFile(InputStream inputStream, String fileName, String mimeType) throws Exception { @@ -242,7 +243,7 @@ public class StorageHubManagement { } URL finalURL = persitedFile.getPublicLink(); - logger.debug("File persistence has been ensured. The file is available at {}", finalURL); + logger.debug("File persistence has been ensured (id={}. The file is available at {}", persitedFile.getId(), finalURL); return finalURL; } @@ -278,7 +279,7 @@ public class StorageHubManagement { public void removePersistedFile(String filename, String mimeType) throws Exception { persitedFile = getPersistedFile(filename, mimeType); if(persitedFile !=null) { - logger.info("Persited file with mimetype {} and name {} was found. Goign to remove it.", mimeType, filename); + logger.info("Persited file with mimetype {} and name {} was found (id={}). Goign to remove it.", mimeType, filename, persitedFile.getId()); persitedFile.delete(); } } @@ -291,7 +292,7 @@ public class StorageHubManagement { public void removePersistedFile(URL shubPublicLink) throws Exception { persitedFile = getFileContainer(shubPublicLink); if(persitedFile !=null) { - logger.info("Persited file available at {} was found. Goign to remove it.", shubPublicLink); + logger.info("Persited file available at {} was found (id={}). Goign to remove it.", shubPublicLink, persitedFile.getId()); persitedFile.delete(); } }