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.voiddeleteAttachment(Attachment attachment) Delete an attachment from the database and from the attachment store.voiddeleteTemporaryAttachment(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) booleanDetermine if screenshot applet has been enabled in JIRA.protected booleanbooleanDetermine if the screenshot applet is supported by the user's operating system.voidmoveAttachments(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> TstreamAttachmentContent(Attachment attachment, InputStreamConsumer<T> consumer) Get binary content of the attachment<T> TstreamTemporaryAttachmentContent(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:AttachmentManagerGet a single attachment by its ID.- Specified by:
getAttachmentin 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:AttachmentManagerGet a list of all attachments for a certain issue.- Specified by:
getAttachmentsin interfaceAttachmentManager- Parameters:
issue- the Issue- Returns:
- a list of
Attachmentobjects
-
getStoredAttachments
-
getAttachments
Description copied from interface:AttachmentManagerGet a list of all attachments for a certain issue, sorted according to the specified comparator.- Specified by:
getAttachmentsin interfaceAttachmentManager- Parameters:
issue- the Issuecomparator- used for sorting- Returns:
- a list of
Attachmentobjects
-
deleteAttachment
Description copied from interface:AttachmentManagerDelete an attachment from the database and from the attachment store.- Specified by:
deleteAttachmentin 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:AttachmentManagerDetermine if screenshot applet has been enabled in JIRA.- Specified by:
isScreenshotAppletEnabledin interfaceAttachmentManager- Returns:
- true if enabled, false otherwise
-
isScreenshotAppletEnabledForLinux
protected boolean isScreenshotAppletEnabledForLinux() -
isScreenshotAppletSupportedByOS
public boolean isScreenshotAppletSupportedByOS()Description copied from interface:AttachmentManagerDetermine 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:
isScreenshotAppletSupportedByOSin 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:AttachmentManagerConverts 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:
tryConvertTemporaryAttachmentsin 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:AttachmentManagerCreate an attachment both on disk, and in the database.- Specified by:
createAttachmentin interfaceAttachmentManager- Parameters:
bean- Parameters which describe created attachment- Returns:
- A
ChangeItemBeanwith 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:AttachmentManagerCreate an attachment.- Specified by:
tryCreateAttachmentin interfaceAttachmentManager- Parameters:
params- Parameters which describe created attachment- Returns:
- Either a
ChangeItemBeanwith 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:AttachmentManagerConverts 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:
convertTemporaryAttachmentsin 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:AttachmentManagerStores the thumbnailable flag for this attachment- Specified by:
setThumbnailablein interfaceAttachmentManager- Parameters:
attachment- The attachmentthumbnailable- True if this attachment is thumbnailable
-
setZip
Description copied from interface:AttachmentManagerStores the zip flag for this attachment- Specified by:
setZipin 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:AttachmentManagerGet binary content of the attachment- Specified by:
streamAttachmentContentin 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:
moveAttachmentsin 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:AttachmentManagerCopy an attachment to another issue.- Specified by:
copyAttachmentin 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:AttachmentManagerCopy Issue attachments to another issue.- Specified by:
copyAttachmentsin 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:AttachmentManagerCopy Issue attachments to another issue and publish an event.- Specified by:
copyAttachmentsin 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:AttachmentManagerCopy Issue attachments to another issue.- Specified by:
copyAttachmentsin 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:AttachmentManagerCreates new temporary attachment which may be later converted into real attachment.- Specified by:
createTemporaryAttachmentin interfaceAttachmentManager- Parameters:
stream- Stream with temporary attachment contentsize- Size of temporary attachment- Returns:
- TemporaryAttachmentId which identifies created attachment
-
deleteTemporaryAttachment
Description copied from interface:AttachmentManagerRemoves temporary attachment with given id- Specified by:
deleteTemporaryAttachmentin interfaceAttachmentManager- Parameters:
temporaryAttachmentId- id of temporary attachment
-
convertTemporaryAttachment
public io.atlassian.fugue.Either<AttachmentError,ChangeItemBean> convertTemporaryAttachment(ConvertTemporaryAttachmentParams params) Description copied from interface:AttachmentManagerConverts temporary attachment into real attachment.- Specified by:
convertTemporaryAttachmentin interfaceAttachmentManager- Parameters:
params- Parameters describing- Returns:
- Attachment error if conversion failed or a
ChangeItemBeanwith all the changes to the issue.
-
streamTemporaryAttachmentContent
public <T> T streamTemporaryAttachmentContent(@Nonnull TemporaryAttachmentId attachmentId, InputStreamConsumer<T> consumer) throws AttachmentReadException, NoAttachmentDataException Description copied from interface:AttachmentManagerGet binary content of temporary attachment- Specified by:
streamTemporaryAttachmentContentin 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.
-