Class EntityFileSystem<Entry extends IFileSystemEntry<Entry>, PersistenceContext, Entity, Scope>
- Type Parameters:
Entry- The type of the file system entry used by the entity.PersistenceContext- The type of the persistence context used to access the persistence layer.Entity- The type of the persistent entity representing the file metadata, such as a JPA entity with the appropriate fields.Scope- The type of the scope for the persisted entities, such as a client or project.
- All Implemented Interfaces:
ICommonFileSystem<Entry>, Serializable, AutoCloseable
file system implementation for entities that represent the files in the file system and
are persisted in some kind of persistence layer, such as for example JPA entities. All changes are immediately
synchronized with the persistence layer.
In order not to couple too tightly to the exact type of persistent entity, this class uses a
persistence adapter that provides the necessary persistence-related
operations for the entities.
It also uses a separate entry accessor to map the entities to the corresponding
file system entries, and to change the entry of an entity (e.g. when moving the entity to a different location in the
file system). Each entity is associated with a file system entry that represents the
location of the corresponding file in the file system. For example, if the entity stores the file path in a string
field, the accessor could split that string at the path separator and return a new file system entry with those path
parts.
The entity type should be the metadata of the file, such as the name or size. A list of those entities is kept in
memory, the file data is loaded on-demand from the persistence layer, via the configured
file node entity adapter).
Only a subset of entities can be selected by specifying a scope. For example,
this could be a client for client-scoped file entities, or a form for form-scoped file entities. Only the entities
that match the context will be loaded into the file system. If you wish to change to a different scope, use
changeScope.
- Since:
- 8.3.0
- Author:
- XIMA MEDIA GmbH
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA builder for configuring a newEntityFileSystem.static final classEntityFileSystem.BuilderStage2<Entry extends IFileSystemEntry<Entry>, Entity, Scope>A builder for configuring a newEntityFileSystem.static final classEntityFileSystem.BuilderStage3<Entry extends IFileSystemEntry<Entry>, PersistenceContext, Entity, Scope>A builder for configuring a newEntityFileSystem.static final classEntityFileSystem.BuilderStage4<Entry extends IFileSystemEntry<Entry>, PersistenceContext, Entity, Scope>A builder for configuring a newEntityFileSystem. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Gets a new builder for configuring a newEntityFileSystem.voidchangeScope(Scope scope) Changes the scope of the entities, and reloads the entities for the new scope from the persistence layer.voidclose()voidCopies the file with the given source key to the target key.voidDeletes the file or directory with the given key.booleanChecks whether this file system contains a file (or folder) with the given key.findEntity(Object entry) Finds the entity for the given file entry, if it exists.getFileLastModifiedAt(Entry entry) Gets the last modified time of the file with the given key.getFileLastModifiedBy(Entry fileKey) Gets the user who last modified the file with the given key.getFiles()Gets the keys of all existing files.getFileSize(Entry entry) Gets the size of the file with the given key.booleanhasPendingChanges(Entry entry) Checks whether the content of the file with the given key has been changed and is in a pending state, not yet persisted or synchronized with an external storage medium.booleanisOpen()Checks whether this file system is open.listFolder(Entry folder) Gets the keys of all existing files within the given folder, non-recursively.listFolderRecursively(Entry folder) Gets the keys of all existing files within the given folder, recursively.voidCreates a new file with no content.voidmakeFolder(Entry entry) Creates a new folder with no content.openFileInput(Entry entry) Gets an input stream for the data of the file with the given key.openFileInputMarkable(Entry entry) Gets an input stream for the data of the file with the given key.openFileOutput(Entry entry) Opens an output stream to the given file key.voidrefresh()If the implementation employs any kind of caching: discards all caches and refreshes the file system so that all entries represent the most up-to-date state.voidIf the implementation employs any kind of caching: discards all caches and refreshes the file system so that all given entries represent the most up-to-date state.Renames the file system entry with the given source key to the target key.<FileSystem>
FileSystemUnwraps this file system to the given type.
-
Method Details
-
changeScope
Changes the scope of the entities, and reloads the entities for the new scope from the persistence layer.For example, when the scope is a client, the file system will contain only entities from that client. You can use this method to switch to the entities of a different client.
- Parameters:
scope- The new scope for the entities. Can be null if theentity adaptersupports null scopes (which usually corresponds the global scope).- Throws:
IOException- When the entities for the new scope cannot be loaded.
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
copy
Description copied from interface:ICommonFileSystemCopies the file with the given source key to the target key. If the source key does not exist, this method does nothing. If the target key exists already, anIOExceptionis thrown.If the source is a directory, all contents of the source must also be copied to the target.
- Specified by:
copyin interfaceICommonFileSystem<Entry extends IFileSystemEntry<Entry>>- Parameters:
source- The descriptor of the file to copy.target- The descriptor of the file to copy to.- Throws:
IOException- If an error occurs while copying the file data.
-
delete
Description copied from interface:ICommonFileSystemDeletes the file or directory with the given key. If the file or directory does not exist, this method does nothing.- Specified by:
deletein interfaceICommonFileSystem<Entry extends IFileSystemEntry<Entry>>- Parameters:
source- The file descriptor of the file to delete.- Throws:
IOException- If an error occurs while deleting the file.
-
exists
Description copied from interface:ICommonFileSystemChecks whether this file system contains a file (or folder) with the given key. Returns false if the file could not be checked.- Specified by:
existsin interfaceICommonFileSystem<Entry extends IFileSystemEntry<Entry>>- Parameters:
entry- The file descriptor.- Returns:
- true if the file (or folder) exists, false otherwise.
-
findEntity
-
getFileLastModifiedAt
Description copied from interface:ICommonFileSystemGets the last modified time of the file with the given key. If the file does not exist, or if the last modified time is not available,Instant.EPOCHis returned.- Specified by:
getFileLastModifiedAtin interfaceICommonFileSystem<Entry extends IFileSystemEntry<Entry>>- Parameters:
entry- The file descriptor.- Returns:
- The last modified time of the file, or
Instant.EPOCHif the file does not exist.
-
getFileLastModifiedBy
Description copied from interface:ICommonFileSystemGets the user who last modified the file with the given key. If the file does not exist, or if the last modified user is not available, the empty string is returned.- Specified by:
getFileLastModifiedByin interfaceICommonFileSystem<Entry extends IFileSystemEntry<Entry>>- Parameters:
fileKey- The key of the file.- Returns:
- The user who last modified the file, or the empty string if the file does not exist.
-
getFileSize
Description copied from interface:ICommonFileSystemGets the size of the file with the given key. If the file does not exist, or if the size cannot be determined 0 is returned.- Specified by:
getFileSizein interfaceICommonFileSystem<Entry extends IFileSystemEntry<Entry>>- Parameters:
entry- The file descriptor.- Returns:
- The size of the file, or 0 if unavailable.
-
getFiles
Description copied from interface:ICommonFileSystemGets the keys of all existing files.- Specified by:
getFilesin interfaceICommonFileSystem<Entry extends IFileSystemEntry<Entry>>- Returns:
- The keys of all existing files.
-
hasPendingChanges
Description copied from interface:ICommonFileSystemChecks whether the content of the file with the given key has been changed and is in a pending state, not yet persisted or synchronized with an external storage medium.- Specified by:
hasPendingChangesin interfaceICommonFileSystem<Entry extends IFileSystemEntry<Entry>>- Parameters:
entry- The file descriptor.- Returns:
- true if the content has pending changes, false otherwise.
-
isOpen
public boolean isOpen()Description copied from interface:ICommonFileSystemChecks whether this file system is open. If the file system is not open, no operations can be performed. SeeAutoCloseable.close().- Specified by:
isOpenin interfaceICommonFileSystem<Entry extends IFileSystemEntry<Entry>>- Returns:
- true if the file system is still open, false otherwise.
-
listFolder
Description copied from interface:ICommonFileSystemGets the keys of all existing files within the given folder, non-recursively. Only the files in the given folder are returned, not files in subfolders.The given folder is not included in the result.
- Specified by:
listFolderin interfaceICommonFileSystem<Entry extends IFileSystemEntry<Entry>>- Parameters:
folder- The key to start at.- Returns:
- The keys of all existing files within the given folder.
-
listFolderRecursively
Description copied from interface:ICommonFileSystemGets the keys of all existing files within the given folder, recursively. This is a recursive operation, so all files in all subfolders are included. Folder contents are returned in breadth-first order, i.e. all files in the same folder are returned before files in subfolders.The given folder is not included in the result.
- Specified by:
listFolderRecursivelyin interfaceICommonFileSystem<Entry extends IFileSystemEntry<Entry>>- Parameters:
folder- The file descriptor of the folder.- Returns:
- The keys of all existing files within the given folder and subfolders.
-
makeFile
Description copied from interface:ICommonFileSystemCreates a new file with no content. Does nothing if the file already exists.- Specified by:
makeFilein interfaceICommonFileSystem<Entry extends IFileSystemEntry<Entry>>- Parameters:
entry- The file descriptor.- Throws:
IOException- If an error occurs while creating the file.
-
makeFolder
Description copied from interface:ICommonFileSystemCreates a new folder with no content. Does nothing if the file already exists.- Specified by:
makeFolderin interfaceICommonFileSystem<Entry extends IFileSystemEntry<Entry>>- Parameters:
entry- The key of the folder.- Throws:
IOException- If an error occurs while creating the folder.
-
openFileInput
Description copied from interface:ICommonFileSystemGets an input stream for the data of the file with the given key. If the file does not exist, or if the file data is not available, an empty input stream is returned.No guarantees are made regarding the features of the input stream, other than data can be read from it.
- Specified by:
openFileInputin interfaceICommonFileSystem<Entry extends IFileSystemEntry<Entry>>- Parameters:
entry- The file descriptor.- Returns:
- An input stream for the data of the file, or an empty stream if the file does not exist or the data is not available.
- Throws:
IOException- If an error occurs while opening the file data from the temporary file.
-
openFileInputMarkable
Description copied from interface:ICommonFileSystemGets an input stream for the data of the file with the given key. If the file does not exist, or if the file data is not available, an empty input stream is returned.The returned input stream supports
markandresetoperations.- Specified by:
openFileInputMarkablein interfaceICommonFileSystem<Entry extends IFileSystemEntry<Entry>>- Parameters:
entry- The file descriptor.- Returns:
- An input stream for the data of the file, or an empty stream if the file does not exist or the data is not available.
- Throws:
IOException- If an error occurs while opening the file data from the temporary file.
-
openFileOutput
Description copied from interface:ICommonFileSystemOpens an output stream to the given file key. If the file does not exist yet, it is created. If the file exists already, the content is overwritten.- Specified by:
openFileOutputin interfaceICommonFileSystem<Entry extends IFileSystemEntry<Entry>>- Parameters:
entry- The file descriptor.- Returns:
- An output stream for writing the file data.
- Throws:
IOException- If an error occurs while opening the file output stream.
-
refresh
Description copied from interface:ICommonFileSystemIf the implementation employs any kind of caching: discards all caches and refreshes the file system so that all entries represent the most up-to-date state.- Specified by:
refreshin interfaceICommonFileSystem<Entry extends IFileSystemEntry<Entry>>- Throws:
IOException- If an error occurs while refreshing the file system.
-
refresh
Description copied from interface:ICommonFileSystemIf the implementation employs any kind of caching: discards all caches and refreshes the file system so that all given entries represent the most up-to-date state. If a file is given, only that file is refreshed. If a folder is given, all files and folder in that folder are refreshed (recursively).- Specified by:
refreshin interfaceICommonFileSystem<Entry extends IFileSystemEntry<Entry>>- Parameters:
files- The files to refresh.- Throws:
IOException- If an error occurs while refreshing the file system.
-
rename
Description copied from interface:ICommonFileSystemRenames the file system entry with the given source key to the target key. If the source key does not exist, this method does nothing.When source and target are directories, all contents of the source must also be moved to the target.
- Specified by:
renamein interfaceICommonFileSystem<Entry extends IFileSystemEntry<Entry>>- Parameters:
source- The descriptor of the file to rename.target- The descriptor of the file towards which to rename.- Returns:
- Mapping from the old to the new files or directories. Includes the contents of directories if the source is a directory.
- Throws:
IOException- If an error occurs while renaming the file.
-
unwrap
Description copied from interface:ICommonFileSystemUnwraps this file system to the given type. If this file system is an instance of the given type, it is returned. Otherwise, potential wrappers are unwrapped until the given type is reached. If the file system cannot be unwrapped to the given type, null is returned.If multiple wrappers are present, the first one that can be unwrapped to the given type is returned.
- Specified by:
unwrapin interfaceICommonFileSystem<Entry extends IFileSystemEntry<Entry>>- Type Parameters:
FileSystem- The type of the desired file system.- Parameters:
type- The type to unwrap to.- Returns:
- The unwrapped file system, or null if the file system cannot be unwrapped to the given type.
-
builder
Gets a new builder for configuring a newEntityFileSystem.- Returns:
- A new builder instance.
-