This commit is contained in:
Lucio Lelii 2018-05-14 14:14:52 +00:00
parent e0043388c9
commit d42a17944b
6 changed files with 51 additions and 20 deletions

View File

@ -11,11 +11,8 @@ 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 extends AbstractFileItem> T uploadFile(InputStream stream, String filename, String description) {
return itemclient.uploadFile(stream, this.folderId , filename, description);
}

View File

@ -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) {

View File

@ -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 extends Item> T getTrashFolder(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("trash");
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);
}
}
@Override
public List<? extends Item> search(Query<SearchableItem<?>> query, String ... excludeNodes) {
Call<WebTarget, ItemList> call = new Call<WebTarget, ItemList>() {
@ -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());

View File

@ -18,4 +18,6 @@ public interface WorkspaceManagerClient {
List<? extends Item> search(Query<SearchableItem<?>> query, String ... excludeNodes);
<T extends Item> T getTrashFolder(String ... excludeNodes);
}

View File

@ -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();
}

View File

@ -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<SearchableItem<?>> query = Queries.queryFor(Item.class);
Query<SearchableItem<?>> 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<? extends Item> 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());
}