2.17.2: 2011-06-17

net.sf.basedb.core
Class FileSet

java.lang.Object
  extended by net.sf.basedb.core.BasicItem<FileSetData>
      extended by net.sf.basedb.core.FileSet
All Implemented Interfaces:
AccessControlled, Identifiable

public class FileSet
extends BasicItem<FileSetData>

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: 2008-09-11 22:11:02 +0200 (Thu, 11 Sep 2008) $

Nested Class Summary
private static class FileSet.DataFileHandlerWrapper
          Wraps a DataFileValidator and /or DataFileMetadataReader.
private static class FileSet.QueryRuntimeFilterImpl
           
 
Field Summary
private  FileStoreEnabled item
          The item this file set belongs to.
private static QueryRuntimeFilter RUNTIME_FILTER
          This filter gives everybody read permission to file sets.
static Item TYPE
          The type of item represented by this class.
 
Constructor Summary
FileSet(FileSetData data)
          Regular constructor if the item is not known beforehand.
FileSet(FileSetData data, FileStoreEnabled item)
          Special constructor to avoid getItem() to hit the database when the item is known beforehand.
 
Method Summary
static FileSet getById(DbControl dc, int id)
          Get a FileSet item when you know the id.
 FileStoreEnabled getItem()
          Get the item this file set belongs to.
 Item getItemType()
          Get the Item type of the item this file set belongs to.
 FileSetMember getMember(DataFileType type)
          Get the member of the given type.
 ItemQuery<FileSetMember> getMembers()
          Get the members of this file set.
 ItemQuery<FileSetMember> getMembers(String genericType)
          Get a query that returns all members in a file set with a specific generic FileType.
 ItemQuery<DataFileType> getMemberTypes()
          Get a query that return the DataFileType for all members of this file set.
 ItemQuery<PlatformFileType> 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.
(package private) static FileSet getNew(DbControl dc, FileStoreEnabled item)
          Create a new file set for the specified item.
(package private)  PluginPermission getPluginPermissions()
           
(package private) static ItemQuery<FileSet> getQuery()
          Get a ItemQuery object configured to retrieve FileSet items.
 Item getType()
          Get the type of item represented by the object.
 Set<ItemProxy> getUsingItems()
          Get the item this file set belongs to.
 boolean hasAllRequiredFiles()
          Checks if this file set contains a file for each DataFileType that is required according to what has been specified by the Platform and PlatformVariant.
 boolean hasMember(DataFileType type)
          Check if the file set contains a 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 removeAllMembers()
          Remove all members in a file set.
 void removeMember(DataFileType type)
          Remove the member of the given type.
(package private)  void setItem(FileStoreEnabled item)
          Set the item this file set belongs to.
 FileSetMember setMember(File file, DataFileType type)
          Set a file of a given type as a member of this file set.
 List<Throwable> validate(DbControl dc, boolean extractMetadata)
          Validate the files in this file set.
 
Methods inherited from class net.sf.basedb.core.BasicItem
addUsingItems, addUsingItems, checkPermission, equals, getData, getDbControl, getId, getPermissions, getSessionControl, getVersion, hashCode, hasPermission, isDetached, isInDatabase, onAfterCommit, onAfterInsert, onBeforeCommit, onRollback, setDbControl, setProjectDefaults, toString, toTransferable, validate
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

TYPE

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

See Also:
Item.FILESET, getType()

RUNTIME_FILTER

private static final QueryRuntimeFilter RUNTIME_FILTER
This filter gives everybody read permission to file sets.


item

private FileStoreEnabled item
The item this file set belongs to.

Constructor Detail

FileSet

FileSet(FileSetData data)
Regular constructor if the item is not known beforehand.


FileSet

FileSet(FileSetData data,
        FileStoreEnabled item)
Special constructor to avoid getItem() to hit the database when the item is known beforehand.

Method Detail

getNew

static FileSet getNew(DbControl dc,
                      FileStoreEnabled item)
               throws BaseException
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 a FileSet item when you know the id.

Parameters:
dc - The DbControl 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 found
PermissionDeniedException - If the logged in user doesn't have read permission to the item
BaseException - If there is another error

getQuery

static ItemQuery<FileSet> getQuery()
Get a ItemQuery object configured to retrieve FileSet 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

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.

Returns:
A value indicating the type of item

isUsed

public boolean isUsed()
               throws BaseException
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 class BasicItem<FileSetData>
Returns:
TRUE if this item is used, FALSE otherwise
Throws:
BaseException - If not able to tell if item is used or not.
See Also:
BasicItem.getUsingItems()

getUsingItems

public Set<ItemProxy> getUsingItems()
                             throws BaseException
Get the item this file set belongs to.

Overrides:
getUsingItems in class BasicItem<FileSetData>
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:
BasicItem.addUsingItems(Set, Item, org.hibernate.Query)

initPermissions

void initPermissions(int granted,
                     int denied)
               throws BaseException
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 class BasicItem<FileSetData>
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

getPluginPermissions

PluginPermission getPluginPermissions()
Overrides:
getPluginPermissions in class BasicItem<FileSetData>

getItem

public FileStoreEnabled getItem()
                         throws PermissionDeniedException,
                                BaseException
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 item
BaseException - If there is another error

setItem

void setItem(FileStoreEnabled item)
Set the item this file set belongs to.


getItemType

public Item getItemType()
Get the Item type of the item this file set belongs to.


getMembers

public ItemQuery<FileSetMember> getMembers()
Get the members of this file set.

Returns:
A query returning FileSetMember items

getMembers

public ItemQuery<FileSetMember> getMembers(String genericType)
Get a query that returns all members in a file set with a specific generic FileType. Note! The query checks the generic type from the DataFileType.getGenericType(), not the File.getFileType().

Parameters:
genericType - The system ID of a generic type as defined by FileType.getSystemId()
Returns:
A query returning FileSetMember items

setMember

public FileSetMember setMember(File file,
                               DataFileType type)
Set a file of a given type as a member of this file set. If another file of the given type already exists, it is replaced with this file. If no member exists, a new entry is created and automatically saved to the database when DbControl.commit() is called.

Parameters:
file - The file to set as a member
type - The type of the file
Returns:
The new FileSetMember item
Throws:
InvalidUseOfNullException - If file or type is null
PermissionDeniedException - If the logged in user doesn't have write permission for this file set or use permission for the file

hasMember

public boolean hasMember(DataFileType type)
Check if the file set contains a file of the specified type.

Parameters:
type - A DataFileType object
Returns:
TRUE if the file set contains a file of the specified type, FALSE otherwise

getMember

public FileSetMember getMember(DataFileType type)
Get the member of the given type.

Parameters:
type - A DataFileType object
Returns:
A FileSetMember object or null if no member of the specified type exists

removeMember

public void removeMember(DataFileType type)
Remove the member of the given type. If a DataFileMetadataReader is associated with the file type this method will call DataFileMetadataReader.resetMetadata(DbControl).

Parameters:
type - A DataFileType object
Throws:
InvalidUseOfNullException - If type is null
PermissionDeniedException - If the logged in user doesn't have write permission for this file set

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

public ItemQuery<DataFileType> getMemberTypes()
Get a query that return the DataFileType for all members of this file set.

Returns:
A query object

hasAllRequiredFiles

public boolean hasAllRequiredFiles()
Checks if this file set contains a file for each DataFileType that is required according to what has been specified by the Platform and PlatformVariant.

Returns:
TRUE if all files are present, FALSE otherwise. If the items has no platform TRUE is always returned
See Also:
PlatformFileType.isRequired()

getMissingDataFileTypes

public ItemQuery<PlatformFileType> 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

public List<Throwable> validate(DbControl dc,
                                boolean extractMetadata)
Validate the files in this file set. This method will load the validator and metadata reader for the DataFileType for each member in the file set. If more than one file type uses the same validator or metadata reader, they will all share the same instance. This method will not throw any errors that have been caused by the validation process. Errors are returned as a list of Throwable:s and is also reported by setting the FileSetMember.isValid() and FileSetMember.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 extraction is still done.

Parameters:
dc - The DbControl to use in the validation process
extractMetadata - TRUE to also extract metadata, FALSE otherwise
Returns:
A list of validation errors, if everything is successful the list is empty

2.17.2: 2011-06-17