This commit is contained in:
Lucio Lelii 2018-06-19 09:42:57 +00:00
parent 4bf7121478
commit 38115cb07a
6 changed files with 27 additions and 29 deletions

13
pom.xml
View File

@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -27,12 +28,12 @@
</dependencyManagement> </dependencyManagement>
<dependencies> <dependencies>
<!-- <dependency> <dependency>
<groupId>org.gcube.common</groupId> <groupId>org.gcube.common</groupId>
<artifactId>gxRest</artifactId> <artifactId>gxRest</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
</dependency> --> </dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
@ -42,7 +43,7 @@
<dependency> <dependency>
<groupId>org.gcube.common</groupId> <groupId>org.gcube.common</groupId>
<artifactId>storagehub-model</artifactId> <artifactId>storagehub-model</artifactId>
<version>1.0.0-SNAPSHOT</version> <version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.glassfish.jersey.core</groupId> <groupId>org.glassfish.jersey.core</groupId>

View File

@ -32,7 +32,8 @@ public class FolderContainer extends ItemContainer<FolderItem>{
return itemclient.getChildren(itemId); return itemclient.getChildren(itemId);
} }
public <T extends AbstractFileItem> T uploadFile(InputStream stream, String filename, String description) { //TODO: change the return to file container
public String uploadFile(InputStream stream, String filename, String description) {
return itemclient.uploadFile(stream, this.itemId , filename, description); return itemclient.uploadFile(stream, this.itemId , filename, description);
} }

View File

@ -13,6 +13,7 @@ public abstract class ItemContainer<I extends Item> {
protected ItemContainer(ItemManagerClient itemclient, I item) { protected ItemContainer(ItemManagerClient itemclient, I item) {
this.itemclient = itemclient; this.itemclient = itemclient;
this.itemId = item.getId();
} }
protected ItemContainer(ItemManagerClient itemclient, String itemId) { protected ItemContainer(ItemManagerClient itemclient, String itemId) {

View File

@ -144,30 +144,29 @@ public class DefaultItemManager implements ItemManagerClient {
@Override @Override
public AbstractFileItem uploadFile(InputStream stream, String parentId, String fileName, String description) { public String uploadFile(InputStream stream, String parentId, String fileName, String description) {
Call<WebTarget, ItemWrapper<AbstractFileItem>> call = new Call<WebTarget, ItemWrapper<AbstractFileItem>>() { Call<WebTarget, String> call = new Call<WebTarget, String>() {
@Override @Override
public ItemWrapper<AbstractFileItem> call(WebTarget manager) throws Exception { public String call(WebTarget manager) throws Exception {
WebTarget myManager = manager.register(MultiPartFeature.class).path(parentId) WebTarget myManager = manager.register(MultiPartFeature.class).path(parentId)
.path("create").path("FILE").queryParam("name", fileName).queryParam("description", description); .path("create").path("FILE").queryParam("name", fileName).queryParam("description", description);
Invocation.Builder builder = myManager.request(); Invocation.Builder builder = myManager.request();
ItemWrapper<AbstractFileItem> response = builder.post(Entity.entity(stream, MediaType.APPLICATION_OCTET_STREAM), ItemWrapper.class); String response = builder.post(Entity.entity(stream, MediaType.APPLICATION_OCTET_STREAM), String.class);
return response; return response;
} }
}; };
try { try {
ItemWrapper<AbstractFileItem> result = delegate.make(call); return delegate.make(call);
return result.getItem();
}catch(Exception e) { }catch(Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@Override @Override
public FolderItem createFolder(String parentId, String name, String description) { public String createFolder(String parentId, String name, String description) {
Call<WebTarget, ItemWrapper<FolderItem>> call = new Call<WebTarget, ItemWrapper<FolderItem>>() { Call<WebTarget, String> call = new Call<WebTarget, String>() {
@Override @Override
public ItemWrapper<FolderItem> call(WebTarget manager) throws Exception { public String call(WebTarget manager) throws Exception {
WebTarget myManager = manager.path(parentId) WebTarget myManager = manager.path(parentId)
.path("create").path("FOLDER").queryParam("name", name).queryParam("description", description); .path("create").path("FOLDER").queryParam("name", name).queryParam("description", description);
Invocation.Builder builder = myManager.request(); Invocation.Builder builder = myManager.request();
@ -175,13 +174,12 @@ public class DefaultItemManager implements ItemManagerClient {
MultivaluedMap<String, String> formData = new MultivaluedHashMap<String, String>(); MultivaluedMap<String, String> formData = new MultivaluedHashMap<String, String>();
formData.add("name", name); formData.add("name", name);
formData.add("description", description); formData.add("description", description);
ItemWrapper<FolderItem> response = builder.post(Entity.form(formData),ItemWrapper.class); String response = builder.post(Entity.form(formData),String.class);
return response; return response;
} }
}; };
try { try {
ItemWrapper<FolderItem> result = delegate.make(call); return delegate.make(call);
return result.getItem();
}catch(Exception e) { }catch(Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }

View File

@ -5,8 +5,6 @@ import java.util.List;
import org.gcube.common.storagehub.client.StreamDescriptor; import org.gcube.common.storagehub.client.StreamDescriptor;
import org.gcube.common.storagehub.model.acls.ACL; import org.gcube.common.storagehub.model.acls.ACL;
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.items.Item;
@ -27,9 +25,9 @@ public interface ItemManagerClient {
StreamDescriptor download(String id); StreamDescriptor download(String id);
<T extends AbstractFileItem> T uploadFile(InputStream stream, String parentId, String fileName, String description); String uploadFile(InputStream stream, String parentId, String fileName, String description);
FolderItem createFolder(String parentId, String name, String description); String createFolder(String parentId, String name, String description);
List<ACL> getACL(String id); List<ACL> getACL(String id);

View File

@ -7,7 +7,6 @@ import java.io.InputStream;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.storagehub.client.dsl.StorageHubClient; import org.gcube.common.storagehub.client.dsl.StorageHubClient;
import org.gcube.common.storagehub.model.items.AbstractFileItem;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
@ -25,9 +24,9 @@ public class Items {
public void uploadFile() { public void uploadFile() {
StorageHubClient shc = new StorageHubClient(); StorageHubClient shc = new StorageHubClient();
try (InputStream is = new FileInputStream(new File("/home/lucio/Downloads/Metodo-Calisthenics.pdf"))){ try (InputStream is = new FileInputStream(new File("/home/lucio/Downloads/fattunite.pdf"))){
AbstractFileItem afi = shc.open("14d498da-eea1-4fb7-8590-9ce91aaba542").asFolder().uploadFile(is, "testVersion", "descr"); String afi = shc.getWSRoot().uploadFile(is, "fattureTest2.pdf", "descr");
System.out.println(afi.getId()); System.out.println(afi);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -38,8 +37,8 @@ public class Items {
StorageHubClient shc = new StorageHubClient(); StorageHubClient shc = new StorageHubClient();
try (InputStream is = new FileInputStream(new File("/home/lucio/Downloads/bonifico ferrara anricipo.pdf"))){ try (InputStream is = new FileInputStream(new File("/home/lucio/Downloads/bonifico ferrara anricipo.pdf"))){
AbstractFileItem afi = shc.getWSRoot().uploadFile(is, "bonificopdf", "descr"); String afi = shc.getWSRoot().uploadFile(is, "bonificopdf", "descr");
System.out.println(afi.toString()); System.out.println(afi);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }