Class DefaultStreamAttachmentStore
java.lang.Object
com.atlassian.jira.issue.attachment.DefaultStreamAttachmentStore
- All Implemented Interfaces:
StreamAttachmentStore
@ParametersAreNonnullByDefault
public class DefaultStreamAttachmentStore
extends Object
implements StreamAttachmentStore
Default implementation of the
StreamAttachmentStore interface, the intention behind this class is that
it will work with any FileStore implementation, so do not add filesystem specific code. There are some
FS-specific code paths that will be removed when S3 support is added for Jira 10.- Since:
- v9.7
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultStreamAttachmentStore(AttachmentConfigStore attachmentConfigStore, AttachmentKeyMapper attachmentKeyMapper, com.atlassian.event.api.EventPublisher eventPublisher, ExecutorServiceWrapper managedExecutor, LocalTemporaryFileStore localTemporaryFileStore, ProjectManager projectManager, StreamAttachmentStoreStats streamAttachmentStoreStats) -
Method Summary
Modifier and TypeMethodDescriptionio.atlassian.util.concurrent.Promise<io.atlassian.fugue.Unit>copyAttachment(AttachmentKey sourceAttachmentKey, AttachmentKey newAttachmentKey) Copies the attachment identified byoldAttachmentKeyto be identified also bynewAttachmentKey.io.atlassian.util.concurrent.Promise<io.atlassian.fugue.Unit>deleteAttachment(AttachmentKey attachmentKey) Deletes the specified attachment.io.atlassian.util.concurrent.Promise<io.atlassian.fugue.Unit>Delete the container for attachments for a given issue if it exists.io.atlassian.util.concurrent.Promise<io.atlassian.fugue.Unit>deleteTemporaryAttachment(TemporaryAttachmentId temporaryAttachmentId) Deletes temporary attachment created previously byStreamAttachmentStore.putTemporaryAttachment(java.io.InputStream, long).io.atlassian.util.concurrent.Promise<Boolean>exists(AttachmentKey attachmentKey) Indicates whether the specified attachment exists.<A> io.atlassian.util.concurrent.Promise<A>getAttachment(AttachmentKey attachmentKey, Function<InputStream, A> inputStreamProcessor) Retrieves the specified attachment.<A> io.atlassian.util.concurrent.Promise<A>getAttachmentData(AttachmentKey attachmentKey, Function<AttachmentGetData, A> attachmentGetDataProcessor) Retrieves the specified attachment.com.atlassian.dc.filestore.api.FileStore.PathgetAttachmentPath(com.atlassian.dc.filestore.api.FileStore.Path rootAttachmentPath, String projectKey, String issueKey) Get the attachment path for the given attachment base directory, project key, and issue key.com.atlassian.dc.filestore.api.FileStore.PathgetAttachmentPath(Attachment attachment) Returns the file for the given attachment.com.atlassian.dc.filestore.api.FileStore.PathgetAttachmentPath(AttachmentKey attachmentKey) Returns the physical File for the given attachment key.Optional<com.atlassian.dc.filestore.api.FileStore.Path>getAttachmentPathForIssue(Issue issue) Returns the path of the attachments for the given issue.<A> io.atlassian.util.concurrent.Promise<A>getTemporaryAttachment(TemporaryAttachmentId temporaryAttachmentId, Function<InputStream, A> inputStreamProcessor) Retrieve data for temporary attachment.io.atlassian.util.concurrent.Promise<Void>move(Attachment attachment, String newIssueKey) Moves an attachment from its current issue to the one with the given key.io.atlassian.util.concurrent.Promise<io.atlassian.fugue.Unit>moveTemporaryToAttachment(TemporaryAttachmentId temporaryAttachmentId, AttachmentKey destinationKey) Moving temporary attachment created byStreamAttachmentStore.putTemporaryAttachment(java.io.InputStream, long)to real attachment.io.atlassian.util.concurrent.Promise<StoreAttachmentResult>putAttachment(StoreAttachmentBean storeAttachmentBean) Stores the given attachment.io.atlassian.util.concurrent.Promise<TemporaryAttachmentId>putTemporaryAttachment(InputStream inputStream, long size) Creates temporaryAttachment in store which can be later moved to attachment viaStreamAttachmentStore.moveTemporaryToAttachment(TemporaryAttachmentId, AttachmentKey)
-
Constructor Details
-
DefaultStreamAttachmentStore
public DefaultStreamAttachmentStore(AttachmentConfigStore attachmentConfigStore, AttachmentKeyMapper attachmentKeyMapper, com.atlassian.event.api.EventPublisher eventPublisher, ExecutorServiceWrapper managedExecutor, LocalTemporaryFileStore localTemporaryFileStore, ProjectManager projectManager, StreamAttachmentStoreStats streamAttachmentStoreStats)
-
-
Method Details
-
putAttachment
public io.atlassian.util.concurrent.Promise<StoreAttachmentResult> putAttachment(StoreAttachmentBean storeAttachmentBean) Description copied from interface:StreamAttachmentStoreStores the given attachment.- Specified by:
putAttachmentin interfaceStreamAttachmentStore- Parameters:
storeAttachmentBean- attachment metadata, used to determine the logical key under which to store the attachment data- Returns:
- A promise of an attachment that performs the 'put' operation once the promise is claimed. The promise
will contain an
AttachmentRuntimeExceptionin case of error.
-
getAttachment
public <A> io.atlassian.util.concurrent.Promise<A> getAttachment(AttachmentKey attachmentKey, Function<InputStream, A> inputStreamProcessor) Description copied from interface:StreamAttachmentStoreRetrieves the specified attachment.- Specified by:
getAttachmentin interfaceStreamAttachmentStore- Type Parameters:
A- The class that the inputStreamProcessor returns when run.- Parameters:
attachmentKey- The key of attachment used to identify attachment datainputStreamProcessor- Function that processes the attachment data.- 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
AttachmentRuntimeExceptionin case of error.
-
getAttachmentData
public <A> io.atlassian.util.concurrent.Promise<A> getAttachmentData(AttachmentKey attachmentKey, Function<AttachmentGetData, A> attachmentGetDataProcessor) Description copied from interface:StreamAttachmentStoreRetrieves the specified attachment. Provides more information to the consumer thanStreamAttachmentStore.getAttachment(AttachmentKey, Function).- Specified by:
getAttachmentDatain interfaceStreamAttachmentStore- Type Parameters:
A- The class that the attachmentGetDataProcessor returns when run.- Parameters:
attachmentKey- The key of attachment used to identify attachment dataattachmentGetDataProcessor- Function that processes the attachment data.- 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
AttachmentRuntimeExceptionin case of error.
-
getAttachmentPath
Description copied from interface:StreamAttachmentStoreReturns the file for the given attachment.- Specified by:
getAttachmentPathin interfaceStreamAttachmentStore- Parameters:
attachment- the attachment for which to retrieve the file.- Returns:
- the filestore path
-
getAttachmentPath
public com.atlassian.dc.filestore.api.FileStore.Path getAttachmentPath(@Nullable AttachmentKey attachmentKey) throws AttachmentsDisabledException, AttachmentCleanupException Returns the physical File for the given attachment key.- Specified by:
getAttachmentPathin interfaceStreamAttachmentStore- Parameters:
attachmentKey- the key of attachment- Returns:
- the file.
- Throws:
AttachmentsDisabledException- if attachments are disabled.AttachmentCleanupException- if there is an error getting the attachment path.
-
deleteAttachmentContainerForIssue
public io.atlassian.util.concurrent.Promise<io.atlassian.fugue.Unit> deleteAttachmentContainerForIssue(Issue issue) Description copied from interface:StreamAttachmentStoreDelete the container for attachments for a given issue if it exists. For file systems, this means the attachment directory for that issue.- Specified by:
deleteAttachmentContainerForIssuein interfaceStreamAttachmentStore- Parameters:
issue- The issue to delete attachments for.- Returns:
- A promise that will contain a AttachmentCleanupException if there is a problem deleting the attachment container.
-
getAttachmentPathForIssue
public Optional<com.atlassian.dc.filestore.api.FileStore.Path> getAttachmentPathForIssue(Issue issue) Description copied from interface:StreamAttachmentStoreReturns the path of the attachments for the given issue.- Specified by:
getAttachmentPathForIssuein interfaceStreamAttachmentStore- Parameters:
issue- the issue whose attachment directory you want- Returns:
- The issue's attachment path if a base attachment path exists and the issue has a project. Otherwise, an empty optional.
-
getAttachmentPath
public com.atlassian.dc.filestore.api.FileStore.Path getAttachmentPath(com.atlassian.dc.filestore.api.FileStore.Path rootAttachmentPath, String projectKey, String issueKey) Description copied from interface:StreamAttachmentStoreGet the attachment path for the given attachment base directory, project key, and issue key.- Specified by:
getAttachmentPathin interfaceStreamAttachmentStore- Parameters:
rootAttachmentPath- base of attachmentsprojectKey- the project key the issue belongs toissueKey- the issue key for the issue- Returns:
- the directory attachments for this issue live in
-
move
Description copied from interface:StreamAttachmentStoreMoves an attachment from its current issue to the one with the given key.- Specified by:
movein interfaceStreamAttachmentStore- Parameters:
attachment- provides the logical key of the attachment to be movednewIssueKey- 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
AttachmentRuntimeExceptionin case of error.
-
copyAttachment
public io.atlassian.util.concurrent.Promise<io.atlassian.fugue.Unit> copyAttachment(AttachmentKey sourceAttachmentKey, AttachmentKey newAttachmentKey) Description copied from interface:StreamAttachmentStoreCopies the attachment identified byoldAttachmentKeyto be identified also bynewAttachmentKey.- Specified by:
copyAttachmentin interfaceStreamAttachmentStore- Parameters:
sourceAttachmentKey- attachmentKey of existing attachment which should be copiednewAttachmentKey- attachmentKey under which copied- Returns:
- a promise of unit
-
deleteAttachment
public io.atlassian.util.concurrent.Promise<io.atlassian.fugue.Unit> deleteAttachment(@Nullable AttachmentKey attachmentKey) Description copied from interface:StreamAttachmentStoreDeletes the specified attachment.- Specified by:
deleteAttachmentin interfaceStreamAttachmentStore- Parameters:
attachmentKey- the attachment key- Returns:
- a promise that will contain an AttachmentCleanupException in case of error.
-
putTemporaryAttachment
public io.atlassian.util.concurrent.Promise<TemporaryAttachmentId> putTemporaryAttachment(InputStream inputStream, long size) Description copied from interface:StreamAttachmentStoreCreates temporaryAttachment in store which can be later moved to attachment viaStreamAttachmentStore.moveTemporaryToAttachment(TemporaryAttachmentId, AttachmentKey)- Specified by:
putTemporaryAttachmentin interfaceStreamAttachmentStore- Parameters:
inputStream- stream to temporary attachment datasize- the size of provided stream- Returns:
- returns promise to temporaryAttachmentId
-
moveTemporaryToAttachment
public io.atlassian.util.concurrent.Promise<io.atlassian.fugue.Unit> moveTemporaryToAttachment(TemporaryAttachmentId temporaryAttachmentId, AttachmentKey destinationKey) Description copied from interface:StreamAttachmentStoreMoving temporary attachment created byStreamAttachmentStore.putTemporaryAttachment(java.io.InputStream, long)to real attachment.- Specified by:
moveTemporaryToAttachmentin interfaceStreamAttachmentStore- Parameters:
temporaryAttachmentId- id of temporary attachment, returned byStreamAttachmentStore.putTemporaryAttachment(java.io.InputStream, long)destinationKey- destination key of under which attachment will be identified- Returns:
- a promise of unit
-
deleteTemporaryAttachment
public io.atlassian.util.concurrent.Promise<io.atlassian.fugue.Unit> deleteTemporaryAttachment(TemporaryAttachmentId temporaryAttachmentId) Description copied from interface:StreamAttachmentStoreDeletes temporary attachment created previously byStreamAttachmentStore.putTemporaryAttachment(java.io.InputStream, long).- Specified by:
deleteTemporaryAttachmentin interfaceStreamAttachmentStore- Parameters:
temporaryAttachmentId- id of temporary attachment- Returns:
- a promise of unit
-
getTemporaryAttachment
public <A> io.atlassian.util.concurrent.Promise<A> getTemporaryAttachment(TemporaryAttachmentId temporaryAttachmentId, Function<InputStream, A> inputStreamProcessor) Description copied from interface:StreamAttachmentStoreRetrieve data for temporary attachment.- Specified by:
getTemporaryAttachmentin interfaceStreamAttachmentStore- Type Parameters:
A- The class that the inputStreamProcessor returns when run.- Parameters:
temporaryAttachmentId- The id of temporary attachmentinputStreamProcessor- Function that processes the attachment data.- 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
AttachmentRuntimeExceptionin case of error.
-
exists
Description copied from interface:StreamAttachmentStoreIndicates whether the specified attachment exists.- Specified by:
existsin interfaceStreamAttachmentStore- Parameters:
attachmentKey- key of attachment to check for existence- Returns:
- a
Promiseto boolean result, true if attachment exists and false otherwise
-