Package net.sf.basedb.core
Class FileSet
java.lang.Object
net.sf.basedb.core.BasicItem
net.sf.basedb.core.FileSet
- All Implemented Interfaces:
AccessControlled
,Identifiable
A file set is the container for files that have been attach to an
item to hold data instead of importing it to the database.
- Version:
- 2.5
- Author:
- Nicklas
- Last modified
- $Date: 2019-02-26 11:10:15 +0100 (tis, 26 feb. 2019) $
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionprivate FileStoreEnabled
The item this file set belongs to.private static final QueryRuntimeFilter
This filter gives everybody read permission to file sets.static final Item
The type of item represented by this class. -
Constructor Summary
ConstructorDescriptionFileSet
(FileSetData data) Regular constructor if the item is not known beforehand.FileSet
(FileSetData data, FileStoreEnabled item) Special constructor to avoidgetItem()
to hit the database when the item is known beforehand. -
Method Summary
Modifier and TypeMethodDescriptionaddMember
(File file, DataFileType type) Add a file as a member to the file set.static FileSet
Get aFileSet
item when you know the id.(package private) FileSetData
getData()
Get theBasicData
object that holds all data for this item.private ExtensionsInvoker<ValidationAction>
getInvoker
(DbControl dc) getItem()
Get the item this file set belongs to.Get theItem
type of the item this file set belongs to.getMember
(DataFileType type) Get the member of the given type assuming that there is only a single member of that type.Get the members of this file set.getMembers
(String genericType) Get a query that returns all members in a file set with a specific genericItemSubtype
.getMembers
(DataFileType type) Get a query that returns all members in a file set with a specificDataFileType
.Get a query that return theDataFileType
for all members of this file set.Get a query that is returning all file types that have been marked as required by the associated platform but has no member in this file set.(package private) static FileSet
getNew
(DbControl dc, FileStoreEnabled item) Create a new file set for the specified item.int
getNumMembers
(DataFileType type) Get the number of members in the file set of the specified type.(package private) PluginPermission
getQuery()
Get aItemQuery
object configured to retrieveFileSet
items.getType()
Get the type of item represented by the object.Get the item this file set belongs to.boolean
Checks if this file set contains a file for eachDataFileType
that is required according to what has been specified by thePlatform
andPlatformVariant
.boolean
hasMember
(DataFileType type) Check if the file set contains at least one file of the specified type.(package private) void
initPermissions
(int granted, int denied) READ permission is granted to all users.boolean
isUsed()
Always return TRUE.void
Remove all members in a file set.int
removeAllOfType
(DataFileType type) Remove all member files of the given type.private FileSetMember
removeAllOfTypeExcept
(DataFileType type, File file) Remove all member files of the given type.boolean
removeMember
(File file, DataFileType type) Remove a file as a member from the file set.void
removeMember
(FileSetMember member) Remove the given member from this file set.(package private) void
setItem
(FileStoreEnabled item) Set the item this file set belongs to.setMember
(File file, DataFileType type) Set a file of a given type as a member of this file set.Validate the files in this file set.Methods inherited from class net.sf.basedb.core.BasicItem
addAnnotatableParents, addUsingItems, addUsingItems, breakCircularReferences, checkBatchAnnotatableUsage, checkPermission, equals, getBasicData, getDbControl, getId, getPermissions, getSessionControl, getVersion, hashCode, hasPermission, isDetached, isInDatabase, onAfterCommit, onAfterInsert, onBeforeCommit, onRollback, setDbControl, setProjectDefaults, toString, validate
-
Field Details
-
TYPE
The type of item represented by this class.- See Also:
-
RUNTIME_FILTER
This filter gives everybody read permission to file sets. -
item
The item this file set belongs to.
-
-
Constructor Details
-
FileSet
FileSet(FileSetData data) Regular constructor if the item is not known beforehand. -
FileSet
FileSet(FileSetData data, FileStoreEnabled item) Special constructor to avoidgetItem()
to hit the database when the item is known beforehand.
-
-
Method Details
-
getNew
Create a new file set for the specified item.- Throws:
BaseException
-
getById
public static FileSet getById(DbControl dc, int id) throws ItemNotFoundException, PermissionDeniedException, BaseException Get aFileSet
item when you know the id.- Parameters:
dc
- TheDbControl
which will be used for permission checking and database access.id
- The id of the item to load- Returns:
- The
FileSet
item - Throws:
ItemNotFoundException
- If an item with the specified id is not foundPermissionDeniedException
- If the logged in user doesn't have read permission to the itemBaseException
- If there is another error
-
getQuery
Get aItemQuery
object configured to retrieveFileSet
items. This query may return items which the logged in user doesn't have read permission to. At the moment there is no way to solve this problem.- Returns:
- An
ItemQuery
object
-
getData
FileSetData getData()Description copied from class:BasicItem
Get theBasicData
object that holds all data for this 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 theItem
enumeration.- Returns:
- A value indicating the type of item
-
isUsed
Always return TRUE. A file set always has a one-to-one relation to some item. The file set is automatically deleted if that item is deleted.- Overrides:
isUsed
in classBasicItem
- Returns:
- TRUE if this item is used, FALSE otherwise
- Throws:
BaseException
- If not able to tell if item is used or not.- See Also:
-
getUsingItems
Get the item this file set belongs to.- Overrides:
getUsingItems
in classBasicItem
- Returns:
- A set containing proxies for the items, or an empty set if no items are using this item
- Throws:
BaseException
- If there is an error loading the items- See Also:
-
initPermissions
READ permission is granted to all users. CREATE, WRITE and DELETE permissions are granted if the logged in user has WRITE permission on the associated item.- Overrides:
initPermissions
in classBasicItem
- Parameters:
granted
- Permissions that have been granted by the subclassdenied
- Permissions that have been denied by the subclass- Throws:
BaseException
- If the permissions couldn't be initialised
-
getPluginPermissions
PluginPermission getPluginPermissions()- Overrides:
getPluginPermissions
in classBasicItem
-
getItem
Get the item this file set belongs to.- Returns:
- The
FileStoreEnabled
item - Throws:
PermissionDeniedException
- If the logged in user doesn't have read permission to the itemBaseException
- If there is another error
-
setItem
Set the item this file set belongs to. -
getItemType
Get theItem
type of the item this file set belongs to. -
getMembers
Get the members of this file set.- Returns:
- A query returning
FileSetMember
items
-
getMembers
Get a query that returns all members in a file set with a specific genericItemSubtype
. Note! The query checks the generic type from theDataFileType.getGenericType()
, not theFile.getItemSubtype()
.- Parameters:
genericType
- The system ID of a generic type as defined byItemSubtype.getSystemId()
- Returns:
- A query returning
FileSetMember
items
-
getMembers
Get a query that returns all members in a file set with a specificDataFileType
.- Parameters:
type
- The type of the file- Returns:
- A query returning
FileSetMember
items - Since:
- 3.0
-
setMember
Set a file of a given type as a member of this file set. If one ore more files of the given type already exists, they are replaced with this file. If no member exists, a new entry is created and automatically saved to the database whenDbControl.commit()
is called. Calling this method is equivalent to first callremoveAllOfType(DataFileType)
and thenaddMember(File, DataFileType)
except that if the given file already is a member that member entry is kept.- Parameters:
file
- The file to set as a member (or null to remove it)type
- The type of the file- Returns:
- The new FileSetMember item
- Throws:
InvalidUseOfNullException
- If file or type is nullPermissionDeniedException
- If the logged in user doesn't have write permission for this file set or use permission for the file
-
addMember
Add a file as a member to the file set.- Parameters:
file
- The file to addtype
- The type of the file- Returns:
- The new FileSetMember item
- Throws:
InvalidUseOfNullException
- If file or type is nullPermissionDeniedException
- If the logged in user doesn't have write permission for this file set or use permission for the file- Since:
- 3.0
-
hasMember
Check if the file set contains at least one file of the specified type.- Parameters:
type
- ADataFileType
object- Returns:
- TRUE if the file set contains a file of the specified type, FALSE otherwise
-
getNumMembers
Get the number of members in the file set of the specified type.- Parameters:
type
- ADataFileType
object- Returns:
- The number of files in the file set with the given type
-
getMember
Get the member of the given type assuming that there is only a single member of that type. If there is more than one member of the given type, it is undefined which file that is returned.- Parameters:
type
- ADataFileType
object- Returns:
- A FileSetMember object or null if no member of the specified type exists
-
removeMember
Remove the given member from this file set.- Parameters:
member
- The member to remove- Since:
- 3.0
-
removeMember
Remove a file as a member from the file set.- Parameters:
file
- The file to removetype
- The type of the file- Returns:
- TRUE if a member was removed, FALSE if not
- Throws:
InvalidUseOfNullException
- If file or type is nullPermissionDeniedException
- If the logged in user doesn't have write permission for this file set- Since:
- 3.0
-
removeAllOfType
Remove all member files of the given type.- Parameters:
type
- ADataFileType
object- Returns:
- The number of removed files
- Throws:
InvalidUseOfNullException
- If type is nullPermissionDeniedException
- If the logged in user doesn't have write permission for this file set- Since:
- 3.0
-
removeAllOfTypeExcept
Remove all member files of the given type.- Parameters:
type
- ADataFileType
object- Returns:
- The number of removed files
- Throws:
InvalidUseOfNullException
- If type is nullPermissionDeniedException
- If the logged in user doesn't have write permission for this file set- Since:
- 3.0
-
removeAllMembers
public void removeAllMembers()Remove all members in a file set.- Throws:
PermissionDeniedException
- If the logged in user doesn't have write permission for this file set
-
getMemberTypes
Get a query that return theDataFileType
for all members of this file set.- Returns:
- A query object
-
hasAllRequiredFiles
public boolean hasAllRequiredFiles()Checks if this file set contains a file for eachDataFileType
that is required according to what has been specified by thePlatform
andPlatformVariant
.- Returns:
- TRUE if all files are present, FALSE otherwise. If the items has no platform TRUE is always returned
- See Also:
-
getMissingDataFileTypes
Get a query that is returning all file types that have been marked as required by the associated platform but has no member in this file set.- Returns:
- A query or null if no platform is associated with this item
-
validate
Validate the files in this file set. This method will invoke extensions for the "net.sf.basedb.core.filehandler.validator" extension point and let them handle the actual validation. This method will not throw any errors that have been caused by the validation process. Errors are returned as a list ofThrowable
:s and is also reported by setting theFileSetMember.isValid()
andFileSetMember.getErrorMessage()
properties for each file.Note!
PermissionDeniedException
:s are not considered validation errors. They are ignored and doesn't change the validation status.InvalidRelationException
is a less severe type of exception and can be used by a validator when the actual file it is validating is valid but a dependent file is not. For example, a valid CEL file has been attached to a raw bioassay, but it doesn't match the CDF file attached to the array design. If a validator throws this exception the member status will be set to invalid, but metadata is not reset.- Parameters:
dc
- The DbControl to use in the validation process- Returns:
- A list of validation errors, if everything is successful the list is empty
-
getInvoker
-