Class StorageHubClientService


  • public class StorageHubClientService
    extends Object
    The Class StorageHubClientService.
    Author:
    Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) Nov 22, 2018
    • Field Detail

      • ACCOUNTING_HL_NODE_NAME

        public static final String ACCOUNTING_HL_NODE_NAME
        The Constant ACCOUNTING_HL_NODE_NAME.
        See Also:
        Constant Field Values
    • Constructor Detail

      • StorageHubClientService

        public StorageHubClientService​(String scope,
                                       String authorizationToken)
        Instantiates a new storage hub service util.
        Parameters:
        scope - the scope
        authorizationToken - the authorization token
    • Method Detail

      • getRoot

        public org.gcube.common.storagehub.model.items.FolderItem getRoot()
                                                                   throws Exception
        Gets the root.
        Returns:
        the root
        Throws:
        Exception - the exception
      • getTrash

        public org.gcube.common.storagehub.model.items.Item getTrash()
        Gets the root.
        Returns:
        the root
      • getChildren

        public List<? extends org.gcube.common.storagehub.model.items.Item> getChildren​(String id,
                                                                                        boolean withAccounting,
                                                                                        boolean withMapProperties)
                                                                                 throws Exception
        Gets the children.
        Parameters:
        id - the id
        withAccounting - the with accounting
        withMapProperties - the with map properties
        Returns:
        the children
        Throws:
        Exception - the exception
      • getChildren

        public List<? extends org.gcube.common.storagehub.model.items.Item> getChildren​(String id,
                                                                                        boolean withAccounting,
                                                                                        boolean withMapProperties,
                                                                                        boolean includeHidden)
                                                                                 throws Exception
        Gets the children.
        Parameters:
        id - the id
        withAccounting - the with accounting
        withMapProperties - the with map properties
        includeHidden - the include hidden
        Returns:
        the children
        Throws:
        Exception - the exception
      • getFilteredChildren

        public List<? extends org.gcube.common.storagehub.model.items.Item> getFilteredChildren​(String id,
                                                                                                Class<? extends org.gcube.common.storagehub.model.items.Item> aType,
                                                                                                boolean withAccounting,
                                                                                                boolean withMapProperties)
                                                                                         throws Exception
        Gets the filtered children.
        Parameters:
        id - the id
        aType - the a type
        withAccounting - the with accounting
        withMapProperties - the with map properties
        Returns:
        the filtered children
        Throws:
        Exception - the exception
      • getItem

        public org.gcube.common.storagehub.model.items.Item getItem​(String itemId,
                                                                    boolean withAccounting,
                                                                    boolean withMetadata)
                                                             throws Exception
        Gets the item.
        Parameters:
        itemId - the item id
        withAccounting - the with accounting
        withMetadata - the with metadata
        Returns:
        the item
        Throws:
        Exception - the exception
      • getItemByPath

        public org.gcube.common.storagehub.model.items.Item getItemByPath​(String folderId,
                                                                          String relativePath)
                                                                   throws Exception
        Gets the item by path.
        Parameters:
        folderId - the folder id
        relativePath - the relative path
        Returns:
        the item by path
        Throws:
        Exception - the exception
      • getItem

        public org.gcube.common.storagehub.model.items.Item getItem​(String itemId)
                                                             throws Exception
        Gets the item.
        Parameters:
        itemId - the item id
        Returns:
        the item
        Throws:
        Exception - the exception
      • setMetadata

        public org.gcube.common.storagehub.model.items.Item setMetadata​(String itemId,
                                                                        org.gcube.common.storagehub.model.Metadata metadata)
                                                                 throws Exception
        Sets the metadata and returns the Item with metadata updated.
        Parameters:
        itemId - the item id
        metadata - the metadata
        Returns:
        the item
        Throws:
        Exception - the exception
      • getMetadata

        public Map<String,​Object> getMetadata​(String itemId)
                                             throws Exception
        Gets the metadata.
        Parameters:
        itemId - the item id
        Returns:
        the metadata
        Throws:
        Exception - the exception
      • getFolderContainer

        public org.gcube.common.storagehub.client.dsl.FolderContainer getFolderContainer​(String itemId)
                                                                                  throws Exception
        Gets the folder container.
        Parameters:
        itemId - the item id
        Returns:
        the folder container
        Throws:
        Exception - the exception
      • getParents

        public List<? extends org.gcube.common.storagehub.model.items.Item> getParents​(String itemId)
                                                                                throws Exception
        Gets the parents.
        Parameters:
        itemId - the item id
        Returns:
        the parents
        Throws:
        Exception - the exception
      • getIdSharedFolder

        public String getIdSharedFolder​(String itemId)
                                 throws Exception
        Gets the id shared folder.
        Parameters:
        itemId - the item id
        Returns:
        the id shared folder
        Throws:
        Exception - the exception
      • getRootSharedFolder

        public org.gcube.common.storagehub.model.items.FolderItem getRootSharedFolder​(String itemId)
                                                                               throws Exception
        Gets the root shared folder.
        Parameters:
        itemId - the item id
        Returns:
        the root shared folder
        Throws:
        Exception - the exception
      • isItemShared

        public boolean isItemShared​(String itemId)
                             throws Exception
        Checks if is item shared.
        Parameters:
        itemId - the item id
        Returns:
        true, if is item shared
        Throws:
        Exception - the exception
      • canWrite

        public boolean canWrite​(String folderContainerId)
                         throws Exception
        Can write.
        Parameters:
        folderContainerId - the folder container id
        Returns:
        true, if true. Otherwise false.
        Throws:
        Exception - the exception
      • getRootSharedFolder

        public org.gcube.common.storagehub.model.items.FolderItem getRootSharedFolder​(org.gcube.common.storagehub.client.dsl.ItemContainer<org.gcube.common.storagehub.model.items.Item> itemContainer)
                                                                               throws Exception
        Gets the root shared folder.
        Parameters:
        itemContainer - the item container
        Returns:
        the root shared folder
        Throws:
        Exception - the exception
      • createFolder

        public org.gcube.common.storagehub.model.items.Item createFolder​(String parentId,
                                                                         String folderName,
                                                                         String folderDescription)
                                                                  throws Exception
        Creates the folder.
        Parameters:
        parentId - the parent id
        folderName - the folder name
        folderDescription - the folder description
        Returns:
        the item
        Throws:
        Exception - the exception
      • getVREFoldersId

        public String getVREFoldersId()
        Gets the VRE folders id.
        Returns:
        the VRE folders id
      • getUserACLForFolderId

        public String getUserACLForFolderId​(String infrastructureName,
                                            String userName,
                                            String folderId)
                                     throws Exception
        Gets the user acl for folder id.
        Parameters:
        infrastructureName - the infrastructure name
        userName - the user name
        folderId - the folder id
        Returns:
        the user acl for folder id
        Throws:
        Exception - the exception
      • getItemChildrenCount

        public int getItemChildrenCount​(String itemId)
                                 throws Exception
        Gets the item children count.
        Parameters:
        itemId - the item id
        Returns:
        the item children count
        Throws:
        Exception - the exception
      • uploadFile

        public org.gcube.common.storagehub.model.items.Item uploadFile​(String folderId,
                                                                       InputStream is,
                                                                       String fileName,
                                                                       String fileDescription,
                                                                       Long fileSize)
                                                                throws Exception
        Upload file.
        Parameters:
        folderId - the folder id
        is - the is
        fileName - the file name
        fileDescription - the file description
        fileSize - the file size
        Returns:
        the item
        Throws:
        Exception - the exception
      • downloadFile

        public org.gcube.common.storagehub.client.StreamDescriptor downloadFile​(String itemId,
                                                                                String versionName,
                                                                                String... nodeIdsToExclude)
                                                                         throws Exception
        Download file.
        Parameters:
        itemId - the item id
        versionName - the version name. If is null or empty returns the latest version of file
        nodeIdsToExclude - the node ids to exclude
        Returns:
        the stream descriptor
        Throws:
        Exception - the exception
      • downloadFolder

        public org.gcube.common.storagehub.client.StreamDescriptor downloadFolder​(String folderId,
                                                                                  String nodeIdsToExclude)
                                                                           throws Exception
        Download folder.
        Parameters:
        folderId - the folder id
        nodeIdsToExclude - the node ids to exclude
        Returns:
        the stream descriptor
        Throws:
        Exception - the exception
      • uploadArchive

        public org.gcube.common.storagehub.model.items.Item uploadArchive​(String folderId,
                                                                          InputStream is,
                                                                          String extractionFolderName,
                                                                          Long fileSize)
                                                                   throws Exception
        Upload archive.
        Parameters:
        folderId - the folder id
        is - the is
        extractionFolderName - the extraction folder name
        fileSize - the file size
        Returns:
        the item
        Throws:
        Exception - the exception
      • getSharedFolderMembers

        public List<Member> getSharedFolderMembers​(String folderId)
                                            throws Exception
        Gets the shared folder members.
        Parameters:
        folderId - the folder id
        Returns:
        the shared folder members
        Throws:
        Exception - the exception
      • getScopeFromVREGroupName

        public static String getScopeFromVREGroupName​(String context,
                                                      String infrastructurName,
                                                      String vreName)
      • findByName

        public List<? extends org.gcube.common.storagehub.model.items.Item> findByName​(String name,
                                                                                       String folderId)
                                                                                throws Exception
        Find by name.
        Parameters:
        name - the name
        folderId - the folder id
        Returns:
        the list
        Throws:
        Exception - the exception
      • searchForText

        public List<? extends org.gcube.common.storagehub.model.items.Item> searchForText​(String text,
                                                                                          String folderId)
                                                                                   throws Exception
        Search for text.
        Parameters:
        text - the text
        folderId - the folder id
        Returns:
        the list
        Throws:
        Exception - the exception
      • deleteItemById

        public void deleteItemById​(String itemId)
                            throws Exception
        Delete item by id.
        Parameters:
        itemId - the item id
        Throws:
        Exception - the exception
      • openTrash

        public org.gcube.common.storagehub.model.items.Item openTrash()
                                                               throws Exception
        Open trash.
        Returns:
        the item
        Throws:
        Exception - the exception
      • emptyTrash

        public void emptyTrash()
                        throws Exception
        Empty trash.
        Throws:
        Exception - the exception
      • restoreThrashItem

        public org.gcube.common.storagehub.model.items.Item restoreThrashItem​(String itemId,
                                                                              String destinationFolderId)
                                                                       throws Exception
        Restore thrash item.
        Parameters:
        itemId - the item id
        destinationFolderId - the destination folder id
        Returns:
        the item
        Throws:
        Exception - the exception
      • moveItem

        public org.gcube.common.storagehub.model.items.Item moveItem​(String itemId,
                                                                     org.gcube.common.storagehub.client.dsl.FolderContainer destFolderContainer)
                                                              throws Exception
        Move item.
        Parameters:
        itemId - the item id
        destFolderContainer - the dest folder container
        Returns:
        the abstract file item
        Throws:
        Exception - the exception
      • copyFileItem

        public org.gcube.common.storagehub.model.items.AbstractFileItem copyFileItem​(String fileItemId,
                                                                                     org.gcube.common.storagehub.client.dsl.FolderContainer destFolderContainer,
                                                                                     String newFileName)
                                                                              throws Exception
        Copy item.
        Parameters:
        fileItemId - the copy item id
        destFolderContainer - the dest folder container
        newFileName - the new file name
        Returns:
        the abstract file item
        Throws:
        Exception - the exception
      • renameItem

        public org.gcube.common.storagehub.model.items.Item renameItem​(String itemId,
                                                                       String newName)
                                                                throws Exception
        Rename item.
        Parameters:
        itemId - the item id
        newName - the new name
        Returns:
        the item
        Throws:
        Exception - the exception
      • getPublicLinkForFile

        public URL getPublicLinkForFile​(String fileItemId)
                                 throws Exception
        Gets the file public link.
        Parameters:
        fileItemId - the file item id
        Returns:
        the file public link
        Throws:
        Exception - the exception
      • getPublicLinkForFileVersion

        public URL getPublicLinkForFileVersion​(String fileItemId,
                                               String version)
                                        throws Exception
        Gets the public link for file version.
        Parameters:
        fileItemId - the file item id
        version - the version
        Returns:
        the public link for file version
        Throws:
        Exception - the exception
      • getListVersions

        public List<org.gcube.common.storagehub.model.service.Version> getListVersions​(String fileItemId)
                                                                                throws Exception
        Gets the list versions.
        Parameters:
        fileItemId - the file item id
        Returns:
        the list versions
        Throws:
        Exception - the exception
      • getImageContent

        public org.gcube.common.storagehub.model.items.nodes.ImageContent getImageContent​(String itemId)
                                                                                   throws Exception
        Gets the image content.
        Parameters:
        itemId - the item id
        Returns:
        the image content
        Throws:
        Exception - the exception
      • getTotalItems

        public long getTotalItems()
                           throws Exception
        Gets the total items.
        Returns:
        the total items
        Throws:
        Exception - the exception
      • getDiskUsage

        public long getDiskUsage()
                          throws Exception
        Gets the disk usage.
        Returns:
        the disk usage
        Throws:
        Exception - the exception
      • getAccounting

        public org.gcube.common.storagehub.model.items.nodes.Accounting getAccounting​(String itemId)
                                                                               throws Exception
        Gets the accounting.
        Parameters:
        itemId - the item id
        Returns:
        the accounting
        Throws:
        Exception - the exception
      • getGcubeItemProperties

        public org.gcube.common.storagehub.model.Metadata getGcubeItemProperties​(String gcubeItemId)
                                                                          throws Exception
        Gets the gcube item properties.
        Parameters:
        gcubeItemId - the gcube item id
        Returns:
        the gcube item properties
        Throws:
        Exception - the exception
      • setMetadata

        public void setMetadata​(String itemId,
                                Map<String,​Object> mapProperties)
                         throws Exception
        Sets the metadata.
        Parameters:
        itemId - the item id
        mapProperties - the map properties
        Throws:
        Exception - the exception
      • setFolderAsHidden

        public void setFolderAsHidden​(String folderId,
                                      boolean hide)
                               throws Exception
        Sets the Folder As Hidden or visible .
        Parameters:
        folderId - the folder id
        hide - true to set hide, false to set visible
        Throws:
        Exception - the exception
      • shareFolder

        public WorkspaceSharedFolder shareFolder​(String folderId,
                                                 Set<String> users,
                                                 ACLType type)
                                          throws Exception
        Share folder.
        Parameters:
        folderId - the folder id to share
        users - the users to share
        type - the permission
        Returns:
        the workspace shared folder
        Throws:
        Exception - the exception
      • unshareFolder

        public WorkspaceSharedFolder unshareFolder​(String folderId,
                                                   Set<String> users)
                                            throws Exception
        Unshare folder.
        Parameters:
        folderId - the folder id to share
        users - the users to share
        Returns:
        the workspace shared folder
        Throws:
        Exception - the exception
      • addURL

        public org.gcube.common.storagehub.model.items.ExternalLink addURL​(String folderId,
                                                                           URL URL,
                                                                           String name,
                                                                           String description)
                                                                    throws org.gcube.common.storagehub.model.exceptions.StorageHubException
        Adds the URL.
        Parameters:
        folderId - the folder id
        URL - the url
        name - the name
        description - the description
        Returns:
        the external link
        Throws:
        org.gcube.common.storagehub.model.exceptions.StorageHubException - the storage hub exception
      • setFolderAsPublic

        public boolean setFolderAsPublic​(String folderId,
                                         boolean setPublic)
                                  throws Exception
        Sets the folder as public.
        Parameters:
        folderId - the folder id
        setPublic - the set public
        Returns:
        boolean value of isPublicItem()
        Throws:
        Exception - the exception
      • updateDescriptionForItem

        public String updateDescriptionForItem​(String itemId,
                                               String newDescription)
                                        throws Exception
        Update description for item.
        Parameters:
        itemId - the item id
        newDescription - the new description
        Returns:
        the description updated
        Throws:
        Exception - the exception
      • toString

        public String toString()
        To string.
        Overrides:
        toString in class Object
        Returns:
        the string