Class FileSet

All Implemented Interfaces:
AccessControlled, Identifiable

public class FileSet extends BasicItem
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) $
  • Field Details

    • TYPE

      public static final Item TYPE
      The type of item represented by this class.
      See Also:
    • 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 Details

    • 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 Details

    • 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
    • getData

      FileSetData getData()
      Description copied from class: BasicItem
      Get the BasicData object that holds all data for this item.
      Specified by:
      getData in class BasicItem
    • 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
      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

      public Set<ItemProxy> getUsingItems() throws BaseException
      Get the item this file set belongs to.
      Overrides:
      getUsingItems in class BasicItem
      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

      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
      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
    • 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 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 ItemSubtype. Note! The query checks the generic type from the DataFileType.getGenericType(), not the File.getItemSubtype().
      Parameters:
      genericType - The system ID of a generic type as defined by ItemSubtype.getSystemId()
      Returns:
      A query returning FileSetMember items
    • getMembers

      public ItemQuery<FileSetMember> getMembers(DataFileType type)
      Get a query that returns all members in a file set with a specific DataFileType.
      Parameters:
      type - The type of the file
      Returns:
      A query returning FileSetMember items
      Since:
      3.0
    • setMember

      public FileSetMember setMember(File file, DataFileType type)
      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 when DbControl.commit() is called. Calling this method is equivalent to first call removeAllOfType(DataFileType) and then addMember(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 null
      PermissionDeniedException - If the logged in user doesn't have write permission for this file set or use permission for the file
    • addMember

      public FileSetMember addMember(File file, DataFileType type)
      Add a file as a member to the file set.
      Parameters:
      file - The file to add
      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
      Since:
      3.0
    • hasMember

      public boolean hasMember(DataFileType type)
      Check if the file set contains at least one 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
    • getNumMembers

      public int getNumMembers(DataFileType type)
      Get the number of members in the file set of the specified type.
      Parameters:
      type - A DataFileType object
      Returns:
      The number of files in the file set with the given type
    • getMember

      public FileSetMember getMember(DataFileType type)
      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 - A DataFileType object
      Returns:
      A FileSetMember object or null if no member of the specified type exists
    • removeMember

      public void removeMember(FileSetMember member)
      Remove the given member from this file set.
      Parameters:
      member - The member to remove
      Since:
      3.0
    • removeMember

      public boolean removeMember(File file, DataFileType type)
      Remove a file as a member from the file set.
      Parameters:
      file - The file to remove
      type - The type of the file
      Returns:
      TRUE if a member was removed, FALSE if not
      Throws:
      InvalidUseOfNullException - If file or type is null
      PermissionDeniedException - If the logged in user doesn't have write permission for this file set
      Since:
      3.0
    • removeAllOfType

      public int removeAllOfType(DataFileType type)
      Remove all member files of the given type.
      Parameters:
      type - A DataFileType object
      Returns:
      The number of removed files
      Throws:
      InvalidUseOfNullException - If type is null
      PermissionDeniedException - If the logged in user doesn't have write permission for this file set
      Since:
      3.0
    • removeAllOfTypeExcept

      private FileSetMember removeAllOfTypeExcept(DataFileType type, File file)
      Remove all member files of the given type.
      Parameters:
      type - A DataFileType object
      Returns:
      The number of removed files
      Throws:
      InvalidUseOfNullException - If type is null
      PermissionDeniedException - 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

      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:
    • 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)
      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 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 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

      private ExtensionsInvoker<ValidationAction> getInvoker(DbControl dc)