Interface Repository

  • All Superinterfaces:
    AutoCloseable
    All Known Subinterfaces:
    BranchRepository, FolderRepository
    All Known Implementing Classes:
    DatasourceDBRepository, FileSystemRepository, JarLocalRepository, JdbcDBRepository, LocalRepository, ZippedLocalRepository

    public interface Repository
    extends AutoCloseable
    The interface of the repository abstraction. It contains a minimal set of methods to be compatible with various of internet storages like Amazon S3, Google Cloud Storage or Azure Storage. And to be simple to implement own storage based on a Database or a File System. This repository does not assume that it should support transactions, sessions or concurrent access. This repository must support only the atomicity of file modification, so the file always contains valid data. All path names in the repository MUST BE relative and satisfy to the following rules:
    1. Only '/' symbol MUST be used to separate folders
    2. The first symbol of the path MUST NOT be started from '/'
    3. The path to the folder MUST be ended with '/'
    4. The path to the file MUST NOT be ended with '/'
    5. The path to the root folder is the empty path
    Examples:
    • '' - the root folder
    • 'file_name' - file
    • 'folder_name/' - folder
    • 'folder_name/inner_file' - file
    • 'folder_name/inner_folder/' - folder
    Author:
    Yury Molchan
    • Method Detail

      • getId

        String getId()
        Get unique identifier for Repository. Used to distinguish one repository from another. Must be unique.
        Returns:
        repository id.
      • getName

        String getName()
        Get repository name shown on UI.
        Returns:
        repository name
      • list

        List<FileData> list​(String path)
                     throws IOException
        Return a list of files recursively in the given folder.
        Parameters:
        path - the folder to scan. The path must be ended by '/' or be empty.
        Returns:
        the list of the file descriptors. Invalid files are ignored.
        Throws:
        IOException - if not possible to read the directory.
      • check

        FileData check​(String name)
                throws IOException
        Read a file descriptor by the given path name.
        Parameters:
        name - the path name of the file to read.
        Returns:
        the file descriptor or null if the file is absent.
        Throws:
        IOException - if not possible to read the file descriptor.
      • read

        FileItem read​(String name)
               throws IOException
        Read a file by the given path name.
        Parameters:
        name - the path name of the file to read.
        Returns:
        the file descriptor or null if the file is absent.
        Throws:
        IOException - if not possible to read the file.
      • save

        FileData save​(FileData data,
                      InputStream stream)
               throws IOException
        Save a file.
        Parameters:
        data - the file descriptor.
        stream - the stream to save with the specified file descriptor.
        Returns:
        the resulted file descriptor after successful writing.
        Throws:
        IOException - if not possible to save the file.
      • save

        List<FileData> save​(List<FileItem> fileItems)
                     throws IOException
        Save multiple projects in one transaction. Used only in deployment services
        Parameters:
        fileItems - list of file descriptor and stream pairs
        Throws:
        IOException - if not possible to save the file.
      • delete

        boolean delete​(FileData data)
                throws IOException
        Delete a file or mark it as deleted.
        Parameters:
        data - the file descriptor to delete.
        Returns:
        true if file has been deleted successfully or false if the file is absent.
        Throws:
        IOException - if not possible to delete the file.
      • delete

        boolean delete​(List<FileData> data)
                throws IOException
        Delete multiple files or mark it as deleted in one transaction.
        Parameters:
        data - list of files to delete
        Returns:
        true if at least one file is deleted
        Throws:
        IOException - if not possible to delete the file
      • setListener

        void setListener​(Listener callback)
        Set a listener to monitor changes in the repository.
        Parameters:
        callback - the listener.
      • listHistory

        List<FileData> listHistory​(String name)
                            throws IOException
        List a versions of the given file. If the repository does not support file versions, then it will return one record of the given file. The order of the file descriptions is undefined, but the first element is the actual file which can be access by read(String) method.
        Parameters:
        name - the file name.
        Returns:
        the list of file descriptions.
        Throws:
        IOException - if not possible to read the directory.
      • checkHistory

        FileData checkHistory​(String name,
                              String version)
                       throws IOException
        Read a file descriptor by the given path name of the given version. If the version is null, then it will work like check(String) method.
        Parameters:
        name - the path name of the file to read.
        version - the version of the file to read, can be null.
        Returns:
        the file descriptor or null if the file is absent.
        Throws:
        IOException - if not possible to read the file descriptor.
        See Also:
        read(String)
      • readHistory

        FileItem readHistory​(String name,
                             String version)
                      throws IOException
        Read a file by the given path name of the given version. If the version is null, then it will work like read(String) method.
        Parameters:
        name - the path name of the file to read.
        version - the version of the file to read, can be null.
        Returns:
        the file descriptor or null if the file is absent.
        Throws:
        IOException - if not possible to read the file.
        See Also:
        read(String)
      • deleteHistory

        boolean deleteHistory​(FileData data)
                       throws IOException
        Delete a file from the history. If the version is null, then it will delete all versions of the file from the history.
        Parameters:
        data - the file descriptor to delete. The fields "name", "version", "author" and "comment" must be initialized.
        Returns:
        true if file has been deleted successfully or false if the file is absent.
        Throws:
        IOException - if not possible to delete the file.
        See Also:
        delete(FileData)
      • copyHistory

        FileData copyHistory​(String srcName,
                             FileData destData,
                             String version)
                      throws IOException
        Copy a file of the given version to the destination file. If the version is null, then copy latest version.
        Parameters:
        srcName - the file to copy.
        destData - the destination file descriptor.
        version - the version of the file to copy
        Returns:
        the file descriptor of the resulted file.
        Throws:
        IOException - if not possible to copy the file
      • supports

        Features supports()
        Get the features supported by the repository. If specific feature is supported, repository instance can be casted to interface class that support that feature.
        Returns:
        Supported features
      • validateConnection

        default void validateConnection()
                                 throws IOException
        Validate underlying connection. Default implementation does nothing.
        Throws:
        IOException - if connection cannot be established