git-svn-id: https://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/Common/storagehub-client@176292 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
66a2bf8d25
commit
dbd167df9b
|
@ -27,7 +27,7 @@ public class FolderContainer extends ItemContainer<FolderItem>{
|
|||
}
|
||||
|
||||
public ListResolverTyped list() {
|
||||
return new ListResolverTyped((onlyType, excludes) -> itemclient.getChildren(itemId, onlyType, excludes), itemclient) ;
|
||||
return new ListResolverTyped((onlyType, includeHidden, excludes) -> itemclient.getChildren(itemId, onlyType, includeHidden, excludes), itemclient) ;
|
||||
}
|
||||
|
||||
public FileContainer uploadFile(InputStream stream, String filename, String description) {
|
||||
|
@ -58,7 +58,7 @@ public class FolderContainer extends ItemContainer<FolderItem>{
|
|||
}
|
||||
|
||||
public ListResolver findByName(String namePattern) {
|
||||
return new ListResolver((onlyType, excludes) -> itemclient.findChildrenByNamePattern(itemId, namePattern , excludes), itemclient);
|
||||
return new ListResolver((onlyType, includeHidden, excludes) -> itemclient.findChildrenByNamePattern(itemId, namePattern , excludes), itemclient);
|
||||
}
|
||||
|
||||
public FolderContainer share(Set<String> users, AccessType accessType) throws Exception {
|
||||
|
|
|
@ -58,7 +58,7 @@ public abstract class ItemContainer<I extends Item> {
|
|||
}
|
||||
|
||||
public ListResolver getAnchestors() {
|
||||
return new ListResolver((onlyType, excludes) -> itemclient.getAnchestors(this.itemId,excludes) , itemclient);
|
||||
return new ListResolver((onlyType, includeHidden, excludes) -> itemclient.getAnchestors(this.itemId, excludes) , itemclient);
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
|
|
|
@ -18,7 +18,7 @@ public class ListResolver {
|
|||
|
||||
Set<String> excludes = new HashSet<>(Arrays.asList(NodeConstants.ACCOUNTING_NAME, NodeConstants.CONTENT_NAME, NodeConstants.METADATA_NAME));
|
||||
Class<? extends Item> onlyType = null;
|
||||
|
||||
boolean includeHidden = false;
|
||||
|
||||
protected ListResolver(ListRetriever retriever, ItemManagerClient itemClient) {
|
||||
this.retriever = retriever;
|
||||
|
@ -42,7 +42,7 @@ public class ListResolver {
|
|||
|
||||
|
||||
public List<? extends Item> getItems(){
|
||||
return retriever.getList(onlyType, excludes.toArray(new String[excludes.size()]));
|
||||
return retriever.getList(onlyType, includeHidden, excludes.toArray(new String[excludes.size()]));
|
||||
}
|
||||
|
||||
public List<ItemContainer<? extends Item>> getContainers(){
|
||||
|
|
|
@ -13,4 +13,10 @@ public class ListResolverTyped extends ListResolver {
|
|||
onlyType = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ListResolver includeHidden(){
|
||||
includeHidden = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,5 +6,5 @@ import org.gcube.common.storagehub.model.items.Item;
|
|||
|
||||
public interface ListRetriever {
|
||||
|
||||
List<? extends Item> getList(Class<? extends Item> onlyType, String ... excludes);
|
||||
List<? extends Item> getList(Class<? extends Item> onlyType, boolean includeHidden, String ... excludes);
|
||||
}
|
||||
|
|
|
@ -77,7 +77,13 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public List<? extends Item> getChildren(String id, Class<? extends Item> onlyOfType, String ... excludeNodes) {
|
||||
return getChildren(id, onlyOfType, false, excludeNodes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Item> getChildren(String id, Class<? extends Item> onlyOfType, boolean showHidden, String ... excludeNodes) {
|
||||
Call<GXWebTargetAdapterRequest, ItemList> call = new Call<GXWebTargetAdapterRequest, ItemList>() {
|
||||
@Override
|
||||
public ItemList call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
|
@ -88,6 +94,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
|
||||
if (onlyOfType!=null)
|
||||
params.put("onlyType", new Object[] {resolveNodeType(onlyOfType)});
|
||||
params.put("showHidden", new Object[] {showHidden});
|
||||
|
||||
GXInboundResponse response = myManager.queryParams(params).get();
|
||||
|
||||
|
@ -111,8 +118,9 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<? extends Item> getChildren(String id, int start, int limit, Class<? extends Item> onlyOfType, String... excludeNodes) {
|
||||
public List<? extends Item> getChildren(String id, int start, int limit, boolean showHidden, Class<? extends Item> onlyOfType, String... excludeNodes) {
|
||||
Call<GXWebTargetAdapterRequest, ItemList> call = new Call<GXWebTargetAdapterRequest, ItemList>() {
|
||||
@Override
|
||||
public ItemList call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
|
@ -128,7 +136,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
|
||||
params.put("start", new Object[] {start});
|
||||
params.put("limit", new Object[] {limit});
|
||||
|
||||
params.put("showHidden", new Object[] {showHidden});
|
||||
|
||||
GXInboundResponse response = myManager.queryParams(params).get();
|
||||
|
||||
|
@ -155,19 +163,30 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
|
||||
|
||||
@Override
|
||||
public List<? extends Item> getChildren(String id, int start, int limit,
|
||||
public List<? extends Item> getChildren(String id, int start, int limit, boolean showHidden,
|
||||
String... excludeNodes) {
|
||||
return getChildren(id, start, limit, null, excludeNodes);
|
||||
return getChildren(id, start, limit, showHidden, null, excludeNodes);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public List<? extends Item> getChildren(String id, String ... excludeNodes) {
|
||||
return getChildren(id, null, excludeNodes);
|
||||
return getChildren(id, false,excludeNodes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Item> getChildren(String id, boolean showHidden, String ... excludeNodes) {
|
||||
return getChildren(id, null, showHidden, excludeNodes);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Integer childrenCount(String id , Class<? extends Item> onlyOfType) {
|
||||
@Deprecated
|
||||
public Integer childrenCount(String id , Class<? extends Item> onlyOfType) {
|
||||
return childrenCount(id , false, onlyOfType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer childrenCount(String id , boolean showHidden, Class<? extends Item> onlyOfType) {
|
||||
Call<GXWebTargetAdapterRequest, Integer> call = new Call<GXWebTargetAdapterRequest, Integer>() {
|
||||
@Override
|
||||
public Integer call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
|
@ -176,6 +195,8 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
if (onlyOfType!=null)
|
||||
params.put("onlyType", new Object[] {resolveNodeType(onlyOfType)});
|
||||
|
||||
params.put("showHidden", new Object[] {showHidden});
|
||||
|
||||
GXInboundResponse response = myManager.queryParams(params).get();
|
||||
|
||||
if (response.isErrorResponse()) {
|
||||
|
@ -197,8 +218,14 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public Integer childrenCount(String id) {
|
||||
return childrenCount(id, null);
|
||||
return childrenCount(id, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer childrenCount(String id, boolean showHidden) {
|
||||
return childrenCount(id, showHidden, null);
|
||||
}
|
||||
|
||||
private String resolveNodeType(Class<? extends Item> itemClass){
|
||||
|
|
|
@ -17,19 +17,19 @@ import org.gcube.common.storagehub.model.service.Version;
|
|||
|
||||
public interface ItemManagerClient {
|
||||
|
||||
List<? extends Item> getChildren(String id, String ... excludeNodes);
|
||||
List<? extends Item> getChildren(String id, boolean includeHidden, String ... excludeNodes);
|
||||
|
||||
List<? extends Item> getChildren(String id, Class<? extends Item> onlyOfType, String ... excludeNodes);
|
||||
List<? extends Item> getChildren(String id, Class<? extends Item> onlyOfType, boolean includeHidden, String ... excludeNodes);
|
||||
|
||||
List<? extends Item> getChildren(String id, int start, int limit, Class<? extends Item> onlyOfType, String ... excludeNodes);
|
||||
List<? extends Item> getChildren(String id, int start, int limit, boolean includeHidden, Class<? extends Item> onlyOfType, String ... excludeNodes);
|
||||
|
||||
List<? extends Item> getChildren(String id, int start, int limit, String ... excludeNodes);
|
||||
List<? extends Item> getChildren(String id, int start, int limit, boolean includeHidden, String ... excludeNodes);
|
||||
|
||||
List<? extends Item> getAnchestors(String id, String ... excludeNodes);
|
||||
|
||||
Integer childrenCount(String id);
|
||||
Integer childrenCount(String id,boolean includeHidden);
|
||||
|
||||
Integer childrenCount(String id, Class<? extends Item> onlyOfType);
|
||||
Integer childrenCount(String id, boolean includeHidden, Class<? extends Item> onlyOfType);
|
||||
|
||||
Item get(String id, String ... excludeNodes);
|
||||
|
||||
|
@ -73,5 +73,17 @@ public interface ItemManagerClient {
|
|||
String createGcubeItem(String parentId, GCubeItem item);
|
||||
|
||||
StreamDescriptor resolvePublicLink(String identifier);
|
||||
|
||||
@Deprecated
|
||||
List<? extends Item> getChildren(String id, Class<? extends Item> onlyOfType, String... excludeNodes);
|
||||
|
||||
@Deprecated
|
||||
List<? extends Item> getChildren(String id, String ... excludeNodes);
|
||||
|
||||
@Deprecated
|
||||
Integer childrenCount(String id, Class<? extends Item> onlyOfType);
|
||||
|
||||
@Deprecated
|
||||
Integer childrenCount(String id);
|
||||
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
|
@ -17,7 +19,9 @@ import org.gcube.common.storagehub.client.dsl.ContainerType;
|
|||
import org.gcube.common.storagehub.client.dsl.FileContainer;
|
||||
import org.gcube.common.storagehub.client.dsl.FolderContainer;
|
||||
import org.gcube.common.storagehub.client.dsl.ItemContainer;
|
||||
import org.gcube.common.storagehub.client.dsl.ListResolver;
|
||||
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
|
||||
import org.gcube.common.storagehub.model.acls.AccessType;
|
||||
import org.gcube.common.storagehub.model.items.FolderItem;
|
||||
import org.gcube.common.storagehub.model.items.Item;
|
||||
import org.junit.BeforeClass;
|
||||
|
@ -29,7 +33,7 @@ public class Items {
|
|||
|
||||
@BeforeClass
|
||||
public static void setUp(){
|
||||
SecurityTokenProvider.instance.set("b7c80297-e4ed-42ab-ab42-fdc0b8b0eabf-98187548");
|
||||
SecurityTokenProvider.instance.set("04269c7d-dab7-498a-841d-8d38ae2d482b-98187548");
|
||||
//SecurityTokenProvider.instance.set("a5b623b6-6577-4271-aba6-7ada687d29cf-98187548");
|
||||
|
||||
ScopeProvider.instance.set("/gcube");
|
||||
|
@ -40,13 +44,15 @@ public class Items {
|
|||
|
||||
@Test
|
||||
public void renameFile() throws Exception{
|
||||
|
||||
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
|
||||
FolderContainer myRoot = shc.getWSRoot().newFolder("AnimalsMatcher", "");
|
||||
|
||||
FolderContainer children = myRoot.newFolder("build", "build folder");
|
||||
|
||||
|
||||
|
||||
|
||||
FileContainer file = null;
|
||||
try(InputStream is = new FileInputStream(new File("/home/lucio/Downloads/mg.jpg"))){
|
||||
file = myRoot.uploadFile(is, "mg.jpg", "file");
|
||||
|
@ -74,10 +80,11 @@ public class Items {
|
|||
public void uploadAndcopyFile() throws Exception {
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
|
||||
|
||||
|
||||
FileContainer file = null;
|
||||
try(InputStream is = new FileInputStream(new File("/home/lucio/Downloads/TatyanaSondre.jpg"))){
|
||||
file = shc.getWSRoot().uploadFile(is, "TatyanaSondre5.jpg", "descr");
|
||||
file = shc.open("0bae39d3-89be-4dd6-ad36-319813cd815a").asFolder().uploadFile(is, "TatyanaSondre5.jpg", "descr");
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
|
@ -146,16 +153,23 @@ public class Items {
|
|||
@Test
|
||||
public void findByName() throws Exception{
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
List<? extends Item> containers = shc.getWSRoot().list().ofType(FolderItem.class).getItems();
|
||||
for (Item container : containers) {
|
||||
System.out.println("name is :"+container.getClass().getSimpleName());
|
||||
}
|
||||
|
||||
FolderContainer root = shc.open("2fd081dc-3b57-4e5f-aadf-38439aea4c1f").asFolder();
|
||||
|
||||
FolderContainer fc = root.newFolder("Computations", "description");
|
||||
|
||||
fc.share(new HashSet<>(Arrays.asList("giancarlo.panichi")), AccessType.READ_ONLY);
|
||||
|
||||
System.out.println(fc.get().getPath()+" "+fc.getId());
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void delete() throws Exception{
|
||||
try {
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
shc.open("328d0097-e024-43fd-afc8-3926a34a5953").asFile().delete();
|
||||
}catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -51,8 +51,8 @@ public class TestCall {
|
|||
|
||||
//SecurityTokenProvider.instance.set("0e2c7963-8d3e-4ea6-a56d-ffda530dd0fa-98187548");
|
||||
//token costantino 9ca79556-54b0-4bbf-ab0f-151ae326f4cf-98187548
|
||||
SecurityTokenProvider.instance.set("e03bfbc4-a144-48e3-aa37-b07bafdf8822-98187548");
|
||||
ScopeProvider.instance.set("/gcube/devsec");
|
||||
SecurityTokenProvider.instance.set("a5b623b6-6577-4271-aba6-7ada687d29cf-98187548");
|
||||
ScopeProvider.instance.set("/gcube");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -61,19 +61,21 @@ public class TestCall {
|
|||
WorkspaceManagerClient client = AbstractPlugin.workspace().build();
|
||||
try {
|
||||
Item ws = client.getWorkspace();
|
||||
List<? extends Item> Vreitems = client.getVreFolders("hl:accounting");
|
||||
System.out.println("vreItems are "+Vreitems.size());
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
/*
|
||||
List<? extends Item> items = itemclient.getChildren(ws.getId(),10, 5, "hl:accounting", "jcr:content");
|
||||
List<? extends Item> Vreitems = client.getVreFolders("hl:accounting");
|
||||
|
||||
/*List<? extends Item> items = itemclient.getChildren(ws.getId(),10, 5, "hl:accounting", "jcr:content");
|
||||
|
||||
List<? extends Item> VreitemsPaged = client.getVreFolders(5,5, "hl:accounting");
|
||||
|
||||
System.out.println("items are "+items.size());
|
||||
*/
|
||||
|
||||
|
||||
System.out.println("vreItems are "+Vreitems.size());
|
||||
|
||||
System.in.read();*/
|
||||
System.in.read();
|
||||
}
|
||||
|
||||
|
||||
|
@ -239,8 +241,11 @@ public class TestCall {
|
|||
public void getVreFolder() {
|
||||
ItemManagerClient itemclient = AbstractPlugin.item().build();
|
||||
WorkspaceManagerClient wsclient = AbstractPlugin.workspace().build();
|
||||
wsclient.getVreFolders("hl:accounting");
|
||||
|
||||
List<? extends Item> folders = wsclient.getVreFolders("hl:accounting");
|
||||
for (Item item: folders) {
|
||||
System.out.println(item.getTitle());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue