Interface AttachmentManager

All Known Implementing Classes:
DefaultAttachmentManager

@PublicApi public interface AttachmentManager
Manages all attachment related tasks in JIRA, which involves retrieving an attachment, creating an attachment and deleting an attachment.
  • Field Details

    • THUMBS_SUBDIR

      static final String THUMBS_SUBDIR
      The name of the issue-specific sub-directory in which its attachment thumbnails are stored.
      Since:
      v6.3 moved from AttachmentUtils
      See Also:
  • Method Details

    • getAttachment

      Get a single attachment by its ID.
      Parameters:
      id - the Attachment ID
      Returns:
      the Attachment can never be null as an exception is thrown if an attachment with the passed id does not exist.
      Throws:
      DataAccessException - if there is a problem accessing the database.
      AttachmentNotFoundException - thrown if an attachment with the passed id does not exist.
    • getAttachments

      List<Attachment> getAttachments(Issue issue) throws DataAccessException
      Get a list of all attachments for a certain issue.
      Parameters:
      issue - the Issue
      Returns:
      a list of Attachment objects
      Throws:
      DataAccessException - if there is a problem accessing the database.
    • getAttachments

      List<Attachment> getAttachments(Issue issue, Comparator<? super Attachment> comparator) throws DataAccessException
      Get a list of all attachments for a certain issue, sorted according to the specified comparator.
      Parameters:
      issue - the Issue
      comparator - used for sorting
      Returns:
      a list of Attachment objects
      Throws:
      DataAccessException - if there is a problem accessing the database.
    • createAttachment

      ChangeItemBean createAttachment(CreateAttachmentParamsBean createAttachmentParamsBean) throws AttachmentException
      Create an attachment both on disk, and in the database.
      Parameters:
      createAttachmentParamsBean - Parameters which describe created attachment
      Returns:
      A ChangeItemBean with all the changes to the issue.
      Throws:
      AttachmentException - if an IO error occurs while attempting to copy the file
      See Also:
    • tryCreateAttachment

      io.atlassian.fugue.Either<AttachmentError,ChangeItemBean> tryCreateAttachment(CreateAttachmentParamsBean params)
      Create an attachment.
      Parameters:
      params - Parameters which describe created attachment
      Returns:
      Either a ChangeItemBean with all the changes to the issue or the AttachmentError in case of any errors while attempting to create attachment.
      See Also:
    • deleteAttachment

      void deleteAttachment(Attachment attachment) throws RemoveException
      Delete an attachment from the database and from the attachment store.
      Parameters:
      attachment - the Attachment
      Throws:
      RemoveException - if the attachment cannot be removed from the attachment store
    • isScreenshotAppletEnabled

      boolean isScreenshotAppletEnabled()
      Determine if screenshot applet has been enabled in JIRA.
      Returns:
      true if enabled, false otherwise
    • isScreenshotAppletSupportedByOS

      boolean isScreenshotAppletSupportedByOS()
      Determine if the screenshot applet is supported by the user's operating system.

      Note. This always returns true now as we support screenshots on all our supported platforms

      Returns:
      true if applet is supported by the user's OS, false otherwise
    • convertTemporaryAttachments

      @Deprecated List<ChangeItemBean> convertTemporaryAttachments(@Nullable ApplicationUser user, Issue issue, List<Long> selectedAttachments, TemporaryAttachmentsMonitor temporaryAttachmentsMonitor) throws AttachmentException
      Deprecated.
      since v6.0. To be removed in Jira 10.
      Converts a set of provided temporary attachments to real attachments attached to an issue. This method will also clean up any temporary attachments still linked to the issue via the TemporaryAttachmentsMonitor.
      Parameters:
      user - The user performing the action
      issue - The issue attachments should be linked to
      selectedAttachments - The temporary attachment ids to convert as selected by the user
      temporaryAttachmentsMonitor - TemporaryAttachmentsMonitor containing information about all temporary attachments
      Returns:
      A list of ChangeItemBeans for any attachments that got created
      Throws:
      AttachmentException - If there were problems with the Attachment itself
    • tryConvertTemporaryAttachments

      @Deprecated AttachmentsBulkOperationResult<ChangeItemBean> tryConvertTemporaryAttachments(@Nullable ApplicationUser user, Issue issue, List<Long> selectedAttachments, TemporaryAttachmentsMonitor temporaryAttachmentsMonitor)
      Converts a set of provided temporary attachments to real attachments attached to an issue. This method will also clean up any temporary attachments still linked to the issue via the TemporaryAttachmentsMonitor.
      Parameters:
      user - The user performing the action
      issue - The issue attachments should be linked to
      selectedAttachments - The temporary attachment ids to convert as selected by the user
      temporaryAttachmentsMonitor - TemporaryAttachmentsMonitor containing information about all temporary attachments
      Returns:
      Object with ChangeItemBeans and optionally Errors if there were problems during attachment conversion
    • setThumbnailable

      Attachment setThumbnailable(Attachment attachment, boolean thumbnailable)
      Stores the thumbnailable flag for this attachment
      Parameters:
      attachment - The attachment
      thumbnailable - True if this attachment is thumbnailable
    • setZip

      Attachment setZip(Attachment attachment, boolean zip)
      Stores the zip flag for this attachment
      Parameters:
      attachment - The attachment
      zip - True if this attachment is a zip file
    • streamAttachmentContent

      <T> T streamAttachmentContent(@Nonnull Attachment attachment, InputStreamConsumer<T> consumer) throws IOException
      Get binary content of the attachment
      Parameters:
      attachment - the attachment whose content to stream (required)
      consumer - the consumer of the stream (required)
      Throws:
      NoAttachmentDataException - if the attachment's contents cannot be found.
      AttachmentReadException - if a problem occurs when the consumer processes the attachment's contents.
      IOException - here for compatibility, but won't actually be thrown
    • moveAttachments

      void moveAttachments(Issue oldIssue, String newIssueKey)
      Move Issue attachments to a new directory. This method is intended for Move/Bulk Move only.
      Parameters:
      oldIssue - the issue attachments will be moved from
      newIssueKey - the new issue key
    • copyAttachment

      io.atlassian.fugue.Either<AttachmentError,Attachment> copyAttachment(Attachment attachment, @Nullable ApplicationUser author, String newIssueKey)
      Copy an attachment to another issue.
      Parameters:
      attachment - the attachment to copy to a new issue
      author - the user that will own the new attachment
      newIssueKey - the key of the issue that the attachment will be copied to
      Returns:
      either the new attachment or an error
    • copyAttachments

      Map<Long,io.atlassian.fugue.Either<AttachmentError,Attachment>> copyAttachments(Issue issue, @Nullable ApplicationUser author, String newIssueKey)
      Copy Issue attachments to another issue.
      Parameters:
      issue - the issue attachments will be copied from
      author - the user that will own the new attachments
      newIssueKey - the key of the issue that the attachment will be copied to
      Returns:
      a map that contains the result of the operation for each attachment of the original issue. The key for each entry is the id of an attachment that belongs to the original issue, and the value is either the related new attachment that belongs to the new issue, or an AttachmentError that explains why that attachment couldn't be copied.
    • copyAttachments

      Map<Long,io.atlassian.fugue.Either<AttachmentError,Attachment>> copyAttachments(Context context, Issue issue, @Nullable ApplicationUser author, String newIssueKey)
      Copy Issue attachments to another issue.
      Parameters:
      context - Task context for recording progress.
      issue - the issue attachments will be copied from
      author - the user that will own the new attachments
      newIssueKey - the key of the issue that the attachment will be copied to
      Returns:
      a map that contains the result of the operation for each attachment of the original issue. The key for each entry is the id of an attachment that belongs to the original issue, and the value is either the related new attachment that belongs to the new issue, or an AttachmentError that explains why that attachment couldn't be copied.
      Since:
      v7.1.1
    • createTemporaryAttachment

      TemporaryAttachmentId createTemporaryAttachment(InputStream stream, long size)
      Creates new temporary attachment which may be later converted into real attachment.
      Parameters:
      stream - Stream with temporary attachment content
      size - Size of temporary attachment
      Returns:
      TemporaryAttachmentId which identifies created attachment
      Since:
      v6.4
    • deleteTemporaryAttachment

      void deleteTemporaryAttachment(TemporaryAttachmentId temporaryAttachmentId)
      Removes temporary attachment with given id
      Parameters:
      temporaryAttachmentId - id of temporary attachment
      Since:
      v6.4
    • convertTemporaryAttachment

      io.atlassian.fugue.Either<AttachmentError,ChangeItemBean> convertTemporaryAttachment(ConvertTemporaryAttachmentParams params)
      Converts temporary attachment into real attachment.
      Parameters:
      params - Parameters describing
      Returns:
      Attachment error if conversion failed or a ChangeItemBean with all the changes to the issue.
      Since:
      v6.4
    • streamTemporaryAttachmentContent

      @ExperimentalApi <T> T streamTemporaryAttachmentContent(@Nonnull TemporaryAttachmentId attachmentId, InputStreamConsumer<T> consumer) throws AttachmentReadException, NoAttachmentDataException
      Get binary content of temporary attachment
      Parameters:
      attachmentId - id of temporary attachment whose content to stream (required)
      consumer - the consumer of the stream (required)
      Throws:
      NoAttachmentDataException - if the attachment's contents cannot be found.
      AttachmentReadException - if a problem occurs when the consumer processes the attachment's contents.
      Since:
      7.7