integrated with the method setDescription reported at #19652#note-1

This commit is contained in:
Francesco Mangiacrapa 2020-07-20 10:38:14 +02:00
parent bd5cfa29ea
commit d203bf71e9
2 changed files with 50 additions and 69 deletions

View File

@ -24,23 +24,6 @@
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path=".apt_generated">
<attributes>
<attribute name="optional" value="true"/>

View File

@ -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<? extends Item> 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<? extends Item> getFilteredChildren(String id, Class<? extends Item> 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<Item> itemCont = shcClient.open(itemId).asItem();
ItemContainer<Item> itemCont = shClient.open(itemId).asItem();
itemCont.setMetadata(metadata);
return itemCont.get();
}
@ -234,8 +234,8 @@ public class StorageHubClientService {
*/
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();
ItemContainer<Item> 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<? extends Item> 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<Item> itemCont = shcClient.open(itemId).asItem();
ItemContainer<Item> 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<Item> itemCont = shcClient.open(itemId).asItem();
ItemContainer<Item> 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<Item> itemCont = shcClient.open(gcubeItemId).asItem();
ItemContainer<Item> itemCont = shClient.open(gcubeItemId).asItem();
Item item = itemCont.get();
if(item instanceof GCubeItem) {
@ -876,7 +876,7 @@ public class StorageHubClientService {
//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));
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();
}