2018-06-21 17:08:26 +02:00
|
|
|
package org.gcube.common.storagehub.client.dsl;
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
|
|
|
import org.gcube.common.storagehub.model.NodeConstants;
|
|
|
|
import org.gcube.common.storagehub.model.items.Item;
|
|
|
|
|
|
|
|
public class ListResolver {
|
|
|
|
|
2018-06-26 15:30:30 +02:00
|
|
|
ListRetriever retriever;
|
|
|
|
ItemManagerClient itemClient;
|
|
|
|
|
|
|
|
|
2018-06-21 17:08:26 +02:00
|
|
|
Set<String> excludes = new HashSet<>(Arrays.asList(NodeConstants.ACCOUNTING_NAME, NodeConstants.CONTENT_NAME, NodeConstants.METADATA_NAME));
|
2018-09-26 15:24:21 +02:00
|
|
|
Class<? extends Item> onlyType = null;
|
|
|
|
|
2018-06-21 17:08:26 +02:00
|
|
|
|
2018-06-26 15:30:30 +02:00
|
|
|
protected ListResolver(ListRetriever retriever, ItemManagerClient itemClient) {
|
|
|
|
this.retriever = retriever;
|
|
|
|
this.itemClient = itemClient;
|
2018-06-21 17:08:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public ListResolver withAccounting(){
|
|
|
|
excludes.remove(NodeConstants.ACCOUNTING_NAME);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ListResolver withContent(){
|
|
|
|
excludes.remove(NodeConstants.CONTENT_NAME);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ListResolver withMetadata(){
|
|
|
|
excludes.remove(NodeConstants.METADATA_NAME);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2018-09-26 15:24:21 +02:00
|
|
|
|
2018-06-21 17:08:26 +02:00
|
|
|
public List<? extends Item> getItems(){
|
2018-09-26 15:24:21 +02:00
|
|
|
return retriever.getList(onlyType, excludes.toArray(new String[excludes.size()]));
|
2018-06-21 17:08:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public List<ItemContainer<? extends Item>> getContainers(){
|
2018-06-26 15:30:30 +02:00
|
|
|
List<? extends Item> items = getItems();
|
2018-06-21 17:08:26 +02:00
|
|
|
List<ItemContainer<? extends Item>> toReturn = items.stream().map(i -> Util.getContainerFromItem(i, itemClient)).collect(Collectors.toList());
|
|
|
|
return toReturn;
|
|
|
|
}
|
|
|
|
}
|