com.atlassian.jira.issue.attachment
Class DefaultAttachmentStore

java.lang.Object
  extended by com.atlassian.jira.issue.attachment.DefaultAttachmentStore
All Implemented Interfaces:
AttachmentHealth, FileBasedAttachmentStore, FileSystemAttachmentStore, SimpleAttachmentStore

public final class DefaultAttachmentStore
extends Object
implements FileSystemAttachmentStore

Since:
v6.1

Constructor Summary
DefaultAttachmentStore(AttachmentDirectoryAccessor da, com.atlassian.event.api.EventPublisher eventPublisher)
           
 
Method Summary
 com.atlassian.util.concurrent.Promise<io.atlassian.blobstore.client.api.Unit> delete(Attachment attachment)
          Delete the specified attachment.
 com.atlassian.util.concurrent.Promise<io.atlassian.blobstore.client.api.Unit> deleteAttachmentContainerForIssue(Issue issue)
          Delete the container for attachments for a given issue.
 com.atlassian.fugue.Option<ErrorCollection> errors()
          Health status for this component.
 com.atlassian.util.concurrent.Promise<Boolean> exists(Attachment metaData)
          Returns true if the attachment exists in the store.
<A> com.atlassian.util.concurrent.Promise<A>
get(Attachment metadata, com.google.common.base.Function<InputStream,A> inputStreamProcessor)
          Retrieve data for a given attachment.
 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.
 com.atlassian.util.concurrent.Promise<io.atlassian.blobstore.client.api.Unit> move(Attachment metaData, String newIssueKey)
          Moves an attachment from its current issue under a new one
 com.atlassian.util.concurrent.Promise<Attachment> put(Attachment metadata, File source)
          Store attachment data for a given attachment.
 com.atlassian.util.concurrent.Promise<Attachment> put(Attachment metadata, InputStream data)
          Store attachment data for a given attachment.
 void stop(ComponentManagerShutdownEvent event)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultAttachmentStore

public DefaultAttachmentStore(AttachmentDirectoryAccessor da,
                              com.atlassian.event.api.EventPublisher eventPublisher)
Method Detail

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

put

public com.atlassian.util.concurrent.Promise<Attachment> put(Attachment metadata,
                                                             InputStream data)
Description copied from interface: SimpleAttachmentStore
Store attachment data for a given attachment.

Specified by:
put in interface SimpleAttachmentStore
Parameters:
metadata - attachment metadata, used to determine the logical key under which to store the attachment data
data - source data. The attachment store will close this stream when it has completed. The stream will be closed once the operation is complete.
Returns:
A promise of an attachment that performs the 'put' operation once the promise is claimed. The promise will contain an AttachmentRuntimeException in case of error.

put

public com.atlassian.util.concurrent.Promise<Attachment> put(Attachment metadata,
                                                             File source)
Description copied from interface: SimpleAttachmentStore
Store attachment data for a given attachment.

Specified by:
put in interface SimpleAttachmentStore
Parameters:
metadata - attachment metadata, used to determine the logical key under which to store the attachment data
source - source data. It is assumed that the file will exist during the attachment process (i.e. relatively long lived).
Returns:
A promise of an attachment that performs the 'put' operation once the promise is claimed.

get

public <A> com.atlassian.util.concurrent.Promise<A> get(Attachment metadata,
                                                        com.google.common.base.Function<InputStream,A> inputStreamProcessor)
Description copied from interface: SimpleAttachmentStore
Retrieve data for a given attachment.

Specified by:
get in interface SimpleAttachmentStore
Type Parameters:
A - The class that the inputStreamProcessor returns when run.
Parameters:
metadata - attachment metadata, used to determine the logical key under which to store the attachment data
inputStreamProcessor - Function that processes the attachment data. This function MUST clean up upon failure of reading from the input stream, and must support being re-executed. e.g. If the function writes out to a temp file, the temp file should be created by the function.
Returns:
A promise of an object that represented the processed attachment data (i.e. from running the inputStreamProcessor over the attachment data). The promise will contain an AttachmentRuntimeException in case of error.

exists

public com.atlassian.util.concurrent.Promise<Boolean> exists(Attachment metaData)
Description copied from interface: SimpleAttachmentStore
Returns true if the attachment exists in the store.

Specified by:
exists in interface SimpleAttachmentStore
Parameters:
metaData - attachment metadata, used to determine the logical key under which to store the attachment data
Returns:
a promise that when claimed will return true if the attachment exists in the store. The promise will contain an AttachmentRuntimeException in case of error.

delete

public com.atlassian.util.concurrent.Promise<io.atlassian.blobstore.client.api.Unit> delete(Attachment attachment)
Description copied from interface: SimpleAttachmentStore
Delete the specified attachment.

Specified by:
delete in interface SimpleAttachmentStore
Parameters:
attachment - The attachment to delete.
Returns:
a promise that contains an AttachmentCleanupException in case of error.

deleteAttachmentContainerForIssue

public com.atlassian.util.concurrent.Promise<io.atlassian.blobstore.client.api.Unit> deleteAttachmentContainerForIssue(Issue issue)
Description copied from interface: FileBasedAttachmentStore
Delete the container for attachments for a given issue. For file systems, this means the attachment directory for that issue.

Specified by:
deleteAttachmentContainerForIssue in interface FileBasedAttachmentStore
Parameters:
issue - The issue to delete attachments for.
Returns:
A promise that will contain a AttachmentCleanupException if there is a problem deleting the attachment directory.

move

public com.atlassian.util.concurrent.Promise<io.atlassian.blobstore.client.api.Unit> move(Attachment metaData,
                                                                                          String newIssueKey)
Description copied from interface: SimpleAttachmentStore
Moves an attachment from its current issue under a new one

Specified by:
move in interface SimpleAttachmentStore
Parameters:
metaData - attachment metadata, used to determine the logical key of the attachment to be moved.
newIssueKey - the key of the new issue under which the attachment will reside.
Returns:
a promise that will be completed when the operation is complete. It will contain an AttachmentRuntimeException in case of error.

errors

public com.atlassian.fugue.Option<ErrorCollection> errors()
Description copied from interface: AttachmentHealth
Health status for this component. Specifically the errors that cause the attachment subsystem to fail.

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.

stop

@EventListener
public void stop(ComponentManagerShutdownEvent event)


Copyright © 2002-2014 Atlassian. All Rights Reserved.