diff --git a/src/main/java/org/gcube/common/storagehub/client/dsl/ItemContainer.java b/src/main/java/org/gcube/common/storagehub/client/dsl/ItemContainer.java index 3f617ce..5926c2e 100644 --- a/src/main/java/org/gcube/common/storagehub/client/dsl/ItemContainer.java +++ b/src/main/java/org/gcube/common/storagehub/client/dsl/ItemContainer.java @@ -49,6 +49,14 @@ public abstract class ItemContainer { itemclient.delete(this.itemId); } + public void rename(String newName) { + //itemclient.rename(this.itemId, newName); + } + + public void move(FolderContainer folder) { + itemclient.move(this.itemId, folder.get().getId()); + } + public FolderContainer getRootSharedFolder() { return new FolderContainer(itemclient, (FolderItem)itemclient.getRootSharedFolder(this.itemId)); } 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 c627ea0..dfdfd35 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 @@ -509,7 +509,8 @@ public class DefaultItemManager implements ItemManagerClient { if (response.hasException()) throw response.getException(); else - throw new BackendGenericError(); + throw new BackendGenericError("error response returned from server "+response.getHTTPCode()); + } return null; @@ -611,5 +612,36 @@ public class DefaultItemManager implements ItemManagerClient { } } + @Override + public String move(String id, String destinationFolderId) { + Call call = new Call() { + @Override + public String call(GXWebTargetAdapterRequest manager) throws Exception { + GXWebTargetAdapterRequest myManager = manager.path(id) + .path("move"); + + MultivaluedMap formData = new MultivaluedHashMap(); + formData.add("destinationId", destinationFolderId); + + + GXInboundResponse response = myManager.put(Entity.form(formData)); + + if (response.isErrorResponse()) { + if (response.hasException()) + throw response.getException(); + else + throw new BackendGenericError(); + } + + return response.getSource().readEntity(String.class); + } + }; + try { + return delegate.make(call); + }catch(Exception e) { + throw new RuntimeException(e); + } + } + } 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 a5422c9..8bffa81 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 @@ -54,6 +54,8 @@ public interface ItemManagerClient { String unshareFolder(String id, Set users); + String move(String id, String destinationFolderId); + } 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 5d7567e..f70d73b 100644 --- a/src/test/java/org/gcube/data/access/fs/Items.java +++ b/src/test/java/org/gcube/data/access/fs/Items.java @@ -60,7 +60,7 @@ public class Items { FileContainer file = null; try(InputStream is = new FileInputStream(new File("/home/lucio/Downloads/TatyanaSondre.jpg"))){ - file = shc.getWSRoot().uploadFile(is, "TatyanaSondre3.jpg", "descr"); + file = shc.getWSRoot().uploadFile(is, "TatyanaSondre5.jpg", "descr"); } catch (Exception e) { @@ -74,9 +74,9 @@ public class Items { public void download() throws Exception { StorageHubClient shc = new StorageHubClient(); - FolderContainer openResolver = shc.open("5cf82ba3-53b9-4352-b37a-c4a94800eaec").asFolder(); + FolderContainer openResolver = shc.open("ad8ba805-bcc5-4d0e-90c9-53216970b3e6").asFolder(); - StreamDescriptor streamDescr = openResolver.findByName("stat_algo.project").getContainers().get(0).download(); + StreamDescriptor streamDescr = openResolver.download(); File output = Files.createTempFile("down", streamDescr.getFileName()).toFile(); @@ -108,8 +108,8 @@ public class Items { String afi = null; - try(InputStream is = new FileInputStream(new File("/home/lucio/Downloads/test7z.7z"))){ - shc.getWSRoot().uploadArchive(is, "test7z"); + try(InputStream is = new FileInputStream(new File("/tmp/down724121986692880606my new folder.zip"))){ + shc.getWSRoot().uploadArchive(is, "testUpload2"); System.out.println(afi); } catch (Exception e) { @@ -137,8 +137,12 @@ public class Items { @Test public void delete() throws Exception{ - StorageHubClient shc = new StorageHubClient(); - shc.open("8dc6fca2-f0f5-4813-b854-f12e414e3a28").asFile().delete(); + try { + StorageHubClient shc = new StorageHubClient(); + shc.open("733a8235-e539-46c6-875d-3038579d4c6a").asFile().delete(); + }catch(Exception e) { + e.printStackTrace(); + } } @Test