com.atlassian.jira.issue.attachment
Class FileSystemAttachmentDirectoryAccessor

java.lang.Object
  extended by com.atlassian.jira.issue.attachment.FileSystemAttachmentDirectoryAccessor
All Implemented Interfaces:
AttachmentDirectoryAccessor, AttachmentHealth

public class FileSystemAttachmentDirectoryAccessor
extends Object
implements AttachmentDirectoryAccessor

Implementation of the AttachmentDirectoryAccessor that deals with filesystem-based attachment storage.

Since:
v6.3

Field Summary
protected  ProjectManager projectManager
           
 
Constructor Summary
FileSystemAttachmentDirectoryAccessor(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()
          Checks that the temporary directory where attachments can be uploaded is writeable.
 com.atlassian.fugue.Option<ErrorCollection> errors()
          Checks that the attachment root directory and the temporary attachment directories exist and are writeable.
 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 getAttachmentRootPath()
          Returns the path used to store all attachments across the system.
 File getTemporaryAttachmentDirectory()
           
 File getThumbnailDirectory(Issue issue)
          Returns the physical directory of the thumbnails for the given issue, creating if necessary.
 
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

FileSystemAttachmentDirectoryAccessor

public FileSystemAttachmentDirectoryAccessor(ProjectManager projectManager,
                                             AttachmentPathManager attachmentPathManager)
Method Detail

getThumbnailDirectory

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

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

getAttachmentDirectory

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

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

getAttachmentDirectory

@Nullable
public File getAttachmentDirectory(@Nonnull
                                            String issueKey)
Specified by:
getAttachmentDirectory in interface AttachmentDirectoryAccessor

getAttachmentDirectory

public File getAttachmentDirectory(@Nonnull
                                   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 AttachmentDirectoryAccessor
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 AttachmentDirectoryAccessor

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 AttachmentDirectoryAccessor
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

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 AttachmentDirectoryAccessor
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
Description copied from interface: AttachmentDirectoryAccessor
Checks that the temporary directory where attachments can be uploaded is writeable.

Specified by:
checkValidTemporaryAttachmentDirectory in interface AttachmentDirectoryAccessor
Throws:
AttachmentException - if the directory is not writable or missing and cannot be created.

getAttachmentRootPath

public File getAttachmentRootPath()
Description copied from interface: AttachmentDirectoryAccessor
Returns the path used to store all attachments across the system.

Specified by:
getAttachmentRootPath in interface AttachmentDirectoryAccessor
Returns:
the path used to store all attachments across the system.

errors

public com.atlassian.fugue.Option<ErrorCollection> errors()
Checks that the attachment root directory and the temporary attachment directories exist and are writeable.

Specified by:
errors in interface AttachmentHealth
Returns:
An option of an error collection that contains error messages if there are any issues. The option will be none if there are no errors.


Copyright © 2002-2014 Atlassian. All Rights Reserved.