This commit is contained in:
Lucio Lelii 2018-07-30 10:38:34 +00:00
parent d71c507924
commit 0dfdfde605
5 changed files with 62 additions and 7 deletions

View File

@ -31,6 +31,10 @@ public class FolderContainer extends ItemContainer<FolderItem>{
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);

View File

@ -235,6 +235,31 @@ public class DefaultItemManager implements ItemManagerClient {
}
}
@Override
public String uploadArchive(InputStream stream, String parentId, String extractionFolderName) {
Call<WebTarget, String> call = new Call<WebTarget, String>() {
@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<WebTarget, String> call = new Call<WebTarget, String>() {

View File

@ -41,5 +41,7 @@ public interface ItemManagerClient {
Item getRootSharedFolder(String id);
String shareFolder(String id, Set<String> users, AccessType accessType);
String uploadArchive(InputStream stream, String parentId, String extractionFolderName);
}

View File

@ -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

View File

@ -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