Package net.sf.basedb.core
Class FileStoreUtil
java.lang.Object
net.sf.basedb.core.FileStoreUtil
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic File
getDataFile
(DbControl dc, FileStoreEnabled item, String dataFileType, boolean requireValid) Get the file of the given data file type in theFileStoreEnabled
item's file set assuming that at most one file exists.getDataFiles
(DbControl dc, FileStoreEnabled item, String dataFileType, boolean requireValid) Get the file of the given data file type in theFileStoreEnabled
item's file set.getGenericDataFiles
(DbControl dc, FileStoreEnabled item, String genericType) Get all files with a specific genericItemSubtype
in a given item's file set.static List<FileSetMember>
getGenericMembers
(DbControl dc, FileStoreEnabled item, String genericType) Get all file members with a specific genericItemSubtype
in a given item's file set.static List<PlatformFileType>
getGenericPlatformFileTypes
(DbControl dc, FileStoreEnabled item, String genericType) Get a list of all platform file types that has the specified genericItemSubtype
.static boolean
hasDataFile
(DbControl dc, FileStoreEnabled item, String dataFileType, boolean requireValid) Check if a file of the given data file type is present in aFileStoreEnabled
item's file set.static FileSetMember
setDataFile
(DbControl dc, FileStoreEnabled item, String dataFileType, File file) Set or remove a file toFileStoreEnabled
item based on the file'sDataFileType
.static FileSetMember
setGenericDataFile
(DbControl dc, FileStoreEnabled item, String genericType, String fallbackDataFileType, File file) Set or remove a file toFileStoreEnabled
item based on the file's genericItemSubtype
.
-
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 aFileStoreEnabled
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
- TheFileStoreEnabled
item to checkdataFileType
- The external ID of theDataFileType
to check forrequireValid
- 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 theFileStoreEnabled
item's file set assuming that at most one file exists.- Parameters:
dc
- DbControl used to access the database.item
- TheFileStoreEnabled
item to checkdataFileType
- The external ID of theDataFileType
to check forrequireValid
- 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 theFileStoreEnabled
item's file set.- Parameters:
dc
- DbControl used to access the database.item
- TheFileStoreEnabled
item to checkdataFileType
- The external ID of theDataFileType
to check forrequireValid
- 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 genericItemSubtype
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 fromDataFileType.getGenericType()
, not the file type fromFile.getItemSubtype()
.- Parameters:
dc
- A DbControl to use for database accessitem
- TheFileStoreEnabled
item to checkgenericType
- The system ID of theItemSubtype
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 genericItemSubtype
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 fromDataFileType.getGenericType()
, not the file type fromFile.getItemSubtype()
.- Parameters:
dc
- A DbControl to use for database accessitem
- TheFileStoreEnabled
item to checkgenericType
- The system ID of theItemSubtype
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 genericItemSubtype
. If the item doesn't have any associated platform or variant, no file types are returned.- Parameters:
dc
- A DbControl to use for database accessitem
- TheFileStoreEnabled
item to checkgenericType
- The system ID of theItemSubtype
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 toFileStoreEnabled
item based on the file'sDataFileType
.- Parameters:
dc
- A DbControl to use for database accessitem
- The item to add/remove the file to/fromdataFileType
- The external ID of theDataFileType
of the filefile
- 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 itemInvalidUseOfNullException
- If item is null
-
setGenericDataFile
public static FileSetMember setGenericDataFile(DbControl dc, FileStoreEnabled item, String genericType, String fallbackDataFileType, File file) Set or remove a file toFileStoreEnabled
item based on the file's genericItemSubtype
. Note! This method checks the file type fromDataFileType.getGenericType()
, not the file type fromFile.getItemSubtype()
.- Parameters:
dc
- A DbControl to use for database accessitem
- The item to add/remove the file to/fromgenericType
- The system ID of the genericItemSubtype
fallbackDataFileType
- The external ID of aDataFileType
that is used if the specified generic file type isn't found among the file types registered for the platformfile
- 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 itemInvalidUseOfNullException
- If item is null
-