2018-06-15 17:33:13 +02:00
|
|
|
package org.gcube.common.storagehub.client.dsl;
|
|
|
|
|
|
|
|
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
2018-06-21 17:08:26 +02:00
|
|
|
import org.gcube.common.storagehub.model.items.AbstractFileItem;
|
2019-07-29 16:25:52 +02:00
|
|
|
import org.gcube.common.storagehub.model.items.ExternalLink;
|
2018-06-15 17:33:13 +02:00
|
|
|
import org.gcube.common.storagehub.model.items.FolderItem;
|
|
|
|
import org.gcube.common.storagehub.model.items.Item;
|
|
|
|
|
|
|
|
public class OpenResolver {
|
|
|
|
|
|
|
|
private Item item;
|
|
|
|
private ItemManagerClient itemclient;
|
|
|
|
|
|
|
|
protected OpenResolver(Item item, ItemManagerClient itemclient) {
|
|
|
|
this.item = item;
|
|
|
|
this.itemclient = itemclient;
|
|
|
|
};
|
|
|
|
|
|
|
|
public FolderContainer asFolder() {
|
|
|
|
if (item instanceof FolderItem)
|
|
|
|
return new FolderContainer(itemclient, (FolderItem)item);
|
|
|
|
else throw new RuntimeException("this item is not a folder");
|
|
|
|
}
|
|
|
|
|
2018-06-21 12:08:31 +02:00
|
|
|
public ItemContainer<Item> asItem() {
|
2018-06-22 10:52:56 +02:00
|
|
|
return new GenericItemContainer(itemclient, item);
|
2018-06-21 12:08:31 +02:00
|
|
|
}
|
2018-06-15 17:33:13 +02:00
|
|
|
|
2018-06-21 17:08:26 +02:00
|
|
|
public FileContainer asFile() {
|
2018-06-22 10:52:56 +02:00
|
|
|
if (item instanceof AbstractFileItem)
|
|
|
|
return new FileContainer(itemclient, (AbstractFileItem)item);
|
|
|
|
else throw new RuntimeException("this item is not a File");
|
2018-06-21 17:08:26 +02:00
|
|
|
}
|
2019-07-29 16:25:52 +02:00
|
|
|
|
|
|
|
public URLContainer asURL() {
|
|
|
|
if (item instanceof ExternalLink)
|
|
|
|
return new URLContainer(itemclient, (ExternalLink)item);
|
|
|
|
else throw new RuntimeException("this item is not a File");
|
|
|
|
}
|
2020-03-05 15:19:45 +01:00
|
|
|
|
|
|
|
public ItemContainer<?> resolve(){
|
|
|
|
if (item instanceof FolderItem)
|
|
|
|
return this.asFolder();
|
|
|
|
if (item instanceof AbstractFileItem)
|
|
|
|
return this.asFile();
|
|
|
|
if (item instanceof ExternalLink)
|
|
|
|
return this.asURL();
|
|
|
|
else return this.asItem();
|
|
|
|
|
|
|
|
}
|
2018-06-15 17:33:13 +02:00
|
|
|
}
|