This commit is contained in:
Lucio Lelii 2018-06-22 14:27:21 +00:00
parent 9952e9efff
commit 5ec8908f0a
5 changed files with 34 additions and 16 deletions

View File

@ -1,5 +1,7 @@
package org.gcube.common.storagehub.client.dsl;
import java.net.URL;
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
import org.gcube.common.storagehub.model.items.AbstractFileItem;
@ -17,4 +19,8 @@ public class FileContainer extends ItemContainer<AbstractFileItem> {
return ContainerType.FILE;
}
public URL getPublicLink() {
return itemclient.getPublickLink(this.itemId);
}
}

View File

@ -27,9 +27,8 @@ public class FolderContainer extends ItemContainer<FolderItem>{
return new ListResolver(itemclient, itemId);
}
//TODO: change the return to file container
public String uploadFile(InputStream stream, String filename, String description) {
return itemclient.uploadFile(stream, this.itemId , filename, description);
public FileContainer uploadFile(InputStream stream, String filename, String description) {
return new FileContainer(itemclient, itemclient.uploadFile(stream, this.itemId , filename, description));
}
public FolderContainer newFolder(String name, String description) throws Exception {

View File

@ -1,6 +1,7 @@
package org.gcube.common.storagehub.client.proxies;
import java.io.InputStream;
import java.net.URL;
import java.util.List;
import javax.ws.rs.client.Entity;
@ -100,6 +101,25 @@ public class DefaultItemManager implements ItemManagerClient {
}
@Override
public URL getPublickLink(String id) {
Call<WebTarget, URL> call = new Call<WebTarget, URL>() {
@Override
public URL call(WebTarget manager) throws Exception {
WebTarget myManager = manager.path(id).path("publicklink");
Invocation.Builder builder = myManager.request(MediaType.APPLICATION_JSON);
URL response = builder.get(URL.class);
return response;
}
};
try {
URL result = delegate.make(call);
return result;
}catch(Exception e) {
throw new RuntimeException(e);
}
}
@Override
public List<? extends Item> getChildren(String id, int start, int limit, String... excludeNodes) {
Call<WebTarget, ItemList> call = new Call<WebTarget, ItemList>() {

View File

@ -1,6 +1,7 @@
package org.gcube.common.storagehub.client.proxies;
import java.io.InputStream;
import java.net.URL;
import java.util.List;
import org.gcube.common.storagehub.client.StreamDescriptor;
@ -32,5 +33,7 @@ public interface ItemManagerClient {
List<ACL> getACL(String id);
void moveToTrash(String id);
URL getPublickLink(String id);
}

View File

@ -32,25 +32,15 @@ public class Items {
public void uploadFile() {
StorageHubClient shc = new StorageHubClient();
try (InputStream is = new FileInputStream(new File("/home/lucio/Downloads/fattunite.pdf"))){
String afi = shc.getWSRoot().uploadFile(is, "fattureTest2.pdf", "descr");
try (InputStream is = new FileInputStream(new File("/home/lucio/Downloads/rockandroll.jpeg"))){
String afi = shc.getWSRoot().uploadFile(is, "tes-image.jpeg", "descr").get().getId();
System.out.println(afi);
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void getVreFolder() {
StorageHubClient shc = new StorageHubClient();
try (InputStream is = new FileInputStream(new File("/home/lucio/Downloads/bonifico ferrara anricipo.pdf"))){
String newId = shc.getWSRoot().uploadFile(is, "bonificopdf", "descr");
System.out.println(newId);
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void downloadFile() {