Last update: 2011-06-23

org.proteios.core
Class Directory

java.lang.Object
  extended by org.proteios.core.BasicItem<D>
      extended by org.proteios.core.OwnedItem<D>
          extended by org.proteios.core.SharedItem<DirectoryData>
              extended by org.proteios.core.Directory
All Implemented Interfaces:
AccessControlled, Identifiable, Nameable, Ownable, Removable, Shareable, SystemItem

public class Directory
extends SharedItem<DirectoryData>
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: 2009-10-23 08:06:58 +0200 (Fri, 23 Oct 2009) $

Field Summary
static String HOME
          The id for the Directory item representing the home directory.
static String ROOT
          The id for the Directory item representing the root.
static String TEMPLATE
          The id for the Directory item representing the template directory.
static Item TYPE
          The type of item represented by this class.
 
Fields inherited from interface org.proteios.core.Nameable
MAX_DESCRIPTION_LENGTH, MAX_NAME_LENGTH
 
Method Summary
static boolean exists(DbControl dc, Directory directory, String subdirectoryName)
          Checks if a subdirectory with the specified name exists in a directory.
 Date getCreated()
           
 String getDescription()
          Get the description for the item.
 ItemQuery<File> getFileQuery()
           
 String getName()
          Get the name of the item.
 Directory getParent()
          Get the parent directory of this directory.
 Path getPath()
          Get the complete path to this directory.
 Project getProjectDirectoryProject()
          Returns the project if this directory is assigned to one, else null is returned.
static ItemQuery<Directory> getQuery()
          Get a query configured to retrieve directories.
 ItemQuery<Directory> getSubDirectories()
          Get a query that return subdirectories of this directory.
 String getSystemId()
          Get the system id for the item.
 Item getType()
          Get the type of item represented by the object.
 boolean isHomeDirectory()
          Returns TRUE if this directory is a subdirectory to HOME.
 boolean isProjectDirectory()
          Returns TRUE if this directory is assigned to a project.
 boolean isRemoved()
          Check if the removed flag is set for this item.
 boolean isRootDirectory()
          Returns TRUE if this directories parent equals null and therfore is a root directory.
 boolean isSystemItem()
          Check if the item is a system item or not.
 boolean isUsed()
          Check that: no files are in the directory no subdirectories are in the directory no user has this directory as the home directory
 void setDescription(String description)
          Set the description for the item.
 void setName(String name)
          Set the name of the item.
 void setParent(Directory parent)
          Set the parent directory of this directory.
 void setRemoved(boolean removed)
          Set the removed flag for this item.
 
Methods inherited from class org.proteios.core.SharedItem
getItemKey, getProjectKey, isShared, setItemKey, setProjectKey
 
Methods inherited from class org.proteios.core.OwnedItem
getOwner, setOwner
 
Methods inherited from class org.proteios.core.BasicItem
checkPermission, equals, getDbControl, getId, getPermissions, getSessionControl, getVersion, hashCode, hasPermission, isDetached, isInDatabase, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.proteios.core.Identifiable
getId, getVersion
 
Methods inherited from interface org.proteios.core.AccessControlled
checkPermission, hasPermission
 
Methods inherited from interface org.proteios.core.Ownable
getOwner, setOwner
 

Field Detail

TYPE

public static final Item TYPE
The type of item represented by this class.

See Also:
Item.DIRECTORY, getType()

ROOT

public static final String ROOT
The id for the Directory item representing the root.

See Also:
Constant Field Values

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
Method Detail

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

getQuery

public static ItemQuery<Directory> getQuery()
Get a query configured to retrieve directories.

Returns:
An ItemQuery object

getCreated

public Date getCreated()

getFileQuery

public ItemQuery<File> getFileQuery()
Returns:
An ItemQuery of files in this directory

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

setName

public void setName(String name)
             throws PermissionDeniedException,
                    InvalidDataException
Description copied from interface: Nameable
Set the name of the item. The name cannot be null and mustn't be longer than the value specified by the Nameable.MAX_NAME_LENGTH constant.

Specified by:
setName in interface Nameable
Parameters:
name - The new name for the item
Throws:
PermissionDeniedException - If the logged in user doesn't have write permission
InvalidDataException - If the name is null or longer than specified by the Nameable.MAX_NAME_LENGTH constant

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

setDescription

public void setDescription(String description)
                    throws PermissionDeniedException,
                           InvalidDataException
Description copied from interface: Nameable
Set the description for the item. The description can be null but mustn't be longer than the value specified by the Nameable.MAX_DESCRIPTION_LENGTH constant.

Specified by:
setDescription in interface Nameable
Parameters:
description - The new description for the item
Throws:
PermissionDeniedException - If the logged in user doesn't have write permission
InvalidDataException - If the description longer than specified by the Nameable.MAX_DESCRIPTION_LENGTH constant

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

setRemoved

public void setRemoved(boolean removed)
                throws PermissionDeniedException
Description copied from interface: Removable
Set the removed flag for this item.

Specified by:
setRemoved in interface Removable
Parameters:
removed - TRUE if the item should be flagged as removed, FALSE otherwise
Throws:
PermissionDeniedException - If the logged in user doesn't have Permission.DELETE permission for setting the flag to TRUE or Permission.WRITE permission for setting the flag to FALSE

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:

Specified by:
isUsed in class BasicItem<DirectoryData>
Returns:
TRUE if the directory is used.
Throws:
BaseException - If there is an error.

getParent

public Directory getParent()
                    throws PermissionDeniedException,
                           BaseException
Get the parent directory of this directory.

Returns:
The parent Directory, or null if this directory is a root directory
Throws:
PermissionDeniedException - This exception is thrown if the logged in user doesn't have READ permission to the items
BaseException - If there is another error

setParent

public void setParent(Directory parent)
               throws PermissionDeniedException,
                      InvalidDataException
Set the parent directory of this directory.

Parameters:
parent - The new parent directory. Cant be null.
Throws:
PermissionDeniedException - If the logged in user doesn't have Permission.WRITE permission to this directory or Permission.USE permission to the parent directory permission for the parent directory
InvalidDataException - If parent is null or is a subdirectory to this directory

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.

isProjectDirectory

public boolean isProjectDirectory()
Returns TRUE if this directory is assigned to a project.

Returns:
true if this directory is connected to a project otherwise false

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

getProjectDirectoryProject

public Project getProjectDirectoryProject()
Returns the project if this directory is assigned to one, else null is returned. Also returns null if no read permission to project.

Returns:
Project The assigned project if this directory is assigned to one, else null.

Last update: 2011-06-23