Class MetaFiles
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAttach the givenMetaFile
to the givenModel
object and return an instance of aMetaAttachment
that represents the attachment.Attach the given file to the given record.attach
(InputStream stream, String fileName, Model entity) Upload the given file stream and attach it to the given record.static void
Check whether the given filePath is valid.static void
Check whether the given file is valid.static void
Check whether the given file type is valid.void
Delete the givenDMSFile
and also delete linked file if not referenced by any other record.void
delete
(MetaAttachment attachment) Delete the given attachment and relatedMetaFile
instance along with the file content.void
Delete the givenMetaFile
instance along with the file content if it exists.void
deleteAttachments
(Model entity) Deletes all attachments and related records (MetaFile, DMSFile, MetaAttachment).fileTypeIcon
(MetaFile file) getDownloadLink
(MetaFile metaFile, Model parentModel) Gets download link for given meta file.static Path
Get the storage path of the file represented by the giveMetaFile
instance.static Path
Get the storage path of the given relative file path.static boolean
isBrowserPreviewCompatible
(jakarta.ws.rs.core.MediaType mediaType) Upload the given file to the file upload directory and create an instance ofMetaFile
for the given file.upload
(InputStream chunk, long startOffset, long fileSize, String fileId) Upload the given chunk of file data to a temporary file identified by the given file id.upload
(InputStream stream, MetaFile metaFile) Upload the given stream to the upload directory and link it to the givenMetaFile
.upload
(InputStream stream, String fileName) Upload the given stream to the upload directory.
-
Constructor Details
-
MetaFiles
-
-
Method Details
-
getPath
Get the storage path of the file represented by the giveMetaFile
instance.- Parameters:
file
- the givenMetaFile
instance- Returns:
- actual file path
-
getPath
Get the storage path of the given relative file path.- Parameters:
filePath
- relative file path- Returns:
- actual file path
-
checkPath
Check whether the given filePath is valid.The filePath is valid if it matches upload file whitelist pattern and doesn't match upload blacklist pattern.
- Parameters:
filePath
- the file path to check- Throws:
IllegalArgumentException
- if the file path to check is not valid
-
checkType
Check whether the given file type is valid.The file is valid if it matches file upload whitelist types and doesn't match upload blacklist types.
- Parameters:
fileType
- the file type to check- Throws:
IllegalArgumentException
- if the file type to check is not valid
-
checkType
Check whether the given file is valid.The file is valid if it matches file upload whitelist types and doesn't match upload blacklist types.
- Parameters:
file
- the file to check- Throws:
IllegalArgumentException
-
upload
public File upload(InputStream chunk, long startOffset, long fileSize, String fileId) throws IOException Upload the given chunk of file data to a temporary file identified by the given file id.Upload would restart if startOffset is 0 (zero), otherwise upload file size is checked against given startOffset. The startOffset must be less than expected fileSize.
Unlike the
upload(File, MetaFile)
orupload(File)
methods, this method doesn't createMetaFile
instance.The temporary file generated should be manually uploaded again using
upload(File, MetaFile)
or should be deleted usingTempFiles.clean(String)
method if something went wrong.- Parameters:
chunk
- the input streamstartOffset
- the start offset byte positionfileSize
- the actual file sizefileId
- an unique upload file identifier- Returns:
- a temporary file where upload is being saved
- Throws:
IOException
- if there is any error during io operations
-
upload
Upload the given file to the file upload directory and create an instance ofMetaFile
for the given file.- Parameters:
file
- the given file- Returns:
- an instance of
MetaFile
- Throws:
IOException
- if unable to read the filejakarta.persistence.PersistenceException
- if unable to save to aMetaFile
instance
-
upload
Upload the givenFile
to the upload directory and link it to the to givenMetaFile
.Any existing file linked to the given
MetaFile
will be removed from the upload directory.- Parameters:
file
- the file to uploadmetaFile
- the targetMetaFile
instance- Returns:
- persisted
MetaFile
instance - Throws:
IOException
- if unable to read the filejakarta.persistence.PersistenceException
- if unable to save toMetaFile
instance
-
upload
Upload the given stream to the upload directory and link it to the givenMetaFile
.The given
MetaFile
instance must have fileName set to save the stream as file. Upload the stream- Parameters:
stream
- the stream to uploadmetaFile
- theMetaFile
to link the uploaded file- Returns:
- the given
MetaFile
instance - Throws:
IOException
- if an I/O error occurs
-
upload
Upload the given stream to the upload directory.- Parameters:
stream
- the stream to uploadfileName
- the file name to use- Returns:
- a new
MetaFile
instance - Throws:
IOException
- if an I/O error occurs
-
attach
Upload the given file stream and attach it to the given record.The attachment will be saved as
DMSFile
and will be visible in DMS user interface. Useupload(InputStream, String)
along withattach(MetaFile, Model)
if you don't want to show the attachment in DMS interface.- Parameters:
stream
- the stream to uploadfileName
- the file name to useentity
- the record to attach to- Returns:
- a
DMSFile
record created for the attachment - Throws:
IOException
- if an I/O error occurs
-
attach
Attach the given file to the given record.- Parameters:
metaFile
- the file to attachfileName
- alternative file name to use (optional, can be null)entity
- the record to attach to- Returns:
- a
DMSFile
record created for the attachment
-
delete
Delete the givenDMSFile
and also delete linked file if not referenced by any other record.It will attempt to clean up associated
MetaFile
andMetaAttachment
records and also try to delete linked file from upload directory.- Parameters:
file
- theDMSFile
to delete
-
attach
Attach the givenMetaFile
to the givenModel
object and return an instance of aMetaAttachment
that represents the attachment.The
MetaAttachment
instance is not persisted.- Parameters:
file
- the givenMetaFile
instanceentity
- the givenModel
instance- Returns:
- a new instance of
MetaAttachment
-
delete
Delete the given attachment and relatedMetaFile
instance along with the file content.- Parameters:
attachment
- the attachment to delete- Throws:
IOException
- if unable to delete file
-
delete
Delete the givenMetaFile
instance along with the file content if it exists.- Parameters:
metaFile
- the file to delete- Throws:
IOException
- if unable to delete file
-
deleteAttachments
Deletes all attachments and related records (MetaFile, DMSFile, MetaAttachment). Finally, deletes all real files.- Parameters:
entity
-
-
fileTypeIcon
-
getDownloadLink
Gets download link for given meta file. Permissions can be checked from given parent record.- Parameters:
metaFile
-parentModel
-- Returns:
- download link
-
isBrowserPreviewCompatible
public static boolean isBrowserPreviewCompatible(jakarta.ws.rs.core.MediaType mediaType)
-