Class DefaultFileHandler
In the case of JpaDao, custom file handling methods can be written, that will be called when saving, deleting, or querying data. Thus, it can be regulated how the files are stored, and during queries, how they are loaded back.
The file handler class can be set in the JBStrapParamType.FILE_HANDLER
class parameter. The Parameter value must be an implementation of the FileHandler
interface. If the parameter is not set, this class will handle the files. The file saving and loading is described in the documentation of this class' methods.
- Since:
- 4.0
- Author:
- JBStrap
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionGets the files from the record, based on the specified metadata.This method is the default handler that runs when the records are successfully persisted to the database.Methods inherited from class com.jbstrap.core.interfaces.FileHandler
processFilesBeforePersist
-
Constructor Details
-
DefaultFileHandler
public DefaultFileHandler()
-
-
Method Details
-
processFilesAfterPersist
public Record processFilesAfterPersist(List<JBFile> fileList, Record record, String attributeName, Client client) throws Exception This method is the default handler that runs when the records are successfully persisted to the database. The default file handler, after iterating the files, checks if thefile
was marked for deletion, or is new.If marked for deletion, the file will be deleted from the defined(in the file)
store
.If the file is new, then it will be saved to the defined
store
, it's metadata will be concatenated to a string, then this string will be saved, to the field, that is handled as a file (attributeName
) The file's metadata will be concatenated like this:
File1ConcatenateMetadata + ::: + File2ConcatenateMetadata + ::: + ....
File1ConcatenateMetadata = fileStoreName + ::: + fileId + ::: + filename + ::: + size.toString()- Overrides:
processFilesAfterPersist
in classFileHandler
- Parameters:
fileList
- The list of the JBFiles, that are specified in the attributeName parameter, in the persisted record.record
- The record that was persistedattributeName
- The name of the field (in the record) that contains the files.client
- The client object, through which the currently logged in user is.- Returns:
- Record, which contains the files. Upon any modifications to the record, it will be persisted to the database.
- Throws:
Exception
- Occurs if any errors are encountered during the saving process.- See Also:
-
getFiles
Gets the files from the record, based on the specified metadata. The files that are specified by this metadata, will be queried from thestore
, and this will be used to generate aJBFile
. There can be multiple files in the field of a record, thus aList
list will be placed in the record. If the record field contained no files, the field value will benull
.- Specified by:
getFiles
in classFileHandler
- Parameters:
record
- The record, to which the file list will be placed into.attributeName
- The name of the field in the record (same type as the file)client
- The client object, through which the currently logged in user is.- Returns:
- The list of the files set in the record's
attributeName
field. - Throws:
Exception
- If the files cannot be queried.- See Also:
-