com.atlassian.jira.issue.managers
Class DefaultAttachmentManager

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

public class DefaultAttachmentManager
extends Object
implements AttachmentManager


Constructor Summary
DefaultAttachmentManager(IssueManager issueManager, OfBizDelegator ofBizDelegator, MimeManager mimeManager, ApplicationProperties applicationProperties, AttachmentPathManager attachmentPathManager, ComponentLocator componentLocator, I18nHelper.BeanFactory i18nBeanFactory)
           
 
Method Summary
 boolean attachmentsEnabled()
          Determine if attachments have been enabled in JIRA and if the attachments directory exists.
 List<ChangeItemBean> convertTemporaryAttachments(com.atlassian.crowd.embedded.api.User user, Issue issue, List<Long> selectedAttachments, TemporaryAttachmentsMonitor temporaryAttachmentsMonitor)
          Converts a set of provided temporary attachments to real attachments attached to an issue.
 ChangeItemBean createAttachment(File file, String filename, String contentType, com.atlassian.crowd.embedded.api.User remoteUser, org.ofbiz.core.entity.GenericValue issue)
          Same as the AttachmentManager.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.
 ChangeItemBean createAttachment(File file, String filename, String contentType, com.atlassian.crowd.embedded.api.User author, org.ofbiz.core.entity.GenericValue issue, Boolean zip, Boolean thumbnailable, Map<String,Object> attachmentProperties, Date createdTime)
          Create an attachment both on disk, and in the database.
 ChangeItemBean createAttachment(File file, String filename, String contentType, com.atlassian.crowd.embedded.api.User author, org.ofbiz.core.entity.GenericValue issue, Map<String,Object> attachmentProperties, Date createdTime)
          Create an attachment both on disk, and in the database.
 ChangeItemBean createAttachment(File file, String filename, String contentType, com.atlassian.crowd.embedded.api.User remoteUser, Issue issue)
          Same as the AttachmentManager.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, com.atlassian.crowd.embedded.api.User remoteUser, Issue issue, Boolean zip, Boolean thumbnailable, Map<String,Object> attachmentProperties, Date createdTime)
          Create an attachment both on disk, and in the database.
 ChangeItemBean createAttachment(File file, String filename, String contentType, com.atlassian.crowd.embedded.api.User remoteUser, Issue issue, Map<String,Object> attachmentProperties, Date createdTime)
          Create an attachment both on disk, and in the database.
 Attachment createAttachment(org.ofbiz.core.entity.GenericValue issue, com.atlassian.crowd.embedded.api.User author, String mimetype, String filename, Long filesize, Map<String,Object> attachmentProperties, Date createdTime)
          Create an attachment in the database.
 Attachment createAttachmentCopySourceFile(File file, String filename, String contentType, String attachmentAuthor, Issue issue, Map<String,Object> attachmentProperties, Date createdTime)
          Create an attachment both on disk, and in the database by copying the provided file instead of moving it.
protected  void createAttachmentOnDisk(Attachment attachment, File file, com.atlassian.crowd.embedded.api.User user)
           
protected  void createAttachmentOnDiskCopySourceFile(Attachment attachment, File file)
           
 void deleteAttachment(Attachment attachment)
          Delete an attachment from the database and from disk.
 void deleteAttachmentDirectory(Issue issue)
          Delete the attachment directory from disk if the directory is empty.
 Attachment getAttachment(Long id)
          Get a single attachment by its ID.
 List<Attachment> getAttachments(Issue issue)
          Get a list of all attachments for a certain issue.
 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> getStoredAttachments(Issue issue)
           
 boolean isScreenshotAppletEnabled()
          Determine if screenshot applet has been enabled in JIRA.
protected  boolean isScreenshotAppletEnabledForLinux()
           
 boolean isScreenshotAppletSupportedByOS()
          Determine if the screenshot applet is supported by the user's operating system.
 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultAttachmentManager

public DefaultAttachmentManager(IssueManager issueManager,
                                OfBizDelegator ofBizDelegator,
                                MimeManager mimeManager,
                                ApplicationProperties applicationProperties,
                                AttachmentPathManager attachmentPathManager,
                                ComponentLocator componentLocator,
                                I18nHelper.BeanFactory i18nBeanFactory)
Method Detail

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

createAttachmentCopySourceFile

public Attachment createAttachmentCopySourceFile(File file,
                                                 String filename,
                                                 String contentType,
                                                 String attachmentAuthor,
                                                 Issue issue,
                                                 Map<String,Object> attachmentProperties,
                                                 Date createdTime)
                                          throws AttachmentException
Description copied from interface: AttachmentManager
Create an attachment both on disk, and in the database by copying the provided file instead of moving it.

Specified by:
createAttachmentCopySourceFile in interface AttachmentManager
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 (Attachment.getProperties(). Pass null to set no properties
createdTime - when the attachment was created
Returns:
the Attachment
Throws:
AttachmentException - if any errors occur.

createAttachment

public Attachment createAttachment(org.ofbiz.core.entity.GenericValue issue,
                                   com.atlassian.crowd.embedded.api.User author,
                                   String mimetype,
                                   String filename,
                                   Long filesize,
                                   Map<String,Object> attachmentProperties,
                                   Date createdTime)
Description copied from interface: AttachmentManager
Create an attachment in the database. Note that this does not create it on disk, nor does it create a change item.

Specified by:
createAttachment in interface AttachmentManager
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

deleteAttachment

public void deleteAttachment(Attachment attachment)
                      throws RemoveException
Description copied from interface: AttachmentManager
Delete an attachment from the database and from disk.

Specified by:
deleteAttachment in interface AttachmentManager
Parameters:
attachment - the Attachment
Throws:
RemoveException - if the attachment cannot be removed from the disk

deleteAttachmentDirectory

public void deleteAttachmentDirectory(Issue issue)
                               throws RemoveException
Description copied from interface: AttachmentManager
Delete the attachment directory from disk if the directory is empty.

Specified by:
deleteAttachmentDirectory in interface AttachmentManager
Parameters:
issue - the issue whose attachment directory we wish to delete.
Throws:
RemoveException - if the directory can not be removed or is not empty.

attachmentsEnabled

public boolean attachmentsEnabled()
Description copied from interface: AttachmentManager
Determine if attachments have been enabled in JIRA and if the attachments directory exists.

Specified by:
attachmentsEnabled in interface AttachmentManager
Returns:
true if enabled, false otherwise

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

convertTemporaryAttachments

public List<ChangeItemBean> convertTemporaryAttachments(com.atlassian.crowd.embedded.api.User 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

createAttachment

public ChangeItemBean createAttachment(File file,
                                       String filename,
                                       String contentType,
                                       com.atlassian.crowd.embedded.api.User remoteUser,
                                       Issue issue,
                                       Map<String,Object> attachmentProperties,
                                       Date createdTime)
                                throws AttachmentException
Description copied from interface: AttachmentManager
Create an attachment both on disk, and in the database.

Specified by:
createAttachment in interface AttachmentManager
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 (Attachment.getProperties(). Pass null to set no properties
createdTime - the created time
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:
AttachmentManager.createAttachment(java.io.File, String, String, com.atlassian.crowd.embedded.api.User, Issue)

createAttachment

public ChangeItemBean createAttachment(File file,
                                       String filename,
                                       String contentType,
                                       com.atlassian.crowd.embedded.api.User remoteUser,
                                       Issue issue,
                                       Boolean zip,
                                       Boolean thumbnailable,
                                       Map<String,Object> attachmentProperties,
                                       Date createdTime)
                                throws AttachmentException
Description copied from interface: AttachmentManager
Create an attachment both on disk, and in the database.

Specified by:
createAttachment in interface AttachmentManager
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 (Attachment.getProperties(). Pass null to set no properties
createdTime - the created time
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:
AttachmentManager.createAttachment(java.io.File, String, String, com.atlassian.crowd.embedded.api.User, Issue)

createAttachment

public ChangeItemBean createAttachment(File file,
                                       String filename,
                                       String contentType,
                                       com.atlassian.crowd.embedded.api.User author,
                                       org.ofbiz.core.entity.GenericValue issue,
                                       Map<String,Object> attachmentProperties,
                                       Date createdTime)
                                throws AttachmentException
Description copied from interface: AttachmentManager
Create an attachment both on disk, and in the database.

Specified by:
createAttachment in interface AttachmentManager
Parameters:
contentType - The desired contentType. This may be modified if a better alternative is suggested by MimeManager.getSanitisedMimeType(String, String)
attachmentProperties - String -> Object property map
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)
author - The user who created this attachment
issue - The issue that this attachment is attached to
createdTime - the created time
Returns:
A ChangeItemBean with all the changes to the issue.
Throws:
AttachmentException - if an error occurs while attempting to copy the file

createAttachment

public ChangeItemBean createAttachment(File file,
                                       String filename,
                                       String contentType,
                                       com.atlassian.crowd.embedded.api.User author,
                                       org.ofbiz.core.entity.GenericValue issue,
                                       Boolean zip,
                                       Boolean thumbnailable,
                                       Map<String,Object> attachmentProperties,
                                       Date createdTime)
                                throws AttachmentException
Description copied from interface: AttachmentManager
Create an attachment both on disk, and in the database.

Specified by:
createAttachment in interface AttachmentManager
Parameters:
contentType - The desired contentType. This may be modified if a better alternative is suggested by MimeManager.getSanitisedMimeType(String, String)
attachmentProperties - String -> Object property map
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)
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
createdTime - the created time
Returns:
A ChangeItemBean with all the changes to the issue.
Throws:
AttachmentException - if an error occurs while attempting to copy the file

createAttachment

public ChangeItemBean createAttachment(File file,
                                       String filename,
                                       String contentType,
                                       com.atlassian.crowd.embedded.api.User remoteUser,
                                       org.ofbiz.core.entity.GenericValue issue)
                                throws AttachmentException
Description copied from interface: AttachmentManager
Same as the AttachmentManager.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.

Specified by:
createAttachment in interface AttachmentManager
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:
A ChangeItemBean with all the changes to the issue.
Throws:
AttachmentException - if an error occurs while attempting to copy the file

createAttachment

public ChangeItemBean createAttachment(File file,
                                       String filename,
                                       String contentType,
                                       com.atlassian.crowd.embedded.api.User remoteUser,
                                       Issue issue)
                                throws AttachmentException
Description copied from interface: AttachmentManager
Same as the AttachmentManager.createAttachment(File, String, String, User, Issue, Map, Date) method, except it submits no attachmentProperties and uses now() for the created time.

Specified by:
createAttachment in interface AttachmentManager
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:
A ChangeItemBean with all the changes to the issue.
Throws:
AttachmentException - if an IO error occurs while attempting to copy the file
See Also:
AttachmentManager.createAttachment(java.io.File, String, String, com.atlassian.crowd.embedded.api.User, Issue, java.util.Map, java.util.Date)

createAttachmentOnDisk

protected void createAttachmentOnDisk(Attachment attachment,
                                      File file,
                                      com.atlassian.crowd.embedded.api.User user)
                               throws AttachmentException
Throws:
AttachmentException

createAttachmentOnDiskCopySourceFile

protected void createAttachmentOnDiskCopySourceFile(Attachment attachment,
                                                    File file)
                                             throws AttachmentException
Throws:
AttachmentException

setThumbnailable

public Attachment setThumbnailable(Attachment attachment,
                                   boolean thumbnailable)
Description copied from interface: AttachmentManager
Stores the thumbnailble flag for this attachment

Specified by:
setThumbnailable in interface AttachmentManager
Parameters:
attachment - The attachment
thumbnailable - True if this attachment is thumnailable

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


Copyright © 2002-2013 Atlassian. All Rights Reserved.