Package com.atlassian.jira.issue
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final String
The name of the issue-specific sub-directory in which its attachment thumbnails are stored. -
Method Summary
Modifier and TypeMethodDescriptionio.atlassian.fugue.Either<AttachmentError,
ChangeItemBean> Converts temporary attachment into real attachment.convertTemporaryAttachments
(ApplicationUser user, Issue issue, List<Long> selectedAttachments, TemporaryAttachmentsMonitor temporaryAttachmentsMonitor) Deprecated.since v6.0.io.atlassian.fugue.Either<AttachmentError,
Attachment> copyAttachment
(Attachment attachment, ApplicationUser author, String newIssueKey) Copy an attachment to another issue.Map<Long,
io.atlassian.fugue.Either<AttachmentError, Attachment>> copyAttachments
(Issue issue, ApplicationUser author, String newIssueKey) Copy Issue attachments to another issue.Map<Long,
io.atlassian.fugue.Either<AttachmentError, Attachment>> copyAttachments
(Context context, Issue issue, ApplicationUser author, String newIssueKey) Copy Issue attachments to another issue.createAttachment
(CreateAttachmentParamsBean createAttachmentParamsBean) Create an attachment both on disk, and in the database.createTemporaryAttachment
(InputStream stream, long size) Creates new temporary attachment which may be later converted into real attachment.void
deleteAttachment
(Attachment attachment) Delete an attachment from the database and from the attachment store.void
deleteTemporaryAttachment
(TemporaryAttachmentId temporaryAttachmentId) Removes temporary attachment with given idgetAttachment
(Long id) Get a single attachment by its ID.getAttachments
(Issue issue) Get a list of all attachments for a certain issue.getAttachments
(Issue issue, Comparator<? super Attachment> comparator) Get a list of all attachments for a certain issue, sorted according to the specified comparator.boolean
Determine if screenshot applet has been enabled in JIRA.boolean
Determine if the screenshot applet is supported by the user's operating system.void
moveAttachments
(Issue oldIssue, String newIssueKey) Move Issue attachments to a new directory.setThumbnailable
(Attachment attachment, boolean thumbnailable) Stores the thumbnailable flag for this attachmentsetZip
(Attachment attachment, boolean zip) Stores the zip flag for this attachment<T> T
streamAttachmentContent
(Attachment attachment, InputStreamConsumer<T> consumer) Get binary content of the attachment<T> T
streamTemporaryAttachmentContent
(TemporaryAttachmentId attachmentId, InputStreamConsumer<T> consumer) Get binary content of temporary attachmenttryConvertTemporaryAttachments
(ApplicationUser user, Issue issue, List<Long> selectedAttachments, TemporaryAttachmentsMonitor temporaryAttachmentsMonitor) io.atlassian.fugue.Either<AttachmentError,
ChangeItemBean> Create an attachment.
-
Field Details
-
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
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 Issuecomparator
- 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
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 actionissue
- The issue attachments should be linked toselectedAttachments
- The temporary attachment ids to convert as selected by the usertemporaryAttachmentsMonitor
- 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) Deprecated.UseTemporaryWebAttachmentManager.convertTemporaryAttachments(com.atlassian.jira.user.ApplicationUser, com.atlassian.jira.issue.Issue, java.util.List<java.lang.String>)
instead. Since v6.4. 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 actionissue
- The issue attachments should be linked toselectedAttachments
- The temporary attachment ids to convert as selected by the usertemporaryAttachmentsMonitor
- TemporaryAttachmentsMonitor containing information about all temporary attachments- Returns:
- Object with ChangeItemBeans and optionally Errors if there were problems during attachment conversion
-
setThumbnailable
Stores the thumbnailable flag for this attachment- Parameters:
attachment
- The attachmentthumbnailable
- True if this attachment is thumbnailable
-
setZip
Stores the zip flag for this attachment- Parameters:
attachment
- The attachmentzip
- 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
Move Issue attachments to a new directory. This method is intended for Move/Bulk Move only.- Parameters:
oldIssue
- the issue attachments will be moved fromnewIssueKey
- 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 issueauthor
- the user that will own the new attachmentnewIssueKey
- 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, copyAttachmentsAttachment>> (Issue issue, @Nullable ApplicationUser author, String newIssueKey) Copy Issue attachments to another issue.- Parameters:
issue
- the issue attachments will be copied fromauthor
- the user that will own the new attachmentsnewIssueKey
- 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, copyAttachmentsAttachment>> (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 fromauthor
- the user that will own the new attachmentsnewIssueKey
- 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
Creates new temporary attachment which may be later converted into real attachment.- Parameters:
stream
- Stream with temporary attachment contentsize
- Size of temporary attachment- Returns:
- TemporaryAttachmentId which identifies created attachment
- Since:
- v6.4
-
deleteTemporaryAttachment
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
-