Class FileSystemContentManager
- java.lang.Object
-
- com.aquima.interactions.portal.content.FileSystemContentManager
-
- All Implemented Interfaces:
IContentManager
public class FileSystemContentManager extends Object implements IContentManager
A manager of content on a file system. Path / File name generation is delegated to an instance ofIFileSystemNamingStrategy
. This manager creates two files for snippet of content that is managed:- a file that contains the content;
- another file that contains the meta-data related to the content. meta-data file also contains the roles acquired by the content.
- Since:
- 9.3
- Author:
- G. der Kinderen
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FileSystemContentManager.Metadata
Metadata representation.
-
Field Summary
Fields Modifier and Type Field Description static String
CONTENT_PATHSEGMENT
The identifier of the path segment that is prepended to all files that contain the (raw) content.static String
METADATA_PATHSEGMENT
The identifier of the path segment that is prepended to all files that contain metadata.
-
Constructor Summary
Constructors Constructor Description FileSystemContentManager(FileSystemConnection connection)
Constructs a new manager, using a default naming strategy.FileSystemContentManager(FileSystemConnection connection, IFileSystemNamingStrategy namingStrategy)
Constructs a new manager.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description GUID
create(InputStream stream, String name, String contentType, Long caseId, CustomContentProperties properties, IUserData user, String[] roles)
Add new content to the repository.void
delete(GUID id, IUserData user, boolean checkRoles)
Delete content from the repositoryIDisposableContent
getDisposableContent()
This method returns the content manager's disposable content.boolean
hasDisposableContent()
This method checks if the current content manager has anyIDisposableContent
contents.boolean
isAuthorized(GUID id, IUserData user)
This method checks if the user has roles on this content with the given id.int
readBytes(GUID id, long position, byte[] buffer, int offset, int length, IUserData user)
Reads up tolength
bytes of data from content into a byte array.IContentMetadata
readMetadata(GUID id, IUserData user, boolean checkRoles)
Reads only the meta data for a given content id.String[]
readRoles(GUID id, IUserData user)
Reads the required roles for a given content id.protected String
toContentPath(GUID guid)
Calculates the file system path in which content is stored that is identified by the provided identifier.protected String
toMetadataPath(GUID guid)
Calculates the file system path in which metadata is stored for content identified by the provided identifier.void
update(GUID id, InputStream stream, String name, String contentType, IUserData user)
Update existing content with new data, but keep the existing metadata.void
update(GUID id, InputStream stream, String name, String contentType, Long caseId, CustomContentProperties properties, IUserData user)
Update existing content with new data and metadata.void
update(GUID id, Long caseId, CustomContentProperties properties, IUserData user)
Update existing content with new metadata, but keep the existing data.void
update(GUID id, String[] newRoles, IUserData user)
Update the existing content with new roles, but keep the existing data and metadata.
-
-
-
Field Detail
-
CONTENT_PATHSEGMENT
public static final String CONTENT_PATHSEGMENT
The identifier of the path segment that is prepended to all files that contain the (raw) content.- See Also:
- Constant Field Values
-
METADATA_PATHSEGMENT
public static final String METADATA_PATHSEGMENT
The identifier of the path segment that is prepended to all files that contain metadata.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
FileSystemContentManager
public FileSystemContentManager(FileSystemConnection connection)
Constructs a new manager, using a default naming strategy.- Parameters:
connection
- The connection providing access to the content store (cannot benull
).- Since:
- 9.3
-
FileSystemContentManager
public FileSystemContentManager(FileSystemConnection connection, IFileSystemNamingStrategy namingStrategy)
Constructs a new manager.- Parameters:
namingStrategy
- a path/name converter (cannot benull
).connection
- The connection providing access to the content store (cannot benull
).- Since:
- 9.3
-
-
Method Detail
-
create
public GUID create(InputStream stream, String name, String contentType, Long caseId, CustomContentProperties properties, IUserData user, String[] roles) throws CreateContentException
Description copied from interface:IContentManager
Add new content to the repository.- Specified by:
create
in interfaceIContentManager
- Parameters:
stream
- The stream containing the data, may not benull
.name
- A name for the content, may not benull
.contentType
- The content type of the data, may benull
ifunknown
.caseId
- The id of the case where this content is part of, may benull
.properties
- Custom properties that should be stored with the content, may not benull
.user
- The user who is considered the creator of the content, may not benull
.roles
- The list of authorized roles associated to this content, may not benull
.- Returns:
- Returns a GUID that uniquely identifies the content, never
null
. - Throws:
CreateContentException
- If creation failed for any reason.
-
readMetadata
public IContentMetadata readMetadata(GUID id, IUserData user, boolean checkRoles) throws ReadContentException, ContentAuthorizationException
Description copied from interface:IContentManager
Reads only the meta data for a given content id.- Specified by:
readMetadata
in interfaceIContentManager
- Parameters:
id
- The id of the content for which meta data is requested, may not benull
.user
- The user that is reading the content, may not benull
.checkRoles
- Flag indicating if the roles check should be done or not.- Returns:
- Returns an
IContentMetadata
IContentMetadata object containing the requested meta data, nevernull
. - Throws:
ReadContentException
- If the meta data cannot be read for any reason.ContentAuthorizationException
- If user is not authorized to access the content.
-
readRoles
public String[] readRoles(GUID id, IUserData user) throws ReadContentException, ContentAuthorizationException
Description copied from interface:IContentManager
Reads the required roles for a given content id.- Specified by:
readRoles
in interfaceIContentManager
- Parameters:
id
- The id of the content for which roles are requested, may not benull
.user
- The user that is reading the content, may not benull
.- Returns:
- Returns a list of required roles. Can be
null
. - Throws:
ReadContentException
- If the roles cannot be read for any reason.ContentAuthorizationException
- If user is not authorized to access the content.
-
update
public void update(GUID id, String[] newRoles, IUserData user) throws ContentAuthorizationException
Description copied from interface:IContentManager
Update the existing content with new roles, but keep the existing data and metadata.- Specified by:
update
in interfaceIContentManager
- Parameters:
id
- The id of the content which should be updated, may not benull
.newRoles
- The list of new roles. May not benull
, may beempty
.user
- The user that is updating the content, may not benull
.- Throws:
ContentAuthorizationException
- If user is not authorized to access the content.
-
update
public void update(GUID id, InputStream stream, String name, String contentType, Long caseId, CustomContentProperties properties, IUserData user) throws UpdateContentException, ContentAuthorizationException
Description copied from interface:IContentManager
Update existing content with new data and metadata.- Specified by:
update
in interfaceIContentManager
- Parameters:
id
- The id of the content which should be updated, may not benull
.stream
- The InputStream containing the new data, may not benull
.contentType
- The content type of the new data, may benull
.caseId
- The id of the case where this content is part of, may benull
.properties
- The new set of properties, this will completely overwrite the existing properties, may not benull
.user
- The user that is updating the content, may not benull
.- Throws:
UpdateContentException
- If the content can not be updated for any reason.ContentAuthorizationException
- If user is not authorized to access the content.
-
update
public void update(GUID id, InputStream stream, String name, String contentType, IUserData user) throws UpdateContentException, ContentAuthorizationException
Description copied from interface:IContentManager
Update existing content with new data, but keep the existing metadata.- Specified by:
update
in interfaceIContentManager
- Parameters:
id
- The id of the content which should be updated, may not benull
.stream
- The InputStream containing the new data, may not benull
.contentType
- The content type of the new data, may benull
.user
- The user that is updating the content, may not benull
.- Throws:
UpdateContentException
- If the content can not be updated for any reason.ContentAuthorizationException
- If user is not authorized to access the content.
-
update
public void update(GUID id, Long caseId, CustomContentProperties properties, IUserData user) throws UpdateContentException, ContentAuthorizationException
Description copied from interface:IContentManager
Update existing content with new metadata, but keep the existing data.- Specified by:
update
in interfaceIContentManager
- Parameters:
id
- The id of the content which should be updated, may not benull
.caseId
- The id of the case where this content is part of, may benull
.properties
- The new set of properties, this will completely overwrite the existing properties, may not benull
.user
- The user that is updating the content, may not benull
.- Throws:
UpdateContentException
- If the content can not be updated for any reason.ContentAuthorizationException
- If user is not authorized to access the content.
-
delete
public void delete(GUID id, IUserData user, boolean checkRoles) throws DeleteContentException
Description copied from interface:IContentManager
Delete content from the repository- Specified by:
delete
in interfaceIContentManager
- Parameters:
id
- The id of the content which should be deleted, may not benull
.user
- The user that is deleting the content, may not benull
.checkRoles
- Flag indicating if the roles check should be done or not.- Throws:
DeleteContentException
- If the content can not be deleted for any reason.
-
isAuthorized
public boolean isAuthorized(GUID id, IUserData user)
Description copied from interface:IContentManager
This method checks if the user has roles on this content with the given id.- Specified by:
isAuthorized
in interfaceIContentManager
- Parameters:
id
- The id of the content, nevernull
.user
- The details of the user that wants to access the content, nevernull
.- Returns:
- A flag indicating if the user has roles on the document or not.
-
readBytes
public int readBytes(GUID id, long position, byte[] buffer, int offset, int length, IUserData user) throws ReadContentException
Description copied from interface:IContentManager
Reads up tolength
bytes of data from content into a byte array. The method blocks until some input is available. Although publicly available, this method primarily facilitates the implementation ofContentInputStream
. For reading content from anIContentManager
, usage of
ContentInputStream
is recommended over direct usage of this method. If the user is not authorized it will throw an exception.- Specified by:
readBytes
in interfaceIContentManager
- Parameters:
id
- The id of the content that should be read, may not benull
.position
- the start offset in the source content.buffer
- The buffer into which the data is read, (may not benull
.offset
- The start offset in the destination arraybuffer
.length
- The maximum number of bytes read.user
- The user that is reading the content, may not benull
.- Returns:
- The total number of bytes read into the buffer, or
-1
if there is no more data because the end of the content has been reached. - Throws:
ReadContentException
- If the data cannot be read for any reason.- See Also:
ContentInputStream
-
hasDisposableContent
public boolean hasDisposableContent()
Description copied from interface:IContentManager
This method checks if the current content manager has anyIDisposableContent
contents.- Specified by:
hasDisposableContent
in interfaceIContentManager
- Returns:
- A flag indicating whether the content manager has disposable content objects.
-
getDisposableContent
public IDisposableContent getDisposableContent()
Description copied from interface:IContentManager
This method returns the content manager's disposable content.- Specified by:
getDisposableContent
in interfaceIContentManager
-
toMetadataPath
protected String toMetadataPath(GUID guid)
Calculates the file system path in which metadata is stored for content identified by the provided identifier. The path that is returned will:- reference a file (as opposed to a directory)
- not start with a file name-separator
null
).- Returns:
- A (relative) path (never
null
).
-
toContentPath
protected String toContentPath(GUID guid)
Calculates the file system path in which content is stored that is identified by the provided identifier. The path that is returned will:- reference a file (as opposed to a directory)
- not start with a file name-separator
null
).- Returns:
- A (relative) path (never
null
).
-
-