git-svn-id: https://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/Common/storagehub-client@169444 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
4209d0d5a7
commit
b6824fa421
|
@ -24,7 +24,7 @@ public class FolderContainer extends ItemContainer<FolderItem>{
|
||||||
}
|
}
|
||||||
|
|
||||||
public ListResolver list() {
|
public ListResolver list() {
|
||||||
return new ListResolver(itemclient, itemId);
|
return new ListResolver(excludes -> itemclient.getChildren(itemId, excludes), itemclient);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileContainer uploadFile(InputStream stream, String filename, String description) {
|
public FileContainer uploadFile(InputStream stream, String filename, String description) {
|
||||||
|
@ -40,4 +40,9 @@ public class FolderContainer extends ItemContainer<FolderItem>{
|
||||||
return itemclient.getACL(this.itemId);
|
return itemclient.getACL(this.itemId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ListResolver findByName(String namePattern) {
|
||||||
|
return new ListResolver(excludes -> itemclient.findChildrenByNamePattern(itemId, namePattern , excludes), itemclient);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,14 +12,15 @@ import org.gcube.common.storagehub.model.items.Item;
|
||||||
|
|
||||||
public class ListResolver {
|
public class ListResolver {
|
||||||
|
|
||||||
private ItemManagerClient itemClient;
|
ListRetriever retriever;
|
||||||
private String itemId;
|
ItemManagerClient itemClient;
|
||||||
|
|
||||||
|
|
||||||
Set<String> excludes = new HashSet<>(Arrays.asList(NodeConstants.ACCOUNTING_NAME, NodeConstants.CONTENT_NAME, NodeConstants.METADATA_NAME));
|
Set<String> excludes = new HashSet<>(Arrays.asList(NodeConstants.ACCOUNTING_NAME, NodeConstants.CONTENT_NAME, NodeConstants.METADATA_NAME));
|
||||||
|
|
||||||
protected ListResolver(ItemManagerClient itemclient, String itemId) {
|
protected ListResolver(ListRetriever retriever, ItemManagerClient itemClient) {
|
||||||
this.itemClient = itemclient;
|
this.retriever = retriever;
|
||||||
this.itemId = itemId;
|
this.itemClient = itemClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ListResolver withAccounting(){
|
public ListResolver withAccounting(){
|
||||||
|
@ -38,11 +39,11 @@ public class ListResolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<? extends Item> getItems(){
|
public List<? extends Item> getItems(){
|
||||||
return itemClient.getChildren(itemId, excludes.toArray(new String[excludes.size()]));
|
return retriever.getList(excludes.toArray(new String[excludes.size()]));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ItemContainer<? extends Item>> getContainers(){
|
public List<ItemContainer<? extends Item>> getContainers(){
|
||||||
List<? extends Item> items = itemClient.getChildren(itemId, excludes.toArray(new String[excludes.size()]));
|
List<? extends Item> items = getItems();
|
||||||
List<ItemContainer<? extends Item>> toReturn = items.stream().map(i -> Util.getContainerFromItem(i, itemClient)).collect(Collectors.toList());
|
List<ItemContainer<? extends Item>> toReturn = items.stream().map(i -> Util.getContainerFromItem(i, itemClient)).collect(Collectors.toList());
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
package org.gcube.common.storagehub.client.dsl;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.gcube.common.storagehub.model.items.Item;
|
||||||
|
|
||||||
|
public interface ListRetriever {
|
||||||
|
|
||||||
|
List<? extends Item> getList(String ... excludes);
|
||||||
|
}
|
|
@ -142,6 +142,27 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<? extends Item> findChildrenByNamePattern(String id, String name, String... excludeNodes) {
|
||||||
|
Call<WebTarget, ItemList> call = new Call<WebTarget, ItemList>() {
|
||||||
|
@Override
|
||||||
|
public ItemList call(WebTarget manager) throws Exception {
|
||||||
|
WebTarget myManager = manager.path(id).path("items").path(name);
|
||||||
|
if (excludeNodes !=null && excludeNodes.length>0)
|
||||||
|
myManager = myManager.queryParam("exclude",excludeNodes);
|
||||||
|
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
|
@Override
|
||||||
public Integer childrenCount(String id) {
|
public Integer childrenCount(String id) {
|
||||||
|
|
|
@ -35,5 +35,7 @@ public interface ItemManagerClient {
|
||||||
void delete(String id);
|
void delete(String id);
|
||||||
|
|
||||||
URL getPublickLink(String id);
|
URL getPublickLink(String id);
|
||||||
|
|
||||||
|
List<? extends Item> findChildrenByNamePattern(String id, String name, String[] excludeNodes);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class Items {
|
||||||
|
|
||||||
String afi = null;
|
String afi = null;
|
||||||
try (InputStream is = new FileInputStream(new File("/home/lucio/Downloads/rockandroll.jpeg"))){
|
try (InputStream is = new FileInputStream(new File("/home/lucio/Downloads/rockandroll.jpeg"))){
|
||||||
shc.getWSRoot().uploadFile(is, "tes-image.jpeg", "descr");
|
shc.getWSRoot().uploadFile(is, "test2-image.jpeg", "descr");
|
||||||
|
|
||||||
System.out.println(afi);
|
System.out.println(afi);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -53,6 +53,15 @@ public class Items {
|
||||||
System.out.println(shc.open("c2573eec-3942-47ec-94a7-04869e97bb69").asFile().getPublicLink());
|
System.out.println(shc.open("c2573eec-3942-47ec-94a7-04869e97bb69").asFile().getPublicLink());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findByName() throws Exception{
|
||||||
|
StorageHubClient shc = new StorageHubClient();
|
||||||
|
List<? extends Item> containers = shc.getWSRoot().findByName("DataMiner").getItems();
|
||||||
|
for (Item container : containers) {
|
||||||
|
System.out.println("name is :"+container.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void downloadFile() {
|
public void downloadFile() {
|
||||||
StorageHubClient shc = new StorageHubClient();
|
StorageHubClient shc = new StorageHubClient();
|
||||||
|
|
Loading…
Reference in New Issue