com.atlassian.jira.issue.attachment
Class DefaultAttachmentStore

java.lang.Object
  extended by com.atlassian.jira.issue.attachment.DefaultAttachmentStore
All Implemented Interfaces:
AttachmentStore

public class DefaultAttachmentStore
extends Object
implements AttachmentStore

Since:
v6.1

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.atlassian.jira.issue.attachment.AttachmentStore
AttachmentStore.AttachmentAdapter
 
Field Summary
protected  ProjectManager projectManager
           
 
Constructor Summary
DefaultAttachmentStore(ProjectManager projectManager, AttachmentPathManager attachmentPathManager)
           
 
Method Summary
 void checkValidAttachmentDirectory(Issue issue)
          Checks that the Attachment directory of the given issue is right to go - writable, accessible etc.
 void checkValidTemporaryAttachmentDirectory()
           
static String computeIssueKeyForOriginalProjectKey(String originalProjectKey, String issueKey)
           
 File getAttachmentDirectory(Issue issue)
          Returns the physical directory of the attachments for the given issue.
 File getAttachmentDirectory(Issue issue, boolean createDirectory)
          Returns the physical directory of the attachments for the given issue.
 File getAttachmentDirectory(String issueKey)
           
 File getAttachmentDirectory(String attachmentDirectory, String projectKey, String issueKey)
          Get the attachment directory for the given attachment base directory, project key, and issue key.
 File getAttachmentFile(Attachment attachment)
          Returns the physical File for the given Attachment.
 File getAttachmentFile(AttachmentStore.AttachmentAdapter attachment, File attachmentDir)
          This is intended for cases where you want more control over where the attachment actually lives and you just want something to handle the look up logic for the various possible filenames an attachment can have.
 File getAttachmentFile(Issue issue, Attachment attachment)
          Returns the physical File for the given Attachment.
 File getLegacyThumbnailFile(Attachment attachment)
          Returns the old legacy file name for thumbnails http://jira.atlassian.com/browse/JRA-23311
 File getTemporaryAttachmentDirectory()
           
 File getThumbnailDirectory(Issue issue)
          Returns the physical directory of the thumbnails for the given issue, creating if necessary.
 File getThumbnailFile(Attachment attachment)
          Just like the attachments themselves, thumbnails can succumb to file system encoding problems.
 File getThumbnailFile(Issue issue, Attachment attachment)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

projectManager

protected final ProjectManager projectManager
Constructor Detail

DefaultAttachmentStore

public DefaultAttachmentStore(ProjectManager projectManager,
                              AttachmentPathManager attachmentPathManager)
Method Detail

getThumbnailDirectory

public File getThumbnailDirectory(Issue issue)
Returns the physical directory of the thumbnails for the given issue, creating if necessary.

Specified by:
getThumbnailDirectory in interface AttachmentStore
Parameters:
issue - the issue whose thumbnail directory you want.
Returns:
The issue's thumbnail directory.

getAttachmentDirectory

public File getAttachmentDirectory(Issue issue)
Returns the physical directory of the attachments for the given issue. This will create it if necessary.

Specified by:
getAttachmentDirectory in interface AttachmentStore
Parameters:
issue - the issue whose attachment directory you want.
Returns:
The issue's attachment directory.

getAttachmentDirectory

public File getAttachmentDirectory(String issueKey)
Specified by:
getAttachmentDirectory in interface AttachmentStore

getAttachmentDirectory

public File getAttachmentDirectory(Issue issue,
                                   boolean createDirectory)
Returns the physical directory of the attachments for the given issue. This will create it if necessary.

Specified by:
getAttachmentDirectory in interface AttachmentStore
Parameters:
issue - the issue whose attachment directory you want.
createDirectory - If true, and the directory does not currently exist, then the directory is created.
Returns:
The issue's attachment directory.

getTemporaryAttachmentDirectory

public File getTemporaryAttachmentDirectory()
Specified by:
getTemporaryAttachmentDirectory in interface AttachmentStore

getAttachmentDirectory

public File getAttachmentDirectory(String attachmentDirectory,
                                   String projectKey,
                                   String issueKey)
Get the attachment directory for the given attachment base directory, project key, and issue key.

The idea is to encapsulate all of the path-joinery magic to make future refactoring easier if we ever decide to move away from attachment-base/project-key/issue-ket

Specified by:
getAttachmentDirectory in interface AttachmentStore
Parameters:
attachmentDirectory - base of attachments
projectKey - the project key the issue belongs to
issueKey - the issue key for the issue
Returns:
the directory attachments for this issue live in

computeIssueKeyForOriginalProjectKey

public static String computeIssueKeyForOriginalProjectKey(String originalProjectKey,
                                                          String issueKey)

getAttachmentFile

public File getAttachmentFile(Issue issue,
                              Attachment attachment)
                       throws DataAccessException
Returns the physical File for the given Attachment. This method performs better as it does not need to look up the issue object.

Specified by:
getAttachmentFile in interface AttachmentStore
Parameters:
issue - the issue the attachment belongs to.
attachment - the attachment.
Returns:
the file.
Throws:
DataAccessException - on failure getting required attachment info.

getAttachmentFile

public File getAttachmentFile(Attachment attachment)
                       throws DataAccessException
Returns the physical File for the given Attachment. If you are calling this on multiple attachments for the same issue, consider using the overridden method that passes in the issue. Else, this goes to the database for each call.

Specified by:
getAttachmentFile in interface AttachmentStore
Parameters:
attachment - the attachment.
Returns:
the file.
Throws:
DataAccessException - on failure getting required attachment info.

getAttachmentFile

public File getAttachmentFile(AttachmentStore.AttachmentAdapter attachment,
                              File attachmentDir)
This is intended for cases where you want more control over where the attachment actually lives and you just want something to handle the look up logic for the various possible filenames an attachment can have.

In practice, this is just used during Project Import

Specified by:
getAttachmentFile in interface AttachmentStore
Parameters:
attachment - it's not an attachment but it acts like one for our purposes.
attachmentDir - the directory the attachments live in. This is different that the system-wide attachment directory. i.e. this would "attachments/MKY/MKY-1" and not just "attachments"
Returns:
the actual attachment

getThumbnailFile

public File getThumbnailFile(Attachment attachment)
Just like the attachments themselves, thumbnails can succumb to file system encoding problems. However we are going to regenerate thumbnails by only using the new naming scheme and not the legacy one. We cant do this for attachments but we can for thumbnails since they are epheral objects anyway. http://jira.atlassian.com/browse/JRA-23311

Specified by:
getThumbnailFile in interface AttachmentStore
Parameters:
attachment - the attacment in play
Returns:
the full thumbnail file name

getThumbnailFile

public File getThumbnailFile(Issue issue,
                             Attachment attachment)
Specified by:
getThumbnailFile in interface AttachmentStore

getLegacyThumbnailFile

public File getLegacyThumbnailFile(Attachment attachment)
Returns the old legacy file name for thumbnails http://jira.atlassian.com/browse/JRA-23311

Specified by:
getLegacyThumbnailFile in interface AttachmentStore
Parameters:
attachment - the attacment in play
Returns:
the full legacy thumbnail file name

checkValidAttachmentDirectory

public void checkValidAttachmentDirectory(Issue issue)
                                   throws AttachmentException
Checks that the Attachment directory of the given issue is right to go - writable, accessible etc. Will create it if necessary.

Specified by:
checkValidAttachmentDirectory in interface AttachmentStore
Parameters:
issue - the issue whose attachment directory to check.
Throws:
AttachmentException - if the directory is not writable or missing and cannot be created.

checkValidTemporaryAttachmentDirectory

public void checkValidTemporaryAttachmentDirectory()
                                            throws AttachmentException
Specified by:
checkValidTemporaryAttachmentDirectory in interface AttachmentStore
Throws:
AttachmentException


Copyright © 2002-2014 Atlassian. All Rights Reserved.