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;
|
2018-12-03 12:21:17 +01:00
|
|
|
import java.util.Map;
|
2018-06-26 14:58:41 +02:00
|
|
|
|
|
|
|
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-11-22 12:49:47 +01:00
|
|
|
import org.gcube.common.storagehub.client.dsl.ListResolverTyped;
|
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;
|
2018-11-21 17:45:29 +01:00
|
|
|
import org.gcube.common.storagehub.model.Metadata;
|
2018-06-26 14:58:41 +02:00
|
|
|
import org.gcube.common.storagehub.model.acls.ACL;
|
2019-09-13 16:34:49 +02:00
|
|
|
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
2018-10-05 11:46:31 +02:00
|
|
|
import org.gcube.common.storagehub.model.items.AbstractFileItem;
|
2019-09-13 16:34:49 +02:00
|
|
|
import org.gcube.common.storagehub.model.items.ExternalLink;
|
2018-06-26 14:58:41 +02:00
|
|
|
import org.gcube.common.storagehub.model.items.FolderItem;
|
2019-09-13 16:34:49 +02:00
|
|
|
import org.gcube.common.storagehub.model.items.GCubeItem;
|
2018-06-26 14:58:41 +02:00
|
|
|
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;
|
2019-09-13 16:34:49 +02:00
|
|
|
import org.gcube.common.storagehub.model.items.nodes.Accounting;
|
2018-10-17 15:33:12 +02:00
|
|
|
import org.gcube.common.storagehub.model.items.nodes.ImageContent;
|
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;
|
|
|
|
|
|
|
|
|
2020-03-12 10:19:36 +01:00
|
|
|
// TODO: Auto-generated Javadoc
|
2018-06-26 14:58:41 +02:00
|
|
|
/**
|
|
|
|
* The Class StorageHubClientService.
|
|
|
|
*
|
|
|
|
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
2018-11-22 12:49:47 +01:00
|
|
|
* Nov 22, 2018
|
2018-06-26 14:58:41 +02:00
|
|
|
*/
|
|
|
|
public class StorageHubClientService {
|
|
|
|
|
|
|
|
|
2020-03-12 10:19:36 +01:00
|
|
|
/** The logger. */
|
2018-06-26 14:58:41 +02:00
|
|
|
private static Logger logger = LoggerFactory.getLogger(StorageHubClientService.class);
|
2020-03-12 10:19:36 +01:00
|
|
|
|
|
|
|
/** The Constant ACCOUNTING_HL_NODE_NAME. */
|
2018-06-26 14:58:41 +02:00
|
|
|
public static final String ACCOUNTING_HL_NODE_NAME = "hl:accounting";
|
2020-03-12 10:19:36 +01:00
|
|
|
|
|
|
|
/** The scope. */
|
2018-06-26 14:58:41 +02:00
|
|
|
private String scope;
|
2020-03-12 10:19:36 +01:00
|
|
|
|
|
|
|
/** The authorization token. */
|
2018-06-26 14:58:41 +02:00
|
|
|
private String authorizationToken;
|
2020-03-12 10:19:36 +01:00
|
|
|
|
|
|
|
/** The shc client. */
|
2018-06-26 14:58:41 +02:00
|
|
|
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);
|
2019-09-13 16:34:49 +02:00
|
|
|
logger.debug("Saved the contexts [scope: "+scope+", token: "+authorizationToken.substring(0,15)+"-MASKED]");
|
2018-06-26 14:58:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
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
|
2018-11-22 12:49:47 +01:00
|
|
|
* @param withAccounting the with accounting
|
|
|
|
* @param withMapProperties the with map properties
|
2018-06-26 14:58:41 +02:00
|
|
|
* @return the children
|
2019-09-13 16:34:49 +02:00
|
|
|
* @throws Exception the exception
|
2018-06-26 14:58:41 +02:00
|
|
|
*/
|
2019-04-09 12:34:36 +02:00
|
|
|
public List<? extends Item> getChildren(String id, boolean withAccounting, boolean withMapProperties) throws Exception{
|
2018-06-26 14:58:41 +02:00
|
|
|
setContextProviders(scope, authorizationToken);
|
2018-11-22 12:49:47 +01:00
|
|
|
logger.trace("Requesting getChildren for id: "+id+" [withAccounting: "+withAccounting+", withMapProperties: "+withMapProperties+"]");
|
|
|
|
ListResolverTyped resolverTyped = shcClient.open(id).asFolder().list();
|
|
|
|
ListResolver theResolver = resolverTyped.withContent();
|
|
|
|
|
|
|
|
if(withAccounting)
|
|
|
|
theResolver = theResolver.withAccounting();
|
|
|
|
|
|
|
|
if(withMapProperties)
|
|
|
|
theResolver = theResolver.withMetadata();
|
|
|
|
|
|
|
|
return theResolver.getItems();
|
2019-09-13 16:34:49 +02:00
|
|
|
|
2018-06-26 14:58:41 +02:00
|
|
|
}
|
|
|
|
|
2018-11-22 14:35:01 +01:00
|
|
|
|
2018-09-26 14:37:11 +02:00
|
|
|
/**
|
2018-11-22 14:35:01 +01:00
|
|
|
* Gets the filtered children.
|
2018-09-26 14:37:11 +02:00
|
|
|
*
|
|
|
|
* @param id the id
|
2018-10-03 15:17:47 +02:00
|
|
|
* @param aType the a type
|
2018-11-22 14:35:01 +01:00
|
|
|
* @param withAccounting the with accounting
|
|
|
|
* @param withMapProperties the with map properties
|
|
|
|
* @return the filtered children
|
2019-09-13 16:34:49 +02:00
|
|
|
* @throws Exception the exception
|
2018-09-26 14:37:11 +02:00
|
|
|
*/
|
2019-04-09 12:34:36 +02:00
|
|
|
public List<? extends Item> getFilteredChildren(String id, Class<? extends Item> aType, boolean withAccounting, boolean withMapProperties) throws Exception{
|
2018-09-26 14:37:11 +02:00
|
|
|
setContextProviders(scope, authorizationToken);
|
2018-11-22 14:35:01 +01:00
|
|
|
|
|
|
|
ListResolver resolverTyped = shcClient.open(id).asFolder().list().ofType(aType);
|
|
|
|
ListResolver theResolver = resolverTyped.withContent();
|
|
|
|
|
|
|
|
if(withAccounting)
|
|
|
|
theResolver = theResolver.withAccounting();
|
|
|
|
|
|
|
|
if(withMapProperties)
|
|
|
|
theResolver = theResolver.withMetadata();
|
2019-09-13 16:34:49 +02:00
|
|
|
|
2018-11-22 14:35:01 +01:00
|
|
|
return theResolver.getItems();
|
2018-09-26 14:37:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-26 14:58:41 +02:00
|
|
|
/**
|
|
|
|
* Gets the item.
|
|
|
|
*
|
|
|
|
* @param itemId the item id
|
2018-11-22 12:49:47 +01:00
|
|
|
* @param withAccounting the with accounting
|
|
|
|
* @param withMetadata the with metadata
|
2018-06-26 14:58:41 +02:00
|
|
|
* @return the item
|
2018-06-26 15:45:52 +02:00
|
|
|
* @throws Exception the exception
|
2018-06-26 14:58:41 +02:00
|
|
|
*/
|
2018-11-22 12:49:47 +01:00
|
|
|
public Item getItem(String itemId, boolean withAccounting, boolean withMetadata) throws Exception{
|
2018-06-26 14:58:41 +02:00
|
|
|
setContextProviders(scope, authorizationToken);
|
2018-11-22 12:49:47 +01:00
|
|
|
ItemContainer<Item> itemCont;
|
|
|
|
|
2019-09-13 16:34:49 +02:00
|
|
|
//I'M GOING TO REMAIN THESE OPTIONS FOR POSSIBLE FUTURE SUPPORTING ON SHUB
|
|
|
|
if(withMetadata) {
|
2018-11-22 12:49:47 +01:00
|
|
|
itemCont = shcClient.open(itemId).asItem(); //TODO
|
2019-09-13 16:34:49 +02:00
|
|
|
}else if(withAccounting){
|
2018-11-22 12:49:47 +01:00
|
|
|
itemCont = shcClient.open(itemId).asItem(); //TODO
|
|
|
|
}
|
2019-09-13 16:34:49 +02:00
|
|
|
else {
|
2018-11-22 12:49:47 +01:00
|
|
|
itemCont = shcClient.open(itemId).asItem();
|
2019-09-13 16:34:49 +02:00
|
|
|
}
|
|
|
|
|
2018-06-26 14:58:41 +02:00
|
|
|
return itemCont.get();
|
|
|
|
}
|
|
|
|
|
2018-11-22 18:08:51 +01:00
|
|
|
/**
|
|
|
|
* Gets the item.
|
|
|
|
*
|
|
|
|
* @param itemId the item id
|
|
|
|
* @return the item
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
public Item getItem(String itemId) throws Exception{
|
|
|
|
return getItem(itemId,false,true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-26 14:58:41 +02:00
|
|
|
|
2018-11-21 17:45:29 +01:00
|
|
|
/**
|
2018-11-22 12:49:47 +01:00
|
|
|
* Sets the metadata and returns the Item with metadata updated.
|
2018-11-21 17:45:29 +01:00
|
|
|
*
|
|
|
|
* @param itemId the item id
|
|
|
|
* @param metadata the metadata
|
|
|
|
* @return the item
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
public Item setMetadata(String itemId, Metadata metadata) throws Exception{
|
|
|
|
setContextProviders(scope, authorizationToken);
|
|
|
|
ItemContainer<Item> itemCont = shcClient.open(itemId).asItem();
|
|
|
|
itemCont.setMetadata(metadata);
|
|
|
|
return itemCont.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-12-03 12:21:17 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the metadata.
|
|
|
|
*
|
|
|
|
* @param itemId the item id
|
|
|
|
* @return the metadata
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
public Map<String, Object> getMetadata(String itemId) throws Exception{
|
|
|
|
setContextProviders(scope, authorizationToken);
|
|
|
|
ItemContainer<Item> itemCont = shcClient.open(itemId).asItem();
|
|
|
|
Metadata metadata = shcClient.open(itemId).asItem().get().getMetadata();
|
|
|
|
if(metadata!=null)
|
|
|
|
return metadata.getMap();
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
2019-09-13 16:34:49 +02:00
|
|
|
* @throws Exception the exception
|
2018-06-26 14:58:41 +02:00
|
|
|
*/
|
2019-04-09 12:34:36 +02:00
|
|
|
public List<? extends Item> getParents(String itemId) throws Exception {
|
2018-06-26 14:58:41 +02:00
|
|
|
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-10-17 12:12:44 +02:00
|
|
|
|
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();
|
|
|
|
|
|
|
|
}
|
2019-09-16 12:25:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Can write.
|
|
|
|
*
|
|
|
|
* @param folderContainerId the folder container id
|
|
|
|
* @return true, if true. Otherwise false.
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
public boolean canWrite(String folderContainerId) throws Exception {
|
|
|
|
setContextProviders(scope, authorizationToken);
|
|
|
|
return shcClient.open(folderContainerId).asFolder().canWrite();
|
|
|
|
}
|
2018-09-20 15:03:00 +02:00
|
|
|
|
2019-09-16 12:25:15 +02:00
|
|
|
|
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 {
|
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);
|
2018-11-22 12:49:47 +01:00
|
|
|
return getItem(folderContainer.get().getId(), false, true);
|
2018-06-26 14:58:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the VRE folders id.
|
|
|
|
*
|
|
|
|
* @return the VRE folders id
|
|
|
|
*/
|
|
|
|
public String getVREFoldersId() {
|
2018-10-17 12:12:44 +02:00
|
|
|
|
2018-06-26 14:58:41 +02:00
|
|
|
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 {
|
2018-10-17 12:12:44 +02:00
|
|
|
|
2018-06-26 14:58:41 +02:00
|
|
|
setContextProviders(scope, authorizationToken);
|
2018-11-22 12:49:47 +01:00
|
|
|
Item theFolder = getItem(folderId, false, true);
|
2018-06-26 14:58:41 +02:00
|
|
|
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
|
2019-09-13 16:34:49 +02:00
|
|
|
* @throws Exception the exception
|
2018-06-26 14:58:41 +02:00
|
|
|
*/
|
2019-04-09 12:34:36 +02:00
|
|
|
public int getItemChildrenCount(String itemId) throws Exception {
|
2018-10-17 12:12:44 +02:00
|
|
|
|
2018-06-26 14:58:41 +02:00
|
|
|
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-17 12:12:44 +02:00
|
|
|
setContextProviders(scope, authorizationToken);
|
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
|
2018-10-12 15:19:11 +02:00
|
|
|
* @param versionName the version name. If is null or empty returns the latest version of file
|
2018-09-26 14:37:11 +02:00
|
|
|
* @param nodeIdsToExclude the node ids to exclude
|
|
|
|
* @return the stream descriptor
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2018-10-12 15:19:11 +02:00
|
|
|
public StreamDescriptor downloadFile(String itemId, String versionName, String... nodeIdsToExclude) throws Exception{
|
2018-09-26 14:37:11 +02:00
|
|
|
|
2018-10-17 12:12:44 +02:00
|
|
|
setContextProviders(scope, authorizationToken);
|
2018-10-12 15:19:11 +02:00
|
|
|
StreamDescriptor streamDesc;
|
|
|
|
if(versionName!=null && !versionName.isEmpty()){
|
|
|
|
streamDesc = shcClient.open(itemId).asFile().downloadSpecificVersion(versionName);
|
|
|
|
}else{
|
|
|
|
streamDesc = shcClient.open(itemId).asFile().download(nodeIdsToExclude);
|
|
|
|
}
|
2019-10-14 10:28:22 +02:00
|
|
|
return new StreamDescriptor(streamDesc.getStream(), streamDesc.getFileName(), streamDesc.getContentType(), streamDesc.getContentLenght());
|
2018-10-03 15:17:47 +02:00
|
|
|
|
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{
|
|
|
|
|
2018-10-17 12:12:44 +02:00
|
|
|
setContextProviders(scope, authorizationToken);
|
2018-10-04 11:26:15 +02:00
|
|
|
StreamDescriptor streamDesc = shcClient.open(folderId).asFolder().download(nodeIdsToExclude);
|
2019-10-14 10:28:22 +02:00
|
|
|
return new StreamDescriptor(streamDesc.getStream(), streamDesc.getFileName(), streamDesc.getContentType(), streamDesc.getContentLenght());
|
2018-10-04 11:26:15 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
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-17 12:12:44 +02:00
|
|
|
setContextProviders(scope, authorizationToken);
|
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-17 12:12:44 +02:00
|
|
|
setContextProviders(scope, authorizationToken);
|
2018-11-22 12:49:47 +01:00
|
|
|
Item item = getItem(folderId, false, true);
|
2018-10-03 15:17:47 +02:00
|
|
|
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 {
|
2018-11-22 12:49:47 +01:00
|
|
|
item = getItem(folderId, false, true);
|
2018-06-26 17:23:09 +02:00
|
|
|
}catch (Exception e) {
|
|
|
|
logger.error("Error during get item with id: "+folderId,e);
|
|
|
|
throw new ItemNotFoundException(e.getMessage());
|
|
|
|
}
|
|
|
|
|
2020-03-12 10:19:36 +01:00
|
|
|
if(item instanceof FolderItem || item instanceof SharedFolder || item instanceof VreFolder){
|
|
|
|
return shcClient.open(folderId).asFolder().findByName(name).withContent().getItems();
|
|
|
|
}else
|
|
|
|
throw new Exception("The input folder id is not a folder");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2020-03-13 12:56:58 +01:00
|
|
|
* Search for text.
|
2020-03-12 10:19:36 +01:00
|
|
|
*
|
2020-03-13 12:56:58 +01:00
|
|
|
* @param text the text
|
2020-03-12 10:19:36 +01:00
|
|
|
* @param folderId the folder id
|
|
|
|
* @return the list<? extends item>
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2020-03-13 12:56:58 +01:00
|
|
|
public List<? extends Item> searchForText(String text, String folderId) throws Exception {
|
2020-03-12 10:19:36 +01:00
|
|
|
|
|
|
|
Item item;
|
|
|
|
try {
|
|
|
|
item = getItem(folderId, false, true);
|
|
|
|
}catch (Exception e) {
|
|
|
|
logger.error("Error during get item with id: "+folderId,e);
|
|
|
|
throw new ItemNotFoundException(e.getMessage());
|
|
|
|
}
|
|
|
|
|
2018-06-26 17:23:09 +02:00
|
|
|
if(item instanceof FolderItem || item instanceof SharedFolder || item instanceof VreFolder){
|
2020-03-13 12:56:58 +01:00
|
|
|
//this does not return the trashed items
|
|
|
|
return shcClient.open(folderId).asFolder().search(text,true).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{
|
|
|
|
|
2019-09-13 16:34:49 +02:00
|
|
|
Validate.notNull(itemId, "Bad request to deleteItemById, the itemId is null");
|
2018-10-17 12:12:44 +02:00
|
|
|
setContextProviders(scope, authorizationToken);
|
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{
|
|
|
|
|
2018-10-17 12:12:44 +02:00
|
|
|
setContextProviders(scope, authorizationToken);
|
2018-09-21 14:54:41 +02:00
|
|
|
return shcClient.openTrash().get();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Empty trash.
|
|
|
|
*
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
public void emptyTrash() throws Exception{
|
|
|
|
|
2018-10-17 12:12:44 +02:00
|
|
|
setContextProviders(scope, authorizationToken);
|
2018-09-21 14:54:41 +02:00
|
|
|
shcClient.emptyTrash();
|
|
|
|
|
|
|
|
}
|
2020-05-18 16:53:59 +02:00
|
|
|
|
|
|
|
|
2018-09-21 14:54:41 +02:00
|
|
|
/**
|
|
|
|
* Restore thrash item.
|
|
|
|
*
|
|
|
|
* @param itemId the item id
|
2020-05-18 16:53:59 +02:00
|
|
|
* @param destinationFolderId the destination folder id
|
2018-09-21 14:54:41 +02:00
|
|
|
* @return the item
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2020-05-18 16:53:59 +02:00
|
|
|
public Item restoreThrashItem(String itemId, String destinationFolderId) throws Exception{
|
2018-09-21 14:54:41 +02:00
|
|
|
|
2019-09-13 16:34:49 +02:00
|
|
|
Validate.notNull(itemId, "Bad request to restoreThrashItem, the itemId is null");
|
2018-10-17 12:12:44 +02:00
|
|
|
setContextProviders(scope, authorizationToken);
|
2020-05-18 16:53:59 +02:00
|
|
|
|
|
|
|
GenericItemContainer container = null;
|
|
|
|
if(destinationFolderId==null)
|
|
|
|
container = shcClient.restoreThrashItem(itemId);
|
|
|
|
else
|
|
|
|
container = shcClient.restoreThrashItem(itemId, destinationFolderId);
|
|
|
|
|
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
|
|
|
|
2019-09-13 16:34:49 +02:00
|
|
|
Validate.notNull(itemId, "Bad request to moveItem, the itemId is null");
|
|
|
|
Validate.notNull(destFolderContainer, "Bad request to moveItem, the itemId is null");
|
2018-10-17 12:12:44 +02:00
|
|
|
setContextProviders(scope, authorizationToken);
|
2018-10-16 15:18:59 +02:00
|
|
|
shcClient.open(itemId).asItem().move(destFolderContainer);
|
|
|
|
return shcClient.open(itemId).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{
|
|
|
|
|
2019-09-13 16:34:49 +02:00
|
|
|
Validate.notNull(fileItemId, "Bad request to copyFileItem, the fileItemId is null");
|
|
|
|
Validate.notNull(destFolderContainer, "Bad request to copyFileItem, the destFolderContainer is null");
|
2018-10-17 12:12:44 +02:00
|
|
|
setContextProviders(scope, authorizationToken);
|
2018-10-05 11:46:31 +02:00
|
|
|
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{
|
|
|
|
|
2019-09-13 16:34:49 +02:00
|
|
|
Validate.notNull(itemId, "Bad request to renameItem, the itemId is null");
|
2018-10-17 12:12:44 +02:00
|
|
|
setContextProviders(scope, authorizationToken);
|
2018-10-16 15:18:59 +02:00
|
|
|
shcClient.open(itemId).asItem().rename(newName);
|
|
|
|
return shcClient.open(itemId).asItem().get();
|
2018-10-09 17:38:06 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2019-09-13 16:34:49 +02:00
|
|
|
Validate.notNull(fileItemId, "Bad request to getPublicLinkForFile, the fileItemId is null");
|
2018-10-17 12:12:44 +02:00
|
|
|
setContextProviders(scope, authorizationToken);
|
2018-10-12 10:19:20 +02:00
|
|
|
return shcClient.open(fileItemId).asFile().getPublicLink();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-08 15:24:42 +01:00
|
|
|
/**
|
|
|
|
* Gets the public link for file version.
|
|
|
|
*
|
|
|
|
* @param fileItemId the file item id
|
2019-09-13 16:34:49 +02:00
|
|
|
* @param version the version
|
2019-01-08 15:24:42 +01:00
|
|
|
* @return the public link for file version
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
public URL getPublicLinkForFileVersion(String fileItemId, String version) throws Exception{
|
|
|
|
|
2019-09-13 16:34:49 +02:00
|
|
|
Validate.notNull(fileItemId, "Bad request to getPublicLinkForFile, the fileItemId is null");
|
|
|
|
Validate.notNull(version, "Bad request to getPublicLinkForFileVersion, the version is null");
|
|
|
|
Validate.notEmpty(version, "Bad request to getPublicLinkForFileVersion, the version is empty");
|
2019-01-08 15:24:42 +01:00
|
|
|
setContextProviders(scope, authorizationToken);
|
|
|
|
return shcClient.open(fileItemId).asFile().getPublicLink(version);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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{
|
|
|
|
|
2019-09-13 16:34:49 +02:00
|
|
|
Validate.notNull(fileItemId, "Bad request to getListVersions, the fileItemId is null");
|
2018-10-12 14:19:09 +02:00
|
|
|
|
|
|
|
return shcClient.open(fileItemId).asFile().getVersions();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-10-17 12:12:44 +02:00
|
|
|
/**
|
2018-10-17 15:33:12 +02:00
|
|
|
* Gets the image content.
|
2018-10-17 12:12:44 +02:00
|
|
|
*
|
|
|
|
* @param itemId the item id
|
2018-10-17 15:33:12 +02:00
|
|
|
* @return the image content
|
2018-10-17 12:12:44 +02:00
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2018-10-17 15:33:12 +02:00
|
|
|
public ImageContent getImageContent(String itemId) throws Exception{
|
2018-10-17 12:12:44 +02:00
|
|
|
|
2019-09-13 16:34:49 +02:00
|
|
|
Validate.notNull(itemId, "Bad request to getImageContent, the itemId is null");
|
2018-10-17 12:12:44 +02:00
|
|
|
setContextProviders(scope, authorizationToken);
|
|
|
|
ItemContainer<Item> itemCont = shcClient.open(itemId).asItem();
|
|
|
|
Item item = itemCont.get();
|
|
|
|
if(item instanceof org.gcube.common.storagehub.model.items.ImageFile){
|
|
|
|
org.gcube.common.storagehub.model.items.ImageFile imgFI = (org.gcube.common.storagehub.model.items.ImageFile) item; //??
|
2018-10-17 15:33:12 +02:00
|
|
|
return imgFI.getContent();
|
2018-10-17 12:12:44 +02:00
|
|
|
}else
|
|
|
|
throw new Exception("Thumbnail Data is not available for type: "+item.getClass().getSimpleName());
|
|
|
|
}
|
|
|
|
|
2019-09-13 16:34:49 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the total items.
|
|
|
|
*
|
|
|
|
* @return the total items
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
public long getTotalItems() throws Exception{
|
|
|
|
|
|
|
|
setContextProviders(scope, authorizationToken);
|
|
|
|
return shcClient.getTotalItemCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the disk usage.
|
|
|
|
*
|
|
|
|
* @return the disk usage
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
public long getDiskUsage() throws Exception{
|
|
|
|
setContextProviders(scope, authorizationToken);
|
|
|
|
return shcClient.getTotalVolume();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the accounting.
|
|
|
|
*
|
|
|
|
* @param itemId the item id
|
|
|
|
* @return the accounting
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
public Accounting getAccounting(String itemId) throws Exception{
|
|
|
|
|
|
|
|
Validate.notNull(itemId, "Bad request to getAccounting, the itemId is null");
|
|
|
|
setContextProviders(scope, authorizationToken);
|
|
|
|
ItemContainer<Item> itemCont = shcClient.open(itemId).asItem();
|
|
|
|
Item item = itemCont.get();
|
|
|
|
return item.getAccounting();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the gcube item properties.
|
|
|
|
*
|
|
|
|
* @param gcubeItemId the gcube item id
|
|
|
|
* @return the gcube item properties
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
public Metadata getGcubeItemProperties(String gcubeItemId) throws Exception {
|
|
|
|
Validate.notNull(gcubeItemId, "Bad request to loadGcubeItemProperties, the itemId is null");
|
|
|
|
setContextProviders(scope, authorizationToken);
|
|
|
|
ItemContainer<Item> itemCont = shcClient.open(gcubeItemId).asItem();
|
|
|
|
Item item = itemCont.get();
|
|
|
|
|
|
|
|
if(item instanceof GCubeItem) {
|
|
|
|
GCubeItem theGcubeItem = (GCubeItem) item;
|
|
|
|
return theGcubeItem.getMetadata();
|
|
|
|
}else
|
|
|
|
throw new Exception("The item with id "+gcubeItemId+" is not an istance of "+GCubeItem.class.getSimpleName());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the metadata.
|
|
|
|
*
|
|
|
|
* @param itemId the item id
|
|
|
|
* @param mapProperties the map properties
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
public void setMetadata(String itemId, Map<String, Object> mapProperties) throws Exception {
|
|
|
|
Validate.notNull(itemId, "Bad request to setMetadata the itemId is null");
|
|
|
|
setContextProviders(scope, authorizationToken);
|
|
|
|
//ItemContainer<Item> itemCont = shcClient.open(itemId).asItem();
|
|
|
|
//itemCont.get().setMetadata(new Metadata(mapProperties));
|
|
|
|
//item.setMetadata(new Metadata(mapProperties));
|
|
|
|
shcClient.open(itemId).asItem().setMetadata(new Metadata(mapProperties));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds the URL.
|
|
|
|
*
|
|
|
|
* @param folderId the folder id
|
|
|
|
* @param URL the url
|
|
|
|
* @param name the name
|
|
|
|
* @param description the description
|
|
|
|
* @return the external link
|
|
|
|
* @throws StorageHubException the storage hub exception
|
|
|
|
*/
|
|
|
|
public ExternalLink addURL(String folderId, URL URL, String name, String description) throws StorageHubException {
|
|
|
|
Validate.notNull(folderId, "Bad request to createURL the folderId is null");
|
|
|
|
setContextProviders(scope, authorizationToken);
|
|
|
|
FolderContainer folder = shcClient.open(folderId).asFolder();
|
|
|
|
|
|
|
|
return folder.addUrl(URL, name, description).get();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the folder as public.
|
|
|
|
*
|
|
|
|
* @param folderId the folder id
|
|
|
|
* @param setPublic the set public
|
|
|
|
* @return boolean value of isPublicItem()
|
2019-09-16 12:25:15 +02:00
|
|
|
* @throws Exception the exception
|
2019-09-13 16:34:49 +02:00
|
|
|
*/
|
|
|
|
public boolean setFolderAsPublic(String folderId, boolean setPublic) throws Exception {
|
|
|
|
Validate.notNull(folderId, "Bad request to setFolderAsPublic the folderId is null");
|
|
|
|
setContextProviders(scope, authorizationToken);
|
|
|
|
FolderContainer folderCont = shcClient.open(folderId).asFolder();
|
|
|
|
|
|
|
|
if(setPublic) {
|
|
|
|
folderCont.publish();
|
|
|
|
logger.debug("Published the folder id: "+folderId);
|
|
|
|
}else {
|
|
|
|
folderCont.unpublish();
|
|
|
|
logger.debug("Unpublished the folder id: "+folderId);
|
|
|
|
}
|
|
|
|
|
|
|
|
return shcClient.open(folderId).asFolder().get().isPublicItem();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-15 15:40:15 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Update description for item.
|
|
|
|
*
|
|
|
|
* @param itemId the item id
|
|
|
|
* @param newDescription the new description
|
|
|
|
* @return the description updated
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
public String updateDescriptionForItem(String itemId, String newDescription) throws Exception {
|
|
|
|
Validate.notNull(itemId, "Bad request the itemId is null");
|
|
|
|
setContextProviders(scope, authorizationToken);
|
|
|
|
|
|
|
|
throw new Exception("Not implemented yet by SHUB");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-10-17 12:12:44 +02:00
|
|
|
|
2020-03-12 10:19:36 +01:00
|
|
|
/**
|
|
|
|
* To string.
|
|
|
|
*
|
|
|
|
* @return the string
|
|
|
|
*/
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-15 15:40:15 +02:00
|
|
|
|
2018-06-26 14:58:41 +02:00
|
|
|
}
|