Class ProxyStorageProvider
- All Implemented Interfaces:
IAssignableStorageProvider<ProxyStorageContext>
,IProxyStorageMarker
,IStorageProvider<ProxyStorageContext>
-
Constructor Summary
ConstructorsConstructorDescriptionProxyStorageProvider
(ProxyLinkRepository proxyLinkRepository, IFileStorageService fileStorageService, DynamicFilesConfig config) -
Method Summary
Modifier and TypeMethodDescriptionvoid
assign
(ProxyStorageContext assignableContext, UUID uuid, String path) Assigns a path to a UUID.void
delete
(ProxyStorageContext context, UUID fileId) Deletes a file from the storage system.boolean
exists
(ProxyStorageContext context, UUID fileId) Checks if a file exists in the storage system.getContentType
(ProxyStorageContext context, UUID uuid) Gets the content type of a file in the storage system.getPath
(ProxyStorageContext context, UUID fileId) Gets publicly accessible path of a file in the storage system.getPaths
(ProxyStorageContext context, List<UUID> ids) Gets publicly accessible paths of multiple files in the storage system.boolean
hasPathAssigned
(ProxyStorageContext assignableContext, UUID uuid) Checks if a path is assigned to a UUID.list
(ProxyStorageContext context) Lists all files in the storage system.boolean
pathExists
(ProxyStorageContext assignableContext, String path) Checks if a path is already assigned to a UUID.retrieve
(ProxyStorageContext context, UUID fileId) Retrieves a file from the storage system.void
store
(ProxyStorageContext context, InputStream fileStream, UUID fileId, String desiredPath, String fileName) Stores a file in the storage system.boolean
unassign
(ProxyStorageContext assignableContext, UUID uuid) Unassigns a path from a UUID.
-
Constructor Details
-
ProxyStorageProvider
@Inject public ProxyStorageProvider(ProxyLinkRepository proxyLinkRepository, IFileStorageService fileStorageService, DynamicFilesConfig config)
-
-
Method Details
-
assign
public void assign(@Nonnull ProxyStorageContext assignableContext, @Nonnull UUID uuid, @Nonnull String path) throws PathAlreadyBoundException, InvalidPathException Description copied from interface:IAssignableStorageProvider
Assigns a path to a UUID.This is useful for when a link needs to be human-readable or similar.
When assigning a path to a UUID using this method the storage provider is expected to respect the desired path, and if it is not possible to store the file at the desired path then an exception should be thrown.
The path specified by the user will generally be affixed to a base path that is determined by the storage provider.
If the path provided does not contain a file extension then the storage provider may add a file extension
If the path provided contains any directory traversal characters (e.g. "..") then the storage provider should throw an
InvalidPathException
.If the path provided is already bound to a file then the storage provider should throw a
PathAlreadyBoundException
.If the path provided is invalid for any other reason then the storage provider should throw an
InvalidPathException
.- Specified by:
assign
in interfaceIAssignableStorageProvider<ProxyStorageContext>
- Parameters:
assignableContext
- The storage context in which the file should be stored, containing any configuration informationuuid
- The unique identifier of the file to assign a path topath
- The path to assign to the file, or null to remove the path- Throws:
PathAlreadyBoundException
- if the desired path is already bound to a fileInvalidPathException
- if the path is invalid for other reasons
-
unassign
Description copied from interface:IAssignableStorageProvider
Unassigns a path from a UUID.When unassigning a path from a UUID using this method the storage provider is expected to remove the path from the UUID, but it is not expected to delete the file.
If the path was not assigned then this method should return false.
- Specified by:
unassign
in interfaceIAssignableStorageProvider<ProxyStorageContext>
- Parameters:
assignableContext
- The storage context in which the file should be stored, containing any configuration informationuuid
- The unique identifier of the file to unassign a path from- Returns:
- true if the path was unassigned, false if the path was not assigned or could not be unassigned
-
hasPathAssigned
Description copied from interface:IAssignableStorageProvider
Checks if a path is assigned to a UUID.While this is specifically available for assignable storage providers, it should still return true if an automatic path is assigned by the storage provider for a given UUID.
- Specified by:
hasPathAssigned
in interfaceIAssignableStorageProvider<ProxyStorageContext>
- Parameters:
assignableContext
- The storage context in which the file should be stored, containing any configuration informationuuid
- The unique identifier of the file to check- Returns:
- true if the path is assigned, false otherwise
-
pathExists
Description copied from interface:IAssignableStorageProvider
Checks if a path is already assigned to a UUID.Only the partial path is checked, not the full path.
- Specified by:
pathExists
in interfaceIAssignableStorageProvider<ProxyStorageContext>
- Parameters:
assignableContext
- The storage context in which the file should be stored, containing any configuration informationpath
- The path to check- Returns:
- true if the path exists, false otherwise
-
store
public void store(ProxyStorageContext context, InputStream fileStream, UUID fileId, @Nullable String desiredPath, String fileName) throws PathAlreadyBoundException Description copied from interface:IStorageProvider
Stores a file in the storage system.Each file is stored in the context of a specific storage context. This allows the storage provider to store the file in a way that is appropriate for the context.
Files do not have names, only identifiers. As such it is up to the storage provider to determine how to store the file and how to retrieve it later, including how to map the identifier to a file name.
The file system also takes a desired path to store the file in the storage system. This path is merely a suggestion and the storage provider may choose to ignore it.
- Specified by:
store
in interfaceIStorageProvider<ProxyStorageContext>
- Parameters:
context
- The storage context in which the file should be stored, containing any configuration informationfileStream
- The stream from which the file can be readfileId
- A unique identifier for the file. If a file with this identifier already exists then it will be overwritten- Throws:
PathAlreadyBoundException
- if the desired path is already bound to a file
-
retrieve
Description copied from interface:IStorageProvider
Retrieves a file from the storage system.If no file with the given identifier exists then an exception is thrown.
- Specified by:
retrieve
in interfaceIStorageProvider<ProxyStorageContext>
- Parameters:
context
- The storage context in which the file is stored, containing any configuration informationfileId
- The unique identifier of the file to retrieve- Returns:
- A stream from which the file can be read
- Throws:
NoSuchFileException
- if the file does not exist
-
delete
Description copied from interface:IStorageProvider
Deletes a file from the storage system.If no file with the given identifier exists then an exception is thrown.
- Specified by:
delete
in interfaceIStorageProvider<ProxyStorageContext>
- Parameters:
context
- The storage context in which the file is stored, containing any configuration informationfileId
- The unique identifier of the file to delete- Throws:
NoSuchFileException
- if the file does not exist
-
exists
Description copied from interface:IStorageProvider
Checks if a file exists in the storage system.- Specified by:
exists
in interfaceIStorageProvider<ProxyStorageContext>
- Parameters:
context
- The storage context in which the file is stored, containing any configuration informationfileId
- The unique identifier of the file to check- Returns:
- true if the file exists, false otherwise
-
list
Description copied from interface:IStorageProvider
Lists all files in the storage system.- Specified by:
list
in interfaceIStorageProvider<ProxyStorageContext>
- Parameters:
context
- The storage context in which the files are stored, containing any configuration information- Returns:
- A stream of unique identifiers for all files in the storage system
-
getPath
Description copied from interface:IStorageProvider
Gets publicly accessible path of a file in the storage system.E.g. if this is a file stored in an S3 bucket then this would return the URL of the file. If this is a file stored in a local file system then this would return the path of the file relative to the root of the web server.
This should return null if the file does not have a path.
- Specified by:
getPath
in interfaceIStorageProvider<ProxyStorageContext>
- Parameters:
context
- The storage context in which the file is stored, containing any configuration informationfileId
- The unique identifier of the file to get the path of- Returns:
- The path of the file, or null if the file does not have a path
-
getPaths
Description copied from interface:IStorageProvider
Gets publicly accessible paths of multiple files in the storage system.E.g. if this is a file stored in an S3 bucket then this would return the URL of the file. If this is a file stored in a local file system then this would return the path of the file relative to the root of the web server.
This is meant to be used when multiple files need to be retrieved at once, so that the storage provider can optimise the retrieval of the paths.
- Specified by:
getPaths
in interfaceIStorageProvider<ProxyStorageContext>
- Parameters:
context
- The storage context in which the files are stored, containing any configuration informationids
- The unique identifiers of the files to get the paths of- Returns:
- A map of file identifiers to their paths
-
getContentType
Description copied from interface:IStorageProvider
Gets the content type of a file in the storage system.This should return null if the file does not have a content type or if the content type is unknown.
The type should be a MIME type, e.g. "application/pdf" or "image/jpeg".
- Specified by:
getContentType
in interfaceIStorageProvider<ProxyStorageContext>
- Parameters:
context
- The storage context in which the file is stored, containing any configuration informationuuid
- The unique identifier of the file to get the content type of- Returns:
- The content type of the file, or null if the file does not have a content type
-