storagehub-client-library/src/main/java/org/gcube/common/storagehub/client/dsl/ItemContainer.java

52 lines
1.2 KiB
Java
Raw Normal View History

package org.gcube.common.storagehub.client.dsl;
import java.util.List;
import org.gcube.common.storagehub.client.StreamDescriptor;
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 ItemContainer<I extends Item> {
protected ItemManagerClient itemclient;
protected String itemId = null;
protected I item;
protected ItemContainer(ItemManagerClient itemclient, I item) {
this.itemclient = itemclient;
this.itemId = item.getId();
}
protected ItemContainer(ItemManagerClient itemclient, String itemId) {
this.itemclient = itemclient;
}
protected void setItem(I item) {
this.item = item;
this.itemId = item.getId();
}
public ContainerType getType() {
return ContainerType.GENERIC_ITEM;
}
@SuppressWarnings("unchecked")
public I get() throws Exception {
if (item==null) return (I)itemclient.get(itemId);
else return item;
}
public StreamDescriptor download() {
return itemclient.download(this.itemId);
}
public List<? extends Item> getAnchestors() {
return itemclient.getAnchestors(this.itemId, NodeConstants.ACCOUNTING_NAME);
}
}