Package org.openl.rules.repository.api
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:- Only '/' symbol MUST be used to separate folders
- The first symbol of the path MUST NOT be started from '/'
- The path to the folder MUST be ended with '/'
- The path to the file MUST NOT be ended with '/'
- The path to the root folder is the empty path
- '' - the root folder
- 'file_name' - file
- 'folder_name/' - folder
- 'folder_name/inner_file' - file
- 'folder_name/inner_folder/' - folder
- Author:
- Yury Molchan
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description FileDatacheck(String name)Read a file descriptor by the given path name.FileDatacheckHistory(String name, String version)Read a file descriptor by the given path name of the given version.default voidclose()FileDatacopyHistory(String srcName, FileData destData, String version)Copy a file of the given version to the destination file.booleandelete(List<FileData> data)Delete multiple files or mark it as deleted in one transaction.booleandelete(FileData data)Delete a file or mark it as deleted.booleandeleteHistory(FileData data)Delete a file from the history.StringgetId()Get unique identifier for Repository.StringgetName()Get repository name shown on UI.List<FileData>list(String path)Return a list of files recursively in the given folder.List<FileData>listHistory(String name)List a versions of the given file.FileItemread(String name)Read a file by the given path name.FileItemreadHistory(String name, String version)Read a file by the given path name of the given version.List<FileData>save(List<FileItem> fileItems)Save multiple projects in one transaction.FileDatasave(FileData data, InputStream stream)Save a file.voidsetListener(Listener callback)Set a listener to monitor changes in the repository.Featuressupports()Get the features supported by the repository.default voidvalidateConnection()Validate underlying connection.
-
-
-
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 byread(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 likecheck(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 likeread(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
-
close
default void close() throws Exception- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
validateConnection
default void validateConnection() throws IOExceptionValidate underlying connection. Default implementation does nothing.- Throws:
IOException- if connection cannot be established
-
-