From 4053c19863387527414cd04d54bd6d06e7e9352b Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Wed, 8 Sep 2021 18:24:05 +0200 Subject: [PATCH] Refs #21970: Remove HL from nlphub Updated to StorageHub --- .../nlphub/workspace/WorkspaceManager.java | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/gcube/data/analysis/nlphub/workspace/WorkspaceManager.java b/src/main/java/org/gcube/data/analysis/nlphub/workspace/WorkspaceManager.java index de18c61..b4c663d 100644 --- a/src/main/java/org/gcube/data/analysis/nlphub/workspace/WorkspaceManager.java +++ b/src/main/java/org/gcube/data/analysis/nlphub/workspace/WorkspaceManager.java @@ -15,7 +15,6 @@ import org.slf4j.LoggerFactory; public class WorkspaceManager { private static final Logger logger = LoggerFactory.getLogger(WorkspaceManager.class); - public String uploadFile(byte[] in, String name, String description) throws NlpHubException { if (name == null || name.isEmpty()) { String error = "Error uploading the file, the filename is invalid: Null"; @@ -26,21 +25,30 @@ public class WorkspaceManager { StorageHubClient shc = new StorageHubClient(); FolderContainer rootContainer = shc.getWSRoot(); InputStream inputStream = new ByteArrayInputStream(in); - + + FileContainer fileContainer; try { - FileContainer fileContainer = rootContainer.uploadFile(inputStream, - name,description); - String itemId=fileContainer.get().getId(); - logger.debug("Item id uploaded: " +itemId ); - URL url = shc.open(itemId).asFile().getPublicLink(); - logger.debug("Item public link: " +url); - - return url.toString(); + fileContainer = rootContainer.uploadFile(inputStream, name, description); } catch (StorageHubException e) { - String error = "Error uploading the file " + name+ " : " + e.getLocalizedMessage(); + String error = "Error uploading the file " + name + " : " + e.getLocalizedMessage(); logger.error(error, e); throw new NlpHubException(error, e); } - + + String itemId = fileContainer.get().getId(); + logger.debug("Item id uploaded: " + itemId); + + URL url; + try { + url = shc.open(itemId).asFile().getPublicLink(); + } catch (StorageHubException e) { + String error = "Error retrieving the public link for the file " + name + " : " + e.getLocalizedMessage(); + logger.error(error, e); + throw new NlpHubException(error, e); + } + logger.debug("Item public link: " + url); + + return url.toString(); + } }