Class FileArchivSupportMethodsService

java.lang.Object
sk.iway.iwcm.components.file_archiv.FileArchivSupportMethodsService
Direct Known Subclasses:
FileArchiveService

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

    • cachePrefix

      protected static String cachePrefix
    • SEPARATOR

      public static final String SEPARATOR
      See Also:
    • request

      protected jakarta.servlet.http.HttpServletRequest request
    • prop

      protected Prop prop
    • currentUser

      protected Identity currentUser
    • domainId

      protected int domainId
    • repository

      protected FileArchiveRepository repository
    • fab

      protected FileArchivatorBean fab
    • referenceId

      protected long referenceId
    • saveLater

      protected boolean saveLater
    • renameFile

      protected boolean renameFile
    • saveAfterId

      protected int saveAfterId
    • isPatternFile

      protected boolean isPatternFile
    • uploadType

      protected FileArchiveService.UploadType uploadType
    • fileToUploadName

      protected String fileToUploadName
    • fileToUpload

      protected IwcmFile fileToUpload
    • errorList

      protected List<String> errorList
    • errorParams

      protected String[] errorParams
    • sameFiles

      protected List<FileArchivatorBean> sameFiles
  • Constructor Details

    • FileArchivSupportMethodsService

      public FileArchivSupportMethodsService()
  • Method Details

    • updateReferenceToMainFile

      protected void updateReferenceToMainFile(String oldReferenceToMain)
      Redirects pattern references from an old main-file path to the current archive file.
      Parameters:
      oldReferenceToMain - previous virtual path of the main file
    • updateReferenceToMainFile

      protected void updateReferenceToMainFile(Long referenceId, String referenceToMain)
      Updates the pattern reference stored by every history record in a file thread.
      Parameters:
      referenceId - identifier of the main file whose history is updated
      referenceToMain - new main-file virtual path
    • isUploadDateCorrect

      protected boolean isUploadDateCorrect(boolean fromEditorFields)
      Checks whether the configured delayed-upload date is in the future.
      Parameters:
      fromEditorFields - true to read the pending editor value; false to read the entity value
      Returns:
      true when 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 - true to read the pending editor value; false to read the entity value
      Returns:
      true when at least one address is present and every address is valid
    • isConcurrentModification

      protected boolean isConcurrentModification(Long oldId, Long referenceId)
      Detects whether the main file changed since the current edit operation began.
      Parameters:
      oldId - identifier of the file originally loaded for editing
      referenceId - identifier used to reload the current archive record
      Returns:
      true when the reloaded record is no longer the main file
    • resolveFileDestinationDirPath

      public String resolveFileDestinationDirPath()
      Resolves and validates the final destination directory without creating it.
      Returns:
      normalized directory path, or null when it is outside the archive root
    • resolveFileDirPath

      protected String 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 null when it is outside the archive root
    • getFileDirPath

      protected String getFileDirPath()
      Resolves the physical storage path and creates its directory when it does not exist.
      Returns:
      normalized storage directory path, or null when 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 directory
      fileName - stored file name
      referenceId - identifier of the main file, or -1 for a new main file
      isNew - true to 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 record
      removePattern - true to exclude pattern files from the result
      isBeforeSave - true to 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 remove
      prefixText - description prefix used in diagnostic messages
      ignoreMissingFile - true to delete the record even when the physical file is absent
      Returns:
      true when permission and physical-file checks allow the record deletion attempt
    • deleteFilePatterns

      protected boolean deleteFilePatterns(FileArchivatorBean file, boolean ignoreMissingFile)
      Deletes all pattern files that refer to the supplied main file.
      Parameters:
      file - main archive record
      ignoreMissingFile - true to remove records whose physical files are already absent
      Returns:
      true when every matching pattern is removed
    • getCacheTime

      protected static int getCacheTime(String methodName)
      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

      public static String normalizePath(String path)
      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

      public static String normalizeToOldPath(String path)
      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:
      true when the current user may perform the selected operation