Class DefaultAttachmentManager

java.lang.Object
com.atlassian.jira.issue.managers.DefaultAttachmentManager
All Implemented Interfaces:
AttachmentManager

public class DefaultAttachmentManager extends Object implements AttachmentManager
  • Constructor Details

  • Method Details

    • getAttachment

      public Attachment getAttachment(Long id)
      Description copied from interface: AttachmentManager
      Get a single attachment by its ID.
      Specified by:
      getAttachment in interface AttachmentManager
      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.
    • getAttachments

      public List<Attachment> getAttachments(Issue issue)
      Description copied from interface: AttachmentManager
      Get a list of all attachments for a certain issue.
      Specified by:
      getAttachments in interface AttachmentManager
      Parameters:
      issue - the Issue
      Returns:
      a list of Attachment objects
    • getStoredAttachments

      public List<Attachment> getStoredAttachments(Issue issue)
    • getAttachments

      public List<Attachment> getAttachments(Issue issue, Comparator<? super Attachment> comparator)
      Description copied from interface: AttachmentManager
      Get a list of all attachments for a certain issue, sorted according to the specified comparator.
      Specified by:
      getAttachments in interface AttachmentManager
      Parameters:
      issue - the Issue
      comparator - used for sorting
      Returns:
      a list of Attachment objects
    • deleteAttachment

      public void deleteAttachment(Attachment attachment) throws RemoveException
      Description copied from interface: AttachmentManager
      Delete an attachment from the database and from the attachment store.
      Specified by:
      deleteAttachment in interface AttachmentManager
      Parameters:
      attachment - the Attachment
      Throws:
      RemoveException - if the attachment cannot be removed from the attachment store
    • isScreenshotAppletEnabled

      public boolean isScreenshotAppletEnabled()
      Description copied from interface: AttachmentManager
      Determine if screenshot applet has been enabled in JIRA.
      Specified by:
      isScreenshotAppletEnabled in interface AttachmentManager
      Returns:
      true if enabled, false otherwise
    • isScreenshotAppletEnabledForLinux

      protected boolean isScreenshotAppletEnabledForLinux()
    • isScreenshotAppletSupportedByOS

      public boolean isScreenshotAppletSupportedByOS()
      Description copied from interface: AttachmentManager
      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

      Specified by:
      isScreenshotAppletSupportedByOS in interface AttachmentManager
      Returns:
      true if applet is supported by the user's OS, false otherwise
    • tryConvertTemporaryAttachments

      public AttachmentsBulkOperationResult<ChangeItemBean> tryConvertTemporaryAttachments(@Nullable ApplicationUser user, Issue issue, List<Long> selectedAttachments, TemporaryAttachmentsMonitor temporaryAttachmentsMonitor)
      Description copied from interface: AttachmentManager
      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.
      Specified by:
      tryConvertTemporaryAttachments in interface AttachmentManager
      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
    • createAttachment

      public ChangeItemBean createAttachment(CreateAttachmentParamsBean bean) throws AttachmentException
      Description copied from interface: AttachmentManager
      Create an attachment both on disk, and in the database.
      Specified by:
      createAttachment in interface AttachmentManager
      Parameters:
      bean - 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

      public io.atlassian.fugue.Either<AttachmentError,ChangeItemBean> tryCreateAttachment(CreateAttachmentParamsBean params)
      Description copied from interface: AttachmentManager
      Create an attachment.
      Specified by:
      tryCreateAttachment in interface AttachmentManager
      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:
    • convertTemporaryAttachments

      public List<ChangeItemBean> convertTemporaryAttachments(@Nullable ApplicationUser user, Issue issue, List<Long> selectedAttachments, TemporaryAttachmentsMonitor temporaryAttachmentsMonitor) throws AttachmentException
      Description copied from interface: AttachmentManager
      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.
      Specified by:
      convertTemporaryAttachments in interface AttachmentManager
      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
    • setThumbnailable

      public Attachment setThumbnailable(Attachment attachment, boolean thumbnailable)
      Description copied from interface: AttachmentManager
      Stores the thumbnailable flag for this attachment
      Specified by:
      setThumbnailable in interface AttachmentManager
      Parameters:
      attachment - The attachment
      thumbnailable - True if this attachment is thumbnailable
    • setZip

      public Attachment setZip(Attachment attachment, boolean zip)
      Description copied from interface: AttachmentManager
      Stores the zip flag for this attachment
      Specified by:
      setZip in interface AttachmentManager
      Parameters:
      attachment - The attachment
      zip - True if this attachment is a zip file
    • streamAttachmentContent

      public <T> T streamAttachmentContent(@Nonnull Attachment attachment, InputStreamConsumer<T> consumer) throws AttachmentReadException, NoAttachmentDataException
      Description copied from interface: AttachmentManager
      Get binary content of the attachment
      Specified by:
      streamAttachmentContent in interface AttachmentManager
      Parameters:
      attachment - the attachment whose content to stream (required)
      consumer - the consumer of the stream (required)
      Throws:
      AttachmentReadException - if a problem occurs when the consumer processes the attachment's contents.
      NoAttachmentDataException - if the attachment's contents cannot be found.
    • moveAttachments

      public void moveAttachments(Issue oldIssue, String newIssueKey)
      Create a new directory for this issue, and move all the attachments from the old directory to the new directory.

      NB - this will fail if the old directory and new directory are on different filesystems as File.renameTo(java.io.File) fails across filesystems.

      Specified by:
      moveAttachments in interface AttachmentManager
      Parameters:
      oldIssue - the issue we're moving attachments from
      newIssueKey - the new destination issue key
    • copyAttachment

      public io.atlassian.fugue.Either<AttachmentError,Attachment> copyAttachment(Attachment attachment, @Nullable ApplicationUser author, String newIssueKey)
      Description copied from interface: AttachmentManager
      Copy an attachment to another issue.
      Specified by:
      copyAttachment in interface AttachmentManager
      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

      public Map<Long,io.atlassian.fugue.Either<AttachmentError,Attachment>> copyAttachments(Issue issue, @Nullable ApplicationUser author, String newIssueKey)
      Description copied from interface: AttachmentManager
      Copy Issue attachments to another issue.
      Specified by:
      copyAttachments in interface AttachmentManager
      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

      public Map<Long,io.atlassian.fugue.Either<AttachmentError,Attachment>> copyAttachments(Issue issue, @Nullable ApplicationUser author, String newIssueKey, boolean sendMail)
      Description copied from interface: AttachmentManager
      Copy Issue attachments to another issue and publish an event.
      Specified by:
      copyAttachments in interface AttachmentManager
      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
      sendMail - whether to send mail notification or not
      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

      public Map<Long,io.atlassian.fugue.Either<AttachmentError,Attachment>> copyAttachments(Context context, Issue issue, @Nullable ApplicationUser author, String newIssueKey)
      Description copied from interface: AttachmentManager
      Copy Issue attachments to another issue.
      Specified by:
      copyAttachments in interface AttachmentManager
      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.
    • createTemporaryAttachment

      public TemporaryAttachmentId createTemporaryAttachment(InputStream stream, long size)
      Description copied from interface: AttachmentManager
      Creates new temporary attachment which may be later converted into real attachment.
      Specified by:
      createTemporaryAttachment in interface AttachmentManager
      Parameters:
      stream - Stream with temporary attachment content
      size - Size of temporary attachment
      Returns:
      TemporaryAttachmentId which identifies created attachment
    • deleteTemporaryAttachment

      public void deleteTemporaryAttachment(TemporaryAttachmentId temporaryAttachmentId)
      Description copied from interface: AttachmentManager
      Removes temporary attachment with given id
      Specified by:
      deleteTemporaryAttachment in interface AttachmentManager
      Parameters:
      temporaryAttachmentId - id of temporary attachment
    • convertTemporaryAttachment

      public io.atlassian.fugue.Either<AttachmentError,ChangeItemBean> convertTemporaryAttachment(ConvertTemporaryAttachmentParams params)
      Description copied from interface: AttachmentManager
      Converts temporary attachment into real attachment.
      Specified by:
      convertTemporaryAttachment in interface AttachmentManager
      Parameters:
      params - Parameters describing
      Returns:
      Attachment error if conversion failed or a ChangeItemBean with all the changes to the issue.
    • streamTemporaryAttachmentContent

      public <T> T streamTemporaryAttachmentContent(@Nonnull TemporaryAttachmentId attachmentId, InputStreamConsumer<T> consumer) throws AttachmentReadException, NoAttachmentDataException
      Description copied from interface: AttachmentManager
      Get binary content of temporary attachment
      Specified by:
      streamTemporaryAttachmentContent in interface AttachmentManager
      Parameters:
      attachmentId - id of temporary attachment whose content to stream (required)
      consumer - the consumer of the stream (required)
      Throws:
      AttachmentReadException - if a problem occurs when the consumer processes the attachment's contents.
      NoAttachmentDataException - if the attachment's contents cannot be found.