Added method to set isRoot property
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/storagehub-client-wrapper@179056 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
a34fa96a9a
commit
48c7fdaa9c
|
@ -52,11 +52,13 @@ import org.slf4j.LoggerFactory;
|
|||
public final class WorkspaceStorageHubClientService implements Workspace{
|
||||
|
||||
//public static final String ACCOUNTING_HL_NODE_NAME = "hl:accounting";
|
||||
private static Logger logger = LoggerFactory.getLogger(WorkspaceStorageHubClientService.class);
|
||||
private static Logger LOGGER = LoggerFactory.getLogger(WorkspaceStorageHubClientService.class);
|
||||
private StorageHubClientService storageHubClientService;
|
||||
private boolean withAccounting;
|
||||
private boolean withFileDetails;
|
||||
private boolean withMapProperties;
|
||||
|
||||
private WorkspaceFolder workspaceRoot = null;
|
||||
|
||||
/**
|
||||
* Gets the storage hub client service.
|
||||
|
@ -255,21 +257,43 @@ public final class WorkspaceStorageHubClientService implements Workspace{
|
|||
*/
|
||||
@Override
|
||||
public WorkspaceFolder getRoot() throws InternalErrorException, Exception{
|
||||
logger.debug("Getting root");
|
||||
LOGGER.debug("Getting root");
|
||||
FolderItem root;
|
||||
try {
|
||||
root = storageHubClientService.getRoot();
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.error("Error on getting root: ", e);
|
||||
LOGGER.error("Error on getting root: ", e);
|
||||
throw new InternalErrorException("Sorry an error occurred when getting the workspace root. Refresh and try again");
|
||||
}
|
||||
WorkspaceFolder workspaceFolder = (WorkspaceFolder) HLMapper.toWorkspaceItem(root, withAccounting, withFileDetails, withMapProperties);
|
||||
workspaceFolder.setRoot(true);
|
||||
workspaceRoot = workspaceFolder;
|
||||
return workspaceFolder;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* We need to perform this method to set the root attribute.
|
||||
* No other way to get this information by SHUB
|
||||
*
|
||||
* @param item the item
|
||||
* @return the workspace item
|
||||
* @throws InternalErrorException the internal error exception
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
private WorkspaceItem setIsRoot(org.gcube.common.storagehubwrapper.shared.tohl.impl.WorkspaceItem item) throws InternalErrorException, Exception {
|
||||
Validate.notNull(item,"The input item is null");
|
||||
if(workspaceRoot==null) {
|
||||
getRoot();
|
||||
}
|
||||
boolean isRoot = workspaceRoot.getId().compareTo(item.getId())==0;
|
||||
item.setRoot(isRoot);
|
||||
LOGGER.info("Is the item '"+item.getName()+"' with id '"+item.getId()+"' the root? " +item.isRoot());
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.gcube.portal.storagehubwrapper.shared.tohl.Workspace#getChildren(java.lang.String)
|
||||
*/
|
||||
|
@ -317,6 +341,7 @@ public final class WorkspaceStorageHubClientService implements Workspace{
|
|||
|
||||
for (Item item : parents) {
|
||||
WorkspaceItem child = HLMapper.toWorkspaceItem(item, withAccounting, withFileDetails, withMapProperties);
|
||||
setIsRoot((org.gcube.common.storagehubwrapper.shared.tohl.impl.WorkspaceItem) child);
|
||||
toParents.add(child);
|
||||
}
|
||||
|
||||
|
@ -341,7 +366,7 @@ public final class WorkspaceStorageHubClientService implements Workspace{
|
|||
return (WorkspaceFolder) HLMapper.toWorkspaceItem(item, withAccounting, withFileDetails, withMapProperties);
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.error("Error on creating the folder: ",e);
|
||||
LOGGER.error("Error on creating the folder: ",e);
|
||||
throw new InternalErrorException(e.getMessage());
|
||||
}
|
||||
|
||||
|
@ -372,10 +397,12 @@ public final class WorkspaceStorageHubClientService implements Workspace{
|
|||
item = storageHubClientService.getItem(itemId, withAccounting, withMapProperties);
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.error("Error during get item with id: "+itemId,e);
|
||||
LOGGER.error("Error during get item with id: "+itemId,e);
|
||||
throw new InternalErrorException(e.getMessage());
|
||||
}
|
||||
return HLMapper.toWorkspaceItem(item, withAccounting, withFileDetails, withMapProperties);
|
||||
WorkspaceItem workspaceItem = HLMapper.toWorkspaceItem(item, withAccounting, withFileDetails, withMapProperties);
|
||||
setIsRoot((org.gcube.common.storagehubwrapper.shared.tohl.impl.WorkspaceItem) workspaceItem);
|
||||
return workspaceItem;
|
||||
}
|
||||
|
||||
|
||||
|
@ -411,7 +438,7 @@ public final class WorkspaceStorageHubClientService implements Workspace{
|
|||
wsItem = HLMapper.toWorkspaceItem(item);
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.error("Error during uploading the file: "+fileName+" in the folderId: "+folderId, e);
|
||||
LOGGER.error("Error during uploading the file: "+fileName+" in the folderId: "+folderId, e);
|
||||
String error = e.getMessage()!=null?e.getMessage():"";
|
||||
throw new InternalErrorException("Error during uploading the file: "+fileName+". "+error);
|
||||
|
||||
|
@ -433,7 +460,7 @@ public final class WorkspaceStorageHubClientService implements Workspace{
|
|||
Validate.notNull(folderId,"The input folderid is null");
|
||||
return storageHubClientService.getSharedFolderMembers(folderId);
|
||||
}catch (Exception e) {
|
||||
logger.error("Error during get shared folder members with id: "+folderId,e);
|
||||
LOGGER.error("Error during get shared folder members with id: "+folderId,e);
|
||||
throw new ItemNotFoundException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -472,7 +499,7 @@ public final class WorkspaceStorageHubClientService implements Workspace{
|
|||
return wsItems;
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.error("Error during search items with name "+name+" in the parent id: "+folderId, e);
|
||||
LOGGER.error("Error during search items with name "+name+" in the parent id: "+folderId, e);
|
||||
throw new InternalErrorException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -492,7 +519,7 @@ public final class WorkspaceStorageHubClientService implements Workspace{
|
|||
FolderItem folderItem = storageHubClientService.getRootSharedFolder(itemId);
|
||||
return HLMapper.toWorkspaceItem(folderItem);
|
||||
}catch(Exception e){
|
||||
logger.error("Get root shared folder error: ", e);
|
||||
LOGGER.error("Get root shared folder error: ", e);
|
||||
throw new Exception("Error on getting the root shared folder. "+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -512,7 +539,7 @@ public final class WorkspaceStorageHubClientService implements Workspace{
|
|||
storageHubClientService.deleteItemById(itemId);
|
||||
|
||||
}catch(Exception e){
|
||||
logger.error("Delete item by id error: "+e.getMessage());
|
||||
LOGGER.error("Delete item by id error: "+e.getMessage());
|
||||
throw new Exception("Erro on deleting the item. "+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -554,7 +581,7 @@ public final class WorkspaceStorageHubClientService implements Workspace{
|
|||
wsItem = HLMapper.toWorkspaceItem(item);
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.error("Error during uploading the archive: "+extractionFolderName+" in the folderId: "+folderId, e);
|
||||
LOGGER.error("Error during uploading the archive: "+extractionFolderName+" in the folderId: "+folderId, e);
|
||||
String error = e.getMessage()!=null?e.getMessage():"";
|
||||
throw new InternalErrorException("Error on uploading the archive. "+error);
|
||||
}
|
||||
|
@ -667,7 +694,7 @@ public final class WorkspaceStorageHubClientService implements Workspace{
|
|||
StreamDescriptor streamDesc = storageHubClientService.downloadFile(itemId, versionName, nodeIdsToExclude);
|
||||
return new org.gcube.common.storagehubwrapper.shared.tohl.impl.StreamDescriptor(streamDesc.getStream(), streamDesc.getFileName(), null, null);
|
||||
} catch (Exception e) {
|
||||
logger.error("Error on downloading the file: "+fileName+ " with id: "+itemId, e);
|
||||
LOGGER.error("Error on downloading the file: "+fileName+ " with id: "+itemId, e);
|
||||
String error = e.getMessage()!=null?e.getMessage():"";
|
||||
throw new Exception("Error on downloading the file: "+fileName+". "+error);
|
||||
}
|
||||
|
@ -691,7 +718,7 @@ public final class WorkspaceStorageHubClientService implements Workspace{
|
|||
StreamDescriptor streamDesc = storageHubClientService.downloadFolder(folderId, nodeIdsToExclude);
|
||||
return new org.gcube.common.storagehubwrapper.shared.tohl.impl.StreamDescriptor(streamDesc.getStream(), streamDesc.getFileName(), null, null);
|
||||
} catch (Exception e) {
|
||||
logger.error("Error on downloading the folder: "+folderName+ " with id: "+folderId, e);
|
||||
LOGGER.error("Error on downloading the folder: "+folderName+ " with id: "+folderId, e);
|
||||
String error = e.getMessage()!=null?e.getMessage():"";
|
||||
throw new Exception("Error on downloading the folder: "+folderName+". "+error);
|
||||
}
|
||||
|
@ -722,7 +749,7 @@ public final class WorkspaceStorageHubClientService implements Workspace{
|
|||
Item movedItem = storageHubClientService.moveItem(itemId, destFolderContainer);
|
||||
toReturnItems.add(HLMapper.toWorkspaceItem(movedItem));
|
||||
}catch(Exception e){
|
||||
logger.error("Error on moving the item with id: "+itemId+ " in the folder id: "+destFolderContainer.get().getId(), e);
|
||||
LOGGER.error("Error on moving the item with id: "+itemId+ " in the folder id: "+destFolderContainer.get().getId(), e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
@ -730,7 +757,7 @@ public final class WorkspaceStorageHubClientService implements Workspace{
|
|||
return toReturnItems;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Error on moving item in the folder with id: "+folderDestinationId + e.getMessage());
|
||||
LOGGER.error("Error on moving item in the folder with id: "+folderDestinationId + e.getMessage());
|
||||
String error = e.getMessage()!=null?e.getMessage():"";
|
||||
throw new Exception("Error on moving item/s. "+error);
|
||||
}
|
||||
|
@ -762,14 +789,14 @@ public final class WorkspaceStorageHubClientService implements Workspace{
|
|||
AbstractFileItem toReturnItem = storageHubClientService.copyFileItem(itemId, destFolderContainer, null);
|
||||
toReturnItems.add(HLMapper.toWorkspaceItem(toReturnItem));
|
||||
}catch(Exception e){
|
||||
logger.error("Error on copying the item with id: "+itemId+ " in the folder id: "+destFolderContainer.get().getId(), e);
|
||||
LOGGER.error("Error on copying the item with id: "+itemId+ " in the folder id: "+destFolderContainer.get().getId(), e);
|
||||
}
|
||||
}
|
||||
|
||||
return toReturnItems;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Error on copying item/items in the folder with id: "+folderDestinationId, e);
|
||||
LOGGER.error("Error on copying item/items in the folder with id: "+folderDestinationId, e);
|
||||
String error = e.getMessage()!=null?e.getMessage():"";
|
||||
throw new Exception("Error on copying item/s. "+error);
|
||||
}
|
||||
|
@ -815,7 +842,7 @@ public final class WorkspaceStorageHubClientService implements Workspace{
|
|||
Item item = storageHubClientService.renameItem(itemId, newName);
|
||||
return HLMapper.toWorkspaceItem(item);
|
||||
}catch(Exception e){
|
||||
logger.error("Error on renaming item with id: "+itemId, e);
|
||||
LOGGER.error("Error on renaming item with id: "+itemId, e);
|
||||
String error = e.getMessage()!=null?e.getMessage():"Operation not allowed";
|
||||
throw new Exception("Error on renaming. "+error);
|
||||
}
|
||||
|
@ -835,7 +862,7 @@ public final class WorkspaceStorageHubClientService implements Workspace{
|
|||
try{
|
||||
return storageHubClientService.getPublicLinkForFile(fileItemId);
|
||||
}catch(Exception e){
|
||||
logger.error("Error on getting public link: "+fileItemId, e);
|
||||
LOGGER.error("Error on getting public link: "+fileItemId, e);
|
||||
String error = e.getMessage()!=null?e.getMessage():"Operation not allowed";
|
||||
throw new Exception("Error on getting public link. "+error);
|
||||
}
|
||||
|
@ -855,7 +882,7 @@ public final class WorkspaceStorageHubClientService implements Workspace{
|
|||
try{
|
||||
return storageHubClientService.getPublicLinkForFileVersion(fileItemId, version);
|
||||
}catch(Exception e){
|
||||
logger.error("Error on getting public link for file: "+fileItemId +" with version: "+version, e);
|
||||
LOGGER.error("Error on getting public link for file: "+fileItemId +" with version: "+version, e);
|
||||
String error = e.getMessage()!=null?e.getMessage():"Operation not allowed";
|
||||
throw new Exception("Error on getting public link for file: "+fileItemId +" with version: "+version+". Error: "+error);
|
||||
}
|
||||
|
@ -874,7 +901,7 @@ public final class WorkspaceStorageHubClientService implements Workspace{
|
|||
List<Version> versions = storageHubClientService.getListVersions(fileItemId);
|
||||
|
||||
if(versions==null || versions.size()==0){
|
||||
logger.info("No version found for fileItemId: "+fileItemId);
|
||||
LOGGER.info("No version found for fileItemId: "+fileItemId);
|
||||
return new ArrayList<WorkspaceFileVersion>(1);
|
||||
}
|
||||
|
||||
|
@ -887,7 +914,7 @@ public final class WorkspaceStorageHubClientService implements Workspace{
|
|||
return listVersions;
|
||||
|
||||
}catch(Exception e){
|
||||
logger.error("Error on getting list of versions for: "+fileItemId, e);
|
||||
LOGGER.error("Error on getting list of versions for: "+fileItemId, e);
|
||||
String error = e.getMessage()!=null?e.getMessage():"Operation not allowed";
|
||||
throw new Exception("Error on getting public link. "+error);
|
||||
}
|
||||
|
@ -909,7 +936,7 @@ public final class WorkspaceStorageHubClientService implements Workspace{
|
|||
return new org.gcube.common.storagehubwrapper.shared.tohl.impl.StreamDescriptor(new ByteArrayInputStream(thumbBytes), null, new Long(thumbBytes.length),imgContent.getMimeType());
|
||||
|
||||
}catch(Exception e){
|
||||
logger.error("Error on getThumbnailData for: "+itemId, e);
|
||||
LOGGER.error("Error on getThumbnailData for: "+itemId, e);
|
||||
throw new Exception("Error on getting the Thumbnail. "+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -926,7 +953,7 @@ public final class WorkspaceStorageHubClientService implements Workspace{
|
|||
return storageHubClientService.getMetadata(itemId);
|
||||
|
||||
}catch(Exception e){
|
||||
logger.error("Error on getting Metadata for: "+itemId, e);
|
||||
LOGGER.error("Error on getting Metadata for: "+itemId, e);
|
||||
throw new Exception("Error on getting Metadata for: "+itemId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -337,7 +337,7 @@ public class HLMapper {
|
|||
theItem.setAccounting(accountingEntries);
|
||||
theItem.setType(type);
|
||||
theItem.setFolder(isFolder);
|
||||
theItem.setRoot(isRoot); //IS ALWAYS FALSE
|
||||
theItem.setRoot(isRoot); //THIS IS ALWAYS FALSE. SHUB DOES NOT RETURN THIS INFORMATION
|
||||
theItem.setPropertyMap(pm);
|
||||
|
||||
logger.debug("Wrapped WsItem: "+theItem);
|
||||
|
|
Loading…
Reference in New Issue