Package org.openl.rules.repository.file
Class FileSystemRepository
- java.lang.Object
-
- org.openl.rules.repository.file.FileSystemRepository
-
- All Implemented Interfaces:
Closeable,AutoCloseable,FolderRepository,Repository
- Direct Known Subclasses:
LocalRepository
public class FileSystemRepository extends Object implements FolderRepository, Closeable
A simple implementation of a file-system-based repository. This repository does not support versioning.- Author:
- Yury Molchan
-
-
Constructor Summary
Constructors Constructor Description FileSystemRepository()
-
Method Summary
All Methods Instance Methods Concrete 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.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.protected FileDatagetFileData(File file)StringgetId()Get unique identifier for Repository.StringgetName()Get repository name shown on UI.FilegetRoot()protected StringgetVersion(File file)voidinitialize()protected voidinvokeListener()protected booleanisSkip(File file)List<FileData>list(String path)Return a list of files recursively in the given folder.List<FileData>listFiles(String path, String version)Return a list of files recursively in the given folder and given version.List<FileData>listFolders(String path)Return a list of folders in the given path (not recursively).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.FileDatasave(FileData folderData, Iterable<FileItem> files, ChangesetType changesetType)Save the folder.voidsetId(String id)voidsetListener(Listener callback)Set a listener to monitor changes in the repository.voidsetListenerTimerPeriod(int listenerTimerPeriod)voidsetName(String name)voidsetRoot(File root)voidsetUri(String path)Featuressupports()Get the features supported by the repository.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.openl.rules.repository.api.Repository
validateConnection
-
-
-
-
Method Detail
-
setRoot
public void setRoot(File root)
-
setUri
public void setUri(String path)
-
initialize
public void initialize()
-
setId
public void setId(String id)
-
getId
public String getId()
Description copied from interface:RepositoryGet unique identifier for Repository. Used to distinguish one repository from another. Must be unique.- Specified by:
getIdin interfaceRepository- Returns:
- repository id.
-
setName
public void setName(String name)
-
getName
public String getName()
Description copied from interface:RepositoryGet repository name shown on UI.- Specified by:
getNamein interfaceRepository- Returns:
- repository name
-
list
public List<FileData> list(String path) throws IOException
Description copied from interface:RepositoryReturn a list of files recursively in the given folder.- Specified by:
listin interfaceRepository- 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
public FileData check(String name) throws IOException
Description copied from interface:RepositoryRead a file descriptor by the given path name.- Specified by:
checkin interfaceRepository- 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
public FileItem read(String name) throws IOException
Description copied from interface:RepositoryRead a file by the given path name.- Specified by:
readin interfaceRepository- 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
public FileData save(FileData data, InputStream stream) throws IOException
Description copied from interface:RepositorySave a file.- Specified by:
savein interfaceRepository- 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
public List<FileData> save(List<FileItem> fileItems) throws IOException
Description copied from interface:RepositorySave multiple projects in one transaction. Used only in deployment services- Specified by:
savein interfaceRepository- Parameters:
fileItems- list of file descriptor and stream pairs- Throws:
IOException- if not possible to save the file.
-
delete
public boolean delete(FileData data) throws IOException
Description copied from interface:RepositoryDelete a file or mark it as deleted.- Specified by:
deletein interfaceRepository- 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
public boolean delete(List<FileData> data) throws IOException
Description copied from interface:RepositoryDelete multiple files or mark it as deleted in one transaction.- Specified by:
deletein interfaceRepository- 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
public void setListener(Listener callback)
Description copied from interface:RepositorySet a listener to monitor changes in the repository.- Specified by:
setListenerin interfaceRepository- Parameters:
callback- the listener.
-
listHistory
public List<FileData> listHistory(String name)
Description copied from interface:RepositoryList 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 byRepository.read(String)method.- Specified by:
listHistoryin interfaceRepository- Parameters:
name- the file name.- Returns:
- the list of file descriptions.
-
checkHistory
public FileData checkHistory(String name, String version) throws IOException
Description copied from interface:RepositoryRead a file descriptor by the given path name of the given version. If the version is null, then it will work likeRepository.check(String)method.- Specified by:
checkHistoryin interfaceRepository- 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:
Repository.read(String)
-
readHistory
public FileItem readHistory(String name, String version) throws IOException
Description copied from interface:RepositoryRead a file by the given path name of the given version. If the version is null, then it will work likeRepository.read(String)method.- Specified by:
readHistoryin interfaceRepository- 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:
Repository.read(String)
-
deleteHistory
public boolean deleteHistory(FileData data) throws IOException
Description copied from interface:RepositoryDelete a file from the history. If the version is null, then it will delete all versions of the file from the history.- Specified by:
deleteHistoryin interfaceRepository- 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:
Repository.delete(FileData)
-
copyHistory
public FileData copyHistory(String srcName, FileData destData, String version) throws IOException
Description copied from interface:RepositoryCopy a file of the given version to the destination file. If the version is null, then copy latest version.- Specified by:
copyHistoryin interfaceRepository- 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
public Features supports()
Description copied from interface:RepositoryGet the features supported by the repository. If specific feature is supported, repository instance can be casted to interface class that support that feature.- Specified by:
supportsin interfaceRepository- Returns:
- Supported features
-
getFileData
protected FileData getFileData(File file) throws IOException
- Throws:
IOException
-
getRoot
public File getRoot()
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceRepository
-
invokeListener
protected void invokeListener()
-
listFolders
public List<FileData> listFolders(String path)
Description copied from interface:FolderRepositoryReturn a list of folders in the given path (not recursively).- Specified by:
listFoldersin interfaceFolderRepository- Parameters:
path- the folder to scan. The path must be ended by '/' or be empty.- Returns:
- the list of the folder descriptors. Invalid folders are ignored.
-
listFiles
public List<FileData> listFiles(String path, String version) throws IOException
Description copied from interface:FolderRepositoryReturn a list of files recursively in the given folder and given version.- Specified by:
listFilesin interfaceFolderRepository- Parameters:
path- the folder to scan. The path must be ended by '/' or be empty.version- the version of the folder to read, can be null.- Returns:
- the list of the file descriptors. Invalid files are ignored.
- Throws:
IOException- if not possible to read the directory.
-
save
public FileData save(FileData folderData, Iterable<FileItem> files, ChangesetType changesetType) throws IOException
Description copied from interface:FolderRepositorySave the folder.- Specified by:
savein interfaceFolderRepository- Parameters:
folderData- folder descriptorfiles- all files inside the folder recursively or only changed (modified, added, deleted) files depending on changesetTypechangesetType- ifChangesetType.DIFF, only changed files. IfChangesetType.FULLall files that exist in project- Returns:
- the resulted folder descriptor after successful writing.
- Throws:
IOException- if not possible to save the folder.
-
isSkip
protected boolean isSkip(File file)
-
setListenerTimerPeriod
public void setListenerTimerPeriod(int listenerTimerPeriod)
-
-