From 11b602fd59f5a63675d5004e0bd21607e6d8f58f Mon Sep 17 00:00:00 2001 From: Francesco Mangiacrapa Date: Fri, 12 Oct 2018 12:19:09 +0000 Subject: [PATCH] added getListVersionsForFile git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/storagehub-client-wrapper@173332 82a268e6-3cf1-43bd-a215-b396298e98cf --- distro/changelog.xml | 2 + .../server/StorageHubClientService.java | 20 ++++++++- .../WorkspaceStorageHubClientService.java | 33 +++++++++++++++ .../server/converter/HLMapper.java | 18 ++++++++ .../server/converter/ObjectMapper.java | 1 + .../server/tohl/Workspace.java | 9 ++++ .../tohl/impl/WorkspaceFileVersion.java | 41 +++++++++++++++++++ .../shared/tohl/items/WorkspaceVersion.java | 14 +++++-- 8 files changed, 133 insertions(+), 5 deletions(-) create mode 100644 src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/WorkspaceFileVersion.java diff --git a/distro/changelog.xml b/distro/changelog.xml index 8002344..c4e4441 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -10,6 +10,8 @@ [Task #12603] added Rename facility to StorageHub [Task #12603] added Public Link facility to StorageHub + [Task #12664] added Versions facility to StorageHub + diff --git a/src/main/java/org/gcube/common/storagehubwrapper/server/StorageHubClientService.java b/src/main/java/org/gcube/common/storagehubwrapper/server/StorageHubClientService.java index 8391ee8..3fe1bf7 100644 --- a/src/main/java/org/gcube/common/storagehubwrapper/server/StorageHubClientService.java +++ b/src/main/java/org/gcube/common/storagehubwrapper/server/StorageHubClientService.java @@ -24,6 +24,7 @@ import org.gcube.common.storagehub.model.items.FolderItem; import org.gcube.common.storagehub.model.items.Item; import org.gcube.common.storagehub.model.items.SharedFolder; import org.gcube.common.storagehub.model.items.VreFolder; +import org.gcube.common.storagehub.model.service.Version; import org.gcube.common.storagehubwrapper.server.converter.ObjectMapper; import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.ItemNotFoundException; import org.slf4j.Logger; @@ -544,7 +545,6 @@ public class StorageHubClientService { } - /** * Rename item. * @@ -572,13 +572,29 @@ public class StorageHubClientService { */ public URL getPublicLinkForFile(String fileItemId) throws Exception{ - Validate.notNull(fileItemId, "Bad invoking get public link, the itemId is null"); + Validate.notNull(fileItemId, "Bad invoking get public link, the fileItemId is null"); return shcClient.open(fileItemId).asFile().getPublicLink(); } + /** + * Gets the list versions. + * + * @param fileItemId the file item id + * @return the list versions + * @throws Exception the exception + */ + public List getListVersions(String fileItemId) throws Exception{ + + Validate.notNull(fileItemId, "Bad invoking get list of versions, the fileItemId is null"); + + return shcClient.open(fileItemId).asFile().getVersions(); + + } + + /* (non-Javadoc) * @see java.lang.Object#toString() */ diff --git a/src/main/java/org/gcube/common/storagehubwrapper/server/WorkspaceStorageHubClientService.java b/src/main/java/org/gcube/common/storagehubwrapper/server/WorkspaceStorageHubClientService.java index 707d120..a6aef12 100644 --- a/src/main/java/org/gcube/common/storagehubwrapper/server/WorkspaceStorageHubClientService.java +++ b/src/main/java/org/gcube/common/storagehubwrapper/server/WorkspaceStorageHubClientService.java @@ -18,6 +18,7 @@ import org.gcube.common.storagehub.client.dsl.FolderContainer; import org.gcube.common.storagehub.model.items.AbstractFileItem; import org.gcube.common.storagehub.model.items.FolderItem; import org.gcube.common.storagehub.model.items.Item; +import org.gcube.common.storagehub.model.service.Version; import org.gcube.common.storagehub.model.types.GenericItemType; import org.gcube.common.storagehubwrapper.server.converter.HLMapper; import org.gcube.common.storagehubwrapper.server.tohl.Workspace; @@ -32,6 +33,7 @@ import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.ItemNotFoundExc import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WorkspaceFolderNotFoundException; import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WrongDestinationException; import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WrongItemTypeException; +import org.gcube.common.storagehubwrapper.shared.tohl.impl.WorkspaceFileVersion; import org.gcube.common.storagehubwrapper.shared.tohl.impl.WorkspaceFolder; import org.gcube.common.storagehubwrapper.shared.tohl.items.ItemStreamDescriptor; import org.gcube.common.storagehubwrapper.shared.tohl.items.URLFileItem; @@ -825,6 +827,37 @@ public final class WorkspaceStorageHubClientService implements Workspace{ } } + /** + * Gets the list versions for file. + * + * @param fileItemId the file item id + * @return the list versions for file + * @throws Exception the exception + */ + public List getListVersionsForFile(String fileItemId) throws Exception{ + try{ + List versions = storageHubClientService.getListVersions(fileItemId); + + if(versions==null || versions.size()==0){ + logger.info("No version found for fileItemId: "+fileItemId); + return new ArrayList(1); + } + + List listVersions = new ArrayList(versions.size()); + + for (Version version : versions) { + listVersions.add(HLMapper.toWorkspaceFileVersion(version)); + } + + return listVersions; + + }catch(Exception e){ + logger.error("Error on getting public link: "+fileItemId, e); + String error = e.getMessage()!=null?e.getMessage():"Operation not allowed"; + throw new Exception("Error on getting public link. "+error); + } + } + diff --git a/src/main/java/org/gcube/common/storagehubwrapper/server/converter/HLMapper.java b/src/main/java/org/gcube/common/storagehubwrapper/server/converter/HLMapper.java index 71b5b92..eb6a1fd 100644 --- a/src/main/java/org/gcube/common/storagehubwrapper/server/converter/HLMapper.java +++ b/src/main/java/org/gcube/common/storagehubwrapper/server/converter/HLMapper.java @@ -23,6 +23,7 @@ import org.gcube.common.storagehub.model.items.nodes.Content; import org.gcube.common.storagehub.model.items.nodes.ImageContent; import org.gcube.common.storagehub.model.items.nodes.PDFContent; import org.gcube.common.storagehub.model.items.nodes.accounting.AccountEntry; +import org.gcube.common.storagehub.model.service.Version; import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem; import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItemType; import org.gcube.common.storagehubwrapper.shared.tohl.impl.AccountingEntry; @@ -32,6 +33,7 @@ import org.gcube.common.storagehubwrapper.shared.tohl.impl.ImageFile; import org.gcube.common.storagehubwrapper.shared.tohl.impl.PDFFile; import org.gcube.common.storagehubwrapper.shared.tohl.impl.PropertyMap; import org.gcube.common.storagehubwrapper.shared.tohl.impl.URLFile; +import org.gcube.common.storagehubwrapper.shared.tohl.impl.WorkspaceFileVersion; import org.gcube.common.storagehubwrapper.shared.tohl.impl.WorkspaceFolder; import org.gcube.common.storagehubwrapper.shared.tohl.impl.WorkspaceSharedFolder; import org.gcube.common.storagehubwrapper.shared.tohl.items.FileItemType; @@ -114,6 +116,22 @@ public class HLMapper { return pm; } + + /** + * To workspace file version. + * + * @param fileVersion the file version + * @return the workspace file version + */ + public static WorkspaceFileVersion toWorkspaceFileVersion(Version fileVersion){ + WorkspaceFileVersion wsFileVersion = new WorkspaceFileVersion(); + wsFileVersion.setId(fileVersion.getId()); + wsFileVersion.setName(fileVersion.getName()); + wsFileVersion.setCreated(fileVersion.getCreated()); + //TODO MUST BE TERMINATED + return wsFileVersion; + } + /** * To workspace item. * diff --git a/src/main/java/org/gcube/common/storagehubwrapper/server/converter/ObjectMapper.java b/src/main/java/org/gcube/common/storagehubwrapper/server/converter/ObjectMapper.java index d996b63..fa97677 100644 --- a/src/main/java/org/gcube/common/storagehubwrapper/server/converter/ObjectMapper.java +++ b/src/main/java/org/gcube/common/storagehubwrapper/server/converter/ObjectMapper.java @@ -40,4 +40,5 @@ public class ObjectMapper { logger.debug("Returning "+listUsers.size()+" member/s for sharedFolder with id: "+sharedfolder.getId()); return listUsers; } + } diff --git a/src/main/java/org/gcube/common/storagehubwrapper/server/tohl/Workspace.java b/src/main/java/org/gcube/common/storagehubwrapper/server/tohl/Workspace.java index 8284f1d..c52942b 100644 --- a/src/main/java/org/gcube/common/storagehubwrapper/server/tohl/Workspace.java +++ b/src/main/java/org/gcube/common/storagehubwrapper/server/tohl/Workspace.java @@ -23,6 +23,7 @@ import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.ItemNotFoundExc import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WorkspaceFolderNotFoundException; import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WrongDestinationException; import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WrongItemTypeException; +import org.gcube.common.storagehubwrapper.shared.tohl.impl.WorkspaceFileVersion; import org.gcube.common.storagehubwrapper.shared.tohl.items.ItemStreamDescriptor; import org.gcube.common.storagehubwrapper.shared.tohl.items.URLFileItem; @@ -283,6 +284,14 @@ public interface Workspace{ public URL getPublicLinkForFile(String fileItemId) throws Exception; + /** + * Gets the list versions for file. + * + * @param fileItemId the file item id + * @return the list versions for file + * @throws Exception the exception + */ + public List getListVersionsForFile(String fileItemId) throws Exception; diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/WorkspaceFileVersion.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/WorkspaceFileVersion.java new file mode 100644 index 0000000..52c4563 --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/WorkspaceFileVersion.java @@ -0,0 +1,41 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl.impl; + +import java.io.Serializable; +import java.util.Calendar; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + + +/** + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Oct 12, 2018 + */ +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter +@ToString +public class WorkspaceFileVersion implements org.gcube.common.storagehubwrapper.shared.tohl.items.WorkspaceVersion, Serializable{ + + /** + * + */ + private static final long serialVersionUID = 7925779107708330163L; + + String id; + String name; + Calendar created; + String owner; + String remotePath; + Long size; + boolean isCurrentVersion; + +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/items/WorkspaceVersion.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/items/WorkspaceVersion.java index 56c1aff..a36bdf4 100644 --- a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/items/WorkspaceVersion.java +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/items/WorkspaceVersion.java @@ -10,10 +10,18 @@ import java.util.Calendar; * The Interface WorkspaceVersion. * * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) - * Jun 15, 2018 + * Oct 12, 2018 */ public interface WorkspaceVersion { + + /** + * Gets the id. + * + * @return the id + */ + public String getId(); + /** * Gets the name. * @@ -33,7 +41,7 @@ public interface WorkspaceVersion { * * @return the user */ - public String getUser(); + public String getOwner(); /** * Gets the remote path. @@ -47,7 +55,7 @@ public interface WorkspaceVersion { * * @return the size */ - public long getSize(); + public Long getSize(); /** * Checks if is current version.