From 0ebc3de5f829841c07365f85ccb6c3e05dd18c83 Mon Sep 17 00:00:00 2001 From: Lucio Lelii Date: Thu, 11 Oct 2018 16:36:21 +0000 Subject: [PATCH] git-svn-id: https://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/Common/storagehub-client@173247 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../storagehub/client/dsl/FileContainer.java | 6 ++++ .../client/proxies/DefaultItemManager.java | 30 +++++++++++++++++++ .../client/proxies/ItemManagerClient.java | 3 +- .../java/org/gcube/data/access/fs/Items.java | 8 ++++- 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/gcube/common/storagehub/client/dsl/FileContainer.java b/src/main/java/org/gcube/common/storagehub/client/dsl/FileContainer.java index 4a8e1d6..38ec9db 100644 --- a/src/main/java/org/gcube/common/storagehub/client/dsl/FileContainer.java +++ b/src/main/java/org/gcube/common/storagehub/client/dsl/FileContainer.java @@ -1,9 +1,11 @@ package org.gcube.common.storagehub.client.dsl; import java.net.URL; +import java.util.List; import org.gcube.common.storagehub.client.proxies.ItemManagerClient; import org.gcube.common.storagehub.model.items.AbstractFileItem; +import org.gcube.common.storagehub.model.service.Version; public class FileContainer extends ItemContainer { @@ -23,6 +25,10 @@ public class FileContainer extends ItemContainer { return itemclient.getPublickLink(this.itemId); } + public List getVersions() { + return itemclient.getFileVersions(this.itemId); + } + public FileContainer copy(FolderContainer folder, String newFileName) { return new FileContainer(itemclient, itemclient.copy(this.itemId, folder.get().getId(), newFileName)); } diff --git a/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultItemManager.java b/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultItemManager.java index 7657e12..db3071c 100644 --- a/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultItemManager.java +++ b/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultItemManager.java @@ -25,6 +25,8 @@ import org.gcube.common.storagehub.model.exceptions.BackendGenericError; import org.gcube.common.storagehub.model.items.Item; import org.gcube.common.storagehub.model.service.ItemList; import org.gcube.common.storagehub.model.service.ItemWrapper; +import org.gcube.common.storagehub.model.service.Version; +import org.gcube.common.storagehub.model.service.VersionList; import org.gcube.common.storagehub.model.types.ACLList; import org.glassfish.jersey.media.multipart.FormDataMultiPart; import org.glassfish.jersey.media.multipart.MultiPartFeature; @@ -207,6 +209,34 @@ public class DefaultItemManager implements ItemManagerClient { } } + @Override + public List getFileVersions(String id) { + Call call = new Call() { + @Override + public VersionList call(GXWebTargetAdapterRequest manager) throws Exception { + GXWebTargetAdapterRequest myManager = manager.path(id).path("versions"); + + GXInboundResponse response = myManager.get(); + + if (response.isErrorResponse()) { + if (response.hasException()) + throw response.getException(); + else + throw new BackendGenericError(); + } + + VersionList versions = response.getSource().readEntity(VersionList.class); + + return versions; + } + }; + try { + VersionList result = delegate.make(call); + return result.getItemlist(); + }catch(Exception e) { + throw new RuntimeException(e); + } + } @Override public Item get(String id, String... excludeNodes) { diff --git a/src/main/java/org/gcube/common/storagehub/client/proxies/ItemManagerClient.java b/src/main/java/org/gcube/common/storagehub/client/proxies/ItemManagerClient.java index e52ac8e..94cd7f4 100644 --- a/src/main/java/org/gcube/common/storagehub/client/proxies/ItemManagerClient.java +++ b/src/main/java/org/gcube/common/storagehub/client/proxies/ItemManagerClient.java @@ -9,6 +9,7 @@ import org.gcube.common.storagehub.client.StreamDescriptor; import org.gcube.common.storagehub.model.acls.ACL; import org.gcube.common.storagehub.model.acls.AccessType; import org.gcube.common.storagehub.model.items.Item; +import org.gcube.common.storagehub.model.service.Version; @@ -58,6 +59,6 @@ public interface ItemManagerClient { String rename(String id, String newName); - + List getFileVersions(String id); } diff --git a/src/test/java/org/gcube/data/access/fs/Items.java b/src/test/java/org/gcube/data/access/fs/Items.java index f70d73b..ba05b62 100644 --- a/src/test/java/org/gcube/data/access/fs/Items.java +++ b/src/test/java/org/gcube/data/access/fs/Items.java @@ -52,6 +52,12 @@ public class Items { } + @Test + public void renameFile() throws Exception{ + StorageHubClient shc = new StorageHubClient(); + shc.open("8822478a-4fd3-41d5-87de-9ff161d0935e").asItem().rename("renamed"); + + } @Test @@ -74,7 +80,7 @@ public class Items { public void download() throws Exception { StorageHubClient shc = new StorageHubClient(); - FolderContainer openResolver = shc.open("ad8ba805-bcc5-4d0e-90c9-53216970b3e6").asFolder(); + FolderContainer openResolver = shc.open("894d23bf-e2e9-42b6-a781-b99bb18119c8").asFolder(); StreamDescriptor streamDescr = openResolver.download();