Class DefaultAttachmentManager
java.lang.Object
com.atlassian.jira.issue.managers.DefaultAttachmentManager
- All Implemented Interfaces:
AttachmentManager
-
Field Summary
Fields inherited from interface com.atlassian.jira.issue.AttachmentManager
THUMBS_SUBDIR
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultAttachmentManager
(IssueManager issueManager, OfBizDelegator ofBizDelegator, MimeManager mimeManager, ApplicationProperties applicationProperties, AttachmentKeyMapper attachmentKeyMapper, I18nHelper.BeanFactory i18nBeanFactory, AttachmentIndexManager attachmentIndexManager, StreamAttachmentStore streamAttachmentStore, ThumbnailAccessor thumbnailAccessor, AttachmentIdSequencer attachmentIdSequencer, AttachmentValidatorInvoker attachmentValidatorInvoker, IssueUpdater issueUpdater) -
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) Converts a set of provided temporary attachments to real attachments attached to an issue.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
(Issue issue, ApplicationUser author, String newIssueKey, boolean sendMail) Copy Issue attachments to another issue and publish an event.Map
<Long, io.atlassian.fugue.Either<AttachmentError, Attachment>> copyAttachments
(Context context, Issue issue, ApplicationUser author, String newIssueKey) Copy Issue attachments to another issue.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.getStoredAttachments
(Issue issue) boolean
Determine if screenshot applet has been enabled in JIRA.protected boolean
boolean
Determine if the screenshot applet is supported by the user's operating system.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.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) Converts a set of provided temporary attachments to real attachments attached to an issue.io.atlassian.fugue.Either
<AttachmentError, ChangeItemBean> Create an attachment.
-
Constructor Details
-
DefaultAttachmentManager
public DefaultAttachmentManager(IssueManager issueManager, OfBizDelegator ofBizDelegator, MimeManager mimeManager, ApplicationProperties applicationProperties, AttachmentKeyMapper attachmentKeyMapper, I18nHelper.BeanFactory i18nBeanFactory, AttachmentIndexManager attachmentIndexManager, StreamAttachmentStore streamAttachmentStore, ThumbnailAccessor thumbnailAccessor, AttachmentIdSequencer attachmentIdSequencer, AttachmentValidatorInvoker attachmentValidatorInvoker, IssueUpdater issueUpdater)
-
-
Method Details
-
getAttachment
Description copied from interface:AttachmentManager
Get a single attachment by its ID.- Specified by:
getAttachment
in interfaceAttachmentManager
- 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
Description copied from interface:AttachmentManager
Get a list of all attachments for a certain issue.- Specified by:
getAttachments
in interfaceAttachmentManager
- Parameters:
issue
- the Issue- Returns:
- a list of
Attachment
objects
-
getStoredAttachments
-
getAttachments
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 interfaceAttachmentManager
- Parameters:
issue
- the Issuecomparator
- used for sorting- Returns:
- a list of
Attachment
objects
-
deleteAttachment
Description copied from interface:AttachmentManager
Delete an attachment from the database and from the attachment store.- Specified by:
deleteAttachment
in interfaceAttachmentManager
- 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 interfaceAttachmentManager
- 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 interfaceAttachmentManager
- 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 interfaceAttachmentManager
- 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
-
createAttachment
Description copied from interface:AttachmentManager
Create an attachment both on disk, and in the database.- Specified by:
createAttachment
in interfaceAttachmentManager
- 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 interfaceAttachmentManager
- 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 interfaceAttachmentManager
- 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
-
setThumbnailable
Description copied from interface:AttachmentManager
Stores the thumbnailable flag for this attachment- Specified by:
setThumbnailable
in interfaceAttachmentManager
- Parameters:
attachment
- The attachmentthumbnailable
- True if this attachment is thumbnailable
-
setZip
Description copied from interface:AttachmentManager
Stores the zip flag for this attachment- Specified by:
setZip
in interfaceAttachmentManager
- Parameters:
attachment
- The attachmentzip
- 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 interfaceAttachmentManager
- 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
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 interfaceAttachmentManager
- Parameters:
oldIssue
- the issue we're moving attachments fromnewIssueKey
- 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 interfaceAttachmentManager
- 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
public Map<Long,io.atlassian.fugue.Either<AttachmentError, copyAttachmentsAttachment>> (Issue issue, @Nullable ApplicationUser author, String newIssueKey) Description copied from interface:AttachmentManager
Copy Issue attachments to another issue.- Specified by:
copyAttachments
in interfaceAttachmentManager
- 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
public Map<Long,io.atlassian.fugue.Either<AttachmentError, copyAttachmentsAttachment>> (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 interfaceAttachmentManager
- 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 tosendMail
- 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, copyAttachmentsAttachment>> (Context context, Issue issue, @Nullable ApplicationUser author, String newIssueKey) Description copied from interface:AttachmentManager
Copy Issue attachments to another issue.- Specified by:
copyAttachments
in interfaceAttachmentManager
- 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.
-
createTemporaryAttachment
Description copied from interface:AttachmentManager
Creates new temporary attachment which may be later converted into real attachment.- Specified by:
createTemporaryAttachment
in interfaceAttachmentManager
- Parameters:
stream
- Stream with temporary attachment contentsize
- Size of temporary attachment- Returns:
- TemporaryAttachmentId which identifies created attachment
-
deleteTemporaryAttachment
Description copied from interface:AttachmentManager
Removes temporary attachment with given id- Specified by:
deleteTemporaryAttachment
in interfaceAttachmentManager
- 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 interfaceAttachmentManager
- 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 interfaceAttachmentManager
- 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.
-