public class

DefaultAttachmentManager

extends Object
implements AttachmentManager
java.lang.Object
   ↳ com.atlassian.jira.issue.managers.DefaultAttachmentManager

Summary

[Expand]
Inherited Constants
From interface com.atlassian.jira.issue.AttachmentManager
Public Constructors
DefaultAttachmentManager(IssueManager issueManager, OfBizDelegator ofBizDelegator, MimeManager mimeManager, ApplicationProperties applicationProperties, AttachmentPathManager attachmentPathManager, ComponentLocator componentLocator, I18nHelper.BeanFactory i18nBeanFactory, UserManager userManager, AttachmentStore attachmentStore, AttachmentIndexManager attachmentIndexManager, StreamAttachmentStore streamAttachmentStore, ThumbnailAccessor thumbnailAccessor, AttachmentIdSequencer attachmentIdSequencer)
Public Methods
boolean attachmentsEnabled()
Determine if attachments have been enabled in JIRA and if the attachments directory exists.
Either<AttachmentErrorChangeItemBean> convertTemporaryAttachment(ConvertTemporaryAttachmentParams params)
Converts temporary attachment into real attachment.
List<ChangeItemBean> convertTemporaryAttachments(ApplicationUser user, Issue issue, List<Long> selectedAttachments, TemporaryAttachmentsMonitor temporaryAttachmentsMonitor)
Converts a set of provided temporary attachments to real attachments attached to an issue.
Either<AttachmentErrorAttachment> copyAttachment(Attachment attachment, ApplicationUser author, String newIssueKey)
Copy an attachment to another issue.
Map<Long, Either<AttachmentErrorAttachment>> copyAttachments(Issue issue, ApplicationUser author, String newIssueKey)
Copy Issue attachments to another issue.
Attachment createAttachment(GenericValue issue, ApplicationUser author, String mimetype, String filename, Long filesize, Map<StringObject> attachmentProperties, Date createdTime)
Create an attachment in the database.
ChangeItemBean createAttachment(File file, String filename, String contentType, ApplicationUser author, GenericValue issue, Map<StringObject> attachmentProperties, Date createdTime)
Create an attachment both on disk, and in the database.
ChangeItemBean createAttachment(File file, String filename, String contentType, ApplicationUser author, GenericValue issue, Boolean zip, Boolean thumbnailable, Map<StringObject> attachmentProperties, Date createdTime)
Create an attachment both on disk, and in the database.
ChangeItemBean createAttachment(CreateAttachmentParamsBean bean)
Create an attachment both on disk, and in the database.
ChangeItemBean createAttachment(File file, String filename, String contentType, ApplicationUser remoteUser, Issue issue, Map<StringObject> attachmentProperties, Date createdTime)
Create an attachment both on disk, and in the database.
ChangeItemBean createAttachment(File file, String filename, String contentType, ApplicationUser remoteUser, Issue issue, Boolean zip, Boolean thumbnailable, Map<StringObject> attachmentProperties, Date createdTime)
Create an attachment both on disk, and in the database.
ChangeItemBean createAttachment(File file, String filename, String contentType, ApplicationUser remoteUser, Issue issue)
Same as the #createAttachment(File, String, String, User, Issue, Map, Date) method, except it submits no attachmentProperties and uses now() for the created time.
ChangeItemBean createAttachment(File file, String filename, String contentType, ApplicationUser remoteUser, GenericValue issue)
Same as the #createAttachment(java.io.File, String, String, User, org.ofbiz.core.entity.GenericValue, java.util.Map, java.util.Date) method, except it submits no attachmentProperties and uses now() for the created time.
Attachment createAttachmentCopySourceFile(File file, String filename, String contentType, String attachmentAuthor, Issue issue, Map<StringObject> attachmentProperties, Date createdTime)
Create an attachment both on disk, and in the database by copying the provided file instead of moving it.
TemporaryAttachmentId 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 deleteAttachmentDirectory(Issue issue)
Delete the attachment directory from disk if the directory is empty.
void deleteTemporaryAttachment(TemporaryAttachmentId temporaryAttachmentId)
Removes temporary attachment with given id
Attachment getAttachment(Long id)
Get a single attachment by its ID.
List<Attachment> getAttachments(Issue issue, Comparator<? super Attachment> comparator)
Get a list of all attachments for a certain issue, sorted according to the specified comparator.
List<Attachment> getAttachments(Issue issue)
Get a list of all attachments for a certain issue.
List<Attachment> getStoredAttachments(Issue issue)
boolean isScreenshotAppletEnabled()
Determine if screenshot applet has been enabled in JIRA.
boolean isScreenshotAppletSupportedByOS()
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.
Attachment setThumbnailable(Attachment attachment, boolean thumbnailable)
Stores the thumbnailble flag for this attachment
Attachment setZip(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
AttachmentsBulkOperationResult<ChangeItemBean> tryConvertTemporaryAttachments(ApplicationUser user, Issue issue, List<Long> selectedAttachments, TemporaryAttachmentsMonitor temporaryAttachmentsMonitor)
Converts a set of provided temporary attachments to real attachments attached to an issue.
Either<AttachmentErrorChangeItemBean> tryCreateAttachment(CreateAttachmentParamsBean params)
Create an attachment.
Protected Methods
boolean isScreenshotAppletEnabledForLinux()
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.atlassian.jira.issue.AttachmentManager

Public Constructors

public DefaultAttachmentManager (IssueManager issueManager, OfBizDelegator ofBizDelegator, MimeManager mimeManager, ApplicationProperties applicationProperties, AttachmentPathManager attachmentPathManager, ComponentLocator componentLocator, I18nHelper.BeanFactory i18nBeanFactory, UserManager userManager, AttachmentStore attachmentStore, AttachmentIndexManager attachmentIndexManager, StreamAttachmentStore streamAttachmentStore, ThumbnailAccessor thumbnailAccessor, AttachmentIdSequencer attachmentIdSequencer)

Public Methods

public boolean attachmentsEnabled ()

Determine if attachments have been enabled in JIRA and if the attachments directory exists.

Returns
  • true if enabled, false otherwise

public Either<AttachmentErrorChangeItemBean> 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.

public List<ChangeItemBean> convertTemporaryAttachments (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
  • A list of ChangeItemBeans for any attachments that got created

public Either<AttachmentErrorAttachment> copyAttachment (Attachment attachment, 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

public Map<Long, Either<AttachmentErrorAttachment>> copyAttachments (Issue issue, 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.

public Attachment createAttachment (GenericValue issue, ApplicationUser author, String mimetype, String filename, Long filesize, Map<StringObject> attachmentProperties, Date createdTime)

Create an attachment in the database. Note that this does not create it on disk, nor does it create a change item.

Parameters
issue the issue that this attachment is attached to
author The user who created this attachment
mimetype mimetype
filename The desired filename for this attachment.
filesize filesize
attachmentProperties Attachment properties (a Map of String -> Object properties).
createdTime when the attachment was created
Returns
  • the Attachment

public ChangeItemBean createAttachment (File file, String filename, String contentType, ApplicationUser author, GenericValue issue, Map<StringObject> attachmentProperties, Date createdTime)

Create an attachment both on disk, and in the database.

Parameters
file A file on a locally accessible filesystem
filename The desired filename for this attachment. This may be different to the filename on disk (for example with temp files used in file uploads)
contentType The desired contentType. This may be modified if a better alternative is suggested by getSanitisedMimeType(String, String)
author The user who created this attachment
issue The issue that this attachment is attached to
attachmentProperties String -> Object property map
createdTime the created time
Returns

public ChangeItemBean createAttachment (File file, String filename, String contentType, ApplicationUser author, GenericValue issue, Boolean zip, Boolean thumbnailable, Map<StringObject> attachmentProperties, Date createdTime)

Create an attachment both on disk, and in the database.

Parameters
file A file on a locally accessible filesystem
filename The desired filename for this attachment. This may be different to the filename on disk (for example with temp files used in file uploads)
contentType The desired contentType. This may be modified if a better alternative is suggested by getSanitisedMimeType(String, String)
author The user who created this attachment
issue The issue that this attachment is attached to
zip This file is a zip file. Null indicates that it is not know if this attachment is a zip file or not
thumbnailable This file is thumbnailable (e.g. a png image). Null indicates that it is not know if this attachment is thumbnailable or not
attachmentProperties String -> Object property map
createdTime the created time
Returns

public ChangeItemBean createAttachment (CreateAttachmentParamsBean bean)

Create an attachment both on disk, and in the database.

Parameters
bean Parameters which describe created attachment
Returns

public ChangeItemBean createAttachment (File file, String filename, String contentType, ApplicationUser remoteUser, Issue issue, Map<StringObject> attachmentProperties, Date createdTime)

Create an attachment both on disk, and in the database.

Parameters
file A file on a locally accessible filesystem
filename The desired filename for this attachment. This may be different to the filename on disk (for example with temp files used in file uploads)
contentType The desired contentType. Implementations of this interface can choose to override this value as appropriate
remoteUser The user who created this attachment
issue The issue that this file is to be attached to
attachmentProperties Attachment properties (a Map of String -> Object properties). These are optional, and are used to populate a PropertySet on the Attachment (getProperties(). Pass null to set no properties
createdTime the created time
Returns

public ChangeItemBean createAttachment (File file, String filename, String contentType, ApplicationUser remoteUser, Issue issue, Boolean zip, Boolean thumbnailable, Map<StringObject> attachmentProperties, Date createdTime)

Create an attachment both on disk, and in the database.

Parameters
file A file on a locally accessible filesystem
filename The desired filename for this attachment. This may be different to the filename on disk (for example with temp files used in file uploads)
contentType The desired contentType. Implementations of this interface can choose to override this value as appropriate
remoteUser The user who created this attachment
issue The issue that this file is to be attached to
zip This file is a zip file. Null indicates that it is not know if this attachment is a zip file or not
thumbnailable This file is thumbnailable (e.g. a png image). Null indicates that it is not know if this attachment is thumbnailable or not
attachmentProperties Attachment properties (a Map of String -> Object properties). These are optional, and are used to populate a PropertySet on the Attachment (getProperties(). Pass null to set no properties
createdTime the created time
Returns

public ChangeItemBean createAttachment (File file, String filename, String contentType, ApplicationUser remoteUser, Issue issue)

Same as the #createAttachment(File, String, String, User, Issue, Map, Date) method, except it submits no attachmentProperties and uses now() for the created time.

Parameters
file A file on a locally accessible filesystem
filename The desired filename for this attachment. This may be different to the filename on disk (for example with temp files used in file uploads)
contentType The desired contentType. Implementations of this interface can choose to override this value as appropriate
remoteUser The user who created this attachment
issue The issue that this attachment is attached to
Returns

public ChangeItemBean createAttachment (File file, String filename, String contentType, ApplicationUser remoteUser, GenericValue issue)

Same as the #createAttachment(java.io.File, String, String, User, org.ofbiz.core.entity.GenericValue, java.util.Map, java.util.Date) method, except it submits no attachmentProperties and uses now() for the created time.

Parameters
file A file on a locally accessible filesystem
filename The desired filename for this attachment. This may be different to the filename on disk (for example with temp files used in file uploads)
contentType The desired contentType. Implementations of this interface can choose to override this value as appropriate
remoteUser The user who created this attachment
issue The issue that this attachment is attached to
Returns

public Attachment createAttachmentCopySourceFile (File file, String filename, String contentType, String attachmentAuthor, Issue issue, Map<StringObject> attachmentProperties, Date createdTime)

Create an attachment both on disk, and in the database by copying the provided file instead of moving it.

Parameters
file A file on a locally accessible filesystem, this will be copied, not moved.
filename The desired filename for this attachment. This may be different to the filename on disk (for example with temp files used in file uploads)
contentType The desired contentType. Implementations of this interface can choose to override this value as appropriate
attachmentAuthor The username of the user who created this attachment, this is not validated so it must be a valid username
issue The id of the issue that this attachment is attached to
attachmentProperties Attachment properties (a Map of String -> Object properties). These are optional, and are used to populate a PropertySet on the Attachment (getProperties(). Pass null to set no properties
createdTime when the attachment was created
Returns
  • the Attachment

public 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

public void deleteAttachment (Attachment attachment)

Delete an attachment from the database and from the attachment store.

Parameters
attachment the Attachment

public void deleteAttachmentDirectory (Issue issue)

Delete the attachment directory from disk if the directory is empty.

Parameters
issue the issue whose attachment directory we wish to delete.

public void deleteTemporaryAttachment (TemporaryAttachmentId temporaryAttachmentId)

Removes temporary attachment with given id

Parameters
temporaryAttachmentId id of temporary attachment

public Attachment getAttachment (Long id)

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.

public List<Attachment> getAttachments (Issue issue, Comparator<? super Attachment> comparator)

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

public List<Attachment> getAttachments (Issue issue)

Get a list of all attachments for a certain issue.

Parameters
issue the Issue
Returns

public List<Attachment> getStoredAttachments (Issue issue)

public boolean isScreenshotAppletEnabled ()

Determine if screenshot applet has been enabled in JIRA.

Returns
  • true if enabled, false otherwise

public 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

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 renameTo(File) fails across filesystems.

Parameters
oldIssue the issue we're moving attachments from
newIssueKey the new destination issue key

public Attachment setThumbnailable (Attachment attachment, boolean thumbnailable)

Stores the thumbnailble flag for this attachment

Parameters
attachment The attachment
thumbnailable True if this attachment is thumnailable

public 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

public T streamAttachmentContent (Attachment attachment, InputStreamConsumer<T> consumer)

Get binary content of the attachment

Parameters
attachment the attachment whose content to stream (required)
consumer the consumer of the stream (required)

public AttachmentsBulkOperationResult<ChangeItemBean> tryConvertTemporaryAttachments (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

public Either<AttachmentErrorChangeItemBean> 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.

Protected Methods

protected boolean isScreenshotAppletEnabledForLinux ()