Class DefaultFileHandler

java.lang.Object
com.jbstrap.core.interfaces.FileHandler
com.jbstrap.core.dao.base.DefaultFileHandler

public class DefaultFileHandler extends FileHandler

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 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 the file 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 class FileHandler
      Parameters:
      fileList - The list of the JBFiles, that are specified in the attributeName parameter, in the persisted record.
      record - The record that was persisted
      attributeName - 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

      public List<JBFile> getFiles(Record record, String attributeName, Client client) throws Exception
      Gets the files from the record, based on the specified metadata. The files that are specified by this metadata, will be queried from the store , and this will be used to generate a JBFile. There can be multiple files in the field of a record, thus a List list will be placed in the record. If the record field contained no files, the field value will be null.
      Specified by:
      getFiles in class FileHandler
      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: