Interface AttachmentService


public interface AttachmentService
Handling of attachments and attachments metadata.
Since:
7.0
  • Method Details

    • delete

      boolean delete(@Nonnull Repository repository, long id)
      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 belongs
      id - the ID as long assigned when the attachment was saved
      Returns:
      true if the specified attachment was deleted; otherwise false if it did not exist or if it could not be deleted
      Throws:
      AttachmentStoreException - if no attachment exists
    • deleteMetadata

      boolean deleteMetadata(@Nonnull Repository repository, long attachmentId)
      Deletes that attachment metadata with the specified ID, if it exists.
      Parameters:
      repository - the repository to which the attachment will have metadata associated with
      attachmentId - the ID of the attachment
      Returns:
      true if the deletion of the attachment metadata is successful; otherwise false if we cannot delete the attachment metadata
    • getById

      @Nullable Attachment getById(long attachmentId)
      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

      @Nonnull AttachmentMetadata getMetadata(@Nonnull Repository repository, long attachmentId)
      Get the attachment metadata that is associated with the attachment metadata ID that is supplied.
      Parameters:
      repository - the repository to which the attachment metadata belongs
      attachmentId - the ID of the attachment
      Returns:
      the attachment metadata object that matches the id
      Throws:
      NoSuchObjectException - if the attachment metadata cannot be found
    • read

      @Nonnull AttachmentSupplier read(@Nonnull Repository repository, long id)
      Reads the attachment with the specified ID.
      Parameters:
      repository - the repository to which the attachment belongs
      id - 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 provided supplier, assigning a unique ID to allow it to be accessed again.
      Parameters:
      repository - the repository to which the attachment belongs
      attachmentSupplier - a supplier containing the attachment data to store
      Returns:
      the attachment object representing the newly created attachment
      Throws:
      ArgumentValidationException - if the attachment 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 belong
      attachmentId - the ID of the attachment
      metadata - 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