git-svn-id: https://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/Common/storagehub-client@167109 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
53c629eeb4
commit
7c7d7f9a50
6
pom.xml
6
pom.xml
|
@ -27,6 +27,12 @@
|
|||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>gxRest</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.common.storagehub.client.dls;
|
||||
package org.gcube.common.storagehub.client.dsl;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
@ -9,15 +9,22 @@ import org.gcube.common.storagehub.model.items.AbstractFileItem;
|
|||
import org.gcube.common.storagehub.model.items.FolderItem;
|
||||
import org.gcube.common.storagehub.model.items.Item;
|
||||
|
||||
public class FolderContainer {
|
||||
public class FolderContainer extends ItemContainer{
|
||||
|
||||
private ItemManagerClient itemclient;
|
||||
|
||||
private FolderItem item = null;
|
||||
|
||||
private String folderId = null;
|
||||
// private String folderPath = null;
|
||||
|
||||
protected FolderContainer(ItemManagerClient itemclient) {
|
||||
this.itemclient = itemclient;
|
||||
super(itemclient);
|
||||
}
|
||||
|
||||
protected void setItem(FolderItem item) {
|
||||
this.item = item;
|
||||
this.folderId = item.getId();
|
||||
}
|
||||
|
||||
protected void setId(String folderId) {
|
||||
|
@ -31,7 +38,8 @@ public class FolderContainer {
|
|||
}*/
|
||||
|
||||
public FolderItem get() throws Exception {
|
||||
return (FolderItem)itemclient.get(folderId);
|
||||
if (item==null) return (FolderItem)itemclient.get(folderId);
|
||||
else return item;
|
||||
}
|
||||
|
||||
public List<? extends Item> list() {
|
|
@ -0,0 +1,24 @@
|
|||
package org.gcube.common.storagehub.client.dsl;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.gcube.common.storagehub.client.StreamDescriptor;
|
||||
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
||||
|
||||
public class ItemContainer {
|
||||
|
||||
private ItemManagerClient itemclient;
|
||||
|
||||
private String folderId = null;
|
||||
// private String folderPath = null;
|
||||
|
||||
protected ItemContainer(ItemManagerClient itemclient) {
|
||||
this.itemclient = itemclient;
|
||||
}
|
||||
|
||||
public StreamDescriptor download(InputStream stream) {
|
||||
return itemclient.download(this.folderId);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.common.storagehub.client.dls;
|
||||
package org.gcube.common.storagehub.client.dsl;
|
||||
|
||||
public class StorageHubClient {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.common.storagehub.client.dls;
|
||||
package org.gcube.common.storagehub.client.dsl;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
@ -46,10 +46,11 @@ public class WorkspaceContainer {
|
|||
return itemclient.uploadFile(stream, this.rootFolder.getId(), filename, description);
|
||||
}
|
||||
|
||||
public StreamDescriptor download(InputStream stream) {
|
||||
public StreamDescriptor download() {
|
||||
init();
|
||||
return itemclient.download(this.rootFolder.getId());
|
||||
}
|
||||
|
||||
|
||||
/*public FolderContainer open(Path path) {
|
||||
FolderContainer fc = new FolderContainer(itemclient);
|
|
@ -53,7 +53,6 @@ public class DefaultWorkspaceManager implements WorkspaceManagerClient {
|
|||
myManager = myManager.queryParam("exclude",excludeNodes);
|
||||
Invocation.Builder builder = myManager.request(MediaType.APPLICATION_JSON);
|
||||
ItemList response = builder.get(ItemList.class);
|
||||
System.out.println(manager.getUri().toString());
|
||||
return response;
|
||||
}
|
||||
};
|
||||
|
@ -90,4 +89,26 @@ public class DefaultWorkspaceManager implements WorkspaceManagerClient {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Item> T getVreFolder(String ... excludeNodes) {
|
||||
Call<WebTarget, ItemWrapper<T>> call = new Call<WebTarget, ItemWrapper<T>>() {
|
||||
@Override
|
||||
public ItemWrapper<T> call(WebTarget manager) throws Exception {
|
||||
WebTarget myManager = manager.path("vrefolder");
|
||||
if (excludeNodes !=null && excludeNodes.length>0)
|
||||
myManager = myManager.queryParam("exclude",excludeNodes);
|
||||
|
||||
Invocation.Builder builder = myManager.request(MediaType.APPLICATION_JSON);
|
||||
ItemWrapper<T> response = builder.get(ItemWrapper.class);
|
||||
return response;
|
||||
}
|
||||
};
|
||||
try {
|
||||
ItemWrapper<T> result = delegate.make(call);
|
||||
return result.getItem();
|
||||
}catch(Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,5 +11,7 @@ public interface WorkspaceManagerClient {
|
|||
List<? extends Item> getVreFolders(String ... excludeNodes);
|
||||
|
||||
List<? extends Item> getVreFolders(int start, int limit, String ... excludeNodes);
|
||||
|
||||
<T extends Item> T getVreFolder(String ... excludeNodes);
|
||||
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@ import java.io.InputStream;
|
|||
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.storagehub.client.dls.FolderContainer;
|
||||
import org.gcube.common.storagehub.client.dls.StorageHubClient;
|
||||
import org.gcube.common.storagehub.client.dsl.FolderContainer;
|
||||
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
|
||||
import org.gcube.common.storagehub.model.items.AbstractFileItem;
|
||||
import org.gcube.common.storagehub.model.items.Item;
|
||||
import org.junit.BeforeClass;
|
||||
|
@ -19,28 +19,35 @@ public class Items {
|
|||
|
||||
@BeforeClass
|
||||
public static void setUp(){
|
||||
SecurityTokenProvider.instance.set("52b59669-ccde-46d2-a4da-108b9e941f7c-98187548");
|
||||
ScopeProvider.instance.set("/gcube/devNext");
|
||||
SecurityTokenProvider.instance.set("595ca591-9921-423c-bfca-f8be19f05882-98187548");
|
||||
ScopeProvider.instance.set("/gcube/devNext/NextNext");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void list() {
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
shc.get().list().stream().forEach(System.out::println);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void uploadFile() {
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
|
||||
try (InputStream is = new FileInputStream(new File("/home/lucio/Downloads/domenica.jpeg"))){
|
||||
AbstractFileItem afi = shc.get().uploadFile(is, "domenica15", "descr");
|
||||
try (InputStream is = new FileInputStream(new File("/home/lucio/Downloads/bonifico ferrara anricipo.pdf"))){
|
||||
AbstractFileItem afi = shc.get().uploadFile(is, "bonificopdf", "descr");
|
||||
System.out.println(afi.toString());
|
||||
} 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"))){
|
||||
AbstractFileItem afi = shc.get().uploadFile(is, "bonificopdf", "descr");
|
||||
System.out.println(afi.toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|
||||
static String baseUrl="http://workspace-repository1-d.d4science.org/storagehub";
|
||||
|
|
|
@ -79,6 +79,14 @@ public class TestCall {
|
|||
System.in.read();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getVreFolder() {
|
||||
ItemManagerClient itemclient = AbstractPlugin.item().build();
|
||||
WorkspaceManagerClient wsclient = AbstractPlugin.workspace().build();
|
||||
Item item = wsclient.getVreFolder("hl:accounting");
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@Test
|
||||
public void createFolder() throws Exception{
|
||||
|
|
Loading…
Reference in New Issue