#23225 Updated the getSharedFolderMembers method
This commit is contained in:
parent
ad890bf313
commit
6ef3fe98bc
|
@ -13,6 +13,7 @@
|
|||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="src/test/resources"/>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
|
@ -32,6 +33,7 @@
|
|||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
|
|
|
@ -1,7 +1,19 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
|
||||
|
||||
|
||||
<wb-module deploy-name="storagehub-client-wrapper">
|
||||
|
||||
|
||||
<wb-resource deploy-path="/" source-path="/src/main/java"/>
|
||||
|
||||
|
||||
<wb-resource deploy-path="/" source-path="/src/main/resources"/>
|
||||
|
||||
|
||||
<wb-resource deploy-path="/" source-path="/.apt_generated"/>
|
||||
|
||||
|
||||
</wb-module>
|
||||
|
||||
|
||||
</project-modules>
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
All notable changes to this project will be documented in this file.
|
||||
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [v1-1-1-SNAPSHOT] - 2022-03-08
|
||||
## [v1.1.2-SNAPSHOT] - 2022-04-28
|
||||
|
||||
#### Enhancements
|
||||
|
||||
[#22782] Moved to SHUB(1.x, 3.x)
|
||||
- [#23225] Updated the method to read the members of VREs
|
||||
|
||||
## [v1-1-0] - 2021-05-12
|
||||
|
||||
|
|
10
pom.xml
10
pom.xml
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
|
@ -10,7 +11,7 @@
|
|||
</parent>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>storagehub-client-wrapper</artifactId>
|
||||
<version>1.1.1-SNAPSHOT</version>
|
||||
<version>1.1.2-SNAPSHOT</version>
|
||||
<name>storagehub-client-wrapper</name>
|
||||
<description>This is a wrapper of storagehub-client library. It allows to interact with storagehub in a simplified way by exposing several utilities. Moreover, It exposes by another inteface java beans as defined in (the old) HL interfaces</description>
|
||||
<scm>
|
||||
|
@ -19,9 +20,12 @@
|
|||
<url>https://code-repo.d4science.org/gCubeSystem/${project.artifactId}</url>
|
||||
</scm>
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<distroDirectory>distro</distroDirectory>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
@ -88,6 +92,7 @@
|
|||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>1.6.4</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
@ -96,6 +101,7 @@
|
|||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
<build>
|
||||
<resources>
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -39,30 +39,16 @@ import org.gcube.common.storagehubwrapper.shared.tohl.items.FileItemType;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
/**
|
||||
* The Class HLMapper.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
* Jun 20, 2018
|
||||
* Jun 20, 2018
|
||||
*/
|
||||
public class HLMapper {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(HLMapper.class);
|
||||
|
||||
// public static Function<org.gcube.common.storagehub.model.items.nodes.accounting.AccountEntry, AccountingEntry> toAccountingEntry = new Function<org.gcube.common.storagehub.model.items.nodes.accounting.AccountEntry, AccountingEntry>() {
|
||||
//
|
||||
// public AccountingEntry apply(org.gcube.common.storagehub.model.items.nodes.accounting.AccountEntry accountingEntry) {
|
||||
//
|
||||
// return new AccountingEntry(
|
||||
// accountingEntry.getUser(),
|
||||
// accountingEntry.getDate(),
|
||||
// accountingEntry.getType(),
|
||||
// accountingEntry.getVersion(),
|
||||
// accountingEntry.getPrimaryType());
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* To URL file.
|
||||
*
|
||||
|
@ -74,232 +60,227 @@ public class HLMapper {
|
|||
return (URLFile) toWorkspaceItem(extLink, false, false, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* To workspace item.
|
||||
*
|
||||
* @param <T> the generic type
|
||||
* @param <T> the generic type
|
||||
* @param item the item
|
||||
* @return the t
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public static<T extends WorkspaceItem> T toWorkspaceItem(Item item) throws Exception{
|
||||
public static <T extends WorkspaceItem> T toWorkspaceItem(Item item) throws Exception {
|
||||
|
||||
return toWorkspaceItem(item, false, false, false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* To accounting entries.
|
||||
*
|
||||
* @param item the item
|
||||
* @return the list
|
||||
*/
|
||||
public static List<AccountEntry> toAccountingEntries(Item item){
|
||||
public static List<AccountEntry> toAccountingEntries(Item item) {
|
||||
|
||||
List<AccountEntry> accountingEntries = null;
|
||||
List<AccountEntry> accountingEntries = null;
|
||||
|
||||
Accounting accounting = item.getAccounting();
|
||||
if(accounting!=null){
|
||||
accountingEntries = accounting.getEntries();
|
||||
// for (AccountEntry ae : accounting.getEntries()) {
|
||||
// accountingEntries.add(toAccountingEntry.apply(ae));
|
||||
// }
|
||||
}
|
||||
if (accounting != null) {
|
||||
accountingEntries = accounting.getEntries();
|
||||
}
|
||||
|
||||
return accountingEntries;
|
||||
return accountingEntries;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* To property map.
|
||||
*
|
||||
* @param metadata the metadata
|
||||
* @return the property map
|
||||
*/
|
||||
public static PropertyMap toPropertyMap(Metadata metadata){
|
||||
public static PropertyMap toPropertyMap(Metadata metadata) {
|
||||
|
||||
PropertyMap pm = null;
|
||||
if(metadata!=null)
|
||||
PropertyMap pm = null;
|
||||
if (metadata != null)
|
||||
pm = new PropertyMap(metadata.getMap());
|
||||
|
||||
//IN CASE OF EMPTY MAP RETURNS NULL
|
||||
if(pm!=null && pm.getValues()!=null && pm.getValues().isEmpty())
|
||||
// IN CASE OF EMPTY MAP RETURNS NULL
|
||||
if (pm != null && pm.getValues() != null && pm.getValues().isEmpty())
|
||||
pm = null;
|
||||
|
||||
return pm;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* To workspace file version.
|
||||
*
|
||||
* @param fileVersion the file version
|
||||
* @return the workspace file version
|
||||
*/
|
||||
public static WorkspaceFileVersion toWorkspaceFileVersion(Version fileVersion){
|
||||
public static WorkspaceFileVersion toWorkspaceFileVersion(Version fileVersion) {
|
||||
WorkspaceFileVersion wsFileVersion = new WorkspaceFileVersion();
|
||||
wsFileVersion.setId(fileVersion.getId());
|
||||
wsFileVersion.setName(fileVersion.getName());
|
||||
wsFileVersion.setCreated(fileVersion.getCreated());
|
||||
wsFileVersion.setCurrentVersion(fileVersion.isCurrent());
|
||||
//TODO MUST BE TERMINATED
|
||||
// TODO MUST BE TERMINATED
|
||||
return wsFileVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* To workspace item.
|
||||
*
|
||||
* @param <T> the generic type
|
||||
* @param item the item
|
||||
* @param withAccounting the with accounting
|
||||
* @param withFileDetails the with file details
|
||||
* @param <T> the generic type
|
||||
* @param item the item
|
||||
* @param withAccounting the with accounting
|
||||
* @param withFileDetails the with file details
|
||||
* @param withMapProperties the with map properties
|
||||
* @return the t
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public static<T extends WorkspaceItem> T toWorkspaceItem(Item item, boolean withAccounting, boolean withFileDetails, boolean withMapProperties) throws Exception{
|
||||
public static <T extends WorkspaceItem> T toWorkspaceItem(Item item, boolean withAccounting,
|
||||
boolean withFileDetails, boolean withMapProperties) throws Exception {
|
||||
|
||||
try{
|
||||
List<AccountEntry> accountingEntries = null;
|
||||
try {
|
||||
List<AccountEntry> accountingEntries = null;
|
||||
|
||||
if(withAccounting)
|
||||
if (withAccounting)
|
||||
accountingEntries = toAccountingEntries(item);
|
||||
|
||||
org.gcube.common.storagehubwrapper.shared.tohl.impl.WorkspaceItem theItem = null;
|
||||
WorkspaceItemType type = null;
|
||||
Boolean isFolder = false;
|
||||
org.gcube.common.storagehubwrapper.shared.tohl.impl.WorkspaceItem theItem = null;
|
||||
WorkspaceItemType type = null;
|
||||
Boolean isFolder = false;
|
||||
|
||||
String itemName = item.getName();
|
||||
boolean isRoot = false;
|
||||
String itemName = item.getName();
|
||||
boolean isRoot = false;
|
||||
|
||||
logger.trace("The item: "+item);
|
||||
logger.trace("Converting Item: "+item.getName() + " with id: "+item.getId());
|
||||
logger.trace("The item: " + item);
|
||||
logger.trace("Converting Item: " + item.getName() + " with id: " + item.getId());
|
||||
|
||||
//THE ITEM IS A KIND OF FOLDER
|
||||
if (item instanceof FolderItem){
|
||||
isFolder = true;
|
||||
FolderItem folderItem = (FolderItem) item; //??
|
||||
// THE ITEM IS A KIND OF FOLDER
|
||||
if (item instanceof FolderItem) {
|
||||
isFolder = true;
|
||||
FolderItem folderItem = (FolderItem) item; // ??
|
||||
theItem = new WorkspaceFolder();
|
||||
type = WorkspaceItemType.FOLDER;
|
||||
if (item instanceof SharedFolder || item instanceof VreFolder) {
|
||||
SharedFolder sharedfolder = (SharedFolder) item; //??
|
||||
theItem = new WorkspaceSharedFolder();
|
||||
if (item instanceof SharedFolder || item instanceof VreFolder) {
|
||||
SharedFolder sharedfolder = (SharedFolder) item; // ??
|
||||
theItem = new WorkspaceSharedFolder();
|
||||
type = WorkspaceItemType.SHARED_FOLDER;
|
||||
itemName = sharedfolder.getTitle(); //IN CASE OF SHARED FOLDER THE NAME IS AN UUID, I'M USING THE TITLE
|
||||
itemName = sharedfolder.getTitle(); // IN CASE OF SHARED FOLDER THE NAME IS AN UUID, I'M USING THE
|
||||
// TITLE
|
||||
|
||||
if (sharedfolder.isVreFolder()){
|
||||
//logger.debug("Converting shared folder: "+theItem.getClass());
|
||||
//VreFolder vreFolder = (VreFolder) item;
|
||||
//theItem = new WorkspaceVREFolder(); //NEVER INSTANCE THE WorkspaceVREFolder because VreFolder is never used by HL/StorageHub
|
||||
itemName = sharedfolder.getDisplayName(); //IN CASE OF VRE FOLDER I'M USING THE DISPLAYNAME
|
||||
if (sharedfolder.isVreFolder()) {
|
||||
// logger.debug("Converting shared folder: "+theItem.getClass());
|
||||
// VreFolder vreFolder = (VreFolder) item;
|
||||
// theItem = new WorkspaceVREFolder(); //NEVER INSTANCE THE WorkspaceVREFolder
|
||||
// because VreFolder is never used by HL/StorageHub
|
||||
itemName = sharedfolder.getDisplayName(); // IN CASE OF VRE FOLDER I'M USING THE DISPLAYNAME
|
||||
((WorkspaceSharedFolder) theItem).setVreFolder(true);
|
||||
type = WorkspaceItemType.VRE_FOLDER;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean isPublicItem = folderItem.isPublicItem();
|
||||
//((WorkspaceFolder) theItem).setPublicFolder(folderItem.isPublicItem());
|
||||
//logger.debug("Wrapped as Folder");
|
||||
boolean isPublicItem = folderItem.isPublicItem();
|
||||
// ((WorkspaceFolder) theItem).setPublicFolder(folderItem.isPublicItem());
|
||||
// logger.debug("Wrapped as Folder");
|
||||
|
||||
//TODO THIS MUST BE REMOVED. Checking the old property isPublic added as "<boolean>true</boolean>" by HL
|
||||
if(!isPublicItem){
|
||||
try{
|
||||
//Map<String, Object> map = item.getPropertyMap().getValues();
|
||||
// TODO THIS MUST BE REMOVED. Checking the old property isPublic added as
|
||||
// "<boolean>true</boolean>" by HL
|
||||
if (!isPublicItem) {
|
||||
try {
|
||||
// Map<String, Object> map = item.getPropertyMap().getValues();
|
||||
// logger.debug("Property Map size: "+map.size());
|
||||
// for (String key : map.keySet()) {
|
||||
// logger.debug("Key: "+key+ "value: "+map.get(key));
|
||||
// }
|
||||
String isPublic = (String) item.getMetadata().getMap().get("isPublic");
|
||||
logger.debug("The item name: "+item.getName()+ " has isPublic property like: "+isPublic);
|
||||
isPublicItem = isPublic!=null?isPublic.toLowerCase().contains("true"):false;
|
||||
}catch(Exception e){
|
||||
//silent
|
||||
}
|
||||
}
|
||||
String isPublic = (String) item.getMetadata().getMap().get("isPublic");
|
||||
logger.debug("The item name: " + item.getName() + " has isPublic property like: " + isPublic);
|
||||
isPublicItem = isPublic != null ? isPublic.toLowerCase().contains("true") : false;
|
||||
} catch (Exception e) {
|
||||
// silent
|
||||
}
|
||||
}
|
||||
|
||||
((WorkspaceFolder) theItem).setPublicFolder(isPublicItem);
|
||||
((WorkspaceFolder) theItem).setPublicFolder(isPublicItem);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//THE ITEM IS A KIND OF FILE
|
||||
if(item instanceof AbstractFileItem){
|
||||
theItem = new FileItem();
|
||||
type = WorkspaceItemType.FILE_ITEM;
|
||||
FileItemType fileItemType = null;
|
||||
if(item instanceof ExternalURL){
|
||||
theItem = new URLFileItem();
|
||||
fileItemType = FileItemType.URL_DOCUMENT;
|
||||
}else if(item instanceof GenericFileItem){
|
||||
GenericFileItem gFI = (GenericFileItem) item; //??
|
||||
fileItemType = FileItemType.DOCUMENT;
|
||||
}else if(item instanceof PDFFileItem){
|
||||
theItem = new PDFFile();
|
||||
fileItemType = FileItemType.PDF_DOCUMENT;
|
||||
if(withFileDetails){
|
||||
PDFFileItem pdfFI = (PDFFileItem) item;
|
||||
PDFContent pdfContent = pdfFI.getContent();
|
||||
PDFFile thePDFFileItem = (PDFFile) theItem;
|
||||
thePDFFileItem.setNumberOfPages(pdfContent.getNumberOfPages());
|
||||
thePDFFileItem.setProducer(pdfContent.getProducer());
|
||||
thePDFFileItem.setVersion(pdfContent.getVersion());
|
||||
thePDFFileItem.setTitle(pdfContent.getTitle());
|
||||
thePDFFileItem.setAuthor(pdfContent.getAuthor());
|
||||
}
|
||||
}else if(item instanceof org.gcube.common.storagehub.model.items.ImageFile){
|
||||
theItem = new ImageFile();
|
||||
fileItemType = FileItemType.IMAGE_DOCUMENT;
|
||||
if(withFileDetails){
|
||||
org.gcube.common.storagehub.model.items.ImageFile imgFI = (org.gcube.common.storagehub.model.items.ImageFile) item; //??
|
||||
ImageFile theImageFileItem = (ImageFile) theItem;
|
||||
ImageContent content = imgFI.getContent();
|
||||
theImageFileItem.setHeight(content.getHeight());
|
||||
theImageFileItem.setWidth(content.getWidth());
|
||||
theImageFileItem.setThumbnailWidth(content.getThumbnailHeight());
|
||||
theImageFileItem.setThumbnailHeight(content.getThumbnailHeight());
|
||||
}
|
||||
}
|
||||
// THE ITEM IS A KIND OF FILE
|
||||
if (item instanceof AbstractFileItem) {
|
||||
theItem = new FileItem();
|
||||
type = WorkspaceItemType.FILE_ITEM;
|
||||
FileItemType fileItemType = null;
|
||||
if (item instanceof ExternalURL) {
|
||||
theItem = new URLFileItem();
|
||||
fileItemType = FileItemType.URL_DOCUMENT;
|
||||
} else if (item instanceof GenericFileItem) {
|
||||
GenericFileItem gFI = (GenericFileItem) item; // ??
|
||||
fileItemType = FileItemType.DOCUMENT;
|
||||
} else if (item instanceof PDFFileItem) {
|
||||
theItem = new PDFFile();
|
||||
fileItemType = FileItemType.PDF_DOCUMENT;
|
||||
if (withFileDetails) {
|
||||
PDFFileItem pdfFI = (PDFFileItem) item;
|
||||
PDFContent pdfContent = pdfFI.getContent();
|
||||
PDFFile thePDFFileItem = (PDFFile) theItem;
|
||||
thePDFFileItem.setNumberOfPages(pdfContent.getNumberOfPages());
|
||||
thePDFFileItem.setProducer(pdfContent.getProducer());
|
||||
thePDFFileItem.setVersion(pdfContent.getVersion());
|
||||
thePDFFileItem.setTitle(pdfContent.getTitle());
|
||||
thePDFFileItem.setAuthor(pdfContent.getAuthor());
|
||||
}
|
||||
} else if (item instanceof org.gcube.common.storagehub.model.items.ImageFile) {
|
||||
theItem = new ImageFile();
|
||||
fileItemType = FileItemType.IMAGE_DOCUMENT;
|
||||
if (withFileDetails) {
|
||||
org.gcube.common.storagehub.model.items.ImageFile imgFI = (org.gcube.common.storagehub.model.items.ImageFile) item; // ??
|
||||
ImageFile theImageFileItem = (ImageFile) theItem;
|
||||
ImageContent content = imgFI.getContent();
|
||||
theImageFileItem.setHeight(content.getHeight());
|
||||
theImageFileItem.setWidth(content.getWidth());
|
||||
theImageFileItem.setThumbnailWidth(content.getThumbnailHeight());
|
||||
theImageFileItem.setThumbnailHeight(content.getThumbnailHeight());
|
||||
}
|
||||
}
|
||||
|
||||
AbstractFileItem itemAb = (AbstractFileItem) item;
|
||||
Content aC = itemAb.getContent();
|
||||
FileItem theFileItem = (FileItem) theItem;
|
||||
theFileItem.setFileItemType(fileItemType);
|
||||
AbstractFileItem itemAb = (AbstractFileItem) item;
|
||||
Content aC = itemAb.getContent();
|
||||
FileItem theFileItem = (FileItem) theItem;
|
||||
theFileItem.setFileItemType(fileItemType);
|
||||
|
||||
if(aC!=null){
|
||||
logger.debug("The content is not null for item: "+itemAb.getId());
|
||||
theFileItem.setMimeType(aC.getMimeType());
|
||||
theFileItem.setSize(aC.getSize());
|
||||
}else
|
||||
logger.warn("The content is null for item: "+itemAb.getId());
|
||||
if (aC != null) {
|
||||
logger.debug("The content is not null for item: " + itemAb.getId());
|
||||
theFileItem.setMimeType(aC.getMimeType());
|
||||
theFileItem.setSize(aC.getSize());
|
||||
} else
|
||||
logger.warn("The content is null for item: " + itemAb.getId());
|
||||
|
||||
//TODO ADD VERSION NAME
|
||||
// TODO ADD VERSION NAME
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//ADDING (GCUBE) PROPERTIES
|
||||
PropertyMap pm = null;
|
||||
if(withMapProperties || isFolder){
|
||||
//System.out.println("Setting map: "+item.getPropertyMap().getValues());
|
||||
pm = toPropertyMap(item.getMetadata());
|
||||
}
|
||||
// ADDING (GCUBE) PROPERTIES
|
||||
PropertyMap pm = null;
|
||||
if (withMapProperties || isFolder) {
|
||||
// System.out.println("Setting map: "+item.getPropertyMap().getValues());
|
||||
pm = toPropertyMap(item.getMetadata());
|
||||
}
|
||||
|
||||
//CONVERTING EXTERNALLINK
|
||||
if(item instanceof ExternalLink) {
|
||||
logger.trace("FOUND an ExternalLink...");
|
||||
type = WorkspaceItemType.URL_ITEM;
|
||||
ExternalLink extLink = (ExternalLink) item;
|
||||
theItem = new URLFile();
|
||||
URLFile theURLFile = (URLFile) theItem;
|
||||
theURLFile.setValue(extLink.getValue());
|
||||
}
|
||||
// CONVERTING EXTERNALLINK
|
||||
if (item instanceof ExternalLink) {
|
||||
logger.trace("FOUND an ExternalLink...");
|
||||
type = WorkspaceItemType.URL_ITEM;
|
||||
ExternalLink extLink = (ExternalLink) item;
|
||||
theItem = new URLFile();
|
||||
URLFile theURLFile = (URLFile) theItem;
|
||||
theURLFile.setValue(extLink.getValue());
|
||||
}
|
||||
|
||||
//CONVERTING TRASH ITEM
|
||||
if(item.isTrashed() && item instanceof TrashItem){
|
||||
// CONVERTING TRASH ITEM
|
||||
if (item.isTrashed() && item instanceof TrashItem) {
|
||||
type = WorkspaceItemType.TRASH_ITEM;
|
||||
TrashItem trashItem = (TrashItem) item;
|
||||
itemName = trashItem.getTitle(); //IN CASE OF TRASHED ITEM THE NAME IS THE ID, SO I'M USING THE TITLE
|
||||
itemName = trashItem.getTitle(); // IN CASE OF TRASHED ITEM THE NAME IS THE ID, SO I'M USING THE TITLE
|
||||
theItem = new org.gcube.common.storagehubwrapper.shared.tohl.impl.TrashItem();
|
||||
org.gcube.common.storagehubwrapper.shared.tohl.impl.TrashItem theTrashItem = (org.gcube.common.storagehubwrapper.shared.tohl.impl.TrashItem) theItem;
|
||||
theTrashItem.setDeletedBy(trashItem.getDeletedBy());
|
||||
|
@ -309,16 +290,16 @@ public class HLMapper {
|
|||
theTrashItem.setLenght(trashItem.getLenght());
|
||||
theTrashItem.setMimeType(trashItem.getMimeType());
|
||||
|
||||
isFolder = trashItem.isFolder(); //DO NOT MOVE THIS SET
|
||||
if(isFolder) //Avoiding null exception on
|
||||
isFolder = trashItem.isFolder(); // DO NOT MOVE THIS SET
|
||||
if (isFolder) // Avoiding null exception on
|
||||
type = WorkspaceItemType.TRASH_FOLDER;
|
||||
|
||||
logger.debug("Wrapped as TrashItem");
|
||||
}
|
||||
|
||||
if(item instanceof GCubeItem){
|
||||
if (item instanceof GCubeItem) {
|
||||
type = WorkspaceItemType.FILE_ITEM;
|
||||
GCubeItem gcubeItem = (GCubeItem) item; //??
|
||||
GCubeItem gcubeItem = (GCubeItem) item; // ??
|
||||
theItem = new GcubeItem();
|
||||
GcubeItem theGcubeItem = (GcubeItem) theItem;
|
||||
theGcubeItem.setFileItemType(FileItemType.GCUBE_ITEM);
|
||||
|
@ -326,7 +307,7 @@ public class HLMapper {
|
|||
theGcubeItem.setCreator(gcubeItem.getCreator());
|
||||
theGcubeItem.setItemType(gcubeItem.getItemType());
|
||||
theGcubeItem.setShared(gcubeItem.isShared());
|
||||
if(withMapProperties){
|
||||
if (withMapProperties) {
|
||||
PropertyMap property = toPropertyMap(gcubeItem.getProperty());
|
||||
theGcubeItem.setProperty(property);
|
||||
}
|
||||
|
@ -334,12 +315,12 @@ public class HLMapper {
|
|||
logger.debug("Wrapped as GcubeItem");
|
||||
}
|
||||
|
||||
if(theItem==null){
|
||||
if (theItem == null) {
|
||||
logger.info("Mapping unknown object as simple FileItem");
|
||||
theItem = new FileItem();
|
||||
type = WorkspaceItemType.FILE_ITEM;
|
||||
FileItem theFileItem = (FileItem) theItem;
|
||||
theFileItem.setFileItemType(FileItemType.DOCUMENT);
|
||||
theFileItem.setFileItemType(FileItemType.DOCUMENT);
|
||||
}
|
||||
|
||||
theItem.setId(item.getId());
|
||||
|
@ -359,23 +340,19 @@ public class HLMapper {
|
|||
theItem.setAccounting(accountingEntries);
|
||||
theItem.setType(type);
|
||||
theItem.setFolder(isFolder);
|
||||
theItem.setRoot(isRoot); //THIS IS ALWAYS FALSE. SHUB DOES NOT RETURN THIS INFORMATION
|
||||
theItem.setRoot(isRoot); // THIS IS ALWAYS FALSE. SHUB DOES NOT RETURN THIS INFORMATION
|
||||
theItem.setPropertyMap(pm);
|
||||
|
||||
logger.debug("Wrapped WsItem: "+theItem);
|
||||
logger.debug("Wrapped WsItem has type: "+theItem.getClass().getName());
|
||||
logger.debug("Wrapped WsItem: " + theItem);
|
||||
logger.debug("Wrapped WsItem has type: " + theItem.getClass().getName());
|
||||
|
||||
return (T) theItem;
|
||||
|
||||
}catch (Exception e){
|
||||
logger.error("Error on converting the item with id: "+item.getId(), e);
|
||||
} catch (Exception e) {
|
||||
logger.error("Error on converting the item with id: " + item.getId(), e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
/resources/
|
|
@ -14,29 +14,24 @@ import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WrongItemTypeEx
|
|||
import org.gcube.common.storagehubwrapper.shared.tohl.impl.FileItem;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.impl.ImageFile;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.impl.PDFFile;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Jun 20, 2018
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Jun 20, 2018
|
||||
*/
|
||||
public class WorkspaceInstance {
|
||||
|
||||
public static String SCOPE = "/gcube";
|
||||
//public static String SCOPE = "/d4science.research-infrastructures.eu";
|
||||
// public static String SCOPE = "/gcube";
|
||||
public static String SCOPE = "/d4science.research-infrastructures.eu";
|
||||
|
||||
|
||||
//public static String USERNAME = "massimiliano.assante";
|
||||
// public static String USERNAME = "massimiliano.assante";
|
||||
public static String USERNAME = "francesco.mangiacrapa";
|
||||
|
||||
public static String TOKEN = System.getenv("TOKEN_gcube"); //YOU MUST SET THIS AS Environment variable
|
||||
|
||||
public static String TOKEN = System.getenv("TOKEN_gcube"); // YOU MUST SET THIS AS Environment variable
|
||||
|
||||
public static String FIND_FILE_NAME = "francesco";
|
||||
public static String rootId = null;
|
||||
|
@ -44,21 +39,20 @@ public class WorkspaceInstance {
|
|||
|
||||
private WorkspaceStorageHubClientService workspace;
|
||||
|
||||
//@Before
|
||||
public void init(){
|
||||
// @Before
|
||||
public void init() {
|
||||
|
||||
if(TOKEN==null) {
|
||||
if (TOKEN == null) {
|
||||
System.err.println("You must set the token as Environment variable");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("Read TOKEN_gcube: "+TOKEN);
|
||||
System.out.println("Read TOKEN_gcube: " + TOKEN);
|
||||
|
||||
//METHOD 1
|
||||
// METHOD 1
|
||||
storageHubWrapper = new StorageHubWrapper(SCOPE, TOKEN, false, false, true);
|
||||
//workspace = storageHubWrapper.getWorkspace();
|
||||
// workspace = storageHubWrapper.getWorkspace();
|
||||
|
||||
//METHOD 2
|
||||
// METHOD 2
|
||||
// StorageHubClientService storageHubClientService = new StorageHubClientService(SCOPE, TOKEN);
|
||||
// workspace = new WorkspaceStorageHubClientService.WorkspaceStorageHubClientServiceBuilder(storageHubClientService).
|
||||
// withAccounting(false).
|
||||
|
@ -66,41 +60,41 @@ public class WorkspaceInstance {
|
|||
// build();
|
||||
}
|
||||
|
||||
//@Test
|
||||
// @Test
|
||||
public void getRoot() {
|
||||
System.out.println("Get Root test");
|
||||
WorkspaceFolder root;
|
||||
try {
|
||||
root = storageHubWrapper.getWorkspace().getRoot();
|
||||
rootId = root.getId();
|
||||
System.out.println("The root is:"+root);
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.out.println("The root is:" + root);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//@Test
|
||||
public void getChildren() throws Exception{
|
||||
// @Test
|
||||
public void getChildren() throws Exception {
|
||||
System.out.println("Get children test");
|
||||
|
||||
WorkspaceFolder root = storageHubWrapper.getWorkspace().getRoot();
|
||||
List<? extends WorkspaceItem> children = storageHubWrapper.getWorkspace().getChildren(root.getId());
|
||||
|
||||
//WorkspaceFolder root = workspace.getRoot();
|
||||
//List<? extends WorkspaceItem> children = workspace.getChildren(root.getId());
|
||||
// WorkspaceFolder root = workspace.getRoot();
|
||||
// List<? extends WorkspaceItem> children = workspace.getChildren(root.getId());
|
||||
|
||||
int i = 0;
|
||||
for (WorkspaceItem workspaceItem : children) {
|
||||
System.out.println(++i+")"+workspaceItem.getId() + " name: "+workspaceItem.getName() + " type: "+workspaceItem.getType() +" class: "+workspaceItem.getClass());
|
||||
System.out.println(++i + ")" + workspaceItem.getId() + " name: " + workspaceItem.getName() + " type: "
|
||||
+ workspaceItem.getType() + " class: " + workspaceItem.getClass());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//@Test
|
||||
public void getPathOnShared() throws Exception{
|
||||
// @Test
|
||||
public void getPathOnShared() throws Exception {
|
||||
System.out.println("Get Path on Shared");
|
||||
|
||||
WorkspaceFolder root = storageHubWrapper.getWorkspace().getRoot();
|
||||
|
@ -108,30 +102,30 @@ public class WorkspaceInstance {
|
|||
|
||||
int i = 0;
|
||||
for (WorkspaceItem workspaceItem : children) {
|
||||
if(workspaceItem.isShared()) {
|
||||
System.out.println(++i+")"+workspaceItem.getId() + " name: "+workspaceItem.getName() + " type: "+workspaceItem.getPath());
|
||||
if (workspaceItem.isShared()) {
|
||||
System.out.println(++i + ")" + workspaceItem.getId() + " name: " + workspaceItem.getName() + " type: "
|
||||
+ workspaceItem.getPath());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//@Test
|
||||
public void getFilteredChildren() throws Exception{
|
||||
// @Test
|
||||
public void getFilteredChildren() throws Exception {
|
||||
System.out.println("Get children test");
|
||||
|
||||
WorkspaceFolder root = storageHubWrapper.getWorkspace().getRoot();
|
||||
Class filterClass = org.gcube.common.storagehub.model.items.FolderItem.class;
|
||||
List<? extends WorkspaceItem> children = storageHubWrapper.getWorkspace().getFilteredChildren(root.getId(), filterClass);
|
||||
List<? extends WorkspaceItem> children = storageHubWrapper.getWorkspace().getFilteredChildren(root.getId(),
|
||||
filterClass);
|
||||
|
||||
//WorkspaceFolder root = workspace.getRoot();
|
||||
//List<? extends WorkspaceItem> children = workspace.getChildren(root.getId());
|
||||
// WorkspaceFolder root = workspace.getRoot();
|
||||
// List<? extends WorkspaceItem> children = workspace.getChildren(root.getId());
|
||||
|
||||
int i = 0;
|
||||
for (WorkspaceItem workspaceItem : children) {
|
||||
System.out.println(++i+")"+workspaceItem);
|
||||
System.out.println(workspaceItem.getType() +" "+workspaceItem.getClass());
|
||||
|
||||
System.out.println(++i + ")" + workspaceItem);
|
||||
System.out.println(workspaceItem.getType() + " " + workspaceItem.getClass());
|
||||
|
||||
// System.out.println(++i+")");
|
||||
// if(workspaceItem.isFolder()){
|
||||
|
@ -145,33 +139,50 @@ public class WorkspaceInstance {
|
|||
|
||||
}
|
||||
|
||||
public static void printMap(WorkspaceItem workspaceItem){
|
||||
if(workspaceItem.getPropertyMap()!=null){
|
||||
System.out.println(workspaceItem.getId() + " name: "+workspaceItem.getName() + " isFolder: "+workspaceItem.isFolder());
|
||||
System.out.println("Property Map: "+workspaceItem.getPropertyMap().getValues().toString());
|
||||
public static void printMap(WorkspaceItem workspaceItem) {
|
||||
if (workspaceItem.getPropertyMap() != null) {
|
||||
System.out.println(workspaceItem.getId() + " name: " + workspaceItem.getName() + " isFolder: "
|
||||
+ workspaceItem.isFolder());
|
||||
System.out.println("Property Map: " + workspaceItem.getPropertyMap().getValues().toString());
|
||||
}
|
||||
}
|
||||
|
||||
//@Test
|
||||
public void getWorkspaceId() {
|
||||
// @Test
|
||||
public void getWorkspaceId() {
|
||||
System.out.println("Getting the workspaceId test");
|
||||
try {
|
||||
|
||||
Workspace ws = storageHubWrapper.getWorkspace();
|
||||
|
||||
//Workspace ws = workspace;
|
||||
// Workspace ws = workspace;
|
||||
|
||||
if(ws!=null){
|
||||
if (ws != null) {
|
||||
WorkspaceFolder root = ws.getRoot();
|
||||
System.out.println("Retrieve the root "+root.getId()+" correctly");
|
||||
System.out.println("Retrieve the root " + root.getId() + " correctly");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
//@Test
|
||||
public void getChildrenPerWorkspaceItem() throws InternalErrorException{
|
||||
@Test
|
||||
public void getSharedFolderMembers() {
|
||||
System.out.println("Getting getSharedFolderMembers");
|
||||
try {
|
||||
|
||||
String sharedFolderId = "b679c6fe-894c-4c4c-aebc-4155321a373a";
|
||||
storageHubWrapper = new StorageHubWrapper(SCOPE, TOKEN);
|
||||
List<String> listLogins = storageHubWrapper.getWorkspace().getSharedFolderMembers(sharedFolderId);
|
||||
|
||||
System.out.println("List: " + listLogins);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// @Test
|
||||
public void getChildrenPerWorkspaceItem() throws InternalErrorException {
|
||||
System.out.println("Get children test per workspace item");
|
||||
|
||||
try {
|
||||
|
@ -183,11 +194,11 @@ public class WorkspaceInstance {
|
|||
// List<? extends WorkspaceItem> children = workspace.getChildren(root.getId());
|
||||
|
||||
int i = 0;
|
||||
Map<String, List<WorkspaceItem>> map = new HashMap<String,List<WorkspaceItem>>();
|
||||
Map<String, List<WorkspaceItem>> map = new HashMap<String, List<WorkspaceItem>>();
|
||||
for (WorkspaceItem workspaceItem : children) {
|
||||
String key = workspaceItem.getType().name();
|
||||
List<WorkspaceItem> list = map.get(key);
|
||||
if(list==null){
|
||||
if (list == null) {
|
||||
list = new ArrayList<WorkspaceItem>();
|
||||
}
|
||||
|
||||
|
@ -204,20 +215,20 @@ public class WorkspaceInstance {
|
|||
switch (fileItem.getFileItemType()) {
|
||||
case PDF_DOCUMENT:
|
||||
PDFFile pdfFile = (PDFFile) fileItem;
|
||||
System.out.println("PDF_DOCUMENT "+pdfFile);
|
||||
PDFFile completeItem = (PDFFile) storageHubWrapper.getWorkspace().getItem(fileItem.getId(), true, true, true);
|
||||
System.out.println("PDF_DOCUMENT " + pdfFile);
|
||||
PDFFile completeItem = (PDFFile) storageHubWrapper.getWorkspace().getItem(fileItem.getId(),
|
||||
true, true, true);
|
||||
System.out.println(completeItem);
|
||||
break;
|
||||
case IMAGE_DOCUMENT:
|
||||
ImageFile imageFile = (ImageFile) fileItem;
|
||||
System.out.println("IMAGE_DOCUMENT "+imageFile);
|
||||
System.out.println("IMAGE_DOCUMENT " + imageFile);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
System.out.println(fileItem.getFileItemType() +" "+workspaceItem.getClass());
|
||||
|
||||
System.out.println(fileItem.getFileItemType() + " " + workspaceItem.getClass());
|
||||
|
||||
break;
|
||||
default:
|
||||
|
@ -225,33 +236,32 @@ public class WorkspaceInstance {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//@Test
|
||||
public void findFileName() throws InternalErrorException{
|
||||
// @Test
|
||||
public void findFileName() throws InternalErrorException {
|
||||
System.out.println("Find file name test");
|
||||
getRoot();
|
||||
try {
|
||||
//List<WorkspaceItem> foundItems = storageHubWrapper.getWorkspace().find(FIND_FILE_NAME,rootId);
|
||||
List<? extends WorkspaceItem> foundItems = workspace.find(FIND_FILE_NAME,rootId);
|
||||
// List<WorkspaceItem> foundItems =
|
||||
// storageHubWrapper.getWorkspace().find(FIND_FILE_NAME,rootId);
|
||||
List<? extends WorkspaceItem> foundItems = workspace.find(FIND_FILE_NAME, rootId);
|
||||
|
||||
if(foundItems==null || foundItems.size()==0){
|
||||
System.out.println("No Items found with name: "+FIND_FILE_NAME+ " in the parent: "+rootId);
|
||||
if (foundItems == null || foundItems.size() == 0) {
|
||||
System.out.println("No Items found with name: " + FIND_FILE_NAME + " in the parent: " + rootId);
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("Items found with name: "+FIND_FILE_NAME+ " in the parent: "+rootId +" are:");
|
||||
System.out.println("Items found with name: " + FIND_FILE_NAME + " in the parent: " + rootId + " are:");
|
||||
for (WorkspaceItem workspaceItem : foundItems) {
|
||||
System.out.println(workspaceItem);
|
||||
}
|
||||
}
|
||||
catch (ItemNotFoundException | WrongItemTypeException e) {
|
||||
} catch (ItemNotFoundException | WrongItemTypeException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue