Class FileArchivSupportMethodsService
java.lang.Object
sk.iway.iwcm.components.file_archiv.FileArchivSupportMethodsService
- Direct Known Subclasses:
FileArchiveService
Provides shared state, validation, path handling, and file operations for file archive services.
Subclasses use these helpers to keep archive records and their physical files synchronized.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static Stringprotected Identityprotected intprotected String[]protected FileArchivatorBeanprotected IwcmFileprotected Stringprotected booleanprotected Propprotected longprotected booleanprotected FileArchiveRepositoryprotected jakarta.servlet.http.HttpServletRequestprotected List<FileArchivatorBean>protected intprotected booleanstatic final Stringprotected FileArchiveService.UploadType -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final booleanChecks the permissions and feature flag required by the current archive operation.protected booleandeleteFile(FileArchivatorBean fabToDelete, String prefixText, boolean ignoreMissingFile) Deletes an archive file and its database record after verifying user permissions.protected booleandeleteFilePatterns(FileArchivatorBean file, boolean ignoreMissingFile) Deletes all pattern files that refer to the supplied main file.protected voidfindSameFiles(FileArchivatorBean newFab, boolean removePattern, boolean isBeforeSave) Finds uploaded main files whose content hash matches the candidate file.protected static intgetCacheTime(String methodName) Resolves the cache lifetime for a specific archive operation with a component-wide fallback.protected StringResolves the physical storage path and creates its directory when it does not exist.protected booleanisConcurrentModification(Long oldId, Long referenceId) Detects whether the main file changed since the current edit operation began.protected booleanisCorrectEmails(boolean fromEditorFields) Validates the comma-separated notification addresses configured for a delayed upload.protected booleanisUploadDateCorrect(boolean fromEditorFields) Checks whether the configured delayed-upload date is in the future.static StringnormalizePath(String path) Normalizes an archive directory path to include leading and trailing separators.static StringnormalizeToOldPath(String path) Converts an archive directory to the legacy form without a leading separator.protected voidprepareFileArchivatorBean(String dirPath, String fileName, Long referenceId, boolean isNew) Populates archive persistence fields from the file placed in its storage directory.Resolves and validates the final destination directory without creating it.protected StringResolves and validates the physical storage directory without creating it.protected voidupdateReferenceToMainFile(Long referenceId, String referenceToMain) Updates the pattern reference stored by every history record in a file thread.protected voidupdateReferenceToMainFile(String oldReferenceToMain) Redirects pattern references from an old main-file path to the current archive file.
-
Field Details
-
cachePrefix
-
SEPARATOR
- See Also:
-
request
protected jakarta.servlet.http.HttpServletRequest request -
prop
-
currentUser
-
domainId
protected int domainId -
repository
-
fab
-
referenceId
protected long referenceId -
saveLater
protected boolean saveLater -
renameFile
protected boolean renameFile -
saveAfterId
protected int saveAfterId -
isPatternFile
protected boolean isPatternFile -
uploadType
-
fileToUploadName
-
fileToUpload
-
errorList
-
errorParams
-
sameFiles
-
-
Constructor Details
-
FileArchivSupportMethodsService
public FileArchivSupportMethodsService()
-
-
Method Details
-
updateReferenceToMainFile
Redirects pattern references from an old main-file path to the current archive file.- Parameters:
oldReferenceToMain- previous virtual path of the main file
-
updateReferenceToMainFile
Updates the pattern reference stored by every history record in a file thread.- Parameters:
referenceId- identifier of the main file whose history is updatedreferenceToMain- new main-file virtual path
-
isUploadDateCorrect
protected boolean isUploadDateCorrect(boolean fromEditorFields) Checks whether the configured delayed-upload date is in the future.- Parameters:
fromEditorFields-trueto read the pending editor value;falseto read the entity value- Returns:
truewhen the selected upload date is present and still in the future
-
isCorrectEmails
protected boolean isCorrectEmails(boolean fromEditorFields) Validates the comma-separated notification addresses configured for a delayed upload.- Parameters:
fromEditorFields-trueto read the pending editor value;falseto read the entity value- Returns:
truewhen at least one address is present and every address is valid
-
isConcurrentModification
Detects whether the main file changed since the current edit operation began.- Parameters:
oldId- identifier of the file originally loaded for editingreferenceId- identifier used to reload the current archive record- Returns:
truewhen the reloaded record is no longer the main file
-
resolveFileDestinationDirPath
Resolves and validates the final destination directory without creating it.- Returns:
- normalized directory path, or
nullwhen it is outside the archive root
-
resolveFileDirPath
Resolves and validates the physical storage directory without creating it. Scheduled uploads use the insert-later staging prefix.- Returns:
- normalized storage directory path, or
nullwhen it is outside the archive root
-
getFileDirPath
Resolves the physical storage path and creates its directory when it does not exist.- Returns:
- normalized storage directory path, or
nullwhen validation fails
-
prepareFileArchivatorBean
protected void prepareFileArchivatorBean(String dirPath, String fileName, Long referenceId, boolean isNew) Populates archive persistence fields from the file placed in its storage directory.- Parameters:
dirPath- normalized storage directoryfileName- stored file namereferenceId- identifier of the main file, or-1for a new main fileisNew-trueto reset the entity identifier before persistence
-
findSameFiles
protected void findSameFiles(FileArchivatorBean newFab, boolean removePattern, boolean isBeforeSave) Finds uploaded main files whose content hash matches the candidate file.- Parameters:
newFab- candidate archive recordremovePattern-trueto exclude pattern files from the resultisBeforeSave-trueto calculate the candidate hash from the temporary upload
-
deleteFile
protected boolean deleteFile(FileArchivatorBean fabToDelete, String prefixText, boolean ignoreMissingFile) Deletes an archive file and its database record after verifying user permissions.- Parameters:
fabToDelete- archive record to removeprefixText- description prefix used in diagnostic messagesignoreMissingFile-trueto delete the record even when the physical file is absent- Returns:
truewhen permission and physical-file checks allow the record deletion attempt
-
deleteFilePatterns
Deletes all pattern files that refer to the supplied main file.- Parameters:
file- main archive recordignoreMissingFile-trueto remove records whose physical files are already absent- Returns:
truewhen every matching pattern is removed
-
getCacheTime
Resolves the cache lifetime for a specific archive operation with a component-wide fallback.- Parameters:
methodName- operation name used in the method-specific configuration key- Returns:
- cache lifetime in minutes
-
normalizePath
Normalizes an archive directory path to include leading and trailing separators.- Parameters:
path- path to normalize- Returns:
- normalized path, or the original empty value
-
normalizeToOldPath
Converts an archive directory to the legacy form without a leading separator.- Parameters:
path- path to normalize- Returns:
- legacy path form, or an empty string for empty input
-
checkPerms
protected final boolean checkPerms()Checks the permissions and feature flag required by the current archive operation.- Returns:
truewhen the current user may perform the selected operation
-