git-svn-id: https://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/Common/storagehub-client@169261 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
88fd166407
commit
4bf7121478
|
@ -3,52 +3,37 @@ package org.gcube.common.storagehub.client.dsl;
|
|||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.storagehub.client.StreamDescriptor;
|
||||
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
||||
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 extends ItemContainer{
|
||||
public class FolderContainer extends ItemContainer<FolderItem>{
|
||||
|
||||
private FolderItem item = null;
|
||||
|
||||
// private String folderPath = null;
|
||||
|
||||
protected FolderContainer(ItemManagerClient itemclient) {
|
||||
super(itemclient);
|
||||
protected FolderContainer(ItemManagerClient itemclient, FolderItem item) {
|
||||
super(itemclient, item);
|
||||
}
|
||||
|
||||
protected void setItem(FolderItem item) {
|
||||
this.item = item;
|
||||
this.folderId = item.getId();
|
||||
protected FolderContainer(ItemManagerClient itemclient, String folderId) {
|
||||
super(itemclient, folderId);
|
||||
}
|
||||
|
||||
protected void setId(String folderId) {
|
||||
this.folderId = folderId;
|
||||
// this.folderPath = null;
|
||||
}
|
||||
/*
|
||||
protected void setPath(String folderPath) {
|
||||
this.folderPath = folderPath;
|
||||
this.folderId = null;
|
||||
}*/
|
||||
|
||||
|
||||
public FolderItem get() throws Exception {
|
||||
if (item==null) return (FolderItem)itemclient.get(folderId);
|
||||
if (item==null) return (FolderItem)itemclient.get(itemId);
|
||||
else return item;
|
||||
}
|
||||
|
||||
public List<? extends Item> list() {
|
||||
return itemclient.getChildren(folderId);
|
||||
return itemclient.getChildren(itemId);
|
||||
}
|
||||
|
||||
public <T extends AbstractFileItem> T uploadFile(InputStream stream, String filename, String description) {
|
||||
|
||||
return itemclient.uploadFile(stream, this.folderId , filename, description);
|
||||
return itemclient.uploadFile(stream, this.itemId , filename, description);
|
||||
}
|
||||
|
||||
public StreamDescriptor download(InputStream stream) {
|
||||
return itemclient.download(this.folderId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,24 +1,31 @@
|
|||
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;
|
||||
import org.gcube.common.storagehub.model.items.Item;
|
||||
|
||||
public class ItemContainer {
|
||||
|
||||
public abstract class ItemContainer<I extends Item> {
|
||||
|
||||
protected ItemManagerClient itemclient;
|
||||
|
||||
protected String folderId = null;
|
||||
// private String folderPath = null;
|
||||
protected String itemId = null;
|
||||
protected I item;
|
||||
|
||||
protected ItemContainer(ItemManagerClient itemclient) {
|
||||
protected ItemContainer(ItemManagerClient itemclient, I item) {
|
||||
this.itemclient = itemclient;
|
||||
}
|
||||
|
||||
public StreamDescriptor download(InputStream stream) {
|
||||
return itemclient.download(this.folderId);
|
||||
protected ItemContainer(ItemManagerClient itemclient, String itemId) {
|
||||
this.itemclient = itemclient;
|
||||
}
|
||||
|
||||
protected void setItem(I item) {
|
||||
this.item = item;
|
||||
this.itemId = item.getId();
|
||||
}
|
||||
|
||||
public StreamDescriptor download() {
|
||||
return itemclient.download(this.itemId);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
package org.gcube.common.storagehub.client.dsl;
|
||||
|
||||
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
||||
import org.gcube.common.storagehub.model.items.FolderItem;
|
||||
import org.gcube.common.storagehub.model.items.Item;
|
||||
|
||||
public class OpenResolver {
|
||||
|
||||
private Item item;
|
||||
private ItemManagerClient itemclient;
|
||||
|
||||
protected OpenResolver(Item item, ItemManagerClient itemclient) {
|
||||
this.item = item;
|
||||
this.itemclient = itemclient;
|
||||
};
|
||||
|
||||
|
||||
public FolderContainer asFolder() {
|
||||
if (item instanceof FolderItem)
|
||||
return new FolderContainer(itemclient, (FolderItem)item);
|
||||
else throw new RuntimeException("this item is not a folder");
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,11 +1,30 @@
|
|||
package org.gcube.common.storagehub.client.dsl;
|
||||
|
||||
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
|
||||
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
||||
import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient;
|
||||
import org.gcube.common.storagehub.model.Path;
|
||||
import org.gcube.common.storagehub.model.items.Item;
|
||||
|
||||
public class StorageHubClient {
|
||||
|
||||
public WorkspaceContainer get() {
|
||||
return new WorkspaceContainer();
|
||||
}
|
||||
private WorkspaceManagerClient wsClient = AbstractPlugin.workspace().build();
|
||||
private ItemManagerClient itemclient = AbstractPlugin.item().build();
|
||||
|
||||
public FolderContainer getWSRoot(){
|
||||
return new FolderContainer(itemclient, wsClient.getWorkspace());
|
||||
}
|
||||
|
||||
public OpenResolver open(Path relativePath) {
|
||||
Item item = wsClient.retieveItemByPath(relativePath.toPath());
|
||||
return new OpenResolver(item, itemclient);
|
||||
}
|
||||
|
||||
public OpenResolver open(String id) {
|
||||
Item item = itemclient.get(id);
|
||||
return new OpenResolver(item, itemclient);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
package org.gcube.common.storagehub.client.dsl;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.storagehub.client.StreamDescriptor;
|
||||
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
|
||||
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
||||
import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient;
|
||||
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 WorkspaceContainer {
|
||||
|
||||
private WorkspaceManagerClient wsClient = AbstractPlugin.workspace().build();
|
||||
private ItemManagerClient itemclient = AbstractPlugin.item().build();
|
||||
|
||||
protected WorkspaceContainer() {}
|
||||
|
||||
FolderItem rootFolder = null;
|
||||
|
||||
private void init() {
|
||||
if (rootFolder == null)
|
||||
rootFolder = (FolderItem) wsClient.getWorkspace();
|
||||
}
|
||||
|
||||
public FolderItem get(String ... excludes) {
|
||||
init();
|
||||
return rootFolder;
|
||||
}
|
||||
|
||||
public List<? extends Item> list() {
|
||||
init();
|
||||
return itemclient.getChildren(rootFolder.getId());
|
||||
}
|
||||
|
||||
public FolderContainer open(String id) {
|
||||
FolderContainer fc = new FolderContainer(itemclient);
|
||||
fc.setId(id);
|
||||
return fc;
|
||||
}
|
||||
|
||||
public <T extends AbstractFileItem> T uploadFile(InputStream stream, String filename, String description) {
|
||||
init();
|
||||
return itemclient.uploadFile(stream, this.rootFolder.getId(), filename, description);
|
||||
}
|
||||
|
||||
public StreamDescriptor download() {
|
||||
init();
|
||||
return itemclient.download(this.rootFolder.getId());
|
||||
}
|
||||
|
||||
|
||||
/*public FolderContainer open(Path path) {
|
||||
FolderContainer fc = new FolderContainer(itemclient);
|
||||
fc.setId(get("hl:accounting","jcr:content").getId());
|
||||
return fc;
|
||||
}*/
|
||||
}
|
|
@ -138,6 +138,26 @@ public class DefaultWorkspaceManager implements WorkspaceManagerClient {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Item> getRecentModifiedFilePerVre() {
|
||||
Call<WebTarget, ItemList> call = new Call<WebTarget, ItemList>() {
|
||||
@Override
|
||||
public ItemList call(WebTarget manager) throws Exception {
|
||||
WebTarget myManager = manager.path("vrefolder").path("recents");
|
||||
|
||||
Invocation.Builder builder = myManager.request(MediaType.APPLICATION_JSON);
|
||||
ItemList response = builder.get(ItemList.class);
|
||||
return response;
|
||||
}
|
||||
};
|
||||
try {
|
||||
ItemList result = delegate.make(call);
|
||||
return result.getItemlist();
|
||||
}catch(Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Item> T getTrashFolder(String ... excludeNodes) {
|
||||
Call<WebTarget, ItemWrapper<T>> call = new Call<WebTarget, ItemWrapper<T>>() {
|
||||
|
|
|
@ -21,5 +21,7 @@ public interface WorkspaceManagerClient {
|
|||
List<? extends Item> search(Query<SearchableItem<?>> query, String ... excludeNodes);
|
||||
|
||||
<T extends Item> T getTrashFolder(String ... excludeNodes);
|
||||
|
||||
List<? extends Item> getRecentModifiedFilePerVre();
|
||||
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ public class Items {
|
|||
StorageHubClient shc = new StorageHubClient();
|
||||
|
||||
try (InputStream is = new FileInputStream(new File("/home/lucio/Downloads/Metodo-Calisthenics.pdf"))){
|
||||
AbstractFileItem afi = shc.get().open("14d498da-eea1-4fb7-8590-9ce91aaba542").uploadFile(is, "testVersion", "descr");
|
||||
AbstractFileItem afi = shc.open("14d498da-eea1-4fb7-8590-9ce91aaba542").asFolder().uploadFile(is, "testVersion", "descr");
|
||||
System.out.println(afi.getId());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
@ -38,7 +38,7 @@ public class Items {
|
|||
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");
|
||||
AbstractFileItem afi = shc.getWSRoot().uploadFile(is, "bonificopdf", "descr");
|
||||
System.out.println(afi.toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -36,8 +36,12 @@ public class TestCall {
|
|||
|
||||
@BeforeClass
|
||||
public static void setUp(){
|
||||
/*
|
||||
SecurityTokenProvider.instance.set("8effc529-44ec-4895-b727-ed0dc14ad113-843339462");
|
||||
ScopeProvider.instance.set("/d4science.research-infrastructures.eu");
|
||||
*/
|
||||
SecurityTokenProvider.instance.set("595ca591-9921-423c-bfca-f8be19f05882-98187548");
|
||||
ScopeProvider.instance.set("/gcube");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -131,6 +135,18 @@ public class TestCall {
|
|||
wsclient.getVreFolders("hl:accounting");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRecents() {
|
||||
ItemManagerClient itemclient = AbstractPlugin.item().build();
|
||||
WorkspaceManagerClient wsclient = AbstractPlugin.workspace().build();
|
||||
List<? extends Item> items = wsclient.getRecentModifiedFilePerVre();
|
||||
|
||||
System.out.println("items are "+items.size());
|
||||
|
||||
for (Item item: items)
|
||||
System.out.println(item.getName()+ " "+item.getPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createFolder() {
|
||||
|
@ -156,7 +172,7 @@ public class TestCall {
|
|||
WorkspaceManagerClient wsclient = AbstractPlugin.workspace().build();
|
||||
//String path = wsclient.getVreFolder("hl:accounting").getPath();
|
||||
//System.out.println("path is "+path);
|
||||
query.setExpression(new ISDescendant(Paths.getPath("/Home/massimiliano.assante/Workspace/MySpecialFolders/d4science.research-infrastructures.eu-gCubeApps-BlueBridgeProject/")));
|
||||
query.setExpression(new ISDescendant(Paths.getPath("/Home/massimiliano.assante/Workspace/MySpecialFolders/gcube-devNext-NextNext/")));
|
||||
query.setLimit(10);
|
||||
query.setOrder(new OrderField(GenericSearchableItem.get().lastModification,MODE.DESC));
|
||||
List<? extends Item> items = wsclient.search(query, "hl:accounting", "jcr:content");
|
||||
|
|
Loading…
Reference in New Issue