2018-04-18 15:55:20 +02:00
|
|
|
package org.gcube.common.storagehub.client.dsl;
|
|
|
|
|
2018-06-21 12:08:31 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
2018-04-18 15:55:20 +02:00
|
|
|
import org.gcube.common.storagehub.client.StreamDescriptor;
|
|
|
|
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
2018-06-21 12:08:31 +02:00
|
|
|
import org.gcube.common.storagehub.model.NodeConstants;
|
2018-06-15 17:33:13 +02:00
|
|
|
import org.gcube.common.storagehub.model.items.Item;
|
2018-04-18 15:55:20 +02:00
|
|
|
|
2018-06-22 10:52:56 +02:00
|
|
|
public abstract class ItemContainer<I extends Item> {
|
2018-06-15 17:33:13 +02:00
|
|
|
|
2018-05-14 16:14:52 +02:00
|
|
|
protected ItemManagerClient itemclient;
|
2018-04-18 15:55:20 +02:00
|
|
|
|
2018-06-15 17:33:13 +02:00
|
|
|
protected String itemId = null;
|
|
|
|
protected I item;
|
2018-04-18 15:55:20 +02:00
|
|
|
|
2018-06-15 17:33:13 +02:00
|
|
|
protected ItemContainer(ItemManagerClient itemclient, I item) {
|
2018-04-18 15:55:20 +02:00
|
|
|
this.itemclient = itemclient;
|
2018-06-19 11:42:57 +02:00
|
|
|
this.itemId = item.getId();
|
2018-04-18 15:55:20 +02:00
|
|
|
}
|
|
|
|
|
2018-06-15 17:33:13 +02:00
|
|
|
protected ItemContainer(ItemManagerClient itemclient, String itemId) {
|
|
|
|
this.itemclient = itemclient;
|
2018-06-22 10:52:56 +02:00
|
|
|
this.itemId = itemId;
|
2018-06-15 17:33:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void setItem(I item) {
|
|
|
|
this.item = item;
|
|
|
|
this.itemId = item.getId();
|
|
|
|
}
|
|
|
|
|
2018-06-22 10:52:56 +02:00
|
|
|
public abstract ContainerType getType();
|
2018-06-21 17:50:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-06-21 15:04:22 +02:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
public I get() throws Exception {
|
|
|
|
if (item==null) return (I)itemclient.get(itemId);
|
|
|
|
else return item;
|
|
|
|
}
|
|
|
|
|
2018-06-15 17:33:13 +02:00
|
|
|
public StreamDescriptor download() {
|
|
|
|
return itemclient.download(this.itemId);
|
2018-04-18 15:55:20 +02:00
|
|
|
}
|
2018-06-21 12:08:31 +02:00
|
|
|
|
|
|
|
public List<? extends Item> getAnchestors() {
|
|
|
|
return itemclient.getAnchestors(this.itemId, NodeConstants.ACCOUNTING_NAME);
|
|
|
|
}
|
|
|
|
|
2018-06-25 16:50:43 +02:00
|
|
|
public void delete() {
|
|
|
|
itemclient.delete(this.itemId);
|
|
|
|
}
|
|
|
|
|
2018-04-18 15:55:20 +02:00
|
|
|
}
|