2018-06-26 14:58:41 +02:00
|
|
|
package org.gcube.common.storagehubwrapper.server;
|
|
|
|
|
|
|
|
import java.io.InputStream;
|
2018-10-12 10:19:20 +02:00
|
|
|
import java.net.URL;
|
2018-06-26 14:58:41 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.apache.commons.lang.Validate;
|
|
|
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
2018-09-26 14:37:11 +02:00
|
|
|
import org.gcube.common.storagehub.client.StreamDescriptor;
|
2018-06-26 14:58:41 +02:00
|
|
|
import org.gcube.common.storagehub.client.dsl.FileContainer;
|
|
|
|
import org.gcube.common.storagehub.client.dsl.FolderContainer;
|
2018-09-24 16:18:06 +02:00
|
|
|
import org.gcube.common.storagehub.client.dsl.GenericItemContainer;
|
2018-06-26 14:58:41 +02:00
|
|
|
import org.gcube.common.storagehub.client.dsl.ItemContainer;
|
2018-09-14 15:34:12 +02:00
|
|
|
import org.gcube.common.storagehub.client.dsl.ListResolver;
|
2018-10-05 15:20:16 +02:00
|
|
|
import org.gcube.common.storagehub.client.dsl.OpenResolver;
|
2018-06-26 14:58:41 +02:00
|
|
|
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
|
|
|
|
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
|
|
|
|
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
|
|
|
import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient;
|
|
|
|
import org.gcube.common.storagehub.model.acls.ACL;
|
2018-10-05 11:46:31 +02:00
|
|
|
import org.gcube.common.storagehub.model.items.AbstractFileItem;
|
2018-06-26 14:58:41 +02:00
|
|
|
import org.gcube.common.storagehub.model.items.FolderItem;
|
|
|
|
import org.gcube.common.storagehub.model.items.Item;
|
|
|
|
import org.gcube.common.storagehub.model.items.SharedFolder;
|
2018-06-26 17:23:09 +02:00
|
|
|
import org.gcube.common.storagehub.model.items.VreFolder;
|
2018-10-12 14:19:09 +02:00
|
|
|
import org.gcube.common.storagehub.model.service.Version;
|
2018-06-26 15:45:52 +02:00
|
|
|
import org.gcube.common.storagehubwrapper.server.converter.ObjectMapper;
|
|
|
|
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.ItemNotFoundException;
|
2018-06-26 14:58:41 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Class StorageHubClientService.
|
|
|
|
*
|
|
|
|
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
|
|
|
* Jun 20, 2018
|
|
|
|
*/
|
|
|
|
public class StorageHubClientService {
|
|
|
|
|
|
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(StorageHubClientService.class);
|
|
|
|
public static final String ACCOUNTING_HL_NODE_NAME = "hl:accounting";
|
|
|
|
private String scope;
|
|
|
|
private String authorizationToken;
|
|
|
|
private StorageHubClient shcClient;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instantiates a new storage hub service util.
|
|
|
|
*
|
|
|
|
* @param scope the scope
|
|
|
|
* @param authorizationToken the authorization token
|
|
|
|
*/
|
|
|
|
public StorageHubClientService(String scope, String authorizationToken) {
|
|
|
|
Validate.notNull(scope, "The scope is null");
|
|
|
|
Validate.notNull(authorizationToken, "The authorizationToken is null");
|
|
|
|
this.scope = scope;
|
|
|
|
this.authorizationToken = authorizationToken;
|
|
|
|
setContextProviders(scope, authorizationToken);
|
|
|
|
shcClient = new StorageHubClient();
|
|
|
|
logger.info("Instancied the "+StorageHubClientService.class.getSimpleName()+" as: "+this.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the context providers.
|
|
|
|
*
|
|
|
|
* @param scope the scope
|
|
|
|
* @param authorizationToken the authorization token
|
|
|
|
*/
|
|
|
|
private void setContextProviders(String scope, String authorizationToken){
|
|
|
|
ScopeProvider.instance.set(scope);
|
|
|
|
SecurityTokenProvider.instance.set(authorizationToken);
|
|
|
|
logger.debug("Saved the contexts [scope: "+scope+", token: "+authorizationToken+"]");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the root.
|
|
|
|
*
|
|
|
|
* @return the root
|
2018-06-26 15:45:52 +02:00
|
|
|
* @throws Exception the exception
|
2018-06-26 14:58:41 +02:00
|
|
|
*/
|
|
|
|
public FolderItem getRoot() throws Exception {
|
|
|
|
setContextProviders(scope, authorizationToken);
|
|
|
|
// WorkspaceManagerClient client = AbstractPlugin.workspace().build();
|
|
|
|
// Item itemRoot = client.getWorkspace(ACCOUNTING_HL_NODE_NAME);
|
|
|
|
FolderContainer root = shcClient.getWSRoot();
|
|
|
|
return root.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the root.
|
|
|
|
*
|
|
|
|
* @return the root
|
|
|
|
*/
|
|
|
|
public Item getTrash() {
|
|
|
|
setContextProviders(scope, authorizationToken);
|
|
|
|
WorkspaceManagerClient client = AbstractPlugin.workspace().build();
|
|
|
|
Item trash = client.getTrashFolder();
|
|
|
|
return trash;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the children.
|
|
|
|
*
|
|
|
|
* @param id the id
|
|
|
|
* @return the children
|
|
|
|
*/
|
|
|
|
public List<? extends Item> getChildren(String id){
|
|
|
|
setContextProviders(scope, authorizationToken);
|
|
|
|
return shcClient.open(id).asFolder().list().withContent().getItems();
|
|
|
|
}
|
|
|
|
|
2018-09-26 14:37:11 +02:00
|
|
|
/**
|
|
|
|
* Gets the children.
|
|
|
|
*
|
|
|
|
* @param id the id
|
2018-10-03 15:17:47 +02:00
|
|
|
* @param aType the a type
|
2018-09-26 14:37:11 +02:00
|
|
|
* @return the children
|
|
|
|
*/
|
|
|
|
public List<? extends Item> getFilteredChildren(String id, Class<? extends Item> aType){
|
|
|
|
setContextProviders(scope, authorizationToken);
|
|
|
|
return shcClient.open(id).asFolder().list().ofType(aType).withContent().getItems();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-06-26 14:58:41 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the item.
|
|
|
|
*
|
|
|
|
* @param itemId the item id
|
|
|
|
* @return the item
|
2018-06-26 15:45:52 +02:00
|
|
|
* @throws Exception the exception
|
2018-06-26 14:58:41 +02:00
|
|
|
*/
|
|
|
|
public Item getItem(String itemId) throws Exception{
|
|
|
|
setContextProviders(scope, authorizationToken);
|
|
|
|
ItemContainer<Item> itemCont = shcClient.open(itemId).asItem();//TODO
|
|
|
|
return itemCont.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-05 11:46:31 +02:00
|
|
|
/**
|
|
|
|
* Gets the folder container.
|
|
|
|
*
|
|
|
|
* @param itemId the item id
|
|
|
|
* @return the folder container
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
public FolderContainer getFolderContainer(String itemId) throws Exception{
|
|
|
|
setContextProviders(scope, authorizationToken);
|
|
|
|
return shcClient.open(itemId).asFolder();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-26 14:58:41 +02:00
|
|
|
/**
|
|
|
|
* Gets the parents.
|
|
|
|
*
|
|
|
|
* @param itemId the item id
|
|
|
|
* @return the parents
|
|
|
|
*/
|
|
|
|
public List<? extends Item> getParents(String itemId) {
|
|
|
|
setContextProviders(scope, authorizationToken);
|
2018-09-14 15:34:12 +02:00
|
|
|
ListResolver toReturn = shcClient.open(itemId).asItem().getAnchestors();
|
|
|
|
if(toReturn==null || toReturn.getItems()==null){
|
|
|
|
logger.warn("Parent List of item id "+itemId+" is null");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return toReturn.getItems();
|
2018-06-26 14:58:41 +02:00
|
|
|
}
|
|
|
|
|
2018-06-27 15:22:52 +02:00
|
|
|
//TODO MAP OF SHARED ROOT ID
|
2018-06-26 14:58:41 +02:00
|
|
|
|
2018-07-02 12:10:12 +02:00
|
|
|
|
2018-06-29 14:16:11 +02:00
|
|
|
/**
|
2018-07-02 12:10:12 +02:00
|
|
|
* Gets the id shared folder.
|
2018-06-29 14:16:11 +02:00
|
|
|
*
|
|
|
|
* @param itemId the item id
|
2018-07-02 12:10:12 +02:00
|
|
|
* @return the id shared folder
|
2018-09-14 15:34:12 +02:00
|
|
|
* @throws Exception the exception
|
2018-06-29 14:16:11 +02:00
|
|
|
*/
|
2018-07-02 12:10:12 +02:00
|
|
|
public String getIdSharedFolder(String itemId) throws Exception {
|
2018-06-29 14:16:11 +02:00
|
|
|
setContextProviders(scope, authorizationToken);
|
2018-07-02 12:10:12 +02:00
|
|
|
return getRootSharedFolder(itemId).getId();
|
|
|
|
}
|
2018-06-29 14:16:11 +02:00
|
|
|
|
|
|
|
|
2018-07-02 12:10:12 +02:00
|
|
|
/**
|
|
|
|
* Gets the root shared folder.
|
|
|
|
*
|
|
|
|
* @param itemId the item id
|
|
|
|
* @return the root shared folder
|
2018-09-14 15:34:12 +02:00
|
|
|
* @throws Exception the exception
|
2018-07-02 12:10:12 +02:00
|
|
|
*/
|
|
|
|
public FolderItem getRootSharedFolder(String itemId) throws Exception {
|
|
|
|
setContextProviders(scope, authorizationToken);
|
2018-09-14 15:34:12 +02:00
|
|
|
return getRootSharedFolder(shcClient.open(itemId).asItem());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-09-20 15:03:00 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if is item shared.
|
|
|
|
*
|
|
|
|
* @param itemId the item id
|
|
|
|
* @return true, if is item shared
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
public boolean isItemShared(String itemId) throws Exception {
|
|
|
|
setContextProviders(scope, authorizationToken);
|
|
|
|
return shcClient.open(itemId).asItem().get().isShared();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-09-14 15:34:12 +02:00
|
|
|
/**
|
|
|
|
* Gets the root shared folder.
|
|
|
|
*
|
|
|
|
* @param itemContainer the item container
|
|
|
|
* @return the root shared folder
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
public FolderItem getRootSharedFolder(ItemContainer<Item> itemContainer) throws Exception {
|
|
|
|
setContextProviders(scope, authorizationToken);
|
2018-07-02 12:10:12 +02:00
|
|
|
|
|
|
|
FolderContainer rootSharedFolder = null;
|
2018-09-14 15:34:12 +02:00
|
|
|
Item item = itemContainer.get();
|
|
|
|
if(item.isShared()){
|
|
|
|
rootSharedFolder = itemContainer.getRootSharedFolder();
|
2018-07-02 12:10:12 +02:00
|
|
|
}else
|
2018-09-14 15:34:12 +02:00
|
|
|
throw new Exception("The item with id: "+item.getId() +" is not shared");
|
2018-07-02 12:10:12 +02:00
|
|
|
|
2018-09-14 15:34:12 +02:00
|
|
|
Validate.notNull(rootSharedFolder, "The root shared folder with children id "+item.getId()+" does not exist");
|
2018-07-02 12:10:12 +02:00
|
|
|
return rootSharedFolder.get();
|
2018-06-29 14:16:11 +02:00
|
|
|
}
|
|
|
|
|
2018-06-26 14:58:41 +02:00
|
|
|
/**
|
|
|
|
* Creates the folder.
|
|
|
|
*
|
|
|
|
* @param parentId the parent id
|
|
|
|
* @param folderName the folder name
|
|
|
|
* @param folderDescription the folder description
|
|
|
|
* @return the item
|
2018-06-26 15:45:52 +02:00
|
|
|
* @throws Exception the exception
|
2018-06-26 14:58:41 +02:00
|
|
|
*/
|
|
|
|
public Item createFolder(String parentId, String folderName, String folderDescription) throws Exception {
|
|
|
|
setContextProviders(scope, authorizationToken);
|
|
|
|
FolderContainer folderContainer = shcClient.open(parentId).asFolder().newFolder(folderName, folderDescription);
|
|
|
|
return getItem(folderContainer.get().getId());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the VRE folders id.
|
|
|
|
*
|
|
|
|
* @return the VRE folders id
|
|
|
|
*/
|
|
|
|
public String getVREFoldersId() {
|
|
|
|
setContextProviders(scope, authorizationToken);
|
|
|
|
String toReturn = "";
|
|
|
|
try {
|
|
|
|
WorkspaceManagerClient wsclient = AbstractPlugin.workspace().build();
|
|
|
|
try {
|
|
|
|
List<? extends Item> list = wsclient.getVreFolders(ACCOUNTING_HL_NODE_NAME);
|
|
|
|
toReturn =list.iterator().next().getParentId();
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.info("This user has no VRE Folders", e);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}catch (Exception e) {
|
2018-07-02 12:10:12 +02:00
|
|
|
logger.error("Get VRE Folders Id ",e);
|
|
|
|
//e.printStackTrace();
|
2018-06-26 14:58:41 +02:00
|
|
|
}
|
|
|
|
return toReturn;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-20 18:14:43 +02:00
|
|
|
|
|
|
|
|
2018-06-26 14:58:41 +02:00
|
|
|
/**
|
|
|
|
* Gets the user acl for folder id.
|
|
|
|
*
|
2018-06-26 15:45:52 +02:00
|
|
|
* @param infrastructureName the infrastructure name
|
|
|
|
* @param userName the user name
|
2018-06-26 14:58:41 +02:00
|
|
|
* @param folderId the folder id
|
|
|
|
* @return the user acl for folder id
|
2018-06-26 15:45:52 +02:00
|
|
|
* @throws Exception the exception
|
2018-06-26 14:58:41 +02:00
|
|
|
*/
|
|
|
|
public String getUserACLForFolderId(String infrastructureName, String userName, String folderId) throws Exception {
|
|
|
|
setContextProviders(scope, authorizationToken);
|
|
|
|
Item theFolder = getItem(folderId);
|
|
|
|
if (!theFolder.isShared()) {
|
|
|
|
return "OWNER";
|
|
|
|
} else {
|
|
|
|
ItemManagerClient client = AbstractPlugin.item().build();
|
|
|
|
List<ACL> acls = client.getACL(folderId);
|
|
|
|
SharedFolder sharedFolder = (SharedFolder) theFolder;
|
|
|
|
|
|
|
|
boolean found = false; //this is needed because in case o VRE Foder the permission is assigned to the group and not to the user.
|
|
|
|
for (ACL acl : acls) {
|
|
|
|
if (acl.getPricipal().compareTo(userName) == 0) {
|
|
|
|
found = true;
|
|
|
|
return acl.getAccessTypes().get(0).toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found && sharedFolder.isVreFolder()) {
|
|
|
|
for (ACL acl : acls) {
|
|
|
|
if (acl.getPricipal().startsWith(infrastructureName));
|
|
|
|
return acl.getAccessTypes().get(0).toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "UNDEFINED";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the item children count.
|
|
|
|
*
|
|
|
|
* @param itemId the item id
|
|
|
|
* @return the item children count
|
|
|
|
*/
|
|
|
|
public int getItemChildrenCount(String itemId) {
|
|
|
|
setContextProviders(scope, authorizationToken);
|
|
|
|
ItemManagerClient client = AbstractPlugin.item().build();
|
|
|
|
return client.childrenCount(itemId);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Upload file.
|
|
|
|
*
|
|
|
|
* @param folderId the folder id
|
|
|
|
* @param is the is
|
|
|
|
* @param fileName the file name
|
|
|
|
* @param fileDescription the file description
|
|
|
|
* @return the item
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
public Item uploadFile(String folderId, InputStream is, String fileName, String fileDescription) throws Exception{
|
|
|
|
|
2018-10-03 15:17:47 +02:00
|
|
|
FileContainer fileCont = shcClient.open(folderId).asFolder().uploadFile(is, fileName, fileDescription);
|
|
|
|
return fileCont.get();
|
2018-06-26 14:58:41 +02:00
|
|
|
}
|
|
|
|
|
2018-10-03 15:17:47 +02:00
|
|
|
|
2018-10-04 11:26:15 +02:00
|
|
|
|
2018-09-26 14:37:11 +02:00
|
|
|
/**
|
|
|
|
* Download file.
|
|
|
|
*
|
|
|
|
* @param itemId the item id
|
|
|
|
* @param nodeIdsToExclude the node ids to exclude
|
|
|
|
* @return the stream descriptor
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2018-10-04 11:26:15 +02:00
|
|
|
public StreamDescriptor downloadFile(String itemId, String nodeIdsToExclude) throws Exception{
|
2018-09-26 14:37:11 +02:00
|
|
|
|
2018-10-03 15:17:47 +02:00
|
|
|
StreamDescriptor streamDesc = shcClient.open(itemId).asFile().download(nodeIdsToExclude);
|
|
|
|
return new StreamDescriptor(streamDesc.getStream(), streamDesc.getFileName());
|
|
|
|
|
2018-09-26 14:37:11 +02:00
|
|
|
}
|
|
|
|
|
2018-06-26 15:45:52 +02:00
|
|
|
|
2018-10-04 11:26:15 +02:00
|
|
|
/**
|
|
|
|
* Download folder.
|
|
|
|
*
|
|
|
|
* @param folderId the folder id
|
|
|
|
* @param nodeIdsToExclude the node ids to exclude
|
|
|
|
* @return the stream descriptor
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
public StreamDescriptor downloadFolder(String folderId, String nodeIdsToExclude) throws Exception{
|
|
|
|
|
|
|
|
StreamDescriptor streamDesc = shcClient.open(folderId).asFolder().download(nodeIdsToExclude);
|
|
|
|
return new StreamDescriptor(streamDesc.getStream(), streamDesc.getFileName());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-09-18 16:47:48 +02:00
|
|
|
/**
|
|
|
|
* Upload archive.
|
|
|
|
*
|
|
|
|
* @param folderId the folder id
|
|
|
|
* @param is the is
|
|
|
|
* @param extractionFolderName the extraction folder name
|
|
|
|
* @return the item
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
public Item uploadArchive(String folderId, InputStream is, String extractionFolderName) throws Exception{
|
|
|
|
|
2018-10-03 15:17:47 +02:00
|
|
|
FolderContainer folderCont = shcClient.open(folderId).asFolder().uploadArchive(is, extractionFolderName);
|
|
|
|
return folderCont.get();
|
2018-09-18 16:47:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-06-26 15:45:52 +02:00
|
|
|
/**
|
|
|
|
* Gets the shared folder members.
|
|
|
|
*
|
|
|
|
* @param folderId the folder id
|
|
|
|
* @return the shared folder members
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
public List<String> getSharedFolderMembers(String folderId) throws Exception {
|
|
|
|
|
2018-10-03 15:17:47 +02:00
|
|
|
Item item = getItem(folderId);
|
|
|
|
if(item instanceof SharedFolder){
|
|
|
|
return ObjectMapper.toListLogins((SharedFolder)item);
|
|
|
|
}else
|
|
|
|
throw new Exception("The item with "+folderId+ " is not a Shared Folder");
|
|
|
|
|
2018-06-26 15:45:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-26 17:23:09 +02:00
|
|
|
/**
|
|
|
|
* Find by name.
|
|
|
|
*
|
|
|
|
* @param name the name
|
|
|
|
* @param folderId the folder id
|
|
|
|
* @return the list<? extends item>
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
public List<? extends Item> findByName(String name, String folderId) throws Exception {
|
2018-10-03 15:17:47 +02:00
|
|
|
|
2018-06-26 17:23:09 +02:00
|
|
|
Item item;
|
|
|
|
try {
|
|
|
|
item = getItem(folderId);
|
|
|
|
}catch (Exception e) {
|
|
|
|
logger.error("Error during get item with id: "+folderId,e);
|
|
|
|
throw new ItemNotFoundException(e.getMessage());
|
|
|
|
}
|
|
|
|
|
|
|
|
if(item instanceof FolderItem || item instanceof SharedFolder || item instanceof VreFolder){
|
2018-07-05 18:24:28 +02:00
|
|
|
return shcClient.open(folderId).asFolder().findByName(name).withContent().getItems();
|
2018-06-26 17:23:09 +02:00
|
|
|
}else
|
|
|
|
throw new Exception("The input folder id is not a folder");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-09-14 15:34:12 +02:00
|
|
|
/**
|
|
|
|
* Delete item by id.
|
|
|
|
*
|
|
|
|
* @param itemId the item id
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
public void deleteItemById(String itemId) throws Exception{
|
|
|
|
|
2018-10-05 11:46:31 +02:00
|
|
|
Validate.notNull(itemId, "Bad invoking operation the itemId is null");
|
2018-09-14 15:34:12 +02:00
|
|
|
shcClient.open(itemId).asItem().delete();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-09-21 14:54:41 +02:00
|
|
|
/**
|
|
|
|
* Open trash.
|
|
|
|
*
|
|
|
|
* @return the item
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
public Item openTrash() throws Exception{
|
|
|
|
|
|
|
|
return shcClient.openTrash().get();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Empty trash.
|
|
|
|
*
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
public void emptyTrash() throws Exception{
|
|
|
|
|
|
|
|
shcClient.emptyTrash();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Restore thrash item.
|
|
|
|
*
|
|
|
|
* @param itemId the item id
|
|
|
|
* @return the item
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
public Item restoreThrashItem(String itemId) throws Exception{
|
|
|
|
|
2018-10-05 11:46:31 +02:00
|
|
|
Validate.notNull(itemId, "Bad invoking restore trash item the item Id is null");
|
2018-09-21 14:54:41 +02:00
|
|
|
|
2018-09-24 16:18:06 +02:00
|
|
|
GenericItemContainer container = shcClient.restoreThrashItem(itemId);
|
2018-09-21 14:54:41 +02:00
|
|
|
|
|
|
|
if(container!=null){
|
2018-09-24 16:18:06 +02:00
|
|
|
Item item = container.get();
|
2018-09-21 14:54:41 +02:00
|
|
|
if(item!=null){
|
|
|
|
return item;
|
|
|
|
}else
|
|
|
|
throw new Exception("Restoring failed, FolderItem is null");
|
|
|
|
}else
|
|
|
|
throw new Exception("Restoring failed, contanier is null");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-06-26 17:23:09 +02:00
|
|
|
|
2018-10-05 11:46:31 +02:00
|
|
|
/**
|
|
|
|
* Move item.
|
|
|
|
*
|
2018-10-05 15:20:16 +02:00
|
|
|
* @param itemId the item id
|
2018-10-05 11:46:31 +02:00
|
|
|
* @param destFolderContainer the dest folder container
|
2018-10-05 15:20:16 +02:00
|
|
|
* @return the abstract file item
|
2018-10-05 11:46:31 +02:00
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2018-10-05 17:37:30 +02:00
|
|
|
public Item moveItem(String itemId, FolderContainer destFolderContainer) throws Exception{
|
2018-10-05 11:46:31 +02:00
|
|
|
|
|
|
|
Validate.notNull(itemId, "Bad invoking move file, the itemId is null");
|
|
|
|
Validate.notNull(destFolderContainer, "Bad invoking move file, the itemId is null");
|
|
|
|
|
2018-10-05 15:20:16 +02:00
|
|
|
OpenResolver openResolver = shcClient.open(itemId).asItem().move(destFolderContainer);
|
2018-10-05 17:37:30 +02:00
|
|
|
return openResolver.asItem().get();
|
2018-10-05 11:46:31 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy item.
|
|
|
|
*
|
|
|
|
* @param fileItemId the copy item id
|
|
|
|
* @param destFolderContainer the dest folder container
|
|
|
|
* @param newFileName the new file name
|
|
|
|
* @return the abstract file item
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
public AbstractFileItem copyFileItem(String fileItemId, FolderContainer destFolderContainer, String newFileName) throws Exception{
|
|
|
|
|
|
|
|
Validate.notNull(fileItemId, "Bad invoking copy file, the fileItemId is null");
|
|
|
|
Validate.notNull(destFolderContainer, "Bad invoking copy file, the destFolderContainer is null");
|
|
|
|
|
|
|
|
FileContainer copyingItem = shcClient.open(fileItemId).asFile();
|
|
|
|
String newName = newFileName!=null && !newFileName.isEmpty()?newFileName:"Copy of "+copyingItem.get().getName();
|
|
|
|
FileContainer newItem = copyingItem.copy(destFolderContainer, newName);
|
|
|
|
return newItem.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-09 17:38:06 +02:00
|
|
|
/**
|
|
|
|
* Rename item.
|
|
|
|
*
|
|
|
|
* @param itemId the item id
|
|
|
|
* @param newName the new name
|
|
|
|
* @return the item
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
public Item renameItem(String itemId, String newName) throws Exception{
|
|
|
|
|
|
|
|
Validate.notNull(itemId, "Bad invoking rename item, the itemId is null");
|
|
|
|
|
|
|
|
OpenResolver resolver = shcClient.open(itemId).asItem().rename(newName);
|
|
|
|
return resolver.asItem().get();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-12 10:19:20 +02:00
|
|
|
/**
|
|
|
|
* Gets the file public link.
|
|
|
|
*
|
|
|
|
* @param fileItemId the file item id
|
|
|
|
* @return the file public link
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2018-10-12 10:30:38 +02:00
|
|
|
public URL getPublicLinkForFile(String fileItemId) throws Exception{
|
2018-10-12 10:19:20 +02:00
|
|
|
|
2018-10-12 14:19:09 +02:00
|
|
|
Validate.notNull(fileItemId, "Bad invoking get public link, the fileItemId is null");
|
2018-10-12 10:19:20 +02:00
|
|
|
|
|
|
|
return shcClient.open(fileItemId).asFile().getPublicLink();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-12 14:19:09 +02:00
|
|
|
/**
|
|
|
|
* Gets the list versions.
|
|
|
|
*
|
|
|
|
* @param fileItemId the file item id
|
|
|
|
* @return the list versions
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
public List<Version> getListVersions(String fileItemId) throws Exception{
|
|
|
|
|
|
|
|
Validate.notNull(fileItemId, "Bad invoking get list of versions, the fileItemId is null");
|
|
|
|
|
|
|
|
return shcClient.open(fileItemId).asFile().getVersions();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-26 14:58:41 +02:00
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see java.lang.Object#toString()
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
|
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
builder.append("StorageHubClientService [scope=");
|
|
|
|
builder.append(scope);
|
|
|
|
builder.append(", authorizationToken=");
|
|
|
|
builder.append(authorizationToken.substring(0, authorizationToken.length()-5)+"XXXXX");
|
|
|
|
builder.append(", itemManagerClient=");
|
|
|
|
builder.append(shcClient);
|
|
|
|
builder.append("]");
|
|
|
|
return builder.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|