2018-04-18 15:55:20 +02:00
|
|
|
package org.gcube.common.storagehub.client.dsl;
|
2018-03-29 18:19:01 +02:00
|
|
|
|
|
|
|
import java.io.InputStream;
|
2018-06-22 10:52:56 +02:00
|
|
|
import java.util.List;
|
2018-09-18 14:54:11 +02:00
|
|
|
import java.util.Set;
|
2018-03-29 18:19:01 +02:00
|
|
|
|
2019-06-05 18:10:28 +02:00
|
|
|
import org.gcube.common.authorization.library.AuthorizationEntry;
|
2018-03-29 18:19:01 +02:00
|
|
|
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
2018-06-22 10:52:56 +02:00
|
|
|
import org.gcube.common.storagehub.model.acls.ACL;
|
2018-09-18 14:54:11 +02:00
|
|
|
import org.gcube.common.storagehub.model.acls.AccessType;
|
2019-03-13 18:33:58 +01:00
|
|
|
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
2018-03-29 18:19:01 +02:00
|
|
|
import org.gcube.common.storagehub.model.items.FolderItem;
|
2018-10-15 16:43:53 +02:00
|
|
|
import org.gcube.common.storagehub.model.items.GCubeItem;
|
2018-03-29 18:19:01 +02:00
|
|
|
|
2018-06-15 17:33:13 +02:00
|
|
|
public class FolderContainer extends ItemContainer<FolderItem>{
|
2018-06-21 15:04:22 +02:00
|
|
|
|
2018-03-29 18:19:01 +02:00
|
|
|
// private String folderPath = null;
|
|
|
|
|
2018-06-15 17:33:13 +02:00
|
|
|
protected FolderContainer(ItemManagerClient itemclient, FolderItem item) {
|
|
|
|
super(itemclient, item);
|
2018-04-18 15:55:20 +02:00
|
|
|
}
|
|
|
|
|
2018-06-15 17:33:13 +02:00
|
|
|
protected FolderContainer(ItemManagerClient itemclient, String folderId) {
|
|
|
|
super(itemclient, folderId);
|
2018-03-29 18:19:01 +02:00
|
|
|
}
|
|
|
|
|
2018-06-21 17:50:07 +02:00
|
|
|
public ContainerType getType() {
|
|
|
|
return ContainerType.FOLDER;
|
|
|
|
}
|
|
|
|
|
2019-03-13 18:33:58 +01:00
|
|
|
public ListResolverTyped list() throws StorageHubException {
|
2019-01-03 12:16:53 +01:00
|
|
|
return new ListResolverTyped((onlyType, includeHidden, excludes) -> itemclient.getChildren(itemId, onlyType, includeHidden, excludes), itemclient) ;
|
2018-03-29 18:19:01 +02:00
|
|
|
}
|
|
|
|
|
2019-03-13 18:33:58 +01:00
|
|
|
public FileContainer uploadFile(InputStream stream, String filename, String description) throws StorageHubException {
|
2018-06-22 16:27:21 +02:00
|
|
|
return new FileContainer(itemclient, itemclient.uploadFile(stream, this.itemId , filename, description));
|
2018-03-29 18:19:01 +02:00
|
|
|
}
|
|
|
|
|
2019-03-13 18:33:58 +01:00
|
|
|
public FolderContainer uploadArchive(InputStream stream, String extractionFolderName) throws StorageHubException {
|
2018-07-30 12:38:34 +02:00
|
|
|
return new FolderContainer(itemclient, itemclient.uploadArchive(stream, this.itemId , extractionFolderName));
|
|
|
|
}
|
|
|
|
|
2018-06-21 12:08:31 +02:00
|
|
|
public FolderContainer newFolder(String name, String description) throws Exception {
|
2018-12-18 16:24:08 +01:00
|
|
|
String newFolderId = itemclient.createFolder(this.itemId, name, description, false);
|
|
|
|
return new FolderContainer(itemclient, newFolderId);
|
|
|
|
}
|
|
|
|
|
|
|
|
public FolderContainer newHiddenFolder(String name, String description) throws Exception {
|
|
|
|
String newFolderId = itemclient.createFolder(this.itemId, name, description, true);
|
2018-06-21 12:08:31 +02:00
|
|
|
return new FolderContainer(itemclient, newFolderId);
|
|
|
|
}
|
|
|
|
|
2018-10-15 16:43:53 +02:00
|
|
|
public GenericItemContainer newGcubeItem(GCubeItem item) throws Exception {
|
|
|
|
String itemId = itemclient.createGcubeItem(this.itemId, item);
|
|
|
|
return new GenericItemContainer(itemclient, itemId);
|
|
|
|
}
|
|
|
|
|
2018-06-22 10:52:56 +02:00
|
|
|
public List<ACL> getAcls() throws Exception {
|
|
|
|
return itemclient.getACL(this.itemId);
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:10:28 +02:00
|
|
|
public boolean canWrite() throws Exception {
|
|
|
|
return itemclient.canWriteInto(this.itemId);
|
|
|
|
}
|
|
|
|
|
2019-03-13 18:33:58 +01:00
|
|
|
public ListResolver findByName(String namePattern) throws StorageHubException {
|
2019-01-03 12:16:53 +01:00
|
|
|
return new ListResolver((onlyType, includeHidden, excludes) -> itemclient.findChildrenByNamePattern(itemId, namePattern , excludes), itemclient);
|
2018-06-26 15:30:30 +02:00
|
|
|
}
|
|
|
|
|
2018-09-18 14:54:11 +02:00
|
|
|
public FolderContainer share(Set<String> users, AccessType accessType) throws Exception {
|
|
|
|
itemclient.shareFolder(this.itemId, users, accessType);
|
2019-04-30 14:53:12 +02:00
|
|
|
this.invalidateItem();
|
2018-09-18 14:54:11 +02:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public FolderContainer unshare(Set<String> users) throws Exception {
|
2019-04-30 14:53:12 +02:00
|
|
|
String unsharedId = itemclient.unshareFolder(this.itemId, users);
|
|
|
|
return new FolderContainer(itemclient, unsharedId);
|
2018-09-18 14:54:11 +02:00
|
|
|
}
|
2018-06-26 15:30:30 +02:00
|
|
|
|
2018-03-29 18:19:01 +02:00
|
|
|
}
|