Class FileArchivatorKit
java.lang.Object
sk.iway.iwcm.components.file_archiv.FileArchivatorKit
Provides legacy file archive validation, naming, versioning, and cache utilities.
Older Java and JSP integrations use this class to prepare archive records and keep
their physical files and version references consistent.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringScans every archive record and reports physical files that are missing.booleancheckFileProperties(String fileName, long length, String pathName, Long oldId) Validates an uploaded file name, extension, size, and reserved archive path.static Collection<String>createCollection(String paramName, jakarta.servlet.http.HttpServletRequest req) Parses a plus-delimited request parameter into a collection.static voidClears the local file archive cache and, when configured, requests invalidation on cluster nodes.static booleandeleteStructure(int fabId, UserDetails user) Deprecated.static List<FileArchivatorBean>existSameFiles(FileArchivatorBean newFab, boolean removePattern) Finds other uploaded main files with the same content hash as a newly saved record.static booleanexistsPathInDB(String path) Checks whether an archive record already reserves a requested virtual file path.static intstatic Stringstatic StringFormats the current date and time for use in an archive version file name.static StringgetDateStampAsString(Date date) Formats a date and time for use in an archive version file name.static String[]static StringgetFileExtension(String fileName) static StringgetFileExtension(String fileName, boolean allowNull) static Stringstatic Stringstatic longstatic StringCalculates the MD5 digest of a physical archive file.static StringgetPojoZmeny(Object newObj, Object originalObj) Formats the property differences between an updated object and its original value.static StringgetSecurityHash(String input) Generates the legacy MD5 security hash for a string and its length.static StringgetUniqueFileName(String fileNameParam, String directoryPath, String preferredDate) Creates a sanitized file name that does not collide with an existing file in the directory.static StringReturns a sanitized request parameter value with an empty-string fallback.booleanhasAllowedExtensions(String fileName, Long oldId) Checks whether an uploaded file has an extension allowed for its archive operation.static voidincrementOrderId(Long referenceId) Advances the history order of every version belonging to a main archive file.static booleanisArchivEnabled(jakarta.servlet.http.HttpServletRequest request) Checks whether the current request user can access the file archive module.static booleanisArchivEnabled(Identity userIdentity) Checks whether a user can access the file archive module.prepareAndValidate(FileArchivatorBean fab, Long oldId, UserDetails user) Validates and prepares an uploaded archive record for a create operation.prepareAndValidate(FileArchivatorBean fab, Long oldId, UserDetails user, boolean isEdit) Validates an uploaded archive record and synchronizes its file metadata before persistence.static booleanrenameFile(String dirPath, String fileName, FileArchivatorBean oldFileBean) Exchanges the content of a newly uploaded file with the current archive file through a temporary copy.static booleanreSetReference(Long oldReferenceId, Long newReferenceId) Moves every history reference from an old main-file identifier to a new one.protected voidbooleansetFilePropertiesAfterUpload(FileArchivatorBean newFab, Long oldId) Persists a newly uploaded archive file and updates version references when replacing a current file.
-
Constructor Details
-
FileArchivatorKit
-
-
Method Details
-
isArchivEnabled
public static boolean isArchivEnabled(jakarta.servlet.http.HttpServletRequest request) Checks whether the current request user can access the file archive module.- Parameters:
request- current HTTP request- Returns:
truewhen the current user has file archive access
-
isArchivEnabled
Checks whether a user can access the file archive module.- Parameters:
userIdentity- user identity to check- Returns:
truewhen the user has file archive access
-
getArchivPath
-
getInsertLaterPath
-
getFullInsertLaterPath
-
getUniqueFileName
public static String getUniqueFileName(String fileNameParam, String directoryPath, String preferredDate) Creates a sanitized file name that does not collide with an existing file in the directory.- Parameters:
fileNameParam- requested file namedirectoryPath- destination directorypreferredDate- preferred version timestamp, ornullto use the current timestamp- Returns:
- available file name, or
nullwhen the name or directory is empty
-
renameFile
Exchanges the content of a newly uploaded file with the current archive file through a temporary copy.- Parameters:
dirPath- directory containing the newly uploaded filefileName- name of the newly uploaded fileoldFileBean- record describing the current archive file- Returns:
truewhen all file copies complete successfully
-
reSetReference
Moves every history reference from an old main-file identifier to a new one. The new main record is detached from its previous reference after the migration.- Parameters:
oldReferenceId- previous main-file identifiernewReferenceId- new main-file identifier- Returns:
truewhen all affected records are saved successfully
-
getMD5
Calculates the MD5 digest of a physical archive file.- Parameters:
iwcmFile- file to hash- Returns:
- hexadecimal digest, or the literal
"null"when the file is unavailable
-
getDateStampAsString
Formats the current date and time for use in an archive version file name.- Returns:
- current timestamp in the archive file-name format
-
getDateStampAsString
Formats a date and time for use in an archive version file name.- Parameters:
date- date to format, ornullto use the current time- Returns:
- timestamp in the archive file-name format
-
getFileExtension
-
getFileExtension
-
incrementOrderId
Advances the history order of every version belonging to a main archive file. The archive cache is cleared after the records are updated.- Parameters:
referenceId- main-file identifier shared by the history records
-
getDomainNames
-
existsPathInDB
Checks whether an archive record already reserves a requested virtual file path.- Parameters:
path- virtual path containing a directory and file name- Returns:
truewhen a matching database record exists
-
checkFileConsistency
Scans every archive record and reports physical files that are missing. This operation is expensive because it checks the file system for the full archive table.- Returns:
- HTML-formatted consistency errors, or an empty string when every file exists
-
getSecurityHash
Generates the legacy MD5 security hash for a string and its length.- Parameters:
input- source value- Returns:
- hexadecimal hash, or an empty string when hashing fails
-
existSameFiles
public static List<FileArchivatorBean> existSameFiles(FileArchivatorBean newFab, boolean removePattern) Finds other uploaded main files with the same content hash as a newly saved record.- Parameters:
newFab- newly saved archive recordremovePattern-trueto exclude pattern files- Returns:
- matching archive records, or
nullwhen no duplicate exists
-
deleteFileArchiveCache
public static void deleteFileArchiveCache()Clears the local file archive cache and, when configured, requests invalidation on cluster nodes. -
generateNextGlobalId
public static int generateNextGlobalId() -
createCollection
public static Collection<String> createCollection(String paramName, jakarta.servlet.http.HttpServletRequest req) Parses a plus-delimited request parameter into a collection.- Parameters:
paramName- request parameter namereq- current HTTP request- Returns:
- parsed values, or
nullwhen the parameter contains no values
-
getVal
Returns a sanitized request parameter value with an empty-string fallback.- Parameters:
request- current HTTP requestparameterName- request parameter name- Returns:
- sanitized parameter value, or an empty string when the parameter is absent
-
prepareAndValidate
Validates and prepares an uploaded archive record for a create operation. The record must provide its file path, file name, and upload metadata.- Parameters:
fab- uploaded archive recordoldId- identifier of the record being versioned, or a non-positive value for a new fileuser- user performing the upload- Returns:
- validation result containing the prepared archive record or localized errors
-
prepareAndValidate
public ResultArchivBean prepareAndValidate(FileArchivatorBean fab, Long oldId, UserDetails user, boolean isEdit) Validates an uploaded archive record and synchronizes its file metadata before persistence.- Parameters:
fab- uploaded archive recordoldId- identifier of the record being versioned, or a non-positive value for a new fileuser- user performing the uploadisEdit-trueto allow validation of an existing virtual path- Returns:
- validation result containing the prepared archive record or localized errors
-
setError
-
checkFileProperties
Validates an uploaded file name, extension, size, and reserved archive path.- Parameters:
fileName- uploaded file namelength- uploaded file size in bytespathName- requested virtual file patholdId- existing archive record identifier when uploading a new version- Returns:
truewhen all file properties are valid
-
hasAllowedExtensions
Checks whether an uploaded file has an extension allowed for its archive operation. New versions must retain the extension of the current file, while new files use the configured allowlist.- Parameters:
fileName- uploaded file nameoldId- existing archive record identifier, or a non-positive value for a new file- Returns:
truewhen the file extension is allowed
-
getMaxFileSize
public static long getMaxFileSize() -
setFilePropertiesAfterUpload
Persists a newly uploaded archive file and updates version references when replacing a current file.- Parameters:
newFab- archive record describing the uploaded fileoldId- identifier of the current archive file, or a non-positive value for a new main file- Returns:
truewhen the archive update completes without a detected file or versioning error
-
getPojoZmeny
Formats the property differences between an updated object and its original value.- Parameters:
newObj- updated objectoriginalObj- original object- Returns:
- formatted differences, or
"Bez zmeny"when either object is absent
-
getErrorsList
-
deleteStructure
Deprecated.create aFileArchiveServiceand callFileArchiveService.deleteStructure()Deletes an archive structure through the currentFileArchiveServiceimplementation. Retained for callers that still provide legacy user details and an integer identifier.- Parameters:
fabId- archive record identifieruser- user performing the deletion- Returns:
truewhen the structure is deleted successfully
-
FileArchiveServiceand callFileArchiveService.deleteStructure()