Class Directory

  • All Implemented Interfaces:
    AccessControlled, Identifiable, Nameable, Ownable, Removable, Shareable, SystemItem

    public class Directory
    extends SharedItem
    implements Nameable, Removable, SystemItem
    This is used to represent directory items. Directories can be used to group File:s into more manageable compartments. Directories can be organised into an arbitrarily deep tree-like structure. For each directory no two sub-directories may have the same name, and no two files may have the same name. However, it is legal for a file to have the same name as a directory.
    Version:
    2.0
    Author:
    enell
    Last modified
    $Date: 2017-05-22 14:35:27 +0200 (må, 22 maj 2017) $
    • Field Detail

      • HOME

        public static final String HOME
        The id for the Directory item representing the home directory. The home directory is the parent directory for the user's home directories.
        See Also:
        Constant Field Values
      • TEMPLATE

        public static final String TEMPLATE
        The id for the Directory item representing the template directory. The template directory is used to create the directory structure for new users.
        See Also:
        Constant Field Values
    • Constructor Detail

      • Directory

        Directory​(DirectoryData data)
        Creates a new directory item from the given data.
        Parameters:
        data - the data.
    • Method Detail

      • getNew

        public static Directory getNew​(DbControl dc,
                                       Directory parent)
                                throws BaseException
        Create a new Directory item.
        Parameters:
        dc - The DbControl which will be used for permission checking and database access.
        parent - The parent directory for this directory. It cannot be null
        Returns:
        The new Directory item
        Throws:
        PermissionDeniedException - This exception is thrown if the logged in user doesn't have CREATE permission for this type of items
        BaseException - This exception is thrown if there is another error
      • getNew

        public static Directory getNew​(DbControl dc,
                                       Path path)
        Create a new or existing Directory from a path. Every directory that doesn't exist is created.

        NOTE! If the directory given by the path already exists, the existing directory object is returned. Since there is existing code that expects this behavior we will not change the implementation to throw an exception which might have been expected.

        Parameters:
        dc - The DbControl which will be used for permission checking and database access
        path - The path to create
        Returns:
        The directory representing the path
      • getIdFromPath

        public static int getIdFromPath​(DbControl dc,
                                        Path path)
                                 throws BaseException
        Get the id of a directory when you know the path.
        Parameters:
        dc - The DbControl which will be used for permission checking and database access.
        path - The path to the directory to load
        Returns:
        The id of the Directory item
        Throws:
        ItemNotFoundException - If an item with the specified path is not found
        BaseException - If there is another error
      • exists

        public static boolean exists​(DbControl dc,
                                     Directory directory,
                                     String subdirectoryName)
                              throws BaseException
        Checks if a subdirectory with the specified name exists in a directory.
        Parameters:
        dc - The DbControl which will be used for permission checking and database access.
        directory - The directory to check in
        subdirectoryName - The name of the subdirectory to look for
        Returns:
        TRUE if the file exists, FALSE otherwise
        Throws:
        BaseException - If there is an error
      • createHomeDirectory

        public static Directory createHomeDirectory​(DbControl dc,
                                                    User user,
                                                    boolean copyTemplate)
                                             throws PermissionDeniedException,
                                                    BaseException
        Creates a homedirectory for a specified user. The Directory will be placed in the predefined home directory, HOME.
        Parameters:
        dc - The DbControl which will be used for permission checking and database access.
        user - The user whose home directry should be created.
        copyTemplate - TRUE if the new home directory shold copy the directory structure in the template directory.
        Returns:
        The new hom directory.
        Throws:
        PermissionDeniedException - If the logged in user doesn't have Permission.WRITE or Permission.CREATE permission to the item.
        BaseException - If there is another error.
      • copySubdirectories

        public static void copySubdirectories​(DbControl dc,
                                              Directory from,
                                              Directory to,
                                              User owner)
                                       throws BaseException
        This method copies a directory strucure to the destination directory.
        Parameters:
        dc - The DbControl which will be used for permission checking and database access.
        from - The source directory to copy
        to - The destination directory where the new directory structure is created
        owner - The owner of the destination directory
        Throws:
        BaseException - If there is an error
      • getQuery

        public static ItemQuery<Directory> getQuery()
        Get a query configured to retrieve directories.
        Returns:
        An ItemQuery object
      • getName

        public String getName()
        Description copied from interface: Nameable
        Get the name of the item.
        Specified by:
        getName in interface Nameable
        Returns:
        A String with the name of the item
      • getDescription

        public String getDescription()
        Description copied from interface: Nameable
        Get the description for the item.
        Specified by:
        getDescription in interface Nameable
        Returns:
        A String with a description of the item
      • getType

        public Item getType()
        Description copied from interface: Identifiable
        Get the type of item represented by the object. The returned value is one of the values defined in the Item enumeration.
        Specified by:
        getType in interface Identifiable
        Returns:
        A value indicating the type of item
      • isRemoved

        public boolean isRemoved()
        Description copied from interface: Removable
        Check if the removed flag is set for this item.
        Specified by:
        isRemoved in interface Removable
        Returns:
        TRUE if the item is flagged as removed, FALSE otherwise
      • getSystemId

        public String getSystemId()
        Description copied from interface: SystemItem
        Get the system id for the item.
        Specified by:
        getSystemId in interface SystemItem
        Returns:
        The id of the item or null if it is not a system item
      • isSystemItem

        public boolean isSystemItem()
        Description copied from interface: SystemItem
        Check if the item is a system item or not. A system item have a non-null value for the system id.
        Specified by:
        isSystemItem in interface SystemItem
        Returns:
        TRUE if this item is a system item, FALSE otherwise
      • isUsed

        public boolean isUsed()
                       throws BaseException
        Check that:
        • no files are in the directory
        • no subdirectories are in the directory
        • no user has this directory as the home directory
        Overrides:
        isUsed in class BasicItem
        Returns:
        TRUE if the directory is used.
        Throws:
        BaseException - If there is an error.
        See Also:
        BasicItem.getUsingItems()
      • initPermissions

        void initPermissions​(int granted,
                             int denied)
                      throws BaseException
        Description copied from class: SharedItem
        Grant permissions according to the item and project keys.
        Overrides:
        initPermissions in class SharedItem
        Parameters:
        granted - Permissions that have been granted by the subclass
        denied - Permissions that have been denied by the subclass
        Throws:
        BaseException - If the permissions couldn't be initialised
      • getAutoCompress

        public boolean getAutoCompress()
        If files that are uploaded to this directory should be compressed or not. This setting only affects files when they are uploaded. It doesn't affect files that are moved between directories.
        Returns:
        TRUE to automatically compress files uploaded to this directory
        Since:
        2.5
      • setAutoCompress

        public void setAutoCompress​(boolean autoCompress)
                             throws PermissionDeniedException
        Set if files of should automatically be compressed when they are uploaded to this directory.
        Parameters:
        autoCompress - TRUE to enable auto-compression
        Throws:
        PermissionDeniedException - If the logged in user doesn't have write permission
        Since:
        2.5
      • getAutoShare

        public boolean getAutoShare()
        If new files and subdirectories that are created in this directory automatically should be shared wtih the same permissions as this directory. This setting only affects new files/directories.
        Returns:
        TRUE to automatically share new files and subdreictories
        Since:
        2.8
      • setAutoShare

        public void setAutoShare​(boolean autoShare)
                          throws PermissionDeniedException
        Set if new files and subdirectories of should automatically be shared with the same permissions as this directory. If a project is active and this directory isn't already shared to the project, the permissions will be extended to also share the new item to the project.
        Parameters:
        autoShare - TRUE to enable auto-sharing
        Throws:
        PermissionDeniedException - If the logged in user doesn't have write permission
        Since:
        2.8
      • isRootDirectory

        public boolean isRootDirectory()
        Returns TRUE if this directories parent equals null and therfore is a root directory.
        Returns:
        TRUE if this directory is root directory.
      • isHomeDirectory

        public boolean isHomeDirectory()
        Returns TRUE if this directory is a subdirectory to HOME.
        Returns:
        TRUE is this directory is a home directory.
      • getPath

        public Path getPath()
        Get the complete path to this directory.
        Returns:
        A Path object
      • getSubDirectories

        public ItemQuery<Directory> getSubDirectories()
        Get a query that return subdirectories of this directory.
        Returns:
        An ItemQuery object
      • getFiles

        public ItemQuery<File> getFiles()
        Get a query that return all files in this directory.
        Returns:
        An ItemQuery object