2018-04-18 15:55:20 +02:00
|
|
|
package org.gcube.common.storagehub.client.dsl;
|
|
|
|
|
|
|
|
import org.gcube.common.storagehub.client.StreamDescriptor;
|
|
|
|
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
2018-10-15 15:39:02 +02:00
|
|
|
import org.gcube.common.storagehub.model.Metadata;
|
2019-03-13 18:33:58 +01:00
|
|
|
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
2018-06-27 18:33:32 +02:00
|
|
|
import org.gcube.common.storagehub.model.items.FolderItem;
|
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> {
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-05-14 16:14:52 +02:00
|
|
|
protected ItemManagerClient itemclient;
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-06-15 17:33:13 +02:00
|
|
|
protected String itemId = null;
|
|
|
|
protected I item;
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-10-15 15:39:02 +02:00
|
|
|
boolean invalidated = false;
|
2019-03-13 18:33:58 +01: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;
|
2019-01-25 15:10:16 +01:00
|
|
|
this.item = item;
|
2018-06-19 11:42:57 +02:00
|
|
|
this.itemId = item.getId();
|
2018-04-18 15:55:20 +02:00
|
|
|
}
|
2019-03-13 18:33:58 +01: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
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-06-15 17:33:13 +02:00
|
|
|
protected void setItem(I item) {
|
|
|
|
this.item = item;
|
|
|
|
this.itemId = item.getId();
|
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-10-15 15:44:31 +02:00
|
|
|
public String getId() {
|
2018-10-05 15:02:47 +02:00
|
|
|
return this.itemId;
|
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-06-22 10:52:56 +02:00
|
|
|
public abstract ContainerType getType();
|
2019-03-13 18:33:58 +01:00
|
|
|
|
|
|
|
|
2018-06-21 15:04:22 +02:00
|
|
|
@SuppressWarnings("unchecked")
|
2018-09-21 18:00:47 +02:00
|
|
|
public I get() {
|
2018-10-15 15:39:02 +02:00
|
|
|
if (item==null || invalidated) {
|
2019-03-13 18:33:58 +01:00
|
|
|
try {
|
|
|
|
I toRet = (I)itemclient.get(itemId);
|
|
|
|
invalidated = false;
|
|
|
|
item = toRet;
|
|
|
|
return toRet;
|
|
|
|
}catch(Exception e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
2018-10-15 15:39:02 +02:00
|
|
|
}
|
2018-06-21 15:04:22 +02:00
|
|
|
else return item;
|
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-10-15 15:39:02 +02:00
|
|
|
protected void invalidateItem() {
|
|
|
|
invalidated = true;
|
2018-10-05 15:02:47 +02:00
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
public StreamDescriptor download(String ... nodeIdsToExclude) throws StorageHubException {
|
2018-09-04 11:21:08 +02:00
|
|
|
return itemclient.download(this.itemId, nodeIdsToExclude);
|
2018-04-18 15:55:20 +02:00
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
|
|
|
public ListResolver getAnchestors() throws StorageHubException{
|
2019-01-03 12:16:53 +01:00
|
|
|
return new ListResolver((onlyType, includeHidden, excludes) -> itemclient.getAnchestors(this.itemId, excludes) , itemclient);
|
2018-06-21 12:08:31 +02:00
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
|
|
|
public void delete() throws StorageHubException {
|
2019-05-22 17:12:47 +02:00
|
|
|
itemclient.delete(this.itemId, false);
|
2018-10-15 15:39:02 +02:00
|
|
|
invalidateItem();
|
2018-06-25 16:50:43 +02:00
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2019-05-22 17:12:47 +02:00
|
|
|
public void forceDelete() throws StorageHubException {
|
|
|
|
itemclient.delete(this.itemId, true);
|
|
|
|
invalidateItem();
|
|
|
|
}
|
|
|
|
|
2019-03-13 18:33:58 +01:00
|
|
|
public void rename(String newName) throws StorageHubException {
|
2018-10-08 13:45:23 +02:00
|
|
|
itemclient.rename(this.getId(), newName);
|
2018-10-15 15:39:02 +02:00
|
|
|
invalidateItem();
|
2018-10-04 16:53:47 +02:00
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
|
|
|
public void move(FolderContainer folder) throws StorageHubException {
|
2018-10-08 13:45:23 +02:00
|
|
|
itemclient.move(this.getId(), folder.getId());
|
2018-10-15 15:39:02 +02:00
|
|
|
invalidateItem();
|
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
|
|
|
public void setMetadata(Metadata metadata) throws StorageHubException {
|
2018-10-15 15:39:02 +02:00
|
|
|
itemclient.setMetadata(this.getId(), metadata);
|
|
|
|
invalidateItem();
|
2018-10-04 16:53:47 +02:00
|
|
|
}
|
2020-04-09 14:52:26 +02:00
|
|
|
|
|
|
|
public void setHidden() throws StorageHubException {
|
|
|
|
itemclient.setHidden(this.getId(), true);
|
|
|
|
invalidateItem();
|
|
|
|
}
|
|
|
|
|
2020-09-16 11:03:06 +02:00
|
|
|
public void setDescription(String description) throws StorageHubException {
|
|
|
|
itemclient.setDescription(this.getId(), description);
|
|
|
|
invalidateItem();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-09 14:52:26 +02:00
|
|
|
public void setVisible() throws StorageHubException {
|
|
|
|
itemclient.setHidden(this.getId(), false);
|
|
|
|
invalidateItem();
|
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
|
|
|
public FolderContainer getRootSharedFolder() throws StorageHubException {
|
2018-06-27 18:33:32 +02:00
|
|
|
return new FolderContainer(itemclient, (FolderItem)itemclient.getRootSharedFolder(this.itemId));
|
|
|
|
}
|
2018-04-18 15:55:20 +02:00
|
|
|
}
|