diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..fae1a2b --- /dev/null +++ b/.classpath @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..5d05dc3 --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + storagehub-client-wrapper + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..29abf99 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,6 @@ +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/main/resources=UTF-8 +encoding//src/test/java=UTF-8 +encoding//src/test/resources=UTF-8 +encoding/=UTF-8 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..714351a --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/distro/LICENSE b/distro/LICENSE new file mode 100644 index 0000000..2d9616a --- /dev/null +++ b/distro/LICENSE @@ -0,0 +1 @@ +${gcube.license} \ No newline at end of file diff --git a/distro/README b/distro/README new file mode 100644 index 0000000..3678c90 --- /dev/null +++ b/distro/README @@ -0,0 +1,60 @@ +The gCube System - ${name} +-------------------------------------------------- + +${description} + + +${gcube.description} + +${gcube.funding} + + +Version +-------------------------------------------------- + +${version} (${buildDate}) + +Please see the file named "changelog.xml" in this directory for the release notes. + + +Authors +-------------------------------------------------- + +* Francesco Mangiacrapa (francesco.mangiacrapa-AT-isti.cnr.it), Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo" - CNR, Pisa (Italy). + +Maintainers +----------- + +* Francesco Mangiacrapa (francesco.mangiacrapa-AT-isti.cnr.it), Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo" - CNR, Pisa (Italy). + +Download information +-------------------------------------------------- + +Source code is available from SVN: + ${scm.url} + +Binaries can be downloaded from the gCube website: + ${gcube.website} + + +Installation +-------------------------------------------------- + + +Documentation +-------------------------------------------------- + +Documentation is available on-line in the gCube Wiki: + ${gcube.wikiRoot} + +Support +-------------------------------------------------- + +Bugs and support requests can be reported in the gCube issue tracking tool: + ${gcube.issueTracking} + + +Licensing +-------------------------------------------------- + +This software is licensed under the terms you may find in the file named "LICENSE" in this directory. \ No newline at end of file diff --git a/distro/changelog.xml b/distro/changelog.xml new file mode 100644 index 0000000..aede740 --- /dev/null +++ b/distro/changelog.xml @@ -0,0 +1,6 @@ + + + first release + + diff --git a/distro/descriptor.xml b/distro/descriptor.xml new file mode 100644 index 0000000..c597cd2 --- /dev/null +++ b/distro/descriptor.xml @@ -0,0 +1,32 @@ + + servicearchive + + tar.gz + + / + + + ${distroDirectory} + / + true + + README + LICENSE + changelog.xml + profile.xml + + 755 + true + + + + + target/${build.finalName}.${project.packaging} + /${artifactId} + + + + diff --git a/distro/profile.xml b/distro/profile.xml new file mode 100644 index 0000000..0d01f73 --- /dev/null +++ b/distro/profile.xml @@ -0,0 +1,25 @@ + + + + Library + + ${description} + Common + ${artifactId} + 1.0.0 + + + ${artifactId} + ${version} + + ${groupId} + ${artifactId} + ${version} + + + ${build.finalName}.jar + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..1082ca6 --- /dev/null +++ b/pom.xml @@ -0,0 +1,195 @@ + + + 4.0.0 + + maven-parent + org.gcube.tools + 1.0.0 + + + org.gcube.common + storagehub-client-wrapper + 0.1.0-SNAPSHOT + storagehub-client-wrapper + 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 object as defined in (the old) HL interfaces + + scm:svn:http://svn.d4science.research-infrastructures.eu/gcube/trunk/common/${project.artifactId} + scm:https://svn.d4science.research-infrastructures.eu/gcube/trunk/common/${project.artifactId} + http://svn.d4science.research-infrastructures.eu/gcube/trunk/common/${project.artifactId} + + + + UTF-8 + distro + + + + + org.gcube.distribution + maven-portal-bom + LATEST + pom + import + + + + + + + javax.servlet + javax.servlet-api + provided + + + + commons-lang + commons-lang + provided + + + + org.projectlombok + lombok + 1.14.8 + + + + org.gcube.common + storagehub-client-library + provided + + + org.gcube.portal + storagehub-icons-library + provided + + + + org.gcube.core + common-encryption + provided + + + + + org.gcube.resources.discovery + ic-client + provided + + + org.gcube.core + common-scope-maps + compile + + + + + + + + + + + + + + + + + + + + + + + + org.slf4j + slf4j-log4j12 + + + org.slf4j + slf4j-api + + + + junit + junit + 4.12 + test + + + + + + src/main/java + + **/*.* + + + + + src/main/resources + + **/*.* + + + + + ${artifactId} + + + + maven-compiler-plugin + + ${maven.compiler.source} + ${maven.compiler.target} + + + + org.apache.maven.plugins + maven-resources-plugin + 2.5 + + + copy-profile + install + + copy-resources + + + target + + + ${distroDirectory} + true + + profile.xml + + + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + ${distroDirectory}/descriptor.xml + + + + + servicearchive + install + + single + + + + + + + \ No newline at end of file diff --git a/src/main/java/org/gcube/common/storagehubwrapper/StorageHubWrapper.gwt.xml b/src/main/java/org/gcube/common/storagehubwrapper/StorageHubWrapper.gwt.xml new file mode 100644 index 0000000..1778982 --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/StorageHubWrapper.gwt.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/src/main/java/org/gcube/common/storagehubwrapper/server/StorageHubClientService.java b/src/main/java/org/gcube/common/storagehubwrapper/server/StorageHubClientService.java new file mode 100644 index 0000000..ee232f4 --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/server/StorageHubClientService.java @@ -0,0 +1,263 @@ +package org.gcube.common.storagehubwrapper.server; + +import java.io.InputStream; +import java.util.List; + +import org.apache.commons.lang.Validate; +import org.gcube.common.authorization.library.provider.SecurityTokenProvider; +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.common.storagehub.client.dsl.FileContainer; +import org.gcube.common.storagehub.client.dsl.FolderContainer; +import org.gcube.common.storagehub.client.dsl.ItemContainer; +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; +import org.gcube.common.storagehub.model.acls.ACL; +import org.gcube.common.storagehub.model.items.FolderItem; +import org.gcube.common.storagehub.model.items.Item; +import org.gcube.common.storagehub.model.items.SharedFolder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * The Class StorageHubClientService. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 20, 2018 + */ +public class StorageHubClientService { + + + private static Logger logger = LoggerFactory.getLogger(StorageHubClientService.class); + public static final String ACCOUNTING_HL_NODE_NAME = "hl:accounting"; + private String scope; + private String authorizationToken; + 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); + logger.debug("Saved the contexts [scope: "+scope+", token: "+authorizationToken+"]"); + } + + /** + * Gets the root. + * + * @return the root + * @throws Exception + */ + public FolderItem getRoot() throws Exception { + setContextProviders(scope, authorizationToken); +// WorkspaceManagerClient client = AbstractPlugin.workspace().build(); +// Item itemRoot = client.getWorkspace(ACCOUNTING_HL_NODE_NAME); + 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 + * @param excludeNodes the exclude nodes + * @return the children + */ + public List getChildren(String id){ + setContextProviders(scope, authorizationToken); + return shcClient.open(id).asFolder().list().withContent().getItems(); + } + + + /** + * Gets the item. + * + * @param itemId the item id + * @return the item + * @throws Exception + */ + public Item getItem(String itemId) throws Exception{ + setContextProviders(scope, authorizationToken); + ItemContainer itemCont = shcClient.open(itemId).asItem();//TODO + return itemCont.get(); + } + + + /** + * Gets the parents. + * + * @param itemId the item id + * @return the parents + */ + public List getParents(String itemId) { + setContextProviders(scope, authorizationToken); + List toReturn = shcClient.open(itemId).asItem().getAnchestors(); + return toReturn; + } + + + /** + * Creates the folder. + * + * @param parentId the parent id + * @param folderName the folder name + * @param folderDescription the folder description + * @return the item + * @throws Exception + */ + public Item createFolder(String parentId, String folderName, String folderDescription) throws Exception { + setContextProviders(scope, authorizationToken); + FolderContainer folderContainer = shcClient.open(parentId).asFolder().newFolder(folderName, folderDescription); + return getItem(folderContainer.get().getId()); + } + + + /** + * Gets the VRE folders id. + * + * @return the VRE folders id + */ + public String getVREFoldersId() { + setContextProviders(scope, authorizationToken); + String toReturn = ""; + try { + WorkspaceManagerClient wsclient = AbstractPlugin.workspace().build(); + try { + List 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) { + e.printStackTrace(); + } + return toReturn; + } + + + /** + * Gets the user acl for folder id. + * + * @param request the request + * @param folderId the folder id + * @return the user acl for folder id + * @throws Exception + */ + public String getUserACLForFolderId(String infrastructureName, String userName, String folderId) throws Exception { + setContextProviders(scope, authorizationToken); + Item theFolder = getItem(folderId); + if (!theFolder.isShared()) { + return "OWNER"; + } else { + ItemManagerClient client = AbstractPlugin.item().build(); + List 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 + */ + public int getItemChildrenCount(String itemId) { + 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{ + + try { + FileContainer fileCont = shcClient.open(folderId).asFolder().uploadFile(is, fileName, fileDescription); + return fileCont.get(); + } catch (Exception e) { + logger.error("Error during uploading the file: "+fileName+" in the folderId: "+folderId, e); + throw new Exception("Error during uploading the file: "+fileName+". Try again"); + } + } + + /* (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(); + } + + + +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/server/StorageHubWrapper.java b/src/main/java/org/gcube/common/storagehubwrapper/server/StorageHubWrapper.java new file mode 100644 index 0000000..ad20c17 --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/server/StorageHubWrapper.java @@ -0,0 +1,62 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.server; + +import org.gcube.common.storagehubwrapper.server.tohl.Workspace; + + +/** + * The Class StorageHubWrapper. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 26, 2018 + */ +public class StorageHubWrapper { + + private StorageHubClientService storageHubClientService; + + public Object lock = new Object(); //Thread safety + + private Workspace workspace = null; + + + /** + * Instantiates a new storage hub wrapper. + * + * @param scope the scope + * @param authorizationToken the authorization token + */ + public StorageHubWrapper(String scope, String authorizationToken) { + this.storageHubClientService = new StorageHubClientService(scope, authorizationToken); + } + + /** + * Gets the storage hub client service. + * + * @return the storageHubClientService + */ + public StorageHubClientService getStorageHubClientService() { + + return storageHubClientService; + } + + + /** + * Gets the workspace. + * + * @return the workspace + */ + public Workspace getWorkspace(){ + + synchronized (lock) { + if(workspace==null){ + workspace = new WorkspaceStorageHubClientService.WorkspaceStorageHubClientServiceBuilder(storageHubClientService).build(); + } + + return workspace; + } + + } + +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/server/WorkspaceStorageHubClientService.java b/src/main/java/org/gcube/common/storagehubwrapper/server/WorkspaceStorageHubClientService.java new file mode 100644 index 0000000..6374900 --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/server/WorkspaceStorageHubClientService.java @@ -0,0 +1,868 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.server; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang.Validate; +import org.gcube.common.storagehub.model.items.FolderItem; +import org.gcube.common.storagehub.model.items.Item; +import org.gcube.common.storagehub.model.items.SharedFolder; +import org.gcube.common.storagehub.model.types.GenericItemType; +import org.gcube.common.storagehubwrapper.server.converter.HLMapper; +import org.gcube.common.storagehubwrapper.server.converter.PortalMapper; +import org.gcube.common.storagehubwrapper.server.tohl.Workspace; +import org.gcube.common.storagehubwrapper.shared.ACLType; +import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem; +import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceSharedFolder; +import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceVREFolder; +import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InsufficientPrivilegesException; +import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InternalErrorException; +import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.ItemAlreadyExistException; +import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.ItemNotFoundException; +import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WorkspaceFolderNotFoundException; +import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WrongDestinationException; +import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WrongItemTypeException; +import org.gcube.common.storagehubwrapper.shared.tohl.folder.items.URLFileItem; +import org.gcube.common.storagehubwrapper.shared.tohl.impl.WorkspaceFolder; +import org.gcube.common.storagehubwrapper.shared.tohl.trash.WorkspaceTrashItem; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * The Class WorkspaceStorageHubClientService. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 20, 2018 + */ +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 StorageHubClientService storageHubClientService; + private boolean withAccounting; + private boolean withFileDetails; + private boolean withMapProperties; + + /** + * Gets the storage hub client service. + * + * @return the storageHubClientService + */ + public StorageHubClientService getStorageHubClientService() { + + return storageHubClientService; + } + + + /** + * @return the withAccounting + */ + public boolean isWithAccounting() { + + return withAccounting; + } + + + /** + * @return the withFileDetails + */ + public boolean isWithFileDetails() { + + return withFileDetails; + } + + + /** + * @return the withMapProperties + */ + public boolean isWithMapProperties() { + + return withMapProperties; + } + + + /** + * Instantiates a new workspace storage hub client service. + * + * @param storageHubClientService the storage hub client service + */ + private WorkspaceStorageHubClientService(StorageHubClientService storageHubClientService) { + this.storageHubClientService = storageHubClientService; + } + + /** + * Instantiates a new workspace storage hub client service. + * + * @param storageHubClientService the storage hub client service + * @param withAccounting the with accounting + * @param withFileDetails the with file details + * @param withMapProperties the with map properties + */ + private WorkspaceStorageHubClientService( + StorageHubClientService storageHubClientService, + boolean withAccounting, boolean withFileDetails, + boolean withMapProperties) { + + super(); + this.storageHubClientService = storageHubClientService; + this.withAccounting = withAccounting; + this.withFileDetails = withFileDetails; + this.withMapProperties = withMapProperties; + } + + + /** + * The Class WorkspaceStorageHubClientServiceBuilder. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 22, 2018 + */ + public static class WorkspaceStorageHubClientServiceBuilder{ + private StorageHubClientService storageHubClientService; + private boolean withAccounting; + private boolean withFileDetails; + private boolean withMapProperties; + + /** + * Instantiates a new workspace storage hub client service builder. + * + * @param storageHubClientService the storage hub client service + * @param withAccounting the with accounting + * @param withFileDetails the with file details + * @param withMapProperties the with map properties + */ + public WorkspaceStorageHubClientServiceBuilder( + final StorageHubClientService storageHubClientService, + final boolean withAccounting, final boolean withFileDetails, + final boolean withMapProperties) { + + this.storageHubClientService = storageHubClientService; + this.withAccounting = withAccounting; + this.withFileDetails = withFileDetails; + this.withMapProperties = withMapProperties; + } + + /** + * Instantiates a new workspace storage hub client service builder. + * + * @param storageHubClientService the storage hub client service + * @param withAccounting the with accounting + * @param withFileDetails the with file details + * @param withMapProperties the with map properties + */ + public WorkspaceStorageHubClientServiceBuilder( + final StorageHubClientService storageHubClientService) { + + this.storageHubClientService = storageHubClientService; + this.withAccounting = false; + this.withFileDetails = false; + this.withMapProperties = false; + } + + /** + * Sets the with accounting. + * + * @param withAccounting the withAccounting to set + * @return the workspace storage hub client service builder + */ + public WorkspaceStorageHubClientServiceBuilder withAccounting(final boolean withAccounting) { + + this.withAccounting = withAccounting; + return this; + } + + /** + * Sets the with file details. + * + * @param withFileDetails the withFileDetails to set + * @return the workspace storage hub client service builder + */ + public WorkspaceStorageHubClientServiceBuilder withFileDetails(final boolean withFileDetails) { + + this.withFileDetails = withFileDetails; + return this; + } + + /** + * Sets the with map properties. + * + * @param withMapProperties the withMapProperties to set + * @return the workspace storage hub client service builder + */ + public WorkspaceStorageHubClientServiceBuilder withMapProperties(final boolean withMapProperties) { + + this.withMapProperties = withMapProperties; + return this; + } + + /** + * Builds the WorkspaceStorageHubClientService + * + * @return the workspace storage hub client service + */ + public WorkspaceStorageHubClientService build(){ + return new WorkspaceStorageHubClientService(storageHubClientService, + withAccounting, + withFileDetails, + withMapProperties); + } + } + + + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#getOwner() + */ + @Override + public String getOwner() + throws InternalErrorException { + + WorkspaceFolder root = getRoot(); + return root.getOwner(); + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#getRoot() + */ + @Override + public WorkspaceFolder getRoot() throws InternalErrorException{ + logger.debug("Getting root"); + FolderItem root; + try { + root = storageHubClientService.getRoot(); + } + catch (Exception 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); + workspaceFolder.setRoot(true); + return workspaceFolder; + } + + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.tohl.Workspace#getChildren(java.lang.String) + */ + public List getChildren(String id){ + + Validate.notNull(id,"The input id is null"); + List children = storageHubClientService.getChildren(id); + List toChildren = new ArrayList(children.size()); + + for (Item item : children) { + WorkspaceItem child = HLMapper.toWorkspaceItem(item); + toChildren.add(child); + } + + return toChildren; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#getParentsById(java.lang.String) + */ + @Override + public List getParentsById(String id) + throws InternalErrorException { + + Validate.notNull(id,"The input id is null"); + List parents = storageHubClientService.getParents(id); + List toParents = new ArrayList(parents.size()); + + for (Item item : parents) { + WorkspaceItem child = HLMapper.toWorkspaceItem(item); + toParents.add(child); + } + + return toParents; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#createFolder(java.lang.String, java.lang.String, java.lang.String) + */ + @Override + public WorkspaceFolder createFolder( + String name, String description, String destinationFolderId) + throws InternalErrorException, InsufficientPrivilegesException, + ItemAlreadyExistException, WrongDestinationException, + ItemNotFoundException, WorkspaceFolderNotFoundException { + + Validate.notNull(destinationFolderId,"The destinationFolderId id is null"); + Validate.notNull(name,"The folderName is null"); + Item item; + try { + item = storageHubClientService.createFolder(destinationFolderId, name, description); + return (WorkspaceFolder) HLMapper.toWorkspaceItem(item); + } + catch (Exception e) { + logger.error("Error on creting the folde: ",e); + throw new InternalErrorException(e.getMessage()); + } + + } + + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#getItem(java.lang.String) + */ + @Override + public WorkspaceItem getItem(String itemId) throws ItemNotFoundException, InternalErrorException { + + /*Validate.notNull(itemId,"The input itemId is null"); + Item item; + try { + item = storageHubClientService.getItem(itemId); + } + catch (Exception e) { + logger.error("Error during get item with id: "+itemId,e); + throw new InternalErrorException(e.getMessage()); + } + return HLMapper.toWorkspaceItem(item, withAccounting, withFileDetails, withMapProperties);*/ + + return getItem(itemId, withAccounting, withFileDetails, withMapProperties); + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.server.tohl.Workspace#getItem(java.lang.String, boolean, boolean, boolean) + */ + @Override + public WorkspaceItem getItem( + String itemId, boolean withAccounting, boolean withFileDetails, + boolean withMapProperties) + throws ItemNotFoundException, InternalErrorException { + + Validate.notNull(itemId,"The input itemId is null"); + Item item; + try { + item = storageHubClientService.getItem(itemId); + } + catch (Exception e) { + logger.error("Error during get item with id: "+itemId,e); + throw new InternalErrorException(e.getMessage()); + } + return HLMapper.toWorkspaceItem(item, withAccounting, withFileDetails, withMapProperties); + } + + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#createFolder(java.lang.String, java.lang.String, java.lang.String, java.util.Map) + */ + @Override + public WorkspaceFolder createFolder( + String name, String description, String destinationFolderId, + Map properties) + throws InternalErrorException, InsufficientPrivilegesException, + ItemAlreadyExistException, WrongDestinationException, + ItemNotFoundException, WorkspaceFolderNotFoundException { + + WorkspaceFolder folder = createFolder(name, description, destinationFolderId); + //TODO set gcube properties + return folder; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.server.tohl.Workspace#uploadFile(java.lang.String, java.io.InputStream, java.lang.String, java.lang.String) + */ + @Override + public WorkspaceItem uploadFile( + String folderId, InputStream is, String fileName, String fileDescription) + throws InsufficientPrivilegesException, + WorkspaceFolderNotFoundException, InternalErrorException, + ItemAlreadyExistException, WrongDestinationException { + + WorkspaceItem wsItem = null; + try { + Item item = storageHubClientService.uploadFile(folderId, is, fileName, fileDescription); + wsItem = HLMapper.toWorkspaceItem(item); + } + catch (Exception e) { + logger.error("Error during upload file ",e); + throw new InternalErrorException(e.getMessage()); + } + + return wsItem; + } + + + + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.server.tohl.Workspace#getSharedFolderMembers(java.lang.String) + */ + @Override + public List getSharedFolderMembers(String folderId) throws Exception { + + Validate.notNull(folderId,"The input folderid is null"); + + Item item; + try { + + item = storageHubClientService.getItem(folderId); + + }catch (Exception e) { + logger.error("Error during get item with id: "+folderId,e); + throw new ItemNotFoundException(e.getMessage()); + } + + Validate.notNull(item, "The item with id "+folderId+" was not found"); + + if(item instanceof SharedFolder){ + return PortalMapper.toWorkspaceSharedFolderMembers((SharedFolder)item); + }else + throw new Exception("The item with "+folderId+ " is not a Shared Folder"); + } + + + + + + + + + + + + + + + + + + + + + + + + + + + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#createExternalUrl(java.lang.String, java.lang.String, java.lang.String, java.lang.String) + */ + @Override + public URLFileItem createExternalUrl( + String name, String description, String url, String destinationFolderId) + throws InsufficientPrivilegesException, + WorkspaceFolderNotFoundException, InternalErrorException, + ItemAlreadyExistException, WrongDestinationException, IOException { + + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#createExternalUrl(java.lang.String, java.lang.String, java.io.InputStream, java.lang.String) + */ + @Override + public URLFileItem createExternalUrl( + String name, String description, InputStream url, + String destinationfolderId) + throws InsufficientPrivilegesException, InternalErrorException, + ItemAlreadyExistException, WrongDestinationException, + WorkspaceFolderNotFoundException, IOException { + + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#removeItem(java.lang.String) + */ + @Override + public void removeItem(String itemId) + throws ItemNotFoundException, InternalErrorException, + InsufficientPrivilegesException { + + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#moveItem(java.lang.String, java.lang.String) + */ + @Override + public WorkspaceItem moveItem(String itemId, String destinationFolderId) + throws ItemNotFoundException, WrongDestinationException, + InsufficientPrivilegesException, InternalErrorException, + ItemAlreadyExistException, WorkspaceFolderNotFoundException { + + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#renameItem(java.lang.String, java.lang.String) + */ + @Override + public void renameItem(String itemId, String newName) + throws ItemNotFoundException, InternalErrorException, + ItemAlreadyExistException, InsufficientPrivilegesException { + + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#changeDescription(java.lang.String, java.lang.String) + */ + @Override + public void changeDescription(String itemId, String newDescription) + throws ItemNotFoundException, InternalErrorException { + + // TODO Auto-generated method stub + + } + + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#getItemByPath(java.lang.String) + */ + @Override + public WorkspaceItem getItemByPath(String path) + throws ItemNotFoundException { + + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#remove(java.lang.String, java.lang.String) + */ + @Override + public void remove(String itemName, String folderId) + throws ItemNotFoundException, InternalErrorException, + InsufficientPrivilegesException, WrongItemTypeException { + + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#copy(java.lang.String, java.lang.String, java.lang.String) + */ + @Override + public WorkspaceItem copy( + String itemId, String newName, String destinationFolderId) + throws ItemNotFoundException, WrongDestinationException, + InternalErrorException, ItemAlreadyExistException, + InsufficientPrivilegesException, WorkspaceFolderNotFoundException { + + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#copy(java.lang.String, java.lang.String) + */ + @Override + public WorkspaceItem copy(String itemId, String destinationFolderId) + throws ItemNotFoundException, WrongDestinationException, + InternalErrorException, ItemAlreadyExistException, + InsufficientPrivilegesException, WorkspaceFolderNotFoundException { + + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#exists(java.lang.String, java.lang.String) + */ + @Override + public boolean exists(String name, String folderId) + throws InternalErrorException, ItemNotFoundException, + WrongItemTypeException { + + // TODO Auto-generated method stub + return false; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#exists(java.lang.String) + */ + @Override + public boolean exists(String itemId) + throws InternalErrorException { + + // TODO Auto-generated method stub + return false; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#find(java.lang.String, java.lang.String) + */ + @Override + public WorkspaceItem find(String name, String folderId) + throws InternalErrorException, ItemNotFoundException, + WrongItemTypeException { + + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#find(java.lang.String) + */ + @Override + public WorkspaceItem find(String path) + throws InternalErrorException { + + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#searchByName(java.lang.String, java.lang.String) + */ + @Override + public List searchByName(String name, String folderId) + throws InternalErrorException { + + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#searchByMimeType(java.lang.String) + */ + @Override + public List searchByMimeType(String mimeType) + throws InternalErrorException { + + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#getFolderItems(org.gcube.common.storagehub.model.types.GenericItemType) + */ + @Override + public List getFolderItems(GenericItemType type) + throws InternalErrorException { + + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#createSharedFolder(java.lang.String, java.lang.String, java.util.List, java.lang.String) + */ + @Override + public WorkspaceSharedFolder createSharedFolder( + String name, String description, List users, + String destinationFolderId) + throws InternalErrorException, InsufficientPrivilegesException, + ItemAlreadyExistException, WrongDestinationException, + ItemNotFoundException, WorkspaceFolderNotFoundException { + + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#createSharedFolder(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, boolean) + */ + @Override + public WorkspaceSharedFolder createSharedFolder( + String name, String description, String groupId, + String destinationFolderId, String displayName, boolean isVREFolder) + throws InternalErrorException, InsufficientPrivilegesException, + ItemAlreadyExistException, WrongDestinationException, + ItemNotFoundException, WorkspaceFolderNotFoundException { + + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#shareFolder(java.util.List, java.lang.String) + */ + @Override + public WorkspaceSharedFolder shareFolder( + List users, String destinationFolderId) + throws InternalErrorException, InsufficientPrivilegesException, + ItemAlreadyExistException, WrongDestinationException, + ItemNotFoundException, WorkspaceFolderNotFoundException { + + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#share(java.util.List, java.lang.String) + */ + @Override + public WorkspaceSharedFolder share(List users, String itemId) + throws InternalErrorException, InsufficientPrivilegesException, + ItemAlreadyExistException, WrongDestinationException, + ItemNotFoundException, WorkspaceFolderNotFoundException { + + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#createGcubeItem(java.lang.String, java.lang.String, java.util.List, java.lang.String, java.lang.String, java.util.Map, java.lang.String) + */ + @Override + public WorkspaceItem createGcubeItem( + String name, String description, List scopes, String creator, + String itemType, Map properties, + String destinationFolderId) + throws InsufficientPrivilegesException, + WorkspaceFolderNotFoundException, InternalErrorException, + ItemAlreadyExistException, WrongDestinationException, + ItemNotFoundException { + + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#unshare(java.lang.String) + */ + @Override + public WorkspaceItem unshare(String itemId) + throws InternalErrorException, ItemNotFoundException { + + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#getTrash() + */ + @Override + public WorkspaceTrashItem getTrash() + throws InternalErrorException, ItemNotFoundException { + + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#getMySpecialFolders() + */ + @Override + public WorkspaceFolder getMySpecialFolders() + throws InternalErrorException, ItemNotFoundException { + + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#searchByProperties(java.util.List) + */ + @Override + public List searchByProperties(List properties) + throws InternalErrorException { + + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#getVREFolderByScope(java.lang.String) + */ + @Override + public WorkspaceSharedFolder getVREFolderByScope(String scope) + throws ItemNotFoundException, InternalErrorException { + + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#getDiskUsage() + */ + @Override + public long getDiskUsage() + throws InternalErrorException { + + // TODO Auto-generated method stub + return 0; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#getTotalItems() + */ + @Override + public int getTotalItems() + throws InternalErrorException { + + // TODO Auto-generated method stub + return 0; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#removeItems(java.lang.String[]) + */ + @Override + public Map removeItems(String... id) + throws ItemNotFoundException, InternalErrorException, + InsufficientPrivilegesException { + + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#createVREFolder(java.lang.String, java.lang.String, java.lang.String, org.gcube.portal.storagehubwrapper.shared.ACLType) + */ + @Override + public WorkspaceVREFolder createVREFolder( + String scope, String description, String displayName, ACLType privilege) + throws InternalErrorException, InsufficientPrivilegesException, + ItemAlreadyExistException, WrongDestinationException, + ItemNotFoundException, WorkspaceFolderNotFoundException { + + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#getGroup(java.lang.String) + */ + @Override + public String getGroup(String groupId) + throws InternalErrorException { + + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#isGroup(java.lang.String) + */ + @Override + public boolean isGroup(String groupId) + throws InternalErrorException { + + // TODO Auto-generated method stub + return false; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.Workspace#getPublicFolders() + */ + @Override + public List getPublicFolders() + throws InternalErrorException { + + // TODO Auto-generated method stub + return null; + } + + + + +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/server/converter/HLMapper.java b/src/main/java/org/gcube/common/storagehubwrapper/server/converter/HLMapper.java new file mode 100644 index 0000000..e13dca8 --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/server/converter/HLMapper.java @@ -0,0 +1,269 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.server.converter; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Function; + +import org.gcube.common.storagehub.model.Metadata; +import org.gcube.common.storagehub.model.items.AbstractFileItem; +import org.gcube.common.storagehub.model.items.ExternalURL; +import org.gcube.common.storagehub.model.items.FolderItem; +import org.gcube.common.storagehub.model.items.GenericFileItem; +import org.gcube.common.storagehub.model.items.Item; +import org.gcube.common.storagehub.model.items.PDFFileItem; +import org.gcube.common.storagehub.model.items.SharedFolder; +import org.gcube.common.storagehub.model.items.VreFolder; +import org.gcube.common.storagehub.model.items.nodes.Accounting; +import org.gcube.common.storagehub.model.items.nodes.Content; +import org.gcube.common.storagehub.model.items.nodes.ImageContent; +import org.gcube.common.storagehub.model.items.nodes.PDFContent; +import org.gcube.common.storagehub.model.items.nodes.accounting.AccountEntry; +import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem; +import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItemType; +import org.gcube.common.storagehubwrapper.shared.tohl.folder.items.FileItemType; +import org.gcube.common.storagehubwrapper.shared.tohl.impl.AccountingEntry; +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.gcube.common.storagehubwrapper.shared.tohl.impl.PropertyMap; +import org.gcube.common.storagehubwrapper.shared.tohl.impl.URLFile; +import org.gcube.common.storagehubwrapper.shared.tohl.impl.WorkspaceFolder; +import org.gcube.common.storagehubwrapper.shared.tohl.impl.WorkspaceSharedFolder; +import org.gcube.common.storagehubwrapper.shared.tohl.impl.WorkspaceVREFolder; + + +/** + * The Class HLMapper. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 20, 2018 + */ +public class HLMapper { + + public static Function toAccountingEntry = new Function() { + + public AccountingEntry apply(org.gcube.common.storagehub.model.items.nodes.accounting.AccountEntry accountingEntry) { + + return new AccountingEntry( + accountingEntry.getUser(), + accountingEntry.getDate(), + accountingEntry.getType().name(), + accountingEntry.getVersion(), + accountingEntry.getPrimaryType()); + } + }; + + + /** + * To workspace item. + * + * @param the generic type + * @param item the item + * @return the t + */ + public static T toWorkspaceItem(Item item){ + + return toWorkspaceItem(item, false, false, false); + } + + /** + * To workspace item. + * + * @param the generic type + * @param item the item + * @return the t + */ + public static T toWorkspaceItem(Item item, boolean withAccounting, boolean withFileDetails, boolean withMapProperties){ + + List accountingEntries = null; + + if(withAccounting){ + Accounting accounting = item.getAccounting(); + if(accounting!=null && accounting.getEntries().size()>0){ + accountingEntries = new ArrayList(accounting.getEntries().size()); + for (AccountEntry ae : accounting.getEntries()) { + accountingEntries.add(toAccountingEntry.apply(ae)); + } + } + } + + org.gcube.common.storagehubwrapper.shared.tohl.impl.WorkspaceItem theItem = null; + WorkspaceItemType type = null; + boolean isFolder = false; + + //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(); + type = WorkspaceItemType.SHARED_FOLDER; + if (sharedfolder.isVreFolder()){ + VreFolder vreFolder = (VreFolder) item; + theItem = new WorkspaceVREFolder(); + ((WorkspaceSharedFolder) theItem).setVreFolder(true); + type = WorkspaceItemType.VRE_FOLDER; + } + } + + } + + //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){ + ExternalURL eURL = (ExternalURL) item; //?? + theItem = new URLFile(); + 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.setMimeType(aC.getMimeType()); + theFileItem.setSize(aC.getSize()); + theFileItem.setFileItemType(fileItemType); + + //TODO ADD VERSION NAME + + } + + //ADDING (GCUBE) PROPERTIES + PropertyMap pm = null; + if(withMapProperties){ + Metadata metadata = item.getPropertyMap(); + if(metadata!=null){ + pm = new PropertyMap(metadata.getValues()); + } + + } + + //TRASH //TODO + + if(theItem.isTrashed()) + type = WorkspaceItemType.TRASH_ITEM; + + theItem.setId(item.getId()); + theItem.setName(item.getName()); + theItem.setPath(item.getPath()); + theItem.setParentId(item.getParentId()); + theItem.setTrashed(item.isTrashed()); + theItem.setShared(item.isShared()); + theItem.setLocked(item.isLocked()); + theItem.setTitle(item.getTitle()); + theItem.setDescription(item.getDescription()); + theItem.setLastModifiedBy(item.getLastModifiedBy()); + theItem.setLastModificationTime(item.getLastModificationTime()); + theItem.setCreationTime(item.getCreationTime()); + theItem.setOwner(item.getOwner()); + theItem.setHidden(item.isHidden()); + theItem.setAccounting(accountingEntries); + theItem.setType(type); + theItem.setFolder(isFolder); + theItem.setRoot(false); + theItem.setPropertyMap(pm); + + return (T) theItem; + } + + /*public static Function toWorkspaceItem = new Function() { + + public WorkspaceItem apply(Item item) { + + Accounting accounting = item.getAccounting(); + List accountingEntries = null; + if(accounting!=null && accounting.getEntries().size()>0){ + accountingEntries = new ArrayList(accounting.getEntries().size()); + for (AccountEntry ae : accounting.getEntries()) { + //TODO + accountingEntries.add(toAccountingEntry.apply(ae)); + } + } + + WorkspaceItemImpl theItem = null; + WorkspaceItemType type = null; + boolean isFolder = false; + + //IS THE ITEM A FOLDER TYPE? + if (item instanceof FolderItem){ + isFolder = true; + FolderItem folderItem = (FolderItem) item; //?? + theItem = new WorkspaceFolderImpl(); + type = org.gcube.portal.storagehubwrapper.shared.tohl.WorkspaceItemType.FOLDER_ITEM; + if (item instanceof SharedFolder || item instanceof VreFolder) { + SharedFolder sharedfolder = (SharedFolder) item; //?? + theItem = new WorkspaceSharedFolderImpl(); + type = org.gcube.portal.storagehubwrapper.shared.tohl.WorkspaceItemType.SHARED_FOLDER; + if (sharedfolder.isVreFolder()){ + VreFolder vreFolder = (VreFolder) item; + theItem = new WorkspaceVREFolderImpl(); + type = org.gcube.portal.storagehubwrapper.shared.tohl.WorkspaceItemType.VRE_FOLDER; + } + } + + } + + if(theItem.isTrashed()) + type = org.gcube.portal.storagehubwrapper.shared.tohl.WorkspaceItemType.TRASH_ITEM; + + theItem.setId(item.getId()); + theItem.setName(item.getName()); + theItem.setPath(item.getPath()); + theItem.setParentId(item.getParentId()); + theItem.setTrashed(item.isTrashed()); + theItem.setShared(item.isShared()); + theItem.setLocked(item.isLocked()); + theItem.setTitle(item.getTitle()); + theItem.setDescription(item.getDescription()); + theItem.setLastModifiedBy(item.getLastModifiedBy()); + theItem.setLastModificationTime(item.getLastModificationTime()); + theItem.setCreationTime(item.getCreationTime()); + theItem.setOwner(item.getOwner()); + theItem.setHidden(item.isHidden()); + theItem.setAccounting(accountingEntries); + theItem.setType(type); + theItem.setFolder(isFolder); + theItem.setRoot(false); + + return theItem; + } + };*/ + + +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/server/converter/PortalMapper.java b/src/main/java/org/gcube/common/storagehubwrapper/server/converter/PortalMapper.java new file mode 100644 index 0000000..46f6ec5 --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/server/converter/PortalMapper.java @@ -0,0 +1,41 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.server.converter; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.gcube.common.storagehub.model.Metadata; +import org.gcube.common.storagehub.model.items.SharedFolder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * The Class PortalMapper. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 26, 2018 + */ +public class PortalMapper { + + private static Logger logger = LoggerFactory.getLogger(PortalMapper.class); + + /** + * To workspace shared folder members. + * + * @param sharedfolder the sharedfolder + * @return the list + */ + public static List toWorkspaceSharedFolderMembers(SharedFolder sharedfolder){ + + Metadata users = sharedfolder.getUsers(); + Map mapMember = users.getValues(); + List listUsers = new ArrayList(mapMember.size()); + listUsers.addAll(mapMember.keySet()); + logger.debug("Returning "+listUsers.size()+" member/s for sharedFolder with id: "+sharedfolder.getId()); + return listUsers; + } +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/server/tohl/Workspace.java b/src/main/java/org/gcube/common/storagehubwrapper/server/tohl/Workspace.java new file mode 100644 index 0000000..3e10623 --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/server/tohl/Workspace.java @@ -0,0 +1,625 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.server.tohl; + +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Map; + +import org.gcube.common.storagehub.model.types.GenericItemType; +import org.gcube.common.storagehubwrapper.shared.ACLType; +import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder; +import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem; +import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceSharedFolder; +import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceVREFolder; +import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InsufficientPrivilegesException; +import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InternalErrorException; +import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.ItemAlreadyExistException; +import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.ItemNotFoundException; +import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WorkspaceFolderNotFoundException; +import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WrongDestinationException; +import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WrongItemTypeException; +import org.gcube.common.storagehubwrapper.shared.tohl.folder.items.URLFileItem; +import org.gcube.common.storagehubwrapper.shared.tohl.trash.WorkspaceTrashItem; + + + +/** + * The Interface Workspace. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 15, 2018 + * + * Represents a HL user workspace. + */ +public interface Workspace{ + + + /** + * Gets the owner. + * + * @return the owner + * @throws InternalErrorException the internal error exception + */ + //OK + public String getOwner() throws InternalErrorException; + + /** + * Returns the workspace root. + * + * @return the root. + * @throws InternalErrorException the internal error exception + */ + //OK + public WorkspaceFolder getRoot() throws InternalErrorException; + + + /** + * Gets the children. + * + * @param id the id + * @return the children + */ + //OK + public List getChildren(String id); + + + /** + * Gets the parents by id. + * + * @param id the id + * @return the parents by id + * @throws InternalErrorException the internal error exception + */ + //OK + public List getParentsById(String id) throws InternalErrorException; + + /** + * Return the item with the specified id. + * + * @param itemId the item id. + * @return the item. + * @throws ItemNotFoundException if the item has not been found. + * @throws InternalErrorException the internal error exception + */ + //OK + public WorkspaceItem getItem(String itemId) throws ItemNotFoundException, InternalErrorException; + + + /** + * Return the item with the specified id. + * + * @param itemId the item id. + * @param withAccounting the with accounting + * @param withFileDetails the with file details + * @param withMapProperties the with map properties + * @return the item. + * @throws ItemNotFoundException if the item has not been found. + * @throws InternalErrorException the internal error exception + */ + //OK + public WorkspaceItem getItem(String itemId, boolean withAccounting, boolean withFileDetails, boolean withMapProperties) throws ItemNotFoundException, InternalErrorException; + + + /** + * Create a new folder with specified name. + * The new folder is created into the specified folder. + * + * @param name the folder name. + * @param description the folder description. + * @param destinationFolderId the destination folder. + * @return the new folder. + * @throws InternalErrorException if an internal error occurs. + * @throws InsufficientPrivilegesException if the user don't have sufficient privileges to perform this operation. + * @throws ItemAlreadyExistException if an item with the same exist in the destination folder. + * @throws WrongDestinationException if the destination item is not a folder. + * @throws ItemNotFoundException if the destination folder has not been found. + * @throws WorkspaceFolderNotFoundException if the destination folder has not been found. + * @throws Exception the exception + */ + public WorkspaceFolder createFolder(String name, String description, String destinationFolderId) throws InternalErrorException, InsufficientPrivilegesException, ItemAlreadyExistException, WrongDestinationException, ItemNotFoundException, WorkspaceFolderNotFoundException, Exception; + + /** + * Create a new folder with properties. + * + * @param name the name + * @param description the description + * @param destinationFolderId the destination folder id + * @param properties the properties + * @return the new folder + * @throws InternalErrorException the internal error exception + * @throws InsufficientPrivilegesException the insufficient privileges exception + * @throws ItemAlreadyExistException the item already exist exception + * @throws WrongDestinationException the wrong destination exception + * @throws ItemNotFoundException the item not found exception + * @throws WorkspaceFolderNotFoundException the workspace folder not found exception + */ + public WorkspaceFolder createFolder(String name, String description, String destinationFolderId, Map properties) throws InternalErrorException, InsufficientPrivilegesException, ItemAlreadyExistException, WrongDestinationException, ItemNotFoundException, WorkspaceFolderNotFoundException; + + + /** + * Upload file. + * + * @param folderId the folder id + * @param inputStream the input stream + * @param fileName the file name + * @param fileDescription the file description + * @return the item + * @throws InsufficientPrivilegesException the insufficient privileges exception + * @throws WorkspaceFolderNotFoundException the workspace folder not found exception + * @throws InternalErrorException the internal error exception + * @throws ItemAlreadyExistException the item already exist exception + * @throws WrongDestinationException the wrong destination exception + */ + public WorkspaceItem uploadFile(String folderId, InputStream inputStream, String fileName, String fileDescription) throws InsufficientPrivilegesException, WorkspaceFolderNotFoundException, InternalErrorException, ItemAlreadyExistException, WrongDestinationException; + + /** + * Gets the shared folder members. + * + * @param folderid the folderid + * @return the shared folder members + * @throws Exception the exception + */ + public List getSharedFolderMembers(String folderid) throws Exception; + + + + + + + + + + + + + + /** + * Create a new External URL into a folder. + * + * @param name the external URL name. + * @param description the external URL description. + * @param url the external URL value. + * @param destinationFolderId the destination folder. + * @return the new external URL. + * @throws InsufficientPrivilegesException if the user don't have sufficient privileges to perform this operation. + * @throws WorkspaceFolderNotFoundException if the destination folder has not been found. + * @throws InternalErrorException if an internal error occurs. + * @throws ItemAlreadyExistException if a folder item with same name already exist. + * @throws WrongDestinationException if the destination type is not a folder. + * @throws IOException Signals that an I/O exception has occurred. + */ + public URLFileItem createExternalUrl(String name, String description, String url, String destinationFolderId) throws InsufficientPrivilegesException, WorkspaceFolderNotFoundException, InternalErrorException, ItemAlreadyExistException, WrongDestinationException, IOException; + + /** + * Add a Bookmark. + * + * @param name the name + * @param description the description + * @param url the url + * @param destinationfolderId the destinationfolder id + * @return the external url + * @throws InsufficientPrivilegesException the insufficient privileges exception + * @throws InternalErrorException the internal error exception + * @throws ItemAlreadyExistException the item already exist exception + * @throws WrongDestinationException the wrong destination exception + * @throws WorkspaceFolderNotFoundException the workspace folder not found exception + * @throws IOException Signals that an I/O exception has occurred. + */ + /** + * Create a new External URL into a folder. + * @param name the external URL name. + * @param description the external URL description. + * @param url the external URL. + * @param destinationfolderId the destination folder. + * @return the new external URL. + * @throws InsufficientPrivilegesException if the user don't have sufficient privileges to perform this operation. + * @throws WorkspaceFolderNotFoundException if the destination folder has not been found. + * @throws InternalErrorException if an internal error occurs. + * @throws ItemAlreadyExistException if a folder item with same name already exist. + * @throws WrongDestinationException if the destination type is not a folder. + * @throws IOException + */ + public URLFileItem createExternalUrl(String name, String description, InputStream url, String destinationfolderId) throws InsufficientPrivilegesException, InternalErrorException, ItemAlreadyExistException, WrongDestinationException, WorkspaceFolderNotFoundException, IOException; + + /** + * Remove an item. + * @param itemId the item to remove. + * @throws ItemNotFoundException if the item has not been found. + * @throws InternalErrorException if an internal error occurs. + * @throws InsufficientPrivilegesException if the user don't have sufficient privileges to perform this operation. + */ + public void removeItem(String itemId) throws ItemNotFoundException, InternalErrorException, InsufficientPrivilegesException; + + /** + * Move a workspaceItem to a specified destination. + * @param itemId the item to move. + * @param destinationFolderId the destination folder. + * @return the moved workspaceItem + * @throws ItemNotFoundException if the specified item has not been found. + * @throws WrongDestinationException if the specified destination has not been found. + * @throws InsufficientPrivilegesException if the user don't have sufficient privileges to perform this operation. + * @throws InternalErrorException if an internal error occurs. + * @throws ItemAlreadyExistException if the destination folder have a children with same name. + * @throws WorkspaceFolderNotFoundException if the destination folder is not found. + */ + public WorkspaceItem moveItem(String itemId, String destinationFolderId) throws ItemNotFoundException, WrongDestinationException, InsufficientPrivilegesException, InternalErrorException, ItemAlreadyExistException, WorkspaceFolderNotFoundException; + + /** + * Rename an item. + * + * @param itemId the item id. + * @param newName the new name. + * @throws ItemNotFoundException if the item has not been found. + * @throws InternalErrorException if an internal error occurs. + * @throws ItemAlreadyExistException if the user don't have sufficient privileges to perform this operation. + * @throws InsufficientPrivilegesException the insufficient privileges exception + */ + public void renameItem(String itemId, String newName) throws ItemNotFoundException, InternalErrorException, ItemAlreadyExistException, InsufficientPrivilegesException; + + /** + * Change an item description. + * @param itemId the item to update. + * @param newDescription the new item description. + * @throws ItemNotFoundException if the item has not been found. + * @throws InternalErrorException if an internal error occurs. + */ + public void changeDescription(String itemId, String newDescription) throws ItemNotFoundException, InternalErrorException; + + + /** + * Return the item with the specified path. + * + * @param path the item path. + * @return the item. + * @throws ItemNotFoundException if the item has not been found. + */ + public WorkspaceItem getItemByPath(String path) throws ItemNotFoundException; + + /** + * Remove an item from a folder. + * @param itemName the item name. + * @param folderId the folder id. + * @throws ItemNotFoundException if the folder has not been found. + * @throws InternalErrorException if an internal error occurs. + * @throws InsufficientPrivilegesException if the user don't have sufficient privileges to perform this operation. + * @throws WrongItemTypeException if the specified folder is neither a workspace nor a folder. + */ + public void remove(String itemName, String folderId) throws ItemNotFoundException, InternalErrorException, InsufficientPrivilegesException, WrongItemTypeException; + + /** + * Copy an item from a folder to another folder. + * + * @param itemId the item to copy. + * @param newName the item new name. + * @param destinationFolderId the destination folder id. + * @return the item copy. + * @throws ItemNotFoundException if the item has not been found. + * @throws WrongDestinationException if the destination have a wrong type. + * @throws InternalErrorException if an internal error occurs. + * @throws ItemAlreadyExistException if an item with same name already exist in the destination folder. + * @throws InsufficientPrivilegesException if the user don't have sufficient privileges to perform this operation. + * @throws WorkspaceFolderNotFoundException if the destination folder has not been found. + */ + public WorkspaceItem copy(String itemId, String newName, String destinationFolderId) throws ItemNotFoundException, WrongDestinationException, InternalErrorException, ItemAlreadyExistException, InsufficientPrivilegesException, WorkspaceFolderNotFoundException; + + /** + * Copy an item from a folder to another folder. The item copy have the same name of the original. + * + * @param itemId the item to copy. + * @param destinationFolderId the destination folder id, can't be the same of the item (can't have the same name). + * @return the item copy. + * @throws ItemNotFoundException if the item has not been found. + * @throws WrongDestinationException if the destination have a wrong type. + * @throws InternalErrorException if an internal error occurs. + * @throws ItemAlreadyExistException if an item with same name already exist in the destination folder. + * @throws InsufficientPrivilegesException if the user don't have sufficient privileges to perform this operation. + * @throws WorkspaceFolderNotFoundException if the destination folder has not been found. + */ + public WorkspaceItem copy(String itemId, String destinationFolderId) throws ItemNotFoundException, WrongDestinationException, InternalErrorException, ItemAlreadyExistException, InsufficientPrivilegesException, WorkspaceFolderNotFoundException; + + /** + * Check if an item with the specified name exists in the specified folder. + * @param name the name to check. + * @param folderId the folder where to search the item. + * @return true if the item exists, false otherwise. + * @throws InternalErrorException if an error occurs. + * @throws ItemNotFoundException if the folder has not been found. + * @throws WrongItemTypeException if the folderId referrer to an item with type different from Workspace or folder. + */ + public boolean exists(String name, String folderId) throws InternalErrorException, ItemNotFoundException, WrongItemTypeException; + + /** + * Check if an item with the specified id exists. + * @param itemId the item id to check. + * @return true if the item exists, false otherwise. + * @throws InternalErrorException if an error occurs. + */ + public boolean exists(String itemId) throws InternalErrorException; + + /** + * Get an item with the specified name in the specified folder. + * @param name the item name to find. + * @param folderId the folder where to search the item. + * @return the item if the item is found, null otherwise. + * @throws InternalErrorException if an error occurs. + * @throws ItemNotFoundException if the folder has not been found. + * @throws WrongItemTypeException if the folderId referrer to an item with type different from Workspace or folder. + */ + public WorkspaceItem find(String name, String folderId) throws InternalErrorException, ItemNotFoundException, WrongItemTypeException; + + + /** + * Find an item using the specified path. + * + * @param path the item path. + * @return the item if the item is found, null otherwise. + * @throws InternalErrorException if an error occurs. + */ + public WorkspaceItem find(String path) throws InternalErrorException; + + + /** + * Search by Name. + * + * @param name the name + * @param folderId the folder id + * @return a list of SearchItem + * @throws InternalErrorException the internal error exception + */ + public List searchByName(String name, String folderId) throws InternalErrorException; + + /** + * Search By MimeType. + * + * @param mimeType the mime type + * @return a list of SearchFolderItem + * @throws InternalErrorException the internal error exception + */ + public List searchByMimeType(String mimeType) + throws InternalErrorException; + + /** + * Get items by type. + * + * @param type the type + * @return a list of SearchItem + * @throws InternalErrorException the internal error exception + */ + public List getFolderItems(GenericItemType type) throws InternalErrorException; + + + /** + * Create a shared folder with a list of users. + * + * @param name the name + * @param description the description + * @param users A list of portal logins + * @param destinationFolderId the destination folder id + * @return the shared folder + * @throws InternalErrorException the internal error exception + * @throws InsufficientPrivilegesException the insufficient privileges exception + * @throws ItemAlreadyExistException the item already exist exception + * @throws WrongDestinationException the wrong destination exception + * @throws ItemNotFoundException the item not found exception + * @throws WorkspaceFolderNotFoundException the workspace folder not found exception + */ + public WorkspaceSharedFolder createSharedFolder(String name, String description, + List users, String destinationFolderId) + throws InternalErrorException, InsufficientPrivilegesException, + ItemAlreadyExistException, WrongDestinationException, + ItemNotFoundException, WorkspaceFolderNotFoundException; + + /** + * Create a shared folder associated with a groupId. + * + * @param name the name of the folder + * @param description the description + * @param groupId an existing groupId to associate with the folder + * @param destinationFolderId the destination folder id + * @param displayName a friendly name for the folder + * @param isVREFolder a flag to indicate the folder is a VRE Folder + * @return the shared folder + * @throws InternalErrorException the internal error exception + * @throws InsufficientPrivilegesException the insufficient privileges exception + * @throws ItemAlreadyExistException the item already exist exception + * @throws WrongDestinationException the wrong destination exception + * @throws ItemNotFoundException the item not found exception + * @throws WorkspaceFolderNotFoundException the workspace folder not found exception + */ + public WorkspaceSharedFolder createSharedFolder(String name, String description, + String groupId, String destinationFolderId, String displayName, boolean isVREFolder) + throws InternalErrorException, InsufficientPrivilegesException, + ItemAlreadyExistException, WrongDestinationException, + ItemNotFoundException, WorkspaceFolderNotFoundException; + + /** + * Shared an exist {@link WorkspaceFolder} with a list of users. + * + * @param users A list of portal logins. + * @param destinationFolderId the destination folder id + * @return the shared folder + * @throws InternalErrorException the internal error exception + * @throws InsufficientPrivilegesException the insufficient privileges exception + * @throws ItemAlreadyExistException the item already exist exception + * @throws WrongDestinationException the wrong destination exception + * @throws ItemNotFoundException the item not found exception + * @throws WorkspaceFolderNotFoundException the workspace folder not found exception + */ + public WorkspaceSharedFolder shareFolder(List users, String destinationFolderId) + throws InternalErrorException, InsufficientPrivilegesException, + ItemAlreadyExistException, WrongDestinationException, + ItemNotFoundException, WorkspaceFolderNotFoundException; + + + /** + * Shared an exist {@link WorkspaceFolder} with a list of users. + * + * @param users A list of portal logins. + * @param itemId the item id + * @return the shared folder + * @throws InternalErrorException the internal error exception + * @throws InsufficientPrivilegesException the insufficient privileges exception + * @throws ItemAlreadyExistException the item already exist exception + * @throws WrongDestinationException the wrong destination exception + * @throws ItemNotFoundException the item not found exception + * @throws WorkspaceFolderNotFoundException the workspace folder not found exception + */ + public WorkspaceSharedFolder share(List users, String itemId) + throws InternalErrorException, InsufficientPrivilegesException, + ItemAlreadyExistException, WrongDestinationException, + ItemNotFoundException, WorkspaceFolderNotFoundException; + + /** + * Create a GCubeItem. + * + * @param name the name + * @param description the description + * @param scopes the scopes + * @param creator the creator + * @param itemType the item type + * @param properties the properties + * @param destinationFolderId the destination folder id + * @return a GCubeItem + * @throws InsufficientPrivilegesException the insufficient privileges exception + * @throws WorkspaceFolderNotFoundException the workspace folder not found exception + * @throws InternalErrorException the internal error exception + * @throws ItemAlreadyExistException the item already exist exception + * @throws WrongDestinationException the wrong destination exception + * @throws ItemNotFoundException the item not found exception + */ + public WorkspaceItem createGcubeItem(String name, String description, + List scopes, String creator, String itemType, Map properties, + String destinationFolderId) throws InsufficientPrivilegesException, + WorkspaceFolderNotFoundException, InternalErrorException, + ItemAlreadyExistException, WrongDestinationException, ItemNotFoundException; + + /** + * Unshare a shared item. + * + * @param itemId the item id + * @return the workspace item + * @throws InternalErrorException the internal error exception + * @throws ItemNotFoundException the item not found exception + */ + public WorkspaceItem unshare(String itemId) throws InternalErrorException, ItemNotFoundException; + + /** + * Get Trash Folder. + * + * @return the trash folder + * @throws InternalErrorException the internal error exception + * @throws ItemNotFoundException the item not found exception + */ + public WorkspaceTrashItem getTrash() throws InternalErrorException, ItemNotFoundException; + + /** + * Get MySpecialFolders. + * + * @return my special folders + * @throws InternalErrorException the internal error exception + * @throws ItemNotFoundException the item not found exception + */ + public WorkspaceFolder getMySpecialFolders() throws InternalErrorException, ItemNotFoundException; + + + /** + * Search By Properties. + * + * @param properties the properties + * @return a list of WorkspaceItem + * @throws InternalErrorException the internal error exception + */ + public List searchByProperties(List properties) + throws InternalErrorException; + + /** + * Get VRE Folder By Scope. + * + * @param scope the scope + * @return the VRE folder associated to such scope + * @throws ItemNotFoundException the item not found exception + * @throws InternalErrorException the internal error exception + */ + public WorkspaceSharedFolder getVREFolderByScope(String scope) throws ItemNotFoundException, InternalErrorException; + + /** + * Get the disk usage of a worskpace. + * + * @return the disk usage + * @throws InternalErrorException the internal error exception + */ + public long getDiskUsage() throws InternalErrorException; + + /** + * Get the total number of items in a workspace. + * + * @return the numer of total Items + * @throws InternalErrorException the internal error exception + */ + public int getTotalItems() throws InternalErrorException; + + /** + * Remove a list of items identified by ids. + * + * @param id the id + * @return a map of errors: Map + * @throws ItemNotFoundException the item not found exception + * @throws InternalErrorException the internal error exception + * @throws InsufficientPrivilegesException the insufficient privileges exception + */ + public Map removeItems(String... id) throws ItemNotFoundException, + InternalErrorException, InsufficientPrivilegesException; + + + /** + * Create a VRE folder. + * + * @param scope the scope + * @param description the description + * @param displayName the display name + * @param privilege the privilege + * @return a new VRE folder + * @throws InternalErrorException the internal error exception + * @throws InsufficientPrivilegesException the insufficient privileges exception + * @throws ItemAlreadyExistException the item already exist exception + * @throws WrongDestinationException the wrong destination exception + * @throws ItemNotFoundException the item not found exception + * @throws WorkspaceFolderNotFoundException the workspace folder not found exception + */ + public WorkspaceVREFolder createVREFolder(String scope, String description, + String displayName, ACLType privilege) throws InternalErrorException, + InsufficientPrivilegesException, ItemAlreadyExistException, + WrongDestinationException, ItemNotFoundException, + WorkspaceFolderNotFoundException; + + + /** + * Get group name by group id. + * + * @param groupId the group id + * @return the group name + * @throws InternalErrorException the internal error exception + */ + String getGroup(String groupId) throws InternalErrorException; + + /** + * Check if a user is a group. + * + * @param groupId the group id + * @return true if the user is a group, false otherwise + * @throws InternalErrorException the internal error exception + */ + boolean isGroup(String groupId) throws InternalErrorException; + + /** + * Get public folders. + * + * @return a list of public folder + * @throws InternalErrorException the internal error exception + */ + List getPublicFolders() throws InternalErrorException; + +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/ACLType.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/ACLType.java new file mode 100644 index 0000000..4ad775b --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/ACLType.java @@ -0,0 +1,37 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared; + + +/** + * The Enum ACLType. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 15, 2018 + */ +public enum ACLType { + + /** + * Access denied to user. + */ + NONE, + /** + * Allow users to only read files. + */ + READ_ONLY, + /** + * Allow users to create, edit and delete their own files. + */ + WRITE_OWNER, + /** + * Allow users to create, edit and delete files of everyone in the share. + */ + WRITE_ALL, + /** + * All privileges. + */ + ADMINISTRATOR; + + +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/AccountingEntry.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/AccountingEntry.java new file mode 100644 index 0000000..672ab5f --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/AccountingEntry.java @@ -0,0 +1,43 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl; + +import java.util.Calendar; + +/** + * The Interface AccountingEntry. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 15, 2018 + */ +public interface AccountingEntry { + + /** + * Gets the user. + * + * @return the user + */ + String getUser(); + + /** + * Gets the date. + * + * @return the date + */ + Calendar getDate(); + + /** + * Gets the entry type. + * + * @return the entry type + */ + String getEntryType(); + + /** + * Gets the version. + * + * @return the version + */ + String getVersion(); +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/Properties.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/Properties.java new file mode 100644 index 0000000..c63d0e2 --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/Properties.java @@ -0,0 +1,67 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl; + +import java.util.Map; + +import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InternalErrorException; + + +/** + * The Interface Properties. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 15, 2018 + */ +public interface Properties { + + /** + * Get ID. + * + * @return the properties id. + * @throws InternalErrorException if an internal error occurs. + */ + public String getId() throws InternalErrorException; + + /** + * Get property value. + * + * @param propertyName the property name. + * @return the property value. + * @throws InternalErrorException the internal error exception + */ + public String getPropertyValue(String propertyName) throws InternalErrorException; + + /** + * Get Properties. + * + * @return the properties map. + * @throws InternalErrorException the internal error exception + */ + public Map getProperties() throws InternalErrorException; + +// /** +// * Add properties to item. +// * +// * @param properties a map of properties +// * @throws InternalErrorException the internal error exception +// */ +// public void addProperties(Map properties) throws InternalErrorException; +// +// /** +// * Save modified properties. +// * +// * @throws InternalErrorException the internal error exception +// */ +// public void update() throws InternalErrorException; +// +// /** +// * Check if the item has a given property. +// * +// * @param property the property +// * @return true, if successful +// * @throws InternalErrorException the internal error exception +// */ +// public boolean hasProperty(String property) throws InternalErrorException; +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/WorkspaceFolder.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/WorkspaceFolder.java new file mode 100644 index 0000000..4fc4cad --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/WorkspaceFolder.java @@ -0,0 +1,16 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl; + + + +/** + * The Interface WorkspaceFolder. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 15, 2018 + */ +public interface WorkspaceFolder extends WorkspaceItem { + +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/WorkspaceItem.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/WorkspaceItem.java new file mode 100644 index 0000000..71d964e --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/WorkspaceItem.java @@ -0,0 +1,179 @@ +/** + * + */ + +package org.gcube.common.storagehubwrapper.shared.tohl; + +import java.util.Calendar; +import java.util.List; + +import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InternalErrorException; +import org.gcube.common.storagehubwrapper.shared.tohl.folder.items.PropertyMap; + +/** + * The Interface WorkspaceItem. Define a Workspace item like folder or + * folder-item. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 15, 2018 + */ +public interface WorkspaceItem { + + /** + * This item id. + * + * @return the id. + * @throws InternalErrorException + * if an internal error occurs. + */ + public String getId() + throws InternalErrorException; + + /** + * This item name. + * + * @return the name. + * @throws InternalErrorException + * if an internal error occurs. + */ + public String getName() + throws InternalErrorException; + + /** + * This item description. + * + * @return the description. + * @throws InternalErrorException + * if an internal error occurs. + */ + public String getDescription() + throws InternalErrorException; + + /** + * This item creation time. + * + * @return the creation time. + * @throws InternalErrorException + * if an internal error occurs. + */ + public Calendar getCreationTime() + throws InternalErrorException; + + /** + * This item last modification time. + * + * @return the last modification time. + * @throws InternalErrorException + * if an internal error occurs. + */ + public Calendar getLastModificationTime() + throws InternalErrorException; + + + /** + * Gets the last modified by. + * + * @return the last modified by + * @throws InternalErrorException the internal error exception + */ + public String getLastModifiedBy() + throws InternalErrorException; + + /** + * This item owner. + * + * @return the owner. + * @throws InternalErrorException + * if an internal error occurs. + */ + public String getOwner() + throws InternalErrorException; + + /** + * Gets the map property. + * + * @return the map property + */ + public PropertyMap getPropertyMap(); + + /** + * Gets the accounting. + * + * @return the accounting + */ + public List getAccounting(); + + /** + * Gets the path. + * + * @return the path + */ + public String getPath(); + + /** + * Gets the parent id. + * + * @return the parent id + */ + public String getParentId(); + + /** + * Return this item type. + * + * @return the type. + */ + public WorkspaceItemType getType(); + + /** + * Says if this item is a root element. + * + * @return true if this element is a root, false + * otherwise. + * @throws InternalErrorException + * if an internal error occurs. + */ + public boolean isRoot() + throws InternalErrorException; + + /** + * Return a flag indicating whether the element is hidden. + * + * @return true if the element is hidden, false if + * the element is visible. + * @throws InternalErrorException + * the internal error exception + */ + public boolean isHidden() + throws InternalErrorException; + + /** + * Return a flag indicating whether the element is shared. + * + * @return true if the element is shared, false + * otherwise. + * @throws InternalErrorException + * the internal error exception + */ + public boolean isShared() + throws InternalErrorException; + + /** + * Check if the item is in the trash. + * + * @return true if the item has been trashed + * @throws InternalErrorException + * the internal error exception + */ + public boolean isTrashed() + throws InternalErrorException; + + /** + * Check if the item is a folder. + * + * @return true if the item is a folder + * @throws InternalErrorException + * the internal error exception + */ + public boolean isFolder() + throws InternalErrorException; +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/WorkspaceItemType.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/WorkspaceItemType.java new file mode 100644 index 0000000..5b7ff74 --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/WorkspaceItemType.java @@ -0,0 +1,50 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl; + + + +/** + * The Enum WorkspaceItemType. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 19, 2018 + */ +public enum WorkspaceItemType { + + /** + * A folder. + */ + FOLDER, + + /** + * A shared folder + */ + SHARED_FOLDER, + + /** + * A smart folder + */ + SMART_FOLDER, + + /** + * A folder item. + */ + FILE_ITEM, + + /** + * A trash folder. + */ + TRASH_FOLDER, + + /** + * A trash item. + */ + TRASH_ITEM, + + + VRE_FOLDER; + + +} \ No newline at end of file diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/WorkspaceSharedFolder.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/WorkspaceSharedFolder.java new file mode 100644 index 0000000..7417ff3 --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/WorkspaceSharedFolder.java @@ -0,0 +1,16 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl; + + + +/** + * The Interface WorkspaceSharedFolder. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 15, 2018 + */ +public interface WorkspaceSharedFolder extends WorkspaceFolder{ + +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/WorkspaceVREFolder.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/WorkspaceVREFolder.java new file mode 100644 index 0000000..fec7885 --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/WorkspaceVREFolder.java @@ -0,0 +1,19 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl; + + + + +/** + * The Interface WorkspaceVREFolder. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 19, 2018 + */ +public interface WorkspaceVREFolder extends WorkspaceSharedFolder { + + + +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/exceptions/InsufficientPrivilegesException.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/exceptions/InsufficientPrivilegesException.java new file mode 100644 index 0000000..aadae63 --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/exceptions/InsufficientPrivilegesException.java @@ -0,0 +1,42 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl.exceptions; + + +/** + * The Class InsufficientPrivilegesException. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 15, 2018 + */ +public class InsufficientPrivilegesException extends WorkspaceException { + + private static final long serialVersionUID = 2423742342338757212L; + + /** + * Create a new internal error exception. + * @param cause the exception cause. + */ + public InsufficientPrivilegesException(Throwable cause) { + super(cause); + } + + /** + * Create a new internal error exception. + * @param message the exception message. + */ + public InsufficientPrivilegesException(String message) { + super(message); + } + + /** + * Create a new internal error exception. + * @param message the exception message. + * @param cause the exception cause. + */ + public InsufficientPrivilegesException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/exceptions/InternalErrorException.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/exceptions/InternalErrorException.java new file mode 100644 index 0000000..0606426 --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/exceptions/InternalErrorException.java @@ -0,0 +1,39 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl.exceptions; + + +/** + * The Class InternalErrorException. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 15, 2018 + */ +public class InternalErrorException extends Exception { + + /** + * + */ + private static final long serialVersionUID = -8885298303989967692L; + + + /** + * Instantiates a new internal error exception. + * + * @param arg0 the arg0 + */ + public InternalErrorException(String arg0) { + super(arg0); + } + + /* (non-Javadoc) + * @see java.lang.Throwable#toString() + */ + @Override + public String toString() { + + // TODO Auto-generated method stub + return super.toString(); + } +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/exceptions/ItemAlreadyExistException.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/exceptions/ItemAlreadyExistException.java new file mode 100644 index 0000000..7706150 --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/exceptions/ItemAlreadyExistException.java @@ -0,0 +1,26 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl.exceptions; + + +/** + * The Class ItemAlreadyExistException. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 15, 2018 + */ +public class ItemAlreadyExistException extends WorkspaceException { + + private static final long serialVersionUID = -2884454770219837164L; + + /** + * Instantiates a new item already exist exception. + * + * @param message the exception message. + */ + public ItemAlreadyExistException(String message) { + super(message); + } + +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/exceptions/ItemNotFoundException.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/exceptions/ItemNotFoundException.java new file mode 100644 index 0000000..18df5a7 --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/exceptions/ItemNotFoundException.java @@ -0,0 +1,26 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl.exceptions; + + +/** + * The Class ItemNotFoundException. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 15, 2018 + */ +public class ItemNotFoundException extends WorkspaceException { + + private static final long serialVersionUID = -553175277581696583L; + + /** + * Instantiates a new item not found exception. + * + * @param message the exception message. + */ + public ItemNotFoundException(String message) { + super(message); + } + +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/exceptions/WorkspaceException.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/exceptions/WorkspaceException.java new file mode 100644 index 0000000..fe107a1 --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/exceptions/WorkspaceException.java @@ -0,0 +1,52 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl.exceptions; + + +/** + * A super class for all the workspace exceptions. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 15, 2018 + */ +public class WorkspaceException extends Exception{ + + + /** + * + */ + private static final long serialVersionUID = -5657714325026850145L; + + /** + * + */ + public WorkspaceException() { + + } + /** + * Create a new workspace exception. + * @param message the exception message. + * @param cause the exception cause. + */ + public WorkspaceException(String message, Throwable cause) { + super(message, cause); + } + + /** + * Create a new workspace exception. + * @param message the exception message. + */ + public WorkspaceException(String message) { + super(message); + } + + /** + * Create a new workspace exception. + * @param cause the exception cause. + */ + public WorkspaceException(Throwable cause) { + super(cause); + } + +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/exceptions/WorkspaceFolderAlreadyExistException.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/exceptions/WorkspaceFolderAlreadyExistException.java new file mode 100644 index 0000000..1ea5338 --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/exceptions/WorkspaceFolderAlreadyExistException.java @@ -0,0 +1,25 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl.exceptions; + +/** + * The Class WorkspaceFolderAlreadyExistException. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 15, 2018 + */ +public class WorkspaceFolderAlreadyExistException extends WorkspaceException { + + private static final long serialVersionUID = -6285161417298571997L; + + /** + * Instantiates a new workspace folder already exist exception. + * + * @param message the exception message. + */ + public WorkspaceFolderAlreadyExistException(String message) { + super(message); + } + +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/exceptions/WorkspaceFolderNotFoundException.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/exceptions/WorkspaceFolderNotFoundException.java new file mode 100644 index 0000000..2ddb4a6 --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/exceptions/WorkspaceFolderNotFoundException.java @@ -0,0 +1,25 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl.exceptions; + + +/** + * The Class WorkspaceFolderNotFoundException. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 15, 2018 + */ +public class WorkspaceFolderNotFoundException extends WorkspaceException { + + private static final long serialVersionUID = -729077599735921718L; + + /** + * Instantiates a new workspace folder not found exception. + * + * @param msg the exception message. + */ + public WorkspaceFolderNotFoundException(String msg) { + super(msg); + } +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/exceptions/WrongDestinationException.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/exceptions/WrongDestinationException.java new file mode 100644 index 0000000..e78d0cc --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/exceptions/WrongDestinationException.java @@ -0,0 +1,27 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl.exceptions; + + +/** + * The Class WrongDestinationException. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 15, 2018 + */ +public class WrongDestinationException extends WorkspaceException { + + private static final long serialVersionUID = -1765035358366830708L; + + /** + * Instantiates a new wrong destination exception. + * + * @param message the exception message. + */ + public WrongDestinationException(String message) { + super(message); + } + + +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/exceptions/WrongItemTypeException.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/exceptions/WrongItemTypeException.java new file mode 100644 index 0000000..2c95810 --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/exceptions/WrongItemTypeException.java @@ -0,0 +1,24 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl.exceptions; + +/** + * The Class WrongItemTypeException. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 15, 2018 + */ +public class WrongItemTypeException extends WorkspaceException { + + private static final long serialVersionUID = -5013356582135921634L; + + /** + * Instantiates a new wrong item type exception. + * + * @param message the exception message. + */ + public WrongItemTypeException(String message) { + super(message); + } +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/exceptions/WrongParentTypeException.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/exceptions/WrongParentTypeException.java new file mode 100644 index 0000000..d97b09c --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/exceptions/WrongParentTypeException.java @@ -0,0 +1,27 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl.exceptions; + + +/** + * The Class WrongParentTypeException. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 15, 2018 + */ +public class WrongParentTypeException extends WorkspaceException { + + private static final long serialVersionUID = -6202770939428067425L; + + /** + * Instantiates a new wrong parent type exception. + * + * @param message the exception message. + */ + public WrongParentTypeException(String message) { + super(message); + } + + +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/folder/items/File.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/folder/items/File.java new file mode 100644 index 0000000..29a2b96 --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/folder/items/File.java @@ -0,0 +1,42 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl.folder.items; + +import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InternalErrorException; + +/** + * The Interface File. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 15, 2018 + */ +public interface File { + + + /** + * Gets the folder item type. + * + * @return the folder item type + */ + public FileItemType getFileItemType(); + + + /** + * Gets the size. + * + * @return the size + * @throws InternalErrorException the internal error exception + */ + public Long getSize() throws InternalErrorException; + + /** + * The folder myme type. + * + * @return the myme type + * @throws InternalErrorException the internal error exception + */ + public String getMimeType() throws InternalErrorException; + + +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/folder/items/FileItem.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/folder/items/FileItem.java new file mode 100644 index 0000000..b1d8101 --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/folder/items/FileItem.java @@ -0,0 +1,27 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl.folder.items; + + +import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem; +import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InternalErrorException; + + +/** + * The Interface FolderItem. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 15, 2018 + */ +public interface FileItem extends WorkspaceItem, File { + + /** + * Get Current version. + * + * @return the current version + * @throws InternalErrorException the internal error exception + */ + public WorkspaceVersion getCurrentVersion() throws InternalErrorException; + +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/folder/items/FileItemType.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/folder/items/FileItemType.java new file mode 100644 index 0000000..2cefe6a --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/folder/items/FileItemType.java @@ -0,0 +1,52 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl.folder.items; + +import org.gcube.common.storagehub.model.types.GenericItemType; + + +/** + * The Enum FileItemType. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 21, 2018 + */ +public enum FileItemType implements GenericItemType{ + + /** + * Document. + */ + DOCUMENT, + + /** + * Image document. + */ + IMAGE_DOCUMENT, + + /** + * PDF document. + */ + PDF_DOCUMENT, + + /** + * Url document. + */ + URL_DOCUMENT, + + /** + * Metadata. + */ + METADATA, + + /** + * Trash item + */ + TRASH_ITEM, + + /** + * A gCube item. + */ + GCUBE_ITEM + +} \ No newline at end of file diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/folder/items/GCubeItem.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/folder/items/GCubeItem.java new file mode 100644 index 0000000..6d0544d --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/folder/items/GCubeItem.java @@ -0,0 +1,61 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl.folder.items; + +import java.io.InputStream; +import java.util.List; + +import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceSharedFolder; +import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InternalErrorException; + + +/** + * The Interface GCubeItem. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 15, 2018 + */ +public interface GCubeItem extends FileItem { + + /** + * Gets the scopes. + * + * @return the scopes + * @throws InternalErrorException the internal error exception + */ + public List getScopes() throws InternalErrorException; + + /** + * Gets the item type. + * + * @return the item type + */ + public String getItemType(); + + /** + * Gets the creator. + * + * @return the creator + */ + public String getCreator(); + + /** + * Share. + * + * @param users the users + * @return the workspace shared folder + * @throws InternalErrorException the internal error exception + */ + public WorkspaceSharedFolder share(List users) throws InternalErrorException; + + /** + * Gets the data. + * + * @return the data + * @throws InternalErrorException the internal error exception + */ + public InputStream getData() throws InternalErrorException; + + +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/folder/items/Image.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/folder/items/Image.java new file mode 100644 index 0000000..eb02b5b --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/folder/items/Image.java @@ -0,0 +1,51 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl.folder.items; + +import java.io.InputStream; + +import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InternalErrorException; + + +/** + * The Interface Image. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 15, 2018 + */ +public interface Image extends File { + + /** + * The image width. + * @return the width. + */ + public Long getWidth(); + + /** + * The image height. + * @return the height. + */ + public Long getHeight(); + + /** + * The image thumbnail. + * @return the thumbnail. + * @throws InternalErrorException if an internal error occurs. + */ + public InputStream getThumbnail() throws InternalErrorException; + + /** + * The image thumbanil width. + * @return the thumbnail width. + */ + public Long getThumbnailWidth(); + + /** + * The image thumbnail height. + * @return the thumbnail height. + */ + public Long getThumbnailHeight(); + + +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/folder/items/ImageFileItem.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/folder/items/ImageFileItem.java new file mode 100644 index 0000000..dcc9cf0 --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/folder/items/ImageFileItem.java @@ -0,0 +1,15 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl.folder.items; + + +/** + * The Interface FileItemImage. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 21, 2018 + */ +public interface ImageFileItem extends FileItem, Image { + +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/folder/items/PDFFileItem.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/folder/items/PDFFileItem.java new file mode 100644 index 0000000..88abb57 --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/folder/items/PDFFileItem.java @@ -0,0 +1,55 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl.folder.items; + + +/** + * The Interface FileItemPDF. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 21, 2018 + */ +public interface PDFFileItem extends FileItem{ + + /** + * Gets the number of pages. + * + * @return the numberOfPages + */ + public Long getNumberOfPages(); + + + /** + * Gets the version. + * + * @return the version + */ + public String getVersion(); + + + /** + * Gets the author. + * + * @return the author + */ + public String getAuthor(); + + + /** + * Gets the title. + * + * @return the title + */ + public String getTitle(); + + + /** + * Gets the producer. + * + * @return the producer + */ + public String getProducer(); + + +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/folder/items/PropertyMap.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/folder/items/PropertyMap.java new file mode 100644 index 0000000..3a1dff5 --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/folder/items/PropertyMap.java @@ -0,0 +1,23 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl.folder.items; + +import java.util.Map; + + +/** + * The Interface PropertyMap. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 22, 2018 + */ +public interface PropertyMap { + + /** + * Gets the values. + * + * @return the values + */ + public Map getValues(); +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/folder/items/URLFileItem.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/folder/items/URLFileItem.java new file mode 100644 index 0000000..e6cf27b --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/folder/items/URLFileItem.java @@ -0,0 +1,16 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl.folder.items; + + +/** + * The Interface FileItemURL. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 21, 2018 + */ +public interface URLFileItem extends FileItem{ + + +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/folder/items/WorkspaceVersion.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/folder/items/WorkspaceVersion.java new file mode 100644 index 0000000..c2b8afd --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/folder/items/WorkspaceVersion.java @@ -0,0 +1,60 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl.folder.items; + +import java.util.Calendar; + + +/** + * The Interface WorkspaceVersion. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 15, 2018 + */ +public interface WorkspaceVersion { + + /** + * Gets the name. + * + * @return the name + */ + public String getName(); + + /** + * Gets the created. + * + * @return the created + */ + public Calendar getCreated(); + + /** + * Gets the user. + * + * @return the user + */ + public String getUser(); + + /** + * Gets the remote path. + * + * @return the remote path + */ + public String getRemotePath(); + + /** + * Gets the size. + * + * @return the size + */ + public long getSize(); + + /** + * Checks if is current version. + * + * @return true, if is current version + */ + public boolean isCurrentVersion(); + + +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/AccountingEntry.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/AccountingEntry.java new file mode 100644 index 0000000..fe8dca0 --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/AccountingEntry.java @@ -0,0 +1,35 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl.impl; + +import java.io.Serializable; +import java.util.Calendar; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + + +/** + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Jun 15, 2018 + */ +@Getter +@NoArgsConstructor +@AllArgsConstructor +public class AccountingEntry implements org.gcube.common.storagehubwrapper.shared.tohl.AccountingEntry, Serializable{ + + /** + * + */ + private static final long serialVersionUID = 2880510084929441352L; + + String user; + Calendar date; + String entryType; + String version; + String primaryType; + +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/FileItem.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/FileItem.java new file mode 100644 index 0000000..911edc1 --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/FileItem.java @@ -0,0 +1,85 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl.impl; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InternalErrorException; +import org.gcube.common.storagehubwrapper.shared.tohl.folder.items.FileItemType; +import org.gcube.common.storagehubwrapper.shared.tohl.folder.items.WorkspaceVersion; + + + +/** + * The Class FileItem. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 21, 2018 + */ +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter +public class FileItem extends WorkspaceItem implements org.gcube.common.storagehubwrapper.shared.tohl.folder.items.FileItem { + + /** + * + */ + private static final long serialVersionUID = -4149282274165182444L; + + + private FileItemType fileItemType; + private Long size; + private String mimeType; + private WorkspaceVersion currentVersion; + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.tohl.folder.items.File#getFolderItemType() + */ + @Override + public FileItemType getFileItemType() { + + // TODO Auto-generated method stub + return fileItemType; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.tohl.folder.items.File#getSize() + */ + @Override + public Long getSize() + throws InternalErrorException { + + // TODO Auto-generated method stub + return size; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.tohl.folder.items.File#getMimeType() + */ + @Override + public String getMimeType() + throws InternalErrorException { + + // TODO Auto-generated method stub + return mimeType; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.tohl.folder.items.FileItem#getCurrentVersion() + */ + @Override + public WorkspaceVersion getCurrentVersion() + throws InternalErrorException { + + // TODO Auto-generated method stub + return currentVersion; + } + + + +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/ImageFile.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/ImageFile.java new file mode 100644 index 0000000..9e7d19b --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/ImageFile.java @@ -0,0 +1,88 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl.impl; + +import java.io.InputStream; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InternalErrorException; + + +/** + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Jun 21, 2018 + */ +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter +@ToString(callSuper=false) +public class ImageFile extends FileItem implements org.gcube.common.storagehubwrapper.shared.tohl.folder.items.ImageFileItem{ + /** + * + */ + private static final long serialVersionUID = 7586826417080458164L; + + private Long width; + private Long height; + private Long thumbnailWidth; + private Long thumbnailHeight; + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.tohl.folder.items.Image#getWidth() + */ + @Override + public Long getWidth() { + + // TODO Auto-generated method stub + return width; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.tohl.folder.items.Image#getHeight() + */ + @Override + public Long getHeight() { + + // TODO Auto-generated method stub + return height; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.tohl.folder.items.Image#getThumbnail() + */ + @Override + public InputStream getThumbnail() + throws InternalErrorException { + + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.tohl.folder.items.Image#getThumbnailWidth() + */ + @Override + public Long getThumbnailWidth() { + + // TODO Auto-generated method stub + return thumbnailWidth; + } + + /* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.tohl.folder.items.Image#getThumbnailHeight() + */ + @Override + public Long getThumbnailHeight() { + + // TODO Auto-generated method stub + return thumbnailHeight; + } +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/PDFFile.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/PDFFile.java new file mode 100644 index 0000000..2cdbe78 --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/PDFFile.java @@ -0,0 +1,43 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl.impl; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + + + + +/** + * The Interface FileItemURL. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 21, 2018 + */ +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter +@ToString(callSuper=false) +public class PDFFile extends FileItem implements org.gcube.common.storagehubwrapper.shared.tohl.folder.items.PDFFileItem{ + + /** + * + */ + private static final long serialVersionUID = 1367372682598677200L; + + Long numberOfPages; + + String version; + + String author; + + String title; + + String producer; + +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/PropertyMap.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/PropertyMap.java new file mode 100644 index 0000000..316605f --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/PropertyMap.java @@ -0,0 +1,27 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl.impl; + +import java.util.HashMap; +import java.util.Map; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + + +/** + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Jun 22, 2018 + */ +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +public class PropertyMap implements org.gcube.common.storagehubwrapper.shared.tohl.folder.items.PropertyMap{ + + Map values = new HashMap(); +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/URLFile.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/URLFile.java new file mode 100644 index 0000000..4aa6f34 --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/URLFile.java @@ -0,0 +1,18 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl.impl; + + + +/** + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Jun 21, 2018 + */ +public class URLFile extends FileItem implements org.gcube.common.storagehubwrapper.shared.tohl.folder.items.URLFileItem{ + /** + * + */ + private static final long serialVersionUID = 7586826417080458164L; +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/WorkspaceFolder.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/WorkspaceFolder.java new file mode 100644 index 0000000..376e271 --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/WorkspaceFolder.java @@ -0,0 +1,33 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl.impl; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; + + + +/** + * The Class WorkspaceFolder. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 20, 2018 + */ + +/** + * Instantiates a new workspace folder. + */ +@Getter +@NoArgsConstructor +@ToString(callSuper=true) +public class WorkspaceFolder extends WorkspaceItem implements org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder{ + /* + * + */ + private static final long serialVersionUID = -3767943529796942863L; + + + +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/WorkspaceItem.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/WorkspaceItem.java new file mode 100644 index 0000000..e016e79 --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/WorkspaceItem.java @@ -0,0 +1,96 @@ +/** + * + */ + +package org.gcube.common.storagehubwrapper.shared.tohl.impl; + +import java.io.Serializable; +import java.util.Calendar; +import java.util.List; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +import org.gcube.common.storagehubwrapper.shared.tohl.AccountingEntry; +import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItemType; +import org.gcube.common.storagehubwrapper.shared.tohl.folder.items.PropertyMap; + +/** + * The Class WorkspaceItemImpl. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Jun 15, 2018 + */ + +/* (non-Javadoc) + * @see org.gcube.portal.storagehubwrapper.shared.tohl.WorkspaceItem#isHidden() + */ +@Getter + +/** + * Sets the folder. + * + * @param isFolder the new folder + */ +@Setter + +/** + * Instantiates a new workspace item. + */ +@NoArgsConstructor + +/** + * Instantiates a new workspace item. + * + * @param id the id + * @param name the name + * @param path the path + * @param parentId the parent id + * @param trashed the trashed + * @param shared the shared + * @param locked the locked + * @param title the title + * @param description the description + * @param lastModifiedBy the last modified by + * @param lastModificationTime the last modification time + * @param creationTime the creation time + * @param owner the owner + * @param hidden the hidden + * @param accounting the accounting + * @param type the type + * @param isFolder the is folder + * @param isRoot the is root + */ +@AllArgsConstructor +@ToString +public class WorkspaceItem implements org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem, Serializable { + + /** + * + */ + private static final long serialVersionUID = 5444534091783292538L; + private String id; + private String name; + private String path; + private String parentId; + //private String primaryType; + private boolean trashed; + private boolean shared; + private boolean locked; + private String title; + private String description; + private String lastModifiedBy; + private Calendar lastModificationTime; + private Calendar creationTime; + private String owner; + //private ItemAction lastAction; + private boolean hidden; + private List accounting; + private WorkspaceItemType type; + private boolean isFolder; + boolean isRoot; + private PropertyMap propertyMap; + +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/WorkspaceSharedFolder.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/WorkspaceSharedFolder.java new file mode 100644 index 0000000..03cc395 --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/WorkspaceSharedFolder.java @@ -0,0 +1,32 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl.impl; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + + +/** + * The Class WorkspaceFolderImpl. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Jun 15, 2018 + */ +@Getter + +/** + * Instantiates a new workspace folder impl. + */ +@NoArgsConstructor +@Setter +@ToString(callSuper=true) +public class WorkspaceSharedFolder extends WorkspaceFolder implements org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceSharedFolder{ + + private static final long serialVersionUID = -6493111521916500793L; + + private boolean isVreFolder; + +} \ No newline at end of file diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/WorkspaceVREFolder.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/WorkspaceVREFolder.java new file mode 100644 index 0000000..5b2ae48 --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/impl/WorkspaceVREFolder.java @@ -0,0 +1,23 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl.impl; + +import lombok.NoArgsConstructor; +import lombok.ToString; + + +/** + * The Class WorkspaceVREFolder. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 20, 2018 + */ +@NoArgsConstructor +@ToString(callSuper=true) +public class WorkspaceVREFolder extends WorkspaceFolder implements org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceVREFolder{ + /** + * + */ + private static final long serialVersionUID = 1984917908193397527L; +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/trash/WorkspaceTrashFolder.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/trash/WorkspaceTrashFolder.java new file mode 100644 index 0000000..058d1e3 --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/trash/WorkspaceTrashFolder.java @@ -0,0 +1,78 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl.trash; + +import java.util.List; + +import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder; +import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InternalErrorException; +import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.ItemNotFoundException; + + +/** + * The Interface WorkspaceTrashFolder. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 26, 2018 + */ +public interface WorkspaceTrashFolder extends WorkspaceFolder { + + /** + * Empty Trash. + * + * @return a list of WorkspaceItem ids not removed; the list is null if every item has been removed + * @throws InternalErrorException the internal error exception + */ + public List emptyTrash() throws InternalErrorException; + + /** + * Delete permanently a specific item. + * + * @param id item to delete + * @throws InternalErrorException the internal error exception + */ + public void deletePermanentlyById(String id) throws InternalErrorException; + + /** + * Restore all item in Trash. + * + * @return a list of WorkspaceItem ids not restored; the list is null if every item has been restored + * @throws InternalErrorException the internal error exception + */ + public List restoreAll() throws InternalErrorException; + + /** + * Restore a specific item. + * + * @param id item to restore + * @throws InternalErrorException the internal error exception + */ + public void restoreById(String id) throws InternalErrorException; + + + /** + * Get trashed items. + * + * @return the list of trashed items + * @throws InternalErrorException the internal error exception + * @throws ItemNotFoundException the item not found exception + * @deprecated use {@link #getChildren()} instead + */ + @Deprecated + public List listTrashItems() throws InternalErrorException, ItemNotFoundException; + + /** + * Get Trash Item by Id. + * + * @param id of a trashed item + * @return a trashed item + * @throws InternalErrorException the internal error exception + * @deprecated use {@link org.gcube.portal.storagehubwrapper.server.tohl.homelibrary.home.workspace.Workspace#getItem(String itemId)} instead + */ + @Deprecated + public WorkspaceTrashItem getTrashItemById(String id) throws InternalErrorException; + + + +} diff --git a/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/trash/WorkspaceTrashItem.java b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/trash/WorkspaceTrashItem.java new file mode 100644 index 0000000..b87819e --- /dev/null +++ b/src/main/java/org/gcube/common/storagehubwrapper/shared/tohl/trash/WorkspaceTrashItem.java @@ -0,0 +1,91 @@ +/** + * + */ +package org.gcube.common.storagehubwrapper.shared.tohl.trash; + +import java.util.Calendar; + +import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder; +import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItemType; +import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InternalErrorException; + +/** + * The Interface WorkspaceTrashItem. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jun 15, 2018 + */ +public interface WorkspaceTrashItem extends WorkspaceFolder { + + /** + * Get original parent Id to restore the item. + * + * @return the original parent Id to restore the item + */ + String getOriginalParentId(); + + /** + * Get the path where the item was deleted. + * + * @return the path where the item was deleted + */ + String getDeletedFrom(); + + /** + * Get the user who deleted the item. + * + * @return the user who deleted the item + */ + String getDeletedBy(); + + /** + * Get the date when the item was deleted. + * + * @return the date when the item was deleted + */ + Calendar getDeletedTime(); + + /** + * Return true if the trash item was a folder. + * + * @return true if the trash item was a folder, false otherwise + */ + boolean isFolder(); + + /** + * Get mime type. + * + * @return the mime type of the trashed item + * @throws InternalErrorException the internal error exception + */ + String getMimeType() throws InternalErrorException; + + /** + * Get the name of the trashed item. + * + * @return the name of the trashed item + * @throws InternalErrorException the internal error exception + */ + String getName() throws InternalErrorException; + + /** + * Return this item type. + * @return the type. + */ + WorkspaceItemType getType(); + + /** + * Delete Permanently an item in the trash folder. + * + * @throws InternalErrorException the internal error exception + */ + void deletePermanently() throws InternalErrorException; + + /** + * Restore an item in the trash folder. + * + * @throws InternalErrorException the internal error exception + */ + void restore() throws InternalErrorException; + +} \ No newline at end of file diff --git a/src/test/java/WorkspaceInstance.java b/src/test/java/WorkspaceInstance.java new file mode 100644 index 0000000..fdae7ce --- /dev/null +++ b/src/test/java/WorkspaceInstance.java @@ -0,0 +1,162 @@ +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.gcube.common.storagehubwrapper.server.StorageHubWrapper; +import org.gcube.common.storagehubwrapper.server.tohl.Workspace; +import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder; +import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem; +import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InternalErrorException; +import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.ItemNotFoundException; +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 + */ +public class WorkspaceInstance { + + + + public static String USERNAME = "francesco.mangiacrapa"; + public static String SCOPE = "/gcube"; + public static String TOKEN = "0e2c7963-8d3e-4ea6-a56d-ffda530dd0fa-98187548"; + + StorageHubWrapper storageHubWrapper = null; + //Workspace workspace = null; + + + @Before + public void init(){ + + //METHOD 1 + storageHubWrapper = new StorageHubWrapper(SCOPE, TOKEN); + //workspace = storageHubWrapper.getWorkspace(); + + //METHOD 2 +// StorageHubClientService storageHubClientService = new StorageHubClientService(SCOPE, TOKEN); +// workspace = new WorkspaceStorageHubClientService.WorkspaceStorageHubClientServiceBuilder(storageHubClientService). +// withAccounting(true). +// withMapProperties(true). +// build(); + } + + @Test + public void getRoot() { + System.out.println("Get Root test"); + WorkspaceFolder root; + try { + root = storageHubWrapper.getWorkspace().getRoot(); + System.out.println(root); + } + catch (InternalErrorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + //@Test + public void getChildren() throws InternalErrorException{ + System.out.println("Get children test"); + + WorkspaceFolder root = storageHubWrapper.getWorkspace().getRoot(); + + try { + List children = storageHubWrapper.getWorkspace().getChildren(root.getId()); + int i = 0; + for (WorkspaceItem workspaceItem : children) { + System.out.println(++i+")"+workspaceItem); + System.out.println(workspaceItem.getType() +" "+workspaceItem.getClass()); + } + } + catch (InternalErrorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + @Test + public void getWorkspaceId() { + System.out.println("Getting the workspaceId"); + try { + Workspace workspace = storageHubWrapper.getWorkspace(); + if(workspace!=null){ + WorkspaceFolder root = workspace.getRoot(); + System.out.println("Retrieve the root "+root.getId()+" correctly"); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void getChildrenPerWorkspaceItem() throws InternalErrorException{ + System.out.println("Get children test per workspace item"); + + WorkspaceFolder root = storageHubWrapper.getWorkspace().getRoot(); + + try { + List children = storageHubWrapper.getWorkspace().getChildren(root.getId()); + int i = 0; + Map> map = new HashMap>(); + for (WorkspaceItem workspaceItem : children) { + String key = workspaceItem.getType().name(); + List list = map.get(key); + if(list==null){ + list = new ArrayList(); + } + + list.add(workspaceItem); + map.put(key, list); + } + + for (String key : map.keySet()) { + List list = map.get(key); + for (WorkspaceItem workspaceItem : list) { + switch (workspaceItem.getType()) { + case FILE_ITEM: + FileItem fileItem = (FileItem) workspaceItem; + 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(completeItem); + break; + case IMAGE_DOCUMENT: + ImageFile imageFile = (ImageFile) fileItem; + System.out.println("IMAGE_DOCUMENT "+imageFile); + break; + default: + break; + } + + System.out.println(fileItem.getFileItemType() +" "+workspaceItem.getClass()); + + + break; + default: + break; + } + } + } + } + catch (InternalErrorException | ItemNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } +}