public class Directory extends SharedItem implements Nameable, Removable, SystemItem
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.Modifier and Type | Field and Description |
---|---|
private static java.lang.ThreadLocal<java.util.Map<java.lang.String,Directory>> |
DIRECTORY_CACHE |
static java.lang.String |
HOME
The id for the
Directory item representing
the home directory. |
static java.lang.String |
ROOT
The id for the
Directory item representing
the root. |
static java.lang.String |
TEMPLATE
The id for the
Directory item representing
the template directory. |
static Item |
TYPE
The type of item represented by this class.
|
MAX_DESCRIPTION_LENGTH, MAX_NAME_LENGTH
MAX_SYSTEM_ID_LENGTH
Constructor and Description |
---|
Directory(DirectoryData data)
Creates a new directory item from the given data.
|
Modifier and Type | Method and Description |
---|---|
static void |
copySubdirectories(DbControl dc,
Directory from,
Directory to,
User owner)
This method copies a directory strucure to the destination directory.
|
static Directory |
createHomeDirectory(DbControl dc,
User user,
boolean copyTemplate)
Creates a homedirectory for a specified user.
|
static boolean |
exists(DbControl dc,
Directory directory,
java.lang.String subdirectoryName)
Checks if a subdirectory with the specified name exists in a
directory.
|
boolean |
getAutoCompress()
If files that are uploaded to this directory should be
compressed or not.
|
boolean |
getAutoShare()
If new files and subdirectories that are created in this
directory automatically should be shared wtih the same
permissions as this directory.
|
static Directory |
getById(DbControl dc,
int id)
Get a
Directory item when you know the ID. |
static Directory |
getByPath(DbControl dc,
Path path)
Get a
Directory item when you know the path. |
(package private) DirectoryData |
getData()
Get the
BasicData object that holds all data for this item. |
java.lang.String |
getDescription()
Get the description for the item.
|
ItemQuery<File> |
getFiles()
Get a query that return all files in this directory.
|
static int |
getIdFromPath(DbControl dc,
Path path)
Get the id of a directory when you know the path.
|
java.lang.String |
getName()
Get the name of the item.
|
static Directory |
getNew(DbControl dc,
Directory parent)
Create a new
Directory item. |
static Directory |
getNew(DbControl dc,
Path path)
Create a new or existing
Directory from a path. |
Directory |
getParent()
Get the parent directory of this directory.
|
Path |
getPath()
Get the complete path to this directory.
|
static ItemQuery<Directory> |
getQuery()
Get a query configured to retrieve directories.
|
User |
getRemovedBy()
Get the user that flagged this item for removal.
|
ItemQuery<Directory> |
getSubDirectories()
Get a query that return subdirectories of this directory.
|
java.lang.String |
getSystemId()
Get the system id for the item.
|
Item |
getType()
Get the type of item represented by the object.
|
java.util.Set<ItemProxy> |
getUsingItems()
Get all:
File :s in this directory
Sub-Directory :s in this directory
User :s having this directory as their home-directory
Experiment :s having this directory as the plugin directory
|
(package private) void |
initPermissions(int granted,
int denied)
Grant permissions according to the item and project keys.
|
boolean |
isHomeDirectory()
Returns TRUE if this directory is a subdirectory to
HOME . |
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
|
Directory |
newSubDirectory()
Create a new subdirectory to this directory.
|
void |
setAutoCompress(boolean autoCompress)
Set if files of should automatically
be compressed when they are uploaded to this directory.
|
void |
setAutoShare(boolean autoShare)
Set if new files and subdirectories of should automatically
be shared with the same permissions as this directory.
|
void |
setDescription(java.lang.String description)
Set the description for the item.
|
void |
setName(java.lang.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.
|
getItemKey, getProjectKey, isShared, onBeforeCommit, setItemKey, setProjectKey
getOwner, isOwner, setOwner, takeOwnership
addAnnotatableParents, addUsingItems, addUsingItems, breakCircularReferences, checkBatchAnnotatableUsage, checkPermission, equals, getBasicData, getDbControl, getId, getPermissions, getPluginPermissions, getSessionControl, getVersion, hashCode, hasPermission, isDetached, isInDatabase, onAfterCommit, onAfterInsert, onRollback, setDbControl, setProjectDefaults, toString, validate
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getId, getVersion
checkPermission, getPermissions, hasPermission
getOwner, isOwner, setOwner, takeOwnership
public static final Item TYPE
Item.DIRECTORY
,
getType()
public static final java.lang.String ROOT
Directory
item representing
the root.public static final java.lang.String HOME
Directory
item representing
the home directory. The home directory is the parent directory for
the user's home directories.public static final java.lang.String TEMPLATE
Directory
item representing
the template directory. The template directory is used to create
the directory structure for new users.private static java.lang.ThreadLocal<java.util.Map<java.lang.String,Directory>> DIRECTORY_CACHE
Directory(DirectoryData data)
data
- the data.public static Directory getNew(DbControl dc, Directory parent) throws BaseException
Directory
item.dc
- The DbControl
which will be used for
permission checking and database access.parent
- The parent directory for this directory. It cannot be
nullDirectory
itemPermissionDeniedException
- This exception is thrown if
the logged in user doesn't have CREATE
permission for this type of itemsBaseException
- This exception is thrown if there is another
errorpublic static Directory getNew(DbControl dc, Path path)
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.
dc
- The DbControl
which will be used for
permission checking and database accesspath
- The path to createpublic static Directory getById(DbControl dc, int id) throws ItemNotFoundException, PermissionDeniedException, BaseException
Directory
item when you know the ID.dc
- The DbControl
which will be used for
permission checking and database access.id
- The ID of the item to loadDirectory
itemItemNotFoundException
- If an item with the specified ID is not foundPermissionDeniedException
- If the logged in user doesn't have
Permission.READ
permission to the itemBaseException
- If there is another errorpublic static Directory getByPath(DbControl dc, Path path) throws ItemNotFoundException, PermissionDeniedException, BaseException
Directory
item when you know the path.dc
- The DbControl
which will be used for
permission checking and database access.path
- The path to the directory to loadDirectory
itemItemNotFoundException
- If an item with the specified path is not foundPermissionDeniedException
- If the logged in user doesn't have
Permission.READ
permission to the itemBaseException
- If there is another errorpublic static int getIdFromPath(DbControl dc, Path path) throws BaseException
dc
- The DbControl
which will be used for
permission checking and database access.path
- The path to the directory to loadDirectory
itemItemNotFoundException
- If an item with the specified path is not foundBaseException
- If there is another errorpublic static boolean exists(DbControl dc, Directory directory, java.lang.String subdirectoryName) throws BaseException
dc
- The DbControl
which will be used for
permission checking and database access.directory
- The directory to check insubdirectoryName
- The name of the subdirectory to look forBaseException
- If there is an errorpublic static Directory createHomeDirectory(DbControl dc, User user, boolean copyTemplate) throws PermissionDeniedException, BaseException
HOME
.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.PermissionDeniedException
- If the logged in user doesn't have
Permission.WRITE
or Permission.CREATE
permission
to the item.BaseException
- If there is another error.public static void copySubdirectories(DbControl dc, Directory from, Directory to, User owner) throws BaseException
dc
- The DbControl
which will be used for
permission checking and database access.from
- The source directory to copyto
- The destination directory where the new directory structure is createdowner
- The owner of the destination directoryBaseException
- If there is an errorpublic static ItemQuery<Directory> getQuery()
ItemQuery
objectDirectoryData getData()
BasicItem
BasicData
object that holds all data for this item.getData
in class SharedItem
public java.lang.String getName()
Nameable
public void setName(java.lang.String name) throws PermissionDeniedException, InvalidDataException
Nameable
Nameable.MAX_NAME_LENGTH
constant.setName
in interface Nameable
name
- The new name for the itemPermissionDeniedException
- If the logged in user doesn't
have write permissionInvalidDataException
- If the name is null or longer
than specified by the Nameable.MAX_NAME_LENGTH
constantpublic java.lang.String getDescription()
Nameable
getDescription
in interface Nameable
String
with a description of the itempublic void setDescription(java.lang.String description) throws PermissionDeniedException, InvalidDataException
Nameable
Nameable.MAX_DESCRIPTION_LENGTH
constant.setDescription
in interface Nameable
description
- The new description for the itemPermissionDeniedException
- If the logged in user doesn't
have write permissionInvalidDataException
- If the description longer
than specified by the Nameable.MAX_DESCRIPTION_LENGTH
constantpublic Item getType()
Identifiable
Item
enumeration.getType
in interface Identifiable
public boolean isRemoved()
Removable
public void setRemoved(boolean removed) throws PermissionDeniedException
Removable
setRemoved
in interface Removable
removed
- TRUE if the item should be flagged as removed,
FALSE otherwisePermissionDeniedException
- 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 FALSEpublic User getRemovedBy() throws PermissionDeniedException, ItemNotFoundException
Removable
getRemovedBy
in interface Removable
PermissionDeniedException
- If the logged in user doesn't have
Permission.READ
permission for the userItemNotFoundException
- If the user that removed this item
can't be foundpublic java.lang.String getSystemId()
SystemItem
getSystemId
in interface SystemItem
public boolean isSystemItem()
SystemItem
isSystemItem
in interface SystemItem
public boolean isUsed() throws BaseException
isUsed
in class BasicItem
BaseException
- If there is an error.BasicItem.getUsingItems()
public java.util.Set<ItemProxy> getUsingItems()
File
:s in this directory
Directory
:s in this directory
User
:s having this directory as their home-directory
Experiment
:s having this directory as the plugin directory
getUsingItems
in class BasicItem
BasicItem.addUsingItems(Set, Item, org.hibernate.query.Query)
void initPermissions(int granted, int denied) throws BaseException
SharedItem
initPermissions
in class SharedItem
granted
- Permissions that have been granted by the subclassdenied
- Permissions that have been denied by the subclassBaseException
- If the permissions couldn't be initialisedpublic Directory getParent() throws PermissionDeniedException, BaseException
Directory
, or null if
this directory is a root directoryPermissionDeniedException
- This exception is thrown if
the logged in user doesn't have READ
permission to the itemsBaseException
- If there is another errorpublic void setParent(Directory parent) throws PermissionDeniedException, InvalidDataException
parent
- The new parent directory. Cant be null.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 directoryInvalidDataException
- If parent is null or is a subdirectory
to this directorypublic boolean getAutoCompress()
public void setAutoCompress(boolean autoCompress) throws PermissionDeniedException
autoCompress
- TRUE to enable auto-compressionPermissionDeniedException
- If the logged in user doesn't have
write permissionpublic boolean getAutoShare()
public void setAutoShare(boolean autoShare) throws PermissionDeniedException
autoShare
- TRUE to enable auto-sharingPermissionDeniedException
- If the logged in user doesn't have
write permissionpublic boolean isRootDirectory()
public boolean isHomeDirectory()
HOME
.public Directory newSubDirectory() throws PermissionDeniedException, BaseException
Directory
itemPermissionDeniedException
- This exception is thrown if
the logged in user doesn't have CREATE
permission for directory items, or WRITE
permission for this directoryBaseException
- This exception is thrown if there is another
errorpublic ItemQuery<Directory> getSubDirectories()
ItemQuery
object