From d203bf71e927947197b27d0b66925b46b060aa1c Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 20 Jul 2020 10:38:14 +0200 Subject: [PATCH] integrated with the method setDescription reported at #19652#note-1 --- .classpath | 17 --- .../server/StorageHubClientService.java | 102 +++++++++--------- 2 files changed, 50 insertions(+), 69 deletions(-) diff --git a/.classpath b/.classpath index becc0fb..a80540a 100644 --- a/.classpath +++ b/.classpath @@ -24,23 +24,6 @@ - - - - - - - - - - - - - - - - - diff --git a/src/main/java/org/gcube/common/storagehubwrapper/server/StorageHubClientService.java b/src/main/java/org/gcube/common/storagehubwrapper/server/StorageHubClientService.java index 529328a..9c094d5 100644 --- a/src/main/java/org/gcube/common/storagehubwrapper/server/StorageHubClientService.java +++ b/src/main/java/org/gcube/common/storagehubwrapper/server/StorageHubClientService.java @@ -60,8 +60,8 @@ public class StorageHubClientService { /** The authorization token. */ private String authorizationToken; - /** The shc client. */ - private StorageHubClient shcClient; + + private StorageHubClient shClient; /** @@ -76,7 +76,7 @@ public class StorageHubClientService { this.scope = scope; this.authorizationToken = authorizationToken; setContextProviders(scope, authorizationToken); - shcClient = new StorageHubClient(); + shClient = new StorageHubClient(); logger.info("Instancied the "+StorageHubClientService.class.getSimpleName()+" as: "+this.toString()); } @@ -100,7 +100,7 @@ public class StorageHubClientService { */ public FolderItem getRoot() throws Exception { setContextProviders(scope, authorizationToken); - FolderContainer root = shcClient.getWSRoot(); + FolderContainer root = shClient.getWSRoot(); return root.get(); } @@ -129,7 +129,7 @@ public class StorageHubClientService { public List getChildren(String id, boolean withAccounting, boolean withMapProperties) throws Exception{ setContextProviders(scope, authorizationToken); logger.trace("Requesting getChildren for id: "+id+" [withAccounting: "+withAccounting+", withMapProperties: "+withMapProperties+"]"); - ListResolverTyped resolverTyped = shcClient.open(id).asFolder().list(); + ListResolverTyped resolverTyped = shClient.open(id).asFolder().list(); ListResolver theResolver = resolverTyped.withContent(); if(withAccounting) @@ -156,7 +156,7 @@ public class StorageHubClientService { public List getFilteredChildren(String id, Class aType, boolean withAccounting, boolean withMapProperties) throws Exception{ setContextProviders(scope, authorizationToken); - ListResolver resolverTyped = shcClient.open(id).asFolder().list().ofType(aType); + ListResolver resolverTyped = shClient.open(id).asFolder().list().ofType(aType); ListResolver theResolver = resolverTyped.withContent(); if(withAccounting) @@ -184,12 +184,12 @@ public class StorageHubClientService { //I'M GOING TO REMAIN THESE OPTIONS FOR POSSIBLE FUTURE SUPPORTING ON SHUB if(withMetadata) { - itemCont = shcClient.open(itemId).asItem(); //TODO + itemCont = shClient.open(itemId).asItem(); //TODO }else if(withAccounting){ - itemCont = shcClient.open(itemId).asItem(); //TODO + itemCont = shClient.open(itemId).asItem(); //TODO } else { - itemCont = shcClient.open(itemId).asItem(); + itemCont = shClient.open(itemId).asItem(); } return itemCont.get(); @@ -218,7 +218,7 @@ public class StorageHubClientService { */ public Item setMetadata(String itemId, Metadata metadata) throws Exception{ setContextProviders(scope, authorizationToken); - ItemContainer itemCont = shcClient.open(itemId).asItem(); + ItemContainer itemCont = shClient.open(itemId).asItem(); itemCont.setMetadata(metadata); return itemCont.get(); } @@ -234,8 +234,8 @@ public class StorageHubClientService { */ public Map getMetadata(String itemId) throws Exception{ setContextProviders(scope, authorizationToken); - ItemContainer itemCont = shcClient.open(itemId).asItem(); - Metadata metadata = shcClient.open(itemId).asItem().get().getMetadata(); + ItemContainer itemCont = shClient.open(itemId).asItem(); + Metadata metadata = shClient.open(itemId).asItem().get().getMetadata(); if(metadata!=null) return metadata.getMap(); @@ -252,7 +252,7 @@ public class StorageHubClientService { */ public FolderContainer getFolderContainer(String itemId) throws Exception{ setContextProviders(scope, authorizationToken); - return shcClient.open(itemId).asFolder(); + return shClient.open(itemId).asFolder(); } @@ -265,7 +265,7 @@ public class StorageHubClientService { */ public List getParents(String itemId) throws Exception { setContextProviders(scope, authorizationToken); - ListResolver toReturn = shcClient.open(itemId).asItem().getAnchestors(); + ListResolver toReturn = shClient.open(itemId).asItem().getAnchestors(); if(toReturn==null || toReturn.getItems()==null){ logger.warn("Parent List of item id "+itemId+" is null"); return null; @@ -298,7 +298,7 @@ public class StorageHubClientService { */ public FolderItem getRootSharedFolder(String itemId) throws Exception { setContextProviders(scope, authorizationToken); - return getRootSharedFolder(shcClient.open(itemId).asItem()); + return getRootSharedFolder(shClient.open(itemId).asItem()); } @@ -312,7 +312,7 @@ public class StorageHubClientService { */ public boolean isItemShared(String itemId) throws Exception { setContextProviders(scope, authorizationToken); - return shcClient.open(itemId).asItem().get().isShared(); + return shClient.open(itemId).asItem().get().isShared(); } @@ -326,7 +326,7 @@ public class StorageHubClientService { */ public boolean canWrite(String folderContainerId) throws Exception { setContextProviders(scope, authorizationToken); - return shcClient.open(folderContainerId).asFolder().canWrite(); + return shClient.open(folderContainerId).asFolder().canWrite(); } @@ -361,7 +361,7 @@ public class StorageHubClientService { */ public Item createFolder(String parentId, String folderName, String folderDescription) throws Exception { setContextProviders(scope, authorizationToken); - FolderContainer folderContainer = shcClient.open(parentId).asFolder().newFolder(folderName, folderDescription); + FolderContainer folderContainer = shClient.open(parentId).asFolder().newFolder(folderName, folderDescription); return getItem(folderContainer.get().getId(), false, true); } @@ -459,7 +459,7 @@ public class StorageHubClientService { public Item uploadFile(String folderId, InputStream is, String fileName, String fileDescription) throws Exception{ setContextProviders(scope, authorizationToken); - FileContainer fileCont = shcClient.open(folderId).asFolder().uploadFile(is, fileName, fileDescription); + FileContainer fileCont = shClient.open(folderId).asFolder().uploadFile(is, fileName, fileDescription); return fileCont.get(); } @@ -479,9 +479,9 @@ public class StorageHubClientService { setContextProviders(scope, authorizationToken); StreamDescriptor streamDesc; if(versionName!=null && !versionName.isEmpty()){ - streamDesc = shcClient.open(itemId).asFile().downloadSpecificVersion(versionName); + streamDesc = shClient.open(itemId).asFile().downloadSpecificVersion(versionName); }else{ - streamDesc = shcClient.open(itemId).asFile().download(nodeIdsToExclude); + streamDesc = shClient.open(itemId).asFile().download(nodeIdsToExclude); } return new StreamDescriptor(streamDesc.getStream(), streamDesc.getFileName(), streamDesc.getContentType(), streamDesc.getContentLenght()); @@ -499,7 +499,7 @@ public class StorageHubClientService { public StreamDescriptor downloadFolder(String folderId, String nodeIdsToExclude) throws Exception{ setContextProviders(scope, authorizationToken); - StreamDescriptor streamDesc = shcClient.open(folderId).asFolder().download(nodeIdsToExclude); + StreamDescriptor streamDesc = shClient.open(folderId).asFolder().download(nodeIdsToExclude); return new StreamDescriptor(streamDesc.getStream(), streamDesc.getFileName(), streamDesc.getContentType(), streamDesc.getContentLenght()); } @@ -518,7 +518,7 @@ public class StorageHubClientService { public Item uploadArchive(String folderId, InputStream is, String extractionFolderName) throws Exception{ setContextProviders(scope, authorizationToken); - FolderContainer folderCont = shcClient.open(folderId).asFolder().uploadArchive(is, extractionFolderName); + FolderContainer folderCont = shClient.open(folderId).asFolder().uploadArchive(is, extractionFolderName); return folderCont.get(); } @@ -562,7 +562,7 @@ public class StorageHubClientService { } if(item instanceof FolderItem || item instanceof SharedFolder || item instanceof VreFolder){ - return shcClient.open(folderId).asFolder().findByName(name).withContent().getItems(); + return shClient.open(folderId).asFolder().findByName(name).withContent().getItems(); }else throw new Exception("The input folder id is not a folder"); } @@ -589,7 +589,7 @@ public class StorageHubClientService { if(item instanceof FolderItem || item instanceof SharedFolder || item instanceof VreFolder){ //this does not return the trashed items - return shcClient.open(folderId).asFolder().search(text,true).withContent().getItems(); + return shClient.open(folderId).asFolder().search(text,true).withContent().getItems(); }else throw new Exception("The input folder id is not a folder"); } @@ -606,7 +606,7 @@ public class StorageHubClientService { Validate.notNull(itemId, "Bad request to deleteItemById, the itemId is null"); setContextProviders(scope, authorizationToken); - shcClient.open(itemId).asItem().delete(); + shClient.open(itemId).asItem().delete(); } @@ -621,7 +621,7 @@ public class StorageHubClientService { public Item openTrash() throws Exception{ setContextProviders(scope, authorizationToken); - return shcClient.openTrash().get(); + return shClient.openTrash().get(); } @@ -635,7 +635,7 @@ public class StorageHubClientService { public void emptyTrash() throws Exception{ setContextProviders(scope, authorizationToken); - shcClient.emptyTrash(); + shClient.emptyTrash(); } @@ -655,9 +655,9 @@ public class StorageHubClientService { GenericItemContainer container = null; if(destinationFolderId==null) - container = shcClient.restoreThrashItem(itemId); + container = shClient.restoreThrashItem(itemId); else - container = shcClient.restoreThrashItem(itemId, destinationFolderId); + container = shClient.restoreThrashItem(itemId, destinationFolderId); if(container!=null){ Item item = container.get(); @@ -684,8 +684,8 @@ public class StorageHubClientService { Validate.notNull(itemId, "Bad request to moveItem, the itemId is null"); Validate.notNull(destFolderContainer, "Bad request to moveItem, the itemId is null"); setContextProviders(scope, authorizationToken); - shcClient.open(itemId).asItem().move(destFolderContainer); - return shcClient.open(itemId).asItem().get(); + shClient.open(itemId).asItem().move(destFolderContainer); + return shClient.open(itemId).asItem().get(); } @@ -704,7 +704,7 @@ public class StorageHubClientService { Validate.notNull(fileItemId, "Bad request to copyFileItem, the fileItemId is null"); Validate.notNull(destFolderContainer, "Bad request to copyFileItem, the destFolderContainer is null"); setContextProviders(scope, authorizationToken); - FileContainer copyingItem = shcClient.open(fileItemId).asFile(); + FileContainer copyingItem = shClient.open(fileItemId).asFile(); String newName = newFileName!=null && !newFileName.isEmpty()?newFileName:"Copy of "+copyingItem.get().getName(); FileContainer newItem = copyingItem.copy(destFolderContainer, newName); return newItem.get(); @@ -723,8 +723,8 @@ public class StorageHubClientService { Validate.notNull(itemId, "Bad request to renameItem, the itemId is null"); setContextProviders(scope, authorizationToken); - shcClient.open(itemId).asItem().rename(newName); - return shcClient.open(itemId).asItem().get(); + shClient.open(itemId).asItem().rename(newName); + return shClient.open(itemId).asItem().get(); } @@ -740,7 +740,7 @@ public class StorageHubClientService { Validate.notNull(fileItemId, "Bad request to getPublicLinkForFile, the fileItemId is null"); setContextProviders(scope, authorizationToken); - return shcClient.open(fileItemId).asFile().getPublicLink(); + return shClient.open(fileItemId).asFile().getPublicLink(); } @@ -759,7 +759,7 @@ public class StorageHubClientService { Validate.notNull(version, "Bad request to getPublicLinkForFileVersion, the version is null"); Validate.notEmpty(version, "Bad request to getPublicLinkForFileVersion, the version is empty"); setContextProviders(scope, authorizationToken); - return shcClient.open(fileItemId).asFile().getPublicLink(version); + return shClient.open(fileItemId).asFile().getPublicLink(version); } @@ -775,7 +775,7 @@ public class StorageHubClientService { Validate.notNull(fileItemId, "Bad request to getListVersions, the fileItemId is null"); - return shcClient.open(fileItemId).asFile().getVersions(); + return shClient.open(fileItemId).asFile().getVersions(); } @@ -790,7 +790,7 @@ public class StorageHubClientService { Validate.notNull(itemId, "Bad request to getImageContent, the itemId is null"); setContextProviders(scope, authorizationToken); - ItemContainer itemCont = shcClient.open(itemId).asItem(); + ItemContainer itemCont = shClient.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; //?? @@ -809,7 +809,7 @@ public class StorageHubClientService { public long getTotalItems() throws Exception{ setContextProviders(scope, authorizationToken); - return shcClient.getTotalItemCount(); + return shClient.getTotalItemCount(); } @@ -821,7 +821,7 @@ public class StorageHubClientService { */ public long getDiskUsage() throws Exception{ setContextProviders(scope, authorizationToken); - return shcClient.getTotalVolume(); + return shClient.getTotalVolume(); } /** @@ -835,7 +835,7 @@ public class StorageHubClientService { Validate.notNull(itemId, "Bad request to getAccounting, the itemId is null"); setContextProviders(scope, authorizationToken); - ItemContainer itemCont = shcClient.open(itemId).asItem(); + ItemContainer itemCont = shClient.open(itemId).asItem(); Item item = itemCont.get(); return item.getAccounting(); } @@ -851,7 +851,7 @@ public class StorageHubClientService { public Metadata getGcubeItemProperties(String gcubeItemId) throws Exception { Validate.notNull(gcubeItemId, "Bad request to loadGcubeItemProperties, the itemId is null"); setContextProviders(scope, authorizationToken); - ItemContainer itemCont = shcClient.open(gcubeItemId).asItem(); + ItemContainer itemCont = shClient.open(gcubeItemId).asItem(); Item item = itemCont.get(); if(item instanceof GCubeItem) { @@ -876,7 +876,7 @@ public class StorageHubClientService { //ItemContainer itemCont = shcClient.open(itemId).asItem(); //itemCont.get().setMetadata(new Metadata(mapProperties)); //item.setMetadata(new Metadata(mapProperties)); - shcClient.open(itemId).asItem().setMetadata(new Metadata(mapProperties)); + shClient.open(itemId).asItem().setMetadata(new Metadata(mapProperties)); } @@ -894,7 +894,7 @@ public class StorageHubClientService { 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(); + FolderContainer folder = shClient.open(folderId).asFolder(); return folder.addUrl(URL, name, description).get(); } @@ -911,7 +911,7 @@ public class StorageHubClientService { 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(); + FolderContainer folderCont = shClient.open(folderId).asFolder(); if(setPublic) { folderCont.publish(); @@ -921,11 +921,10 @@ public class StorageHubClientService { logger.debug("Unpublished the folder id: "+folderId); } - return shcClient.open(folderId).asFolder().get().isPublicItem(); + return shClient.open(folderId).asFolder().get().isPublicItem(); } - /** * Update description for item. * @@ -938,13 +937,12 @@ public class StorageHubClientService { Validate.notNull(itemId, "Bad request the itemId is null"); setContextProviders(scope, authorizationToken); - throw new Exception("Not implemented yet by SHUB"); + shClient.open(itemId).asFile().setDescription(newDescription); + return shClient.open(itemId).asFile().get().getDescription(); } - - /** * To string. * @@ -962,7 +960,7 @@ public class StorageHubClientService { builder.append(", authorizationToken="); builder.append(authorizationToken.substring(0, authorizationToken.length()-5)+"XXXXX"); builder.append(", itemManagerClient="); - builder.append(shcClient); + builder.append(shClient); builder.append("]"); return builder.toString(); }