Class AdminConfigEditorBean

java.lang.Object
io.goobi.viewer.managedbeans.AdminConfigEditorBean
All Implemented Interfaces:
Serializable

@Named @SessionScoped public class AdminConfigEditorBean extends Object implements Serializable
JSF backing bean for the admin configuration editor, allowing administrators to view and modify the viewer config file.

Symlink note: the configuration directory (/opt/digiverso/viewer/config/) legitimately contains symbolic links to files that live outside the viewer's own filesystem tree:

  • config_indexer.xml/opt/digiverso/indexer/config_indexer.xml
  • robots.txt/var/www/robots.txt

These symlinks are intentional and must keep working. Any future migration of this bean's Files calls to symlink-rejecting helpers (see FileTools.copyRejectingSymlinks / openRejectingSymlinks / moveRejectingSymlinks / newBufferedWriterRejectingSymlinks) must therefore introduce a path-allowlist for these two files (or the entire config directory) — applying strict-reject here unconditionally would break the config editor's read/write of the indexer config and the robots file.

See Also:
  • Constructor Details

    • AdminConfigEditorBean

      public AdminConfigEditorBean()
      Creates a new AdminConfigEditorBean instance.
  • Method Details

    • init

      @PostConstruct public void init()
      init.
    • isRenderBackend

      public boolean isRenderBackend()
      isRenderBackend.
      Returns:
      true if the admin backend is rendered for the current user, false otherwise
    • refresh

      public void refresh()
      refresh.
    • selectBackup

      public void selectBackup(int backupNumber) throws IOException
      Throws:
      IOException
    • upload

      public void upload(Path file)
    • download

      public void download(Path file) throws IOException
      Throws:
      IOException
    • getFileRecordsModel

      public DataModel<FileRecord> getFileRecordsModel()
      getFileRecordsModel.
      Returns:
      the data model wrapping the current list of config file records
    • getFileInEditionNumber

      public int getFileInEditionNumber()
      Getter for the field fileInEditionNumber.
      Returns:
      a int
    • setFileInEditionNumber

      public void setFileInEditionNumber(int fileInEditionNumber)
      Setter for the field fileInEditionNumber.
      Parameters:
      fileInEditionNumber - zero-based index of the file in the file list
    • getCurrentFileRecord

      public FileRecord getCurrentFileRecord()
      Getter for the field currentFileRecord.
      Returns:
      the FileRecord currently open in the config editor, or null if none selected
    • getFileContent

      public String getFileContent()
      Getter for the field fileContent.
      Returns:
      the text content of the currently open configuration file
    • setFileContent

      public void setFileContent(String fileContent)
      Setter for the field fileContent.
      Parameters:
      fileContent - text content of the currently open config file
    • getBackupRecords

      public List<BackupRecord> getBackupRecords()
      Getter for the field backupRecords.
      Returns:
      a list of backup file records for configuration files
    • getBackupRecordsModel

      public DataModel<BackupRecord> getBackupRecordsModel()
      Getter for the field backupRecordsModel.
      Returns:
      the data model wrapping the list of backup file records
    • isEditable

      public boolean isEditable()
      isEditable.
      Returns:
      true if the currently open config file is in write mode, false if it is read-only
    • setEditable

      public void setEditable(boolean editable)
      Setter for the field editable.
      Parameters:
      editable - true to open the file in write mode; false for read-only
    • isBackupsAvailable

      public boolean isBackupsAvailable()
      isBackupsAvailable.
      Returns:
      true if at least one backup record exists for the current config file, false otherwise
    • getCurrentConfigFileType

      public String getCurrentConfigFileType()
      getCurrentConfigFileType.
      Returns:
      the file type of the currently open config file, or an empty string if none is selected
    • isFileLocked

      public boolean isFileLocked(FileRecord fileRecord)
      Determines whether the given fileRecord is locked, either by a different user session holding the in-memory edit lock or by an external vim process holding a swap-file lock on the file.
      Parameters:
      fileRecord - file record whose lock status is to be checked
      Returns:
      true if locked by another session or by an external vim process; false otherwise
    • isNightMode

      public boolean isNightMode()
      isNightMode.
      Returns:
      true if the editor is in night mode, false otherwise
    • changeNightMode

      public void changeNightMode()
      changeNightMode.
    • openFile

      public void openFile() throws IOException
      openFile.
      Throws:
      IOException
    • closeCurrentFileAction

      public String closeCurrentFileAction()
      closeCurrentFileAction.
      Returns:
      Navigation outcome
    • lockFile

      public static boolean lockFile(Path file, String sessionId)
      Locks the given file for the given session id and creates its owner-tagged vim swap file.
      Parameters:
      file - path of the config file to lock
      sessionId - HTTP session ID acquiring the lock
      Returns:
      true if the lock was acquired; false if held by another session
    • unlockFile

      public static void unlockFile(Path file, String sessionId)
      Unlocks the given file for the given session id and deletes its owner-tagged swap file.
      Parameters:
      file - path of the config file to unlock
      sessionId - HTTP session ID that holds the lock to release
    • renewLock

      public static boolean renewLock(Path file, String sessionId)
      Renews the lease for the given file and session id (heartbeat) in the static (global) fileLocks object.
      Parameters:
      file - path of the config file whose lease should be renewed
      sessionId - HTTP session ID that must hold the lease
      Returns:
      true if the lease was renewed; false otherwise
    • removeExpiredLocks

      public static void removeExpiredLocks()
      Removes all expired leases and deletes each one's owner-tagged vim swap file. Deleting the swap file lets the existing SwapFileWatcher push a lock-status refresh to clients. Invoked periodically by FileLockReaper.
    • editFile

      public String editFile(FileRecord record)
      Selects the given file record for editing and navigates to its edit view. The record is passed explicitly (instead of resolving it via the DataModel's row index) so the correct, clicked file is selected even inside the ui:repeat; this is a POST command (not a prefetchable GET link), avoiding speculative requests that would mutate the shared session selection.
      Parameters:
      record - the file record that was clicked
      Returns:
      the navigation outcome redirecting to the config editor file view
    • saveCurrentFileAction

      public String saveCurrentFileAction()
      Saves the currently open file.
      Returns:
      Navigation outcome
    • createBackup

      public void createBackup(FileRecord rec) throws IOException
      Throws:
      IOException
    • createBackup

      public static void createBackup(String backupFolderPath, String fileName, String content) throws IOException
      Creates a timestamped backup of the given file name and content.
      Parameters:
      backupFolderPath - Backup folder path
      fileName - File name
      content - File content
      Throws:
      IOException
    • refreshBackups

      public void refreshBackups(File backupFolder)
      refreshBackups.
      Parameters:
      backupFolder - directory containing timestamped backup files to list
    • isConfigViewer

      public boolean isConfigViewer()
      isConfigViewer.
      Returns:
      true if currently editing config_viewer.xml; false otherwise
    • selectFileAndShowBackups

      public void selectFileAndShowBackups(boolean writable)
      selectFileAndShowBackups.
      Parameters:
      writable - true to open the file for editing; false for read-only view
    • selectFileAndShowBackups

      public void selectFileAndShowBackups(FileRecord record)
      Selects the given file record explicitly (not via the DataModel row index), so the clicked file inside the ui:repeat is selected reliably. Editability follows the record's own writable flag.
      Parameters:
      record - the file record to select
    • showBackups

      public void showBackups()
      showBackups.
    • downloadFile

      public String downloadFile(BackupRecord rec) throws IOException
      downloadFile.
      Parameters:
      rec - BackupRecord for which to download the file
      Returns:
      Navigation outcome
      Throws:
      IOException
    • clearLocksForSessionId

      public static void clearLocksForSessionId(String sessionId)
      Removes file locks for the given session id.
      Parameters:
      sessionId - HTTP session ID whose locks are to be released
    • getCurrentFileName

      public String getCurrentFileName()
      getCurrentFileName.
      Returns:
      File name of the currently selected file record row
    • setCurrentFileName

      public void setCurrentFileName(String fileName) throws FileNotFoundException
      Getter for the URL pattern.
      Parameters:
      fileName - decoded URL-encoded filename to select from the file list
      Throws:
      FileNotFoundException
    • getRecord

      public FileRecord getRecord(String filename)
    • getCurrentFilePath

      public Path getCurrentFilePath()
      getCurrentFilePath.
      Returns:
      the file system path of the currently open config file, or null if none is selected
    • getFileUploader

      public FileUploader getFileUploader()