Class FileArchivatorKit

java.lang.Object
sk.iway.iwcm.components.file_archiv.FileArchivatorKit

public class FileArchivatorKit extends Object
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 Details

    • FileArchivatorKit

      public FileArchivatorKit(Prop paramProp)
  • 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:
      true when the current user has file archive access
    • isArchivEnabled

      public static boolean isArchivEnabled(Identity userIdentity)
      Checks whether a user can access the file archive module.
      Parameters:
      userIdentity - user identity to check
      Returns:
      true when the user has file archive access
    • getArchivPath

      public static String getArchivPath()
    • getInsertLaterPath

      public static String getInsertLaterPath()
    • getFullInsertLaterPath

      public static String 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 name
      directoryPath - destination directory
      preferredDate - preferred version timestamp, or null to use the current timestamp
      Returns:
      available file name, or null when the name or directory is empty
    • renameFile

      public static boolean renameFile(String dirPath, String fileName, FileArchivatorBean oldFileBean)
      Exchanges the content of a newly uploaded file with the current archive file through a temporary copy.
      Parameters:
      dirPath - directory containing the newly uploaded file
      fileName - name of the newly uploaded file
      oldFileBean - record describing the current archive file
      Returns:
      true when all file copies complete successfully
    • reSetReference

      public static boolean reSetReference(Long oldReferenceId, Long newReferenceId)
      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 identifier
      newReferenceId - new main-file identifier
      Returns:
      true when all affected records are saved successfully
    • getMD5

      public static String getMD5(IwcmFile iwcmFile)
      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

      public static String 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

      public static String getDateStampAsString(Date date)
      Formats a date and time for use in an archive version file name.
      Parameters:
      date - date to format, or null to use the current time
      Returns:
      timestamp in the archive file-name format
    • getFileExtension

      public static String getFileExtension(String fileName)
    • getFileExtension

      public static String getFileExtension(String fileName, boolean allowNull)
    • incrementOrderId

      public static void incrementOrderId(Long referenceId)
      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

      public static String[] getDomainNames()
    • existsPathInDB

      public static boolean existsPathInDB(String path)
      Checks whether an archive record already reserves a requested virtual file path.
      Parameters:
      path - virtual path containing a directory and file name
      Returns:
      true when a matching database record exists
    • checkFileConsistency

      public static String 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

      public static String getSecurityHash(String input)
      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 record
      removePattern - true to exclude pattern files
      Returns:
      matching archive records, or null when 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 name
      req - current HTTP request
      Returns:
      parsed values, or null when the parameter contains no values
    • getVal

      public static String getVal(jakarta.servlet.http.HttpServletRequest request, String parameterName)
      Returns a sanitized request parameter value with an empty-string fallback.
      Parameters:
      request - current HTTP request
      parameterName - request parameter name
      Returns:
      sanitized parameter value, or an empty string when the parameter is absent
    • prepareAndValidate

      public ResultArchivBean prepareAndValidate(FileArchivatorBean fab, Long oldId, UserDetails user)
      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 record
      oldId - identifier of the record being versioned, or a non-positive value for a new file
      user - 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 record
      oldId - identifier of the record being versioned, or a non-positive value for a new file
      user - user performing the upload
      isEdit - true to allow validation of an existing virtual path
      Returns:
      validation result containing the prepared archive record or localized errors
    • setError

      protected void setError(String key)
    • checkFileProperties

      public boolean checkFileProperties(String fileName, long length, String pathName, Long oldId)
      Validates an uploaded file name, extension, size, and reserved archive path.
      Parameters:
      fileName - uploaded file name
      length - uploaded file size in bytes
      pathName - requested virtual file path
      oldId - existing archive record identifier when uploading a new version
      Returns:
      true when all file properties are valid
    • hasAllowedExtensions

      public boolean hasAllowedExtensions(String fileName, Long oldId)
      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 name
      oldId - existing archive record identifier, or a non-positive value for a new file
      Returns:
      true when the file extension is allowed
    • getMaxFileSize

      public static long getMaxFileSize()
    • setFilePropertiesAfterUpload

      public boolean setFilePropertiesAfterUpload(FileArchivatorBean newFab, Long oldId)
      Persists a newly uploaded archive file and updates version references when replacing a current file.
      Parameters:
      newFab - archive record describing the uploaded file
      oldId - identifier of the current archive file, or a non-positive value for a new main file
      Returns:
      true when the archive update completes without a detected file or versioning error
    • getPojoZmeny

      public static String getPojoZmeny(Object newObj, Object originalObj)
      Formats the property differences between an updated object and its original value.
      Parameters:
      newObj - updated object
      originalObj - original object
      Returns:
      formatted differences, or "Bez zmeny" when either object is absent
    • getErrorsList

      public List<String> getErrorsList()
    • deleteStructure

      @Deprecated public static boolean deleteStructure(int fabId, UserDetails user)
      Deletes an archive structure through the current FileArchiveService implementation. Retained for callers that still provide legacy user details and an integer identifier.
      Parameters:
      fabId - archive record identifier
      user - user performing the deletion
      Returns:
      true when the structure is deleted successfully