Class FileStoreUtil

java.lang.Object
net.sf.basedb.core.FileStoreUtil

public class FileStoreUtil extends Object
Utility class working with FileStoreEnabled items.
Version:
2.5
Author:
nicklas
Last modified
$Date: 2017-05-22 14:35:27 +0200 (må, 22 maj 2017) $
  • Constructor Details

    • FileStoreUtil

      public FileStoreUtil()
  • Method Details

    • hasDataFile

      public static boolean hasDataFile(DbControl dc, FileStoreEnabled item, String dataFileType, boolean requireValid)
      Check if a file of the given data file type is present in a FileStoreEnabled item's file set. Optionally, check if the file has been validated as a valid file.
      Parameters:
      dc - DbControl to use when accessing the database.
      item - The FileStoreEnabled item to check
      dataFileType - The external ID of the DataFileType to check for
      requireValid - TRUE if the file must exist and be valid, FALSE if it must only exist. This parameter is ignored if the data file type doesn't have a validator
      Returns:
      TRUE if the file exists, FALSE otherwise
    • getDataFile

      public static File getDataFile(DbControl dc, FileStoreEnabled item, String dataFileType, boolean requireValid)
      Get the file of the given data file type in the FileStoreEnabled item's file set assuming that at most one file exists.
      Parameters:
      dc - DbControl used to access the database.
      item - The FileStoreEnabled item to check
      dataFileType - The external ID of the DataFileType to check for
      requireValid - TRUE to only get the data file if is a valid or unvalidated file
      Returns:
      A file item, or null if no (valid) file of the given type exists
      Throws:
      PermissionDeniedException - If the logged in user doesn't have read permission to the file
      Since:
      3.0
    • getDataFiles

      public static List<File> getDataFiles(DbControl dc, FileStoreEnabled item, String dataFileType, boolean requireValid)
      Get the file of the given data file type in the FileStoreEnabled item's file set.
      Parameters:
      dc - DbControl used to access the database.
      item - The FileStoreEnabled item to check
      dataFileType - The external ID of the DataFileType to check for
      requireValid - TRUE to only get the data file if is a valid or unvalidated file
      Returns:
      A list with file items, empty if no (valid) file of the given type exists
      Throws:
      PermissionDeniedException - If the logged in user doesn't have read permission to the file
      Since:
      3.0
    • getGenericDataFiles

      public static List<File> getGenericDataFiles(DbControl dc, FileStoreEnabled item, String genericType)
      Get all files with a specific generic ItemSubtype in a given item's file set. Note! This method will only return files that the logged in user has permission to read. Other files in the file set will be ignored. Note! This method checks the file type from DataFileType.getGenericType(), not the file type from File.getItemSubtype().
      Parameters:
      dc - A DbControl to use for database access
      item - The FileStoreEnabled item to check
      genericType - The system ID of the ItemSubtype to check for
      Returns:
      A list of file items that matches
    • getGenericMembers

      public static List<FileSetMember> getGenericMembers(DbControl dc, FileStoreEnabled item, String genericType)
      Get all file members with a specific generic ItemSubtype in a given item's file set. Note! This method will only return members that the logged in user has permission to read the file. Other members in the file set will be ignored. Note! This method checks the file type from DataFileType.getGenericType(), not the file type from File.getItemSubtype().
      Parameters:
      dc - A DbControl to use for database access
      item - The FileStoreEnabled item to check
      genericType - The system ID of the ItemSubtype to check for
      Returns:
      A list of member items that matches
      Since:
      3.0
    • getGenericPlatformFileTypes

      public static List<PlatformFileType> getGenericPlatformFileTypes(DbControl dc, FileStoreEnabled item, String genericType)
      Get a list of all platform file types that has the specified generic ItemSubtype. If the item doesn't have any associated platform or variant, no file types are returned.
      Parameters:
      dc - A DbControl to use for database access
      item - The FileStoreEnabled item to check
      genericType - The system ID of the ItemSubtype to check for
      Returns:
      A list of platform file types that matches
      Since:
      3.0
    • setDataFile

      public static FileSetMember setDataFile(DbControl dc, FileStoreEnabled item, String dataFileType, File file)
      Set or remove a file to FileStoreEnabled item based on the file's DataFileType.
      Parameters:
      dc - A DbControl to use for database access
      item - The item to add/remove the file to/from
      dataFileType - The external ID of the DataFileType of the file
      file - The file, or null to remove an existing file
      Returns:
      The new FileSetMember item or null if a file was removed
      Throws:
      PermissionDeniedException - If the logged in user doesn't have write permission to the item
      InvalidUseOfNullException - If item is null
    • setGenericDataFile

      public static FileSetMember setGenericDataFile(DbControl dc, FileStoreEnabled item, String genericType, String fallbackDataFileType, File file)
      Set or remove a file to FileStoreEnabled item based on the file's generic ItemSubtype. Note! This method checks the file type from DataFileType.getGenericType(), not the file type from File.getItemSubtype().
      Parameters:
      dc - A DbControl to use for database access
      item - The item to add/remove the file to/from
      genericType - The system ID of the generic ItemSubtype
      fallbackDataFileType - The external ID of a DataFileType that is used if the specified generic file type isn't found among the file types registered for the platform
      file - The file, or null to remove an existing file
      Returns:
      The new FileSetMember item or null if a file was removed
      Throws:
      PermissionDeniedException - If the logged in user doesn't have write permission to the item
      InvalidUseOfNullException - If item is null