From 0dfdfde60513a0f163305b15403087336d1c4f0b Mon Sep 17 00:00:00 2001 From: Lucio Lelii Date: Mon, 30 Jul 2018 10:38:34 +0000 Subject: [PATCH] git-svn-id: https://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/Common/storagehub-client@169983 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../client/dsl/FolderContainer.java | 4 +++ .../client/proxies/DefaultItemManager.java | 25 +++++++++++++++++++ .../client/proxies/ItemManagerClient.java | 2 ++ .../java/org/gcube/data/access/fs/Items.java | 24 +++++++++++++++--- .../org/gcube/data/access/fs/TestCall.java | 14 ++++++++--- 5 files changed, 62 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/gcube/common/storagehub/client/dsl/FolderContainer.java b/src/main/java/org/gcube/common/storagehub/client/dsl/FolderContainer.java index 6f7b653..e0a0206 100644 --- a/src/main/java/org/gcube/common/storagehub/client/dsl/FolderContainer.java +++ b/src/main/java/org/gcube/common/storagehub/client/dsl/FolderContainer.java @@ -31,6 +31,10 @@ public class FolderContainer extends ItemContainer{ return new FileContainer(itemclient, itemclient.uploadFile(stream, this.itemId , filename, description)); } + public FolderContainer uploadArchive(InputStream stream, String extractionFolderName) { + return new FolderContainer(itemclient, itemclient.uploadArchive(stream, this.itemId , extractionFolderName)); + } + public FolderContainer newFolder(String name, String description) throws Exception { String newFolderId = itemclient.createFolder(this.itemId, name, description); return new FolderContainer(itemclient, newFolderId); 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 9f7da6d..c590a70 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 @@ -235,6 +235,31 @@ public class DefaultItemManager implements ItemManagerClient { } } + @Override + public String uploadArchive(InputStream stream, String parentId, String extractionFolderName) { + Call call = new Call() { + @Override + public String call(WebTarget manager) throws Exception { + WebTarget myManager = manager.register(MultiPartFeature.class).path(parentId) + .path("create").path("ARCHIVE"); + Invocation.Builder builder = myManager.request(); + + FormDataMultiPart multipart = new FormDataMultiPart(); + + multipart.field("parentFolderName", extractionFolderName); + multipart.field("file", stream, MediaType.APPLICATION_OCTET_STREAM_TYPE); + String response = builder.post(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA_TYPE),String.class); + return response; + + } + }; + try { + return delegate.make(call); + }catch(Exception e) { + throw new RuntimeException(e); + } + } + @Override public String createFolder(String parentId, String name, String description) { Call call = new Call() { 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 28e9cd6..e9499ce 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 @@ -41,5 +41,7 @@ public interface ItemManagerClient { Item getRootSharedFolder(String id); String shareFolder(String id, Set users, AccessType accessType); + + String uploadArchive(InputStream stream, String parentId, String extractionFolderName); } 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 a4d0e51..8b12149 100644 --- a/src/test/java/org/gcube/data/access/fs/Items.java +++ b/src/test/java/org/gcube/data/access/fs/Items.java @@ -38,7 +38,7 @@ public class Items { SecurityTokenProvider.instance.set("b7c80297-e4ed-42ab-ab42-fdc0b8b0eabf-98187548"); ScopeProvider.instance.set("/gcube"); } - + @Test public void uploadFile() throws Exception { StorageHubClient shc = new StorageHubClient(); @@ -46,8 +46,8 @@ public class Items { String afi = null; - try(InputStream is = new FileInputStream(new File("/home/lucio/Downloads/test5Gb.zip"))){ - shc.getWSRoot().uploadFile(is, "5g.zip", "descr"); + try(InputStream is = new FileInputStream(new File("/home/lucio/Downloads/ar_bigdata_201705.csv"))){ + shc.getWSRoot().uploadFile(is, "bigfile1GB-test1.scv", "descr"); System.out.println(afi); } catch (Exception e) { @@ -56,6 +56,23 @@ public class Items { } + + @Test + public void uploadArchive() throws Exception { + StorageHubClient shc = new StorageHubClient(); + + + String afi = null; + + try(InputStream is = new FileInputStream(new File("/home/lucio/Downloads/filezilla.zip"))){ + shc.getWSRoot().uploadFile(is, "1gbup.zip", "descr"); + + System.out.println(afi); + } catch (Exception e) { + e.printStackTrace(); + } + + } @@ -78,7 +95,6 @@ public class Items { public void delete() throws Exception{ StorageHubClient shc = new StorageHubClient(); shc.open("8dc6fca2-f0f5-4813-b854-f12e414e3a28").asFile().delete(); - } @Test diff --git a/src/test/java/org/gcube/data/access/fs/TestCall.java b/src/test/java/org/gcube/data/access/fs/TestCall.java index 94646bb..1cbe17a 100644 --- a/src/test/java/org/gcube/data/access/fs/TestCall.java +++ b/src/test/java/org/gcube/data/access/fs/TestCall.java @@ -106,13 +106,13 @@ public class TestCall { Client client = ClientBuilder.newClient(); client.register(MultiPartFeature.class).property(ClientProperties.CHUNKED_ENCODING_SIZE, 1024).property(ClientProperties.OUTBOUND_CONTENT_LENGTH_BUFFER, -1) .property(ClientProperties.REQUEST_ENTITY_PROCESSING, "CHUNKED"); - WebTarget target = client.target("http://workspace-repository1-d.d4science.org:8080/storagehub/workspace/items/bc1c9525-43f7-4565-b5ea-0a0f9d7853a0/create/FILE?gcube-token=595ca591-9921-423c-bfca-f8be19f05882-98187548"); + WebTarget target = client.target("http://workspace-repository1-d.d4science.org:8080/storagehub/workspace/items/bc1c9525-43f7-4565-b5ea-0a0f9d7853a0/create/test-upload?gcube-token=595ca591-9921-423c-bfca-f8be19f05882-98187548"); FormDataMultiPart multipart = new FormDataMultiPart(); - multipart.field("name", "5gb.zip"); + multipart.field("name", "test1Gb.db"); multipart.field("description", "description"); - multipart.field("file", new FileInputStream("/home/lucio/Downloads/test5Gb.zip"), MediaType.APPLICATION_OCTET_STREAM_TYPE); + multipart.field("file", new FileInputStream("/home/lucio/Downloads/ar_bigdata_201705.csv"), MediaType.APPLICATION_OCTET_STREAM_TYPE); target.request().post(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA)); @@ -120,6 +120,14 @@ public class TestCall { } + @Test + public void uploadArchive() throws Exception{ + final ItemManagerClient client = AbstractPlugin.item().at(new URI("http://workspace-repository1-d.d4science.org:8080/storagehub")).build(); + + client.uploadArchive(new FileInputStream("/home/lucio/Downloads/filezilla.tar"), "bc1c9525-43f7-4565-b5ea-0a0f9d7853a0", "filezillaTar1"); + + } + @Test