Interface AttachmentService
public interface AttachmentService
Handling of attachments and attachments metadata.
- Since:
- 7.0
-
Method Summary
Modifier and TypeMethodDescriptionboolean
delete
(Repository repository, long id) Deletes the attachment with the specified ID, if it exists.boolean
deleteMetadata
(Repository repository, long attachmentId) Deletes that attachment metadata with the specified ID, if it exists.getById
(long attachmentId) Get the attachment that matches the ID that is supplied.long
Retrieves the maximum size, in bytes, for uploaded attachments.getMetadata
(Repository repository, long attachmentId) Get the attachment metadata that is associated with the attachment metadata ID that is supplied.read
(Repository repository, long id) Reads the attachment with the specified ID.save
(Repository repository, AttachmentSupplier attachmentSupplier) Saves the attachment contained in the providedsupplier
, assigning a unique ID to allow it to be accessed again.saveMetadata
(Repository repository, long attachmentId, Map<String, Object> metadata) Saves the metadata for an attachment that already exists.
-
Method Details
-
delete
Deletes the attachment with the specified ID, if it exists.Note: If no attachment exists with the specified ID, no exception is thrown.
- Parameters:
repository
- the repository to which the attachment belongsid
- the ID as long assigned when the attachment was saved- Returns:
true
if the specified attachment was deleted; otherwisefalse
if it did not exist or if it could not be deleted- Throws:
AttachmentStoreException
- if no attachment exists
-
deleteMetadata
Deletes that attachment metadata with the specified ID, if it exists.- Parameters:
repository
- the repository to which the attachment will have metadata associated withattachmentId
- the ID of the attachment- Returns:
true
if the deletion of the attachment metadata is successful; otherwisefalse
if we cannot delete the attachment metadata
-
getById
Get the attachment that matches the ID that is supplied.- Parameters:
attachmentId
- the ID of the attachment- Returns:
- the attachment matching the ID or null if the attachment cannot be found with the ID supplied
-
getMaxUploadSize
long getMaxUploadSize()Retrieves the maximum size, in bytes, for uploaded attachments. Attachments uploaded that are larger than this will be rejected by the server.- Returns:
- the maximum size, in bytes, for uploaded attachments
-
getMetadata
Get the attachment metadata that is associated with the attachment metadata ID that is supplied.- Parameters:
repository
- the repository to which the attachment metadata belongsattachmentId
- the ID of the attachment- Returns:
- the attachment metadata object that matches the id
- Throws:
NoSuchObjectException
- if the attachment metadata cannot be found
-
read
Reads the attachment with the specified ID.- Parameters:
repository
- the repository to which the attachment belongsid
- the ID assigned when the attachment was saved- Returns:
- a supplier from which the attachment can be streamed
- Throws:
NoSuchObjectException
- if no attachment exists
-
save
@Nonnull Attachment save(@Nonnull Repository repository, @Nonnull AttachmentSupplier attachmentSupplier) Saves the attachment contained in the providedsupplier
, assigning a unique ID to allow it to be accessed again.- Parameters:
repository
- the repository to which the attachment belongsattachmentSupplier
- a supplier containing the attachment data to store- Returns:
- the attachment object representing the newly created attachment
- Throws:
ArgumentValidationException
- if theattachment name
uses special characters, like..
ServiceException
- if the attachment cannot be stored
-
saveMetadata
@Nonnull AttachmentMetadata saveMetadata(@Nonnull Repository repository, long attachmentId, @Nonnull Map<String, Object> metadata) Saves the metadata for an attachment that already exists. The ID that is used for the metadata matches the ID for the attachment.- Parameters:
repository
- the repository to which the attachments belongattachmentId
- the ID of the attachmentmetadata
- the metadata that is to be associated to the attachment- Returns:
- the attachment metadata object that is saved
- Throws:
NoSuchObjectException
- if the attachment cannot be found in the database
-