diff --git a/src/main/java/org/gcube/common/storagehub/client/dsl/FolderContainer.java b/src/main/java/org/gcube/common/storagehub/client/dsl/FolderContainer.java index e5e0178..e8e256a 100644 --- a/src/main/java/org/gcube/common/storagehub/client/dsl/FolderContainer.java +++ b/src/main/java/org/gcube/common/storagehub/client/dsl/FolderContainer.java @@ -10,12 +10,9 @@ import org.gcube.common.storagehub.model.items.FolderItem; import org.gcube.common.storagehub.model.items.Item; public class FolderContainer extends ItemContainer{ - - private ItemManagerClient itemclient; private FolderItem item = null; - private String folderId = null; // private String folderPath = null; protected FolderContainer(ItemManagerClient itemclient) { @@ -47,6 +44,7 @@ public class FolderContainer extends ItemContainer{ } public T uploadFile(InputStream stream, String filename, String description) { + return itemclient.uploadFile(stream, this.folderId , filename, description); } diff --git a/src/main/java/org/gcube/common/storagehub/client/dsl/ItemContainer.java b/src/main/java/org/gcube/common/storagehub/client/dsl/ItemContainer.java index d47218f..43bd1d4 100644 --- a/src/main/java/org/gcube/common/storagehub/client/dsl/ItemContainer.java +++ b/src/main/java/org/gcube/common/storagehub/client/dsl/ItemContainer.java @@ -7,9 +7,9 @@ import org.gcube.common.storagehub.client.proxies.ItemManagerClient; public class ItemContainer { - private ItemManagerClient itemclient; + protected ItemManagerClient itemclient; - private String folderId = null; + protected String folderId = null; // private String folderPath = null; protected ItemContainer(ItemManagerClient itemclient) { diff --git a/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultWorkspaceManager.java b/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultWorkspaceManager.java index 7a94f36..574caf1 100644 --- a/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultWorkspaceManager.java +++ b/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultWorkspaceManager.java @@ -10,6 +10,7 @@ import javax.ws.rs.core.MediaType; import org.gcube.common.clients.Call; import org.gcube.common.clients.delegates.ProxyDelegate; +import org.gcube.common.storagehub.model.expressions.OrderField; import org.gcube.common.storagehub.model.expressions.SearchableField; import org.gcube.common.storagehub.model.expressions.SearchableItem; import org.gcube.common.storagehub.model.items.Item; @@ -119,6 +120,28 @@ public class DefaultWorkspaceManager implements WorkspaceManagerClient { } } + @Override + public T getTrashFolder(String ... excludeNodes) { + Call> call = new Call>() { + @Override + public ItemWrapper call(WebTarget manager) throws Exception { + WebTarget myManager = manager.path("trash"); + if (excludeNodes !=null && excludeNodes.length>0) + myManager = myManager.queryParam("exclude",excludeNodes); + + Invocation.Builder builder = myManager.request(MediaType.APPLICATION_JSON); + ItemWrapper response = builder.get(ItemWrapper.class); + return response; + } + }; + try { + ItemWrapper result = delegate.make(call); + return result.getItem(); + }catch(Exception e) { + throw new RuntimeException(e); + } + } + @Override public List search(Query> query, String ... excludeNodes) { Call call = new Call() { @@ -129,8 +152,8 @@ public class DefaultWorkspaceManager implements WorkspaceManagerClient { myManager = myManager.queryParam("exclude",excludeNodes); if (query.getOrderFields() !=null && query.getOrderFields().size() >0) { - for (SearchableField field :query.getOrderFields()) - myManager = myManager.queryParam("o",field); + for (OrderField field :query.getOrderFields()) + myManager = myManager.queryParam("o","["+field.getField().getName()+"] "+field.getMode().toString()); } myManager = myManager.queryParam("n", query.getSearchableItem().getNodeValue()); diff --git a/src/main/java/org/gcube/common/storagehub/client/proxies/WorkspaceManagerClient.java b/src/main/java/org/gcube/common/storagehub/client/proxies/WorkspaceManagerClient.java index 9572149..16de6e2 100644 --- a/src/main/java/org/gcube/common/storagehub/client/proxies/WorkspaceManagerClient.java +++ b/src/main/java/org/gcube/common/storagehub/client/proxies/WorkspaceManagerClient.java @@ -17,5 +17,7 @@ public interface WorkspaceManagerClient { T getVreFolder(String ... excludeNodes); List search(Query> query, String ... excludeNodes); + + T getTrashFolder(String ... excludeNodes); } diff --git a/src/test/java/org/gcube/data/access/fs/Items.java b/src/test/java/org/gcube/data/access/fs/Items.java index c24459a..cc45ba6 100644 --- a/src/test/java/org/gcube/data/access/fs/Items.java +++ b/src/test/java/org/gcube/data/access/fs/Items.java @@ -6,10 +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.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; import org.junit.Test; @@ -28,8 +26,8 @@ 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"); - System.out.println(afi.toString()); + AbstractFileItem afi = shc.get().open("14d498da-eea1-4fb7-8590-9ce91aaba542").uploadFile(is, "bonificopdf1", "descr"); + System.out.println(afi.getId()); } catch (Exception e) { e.printStackTrace(); } diff --git a/src/test/java/org/gcube/data/access/fs/TestCall.java b/src/test/java/org/gcube/data/access/fs/TestCall.java index 0d0b3d6..1ed367a 100644 --- a/src/test/java/org/gcube/data/access/fs/TestCall.java +++ b/src/test/java/org/gcube/data/access/fs/TestCall.java @@ -15,23 +15,28 @@ import org.gcube.common.storagehub.client.proxies.ItemManagerClient; import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient; import org.gcube.common.storagehub.model.Paths; import org.gcube.common.storagehub.model.expressions.GenericSearchableItem; +import org.gcube.common.storagehub.model.expressions.OrderField; +import org.gcube.common.storagehub.model.expressions.OrderField.MODE; import org.gcube.common.storagehub.model.expressions.SearchableItem; import org.gcube.common.storagehub.model.expressions.date.Before; import org.gcube.common.storagehub.model.expressions.logical.And; import org.gcube.common.storagehub.model.expressions.logical.ISDescendant; import org.gcube.common.storagehub.model.expressions.text.Contains; +import org.gcube.common.storagehub.model.items.AbstractFileItem; import org.gcube.common.storagehub.model.items.Item; import org.gcube.common.storagehub.model.query.Queries; import org.gcube.common.storagehub.model.query.Query; import org.junit.BeforeClass; import org.junit.Test; +import com.fasterxml.jackson.annotation.JsonCreator.Mode; + public class TestCall { @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 @@ -93,23 +98,28 @@ public class TestCall { public void getVreFolder() { ItemManagerClient itemclient = AbstractPlugin.item().build(); WorkspaceManagerClient wsclient = AbstractPlugin.workspace().build(); - Item item = wsclient.getVreFolder("hl:accounting"); + wsclient.getVreFolders("hl:accounting"); } @Test public void search() { - Query> query = Queries.queryFor(Item.class); - + Query> query = Queries.queryFor(AbstractFileItem.class); + /* Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, 2015); - - query.setExpression(new And(new Contains(GenericSearchableItem.get().title, "Data"), new ISDescendant(Paths.getPath("/Home/lucio.lelii/Workspace/DataMiner")), new Before(GenericSearchableItem.get().creationTime, calendar ))); - query.setLimit(10); - query.setOrder(GenericSearchableItem.get().title); + */ 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/lucio.lelii/Workspace/MySpecialFolders/gcube-devNext-NextNext"))); + query.setLimit(10); + query.setOrder(new OrderField(GenericSearchableItem.get().lastModification,MODE.DESC)); List items = wsclient.search(query, "hl:accounting", "jcr:content"); + for (Item item: items) { + System.out.println(item.getName()+" "+item.getLastModificationTime().getTimeInMillis()); + } System.out.println("items are "+items.size()); }