@ParametersAreNonnullByDefault public class

BackwardCompatibleStoreAdapter

extends Object
implements FileBasedAttachmentStore StreamAttachmentStore
java.lang.Object
   ↳ com.atlassian.jira.issue.attachment.store.BackwardCompatibleStoreAdapter

Class Overview

Simple adapter which delegates to StreamAttachmentStore and optionally to FileBasedAttachmentStore.

Summary

Public Constructors
BackwardCompatibleStoreAdapter(StreamAttachmentStore streamAttachmentStore, Option<FileSystemAttachmentStore> fileSystemAttachmentStore)
Public Methods
Promise<Unit> copyAttachment(AttachmentKey sourceAttachmentKey, AttachmentKey newAttachmentKey)
Copies attachment identified by oldAttachmentKey to be identified also by newAttachmentKey.
Promise<Unit> deleteAttachment(AttachmentKey attachmentKey)
Delete the attachment identified by provided attachmentKey.
Promise<Unit> deleteAttachmentContainerForIssue(Issue issue)
Delete the container for attachments for a given issue.
Promise<Unit> deleteTemporaryAttachment(TemporaryAttachmentId temporaryAttachmentId)
Deletes temporary attachment created previously by putTemporaryAttachment(java.io.InputStream, long).
@Nonnull Option<ErrorCollection> errors()
Health status for this component.
Promise<Boolean> exists(AttachmentKey attachmentKey)
Checks if attachment exists.
<A> Promise<A> getAttachment(AttachmentKey attachmentKey, Function<InputStream, A> inputStreamProcessor)
Retrieve data for a given attachment.
<A> Promise<A> getAttachmentData(AttachmentKey attachmentKey, Function<AttachmentGetData, A> attachmentGetDataProcessor)
Retrieve data for a given attachment.
File getAttachmentFile(AttachmentKey attachmentKey)
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.
boolean hasFileSystemAvailable()
Promise<Unit> moveAttachment(AttachmentKey oldAttachmentKey, AttachmentKey newAttachmentKey)
Move attachment identified by oldAttachmentKey to be identified by newAttachmentKey and will be not reachable under oldAttachmentKey anymore.
Promise<Unit> moveTemporaryToAttachment(TemporaryAttachmentId temporaryAttachmentId, AttachmentKey destinationKey)
Moving temporary attachment created by putTemporaryAttachment(java.io.InputStream, long) to real attachment.
Promise<StoreAttachmentResult> putAttachment(StoreAttachmentBean storeAttachmentBean)
Store attachment data for a given attachment.
Promise<TemporaryAttachmentId> putTemporaryAttachment(InputStream inputStream, long size)
Creates temporaryAttachment in store which can be later moved to attachment via moveTemporaryToAttachment(TemporaryAttachmentId, AttachmentKey)
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.atlassian.jira.issue.attachment.AttachmentHealth
From interface com.atlassian.jira.issue.attachment.FileBasedAttachmentStore
From interface com.atlassian.jira.issue.attachment.StreamAttachmentStore

Public Constructors

public BackwardCompatibleStoreAdapter (StreamAttachmentStore streamAttachmentStore, Option<FileSystemAttachmentStore> fileSystemAttachmentStore)

Public Methods

public Promise<Unit> copyAttachment (AttachmentKey sourceAttachmentKey, AttachmentKey newAttachmentKey)

Copies attachment identified by oldAttachmentKey to be identified also by newAttachmentKey.

Parameters
sourceAttachmentKey attachmentKey of existing attachment which should be copied
newAttachmentKey attachmentKey under which copied

public Promise<Unit> deleteAttachment (AttachmentKey attachmentKey)

Delete the attachment identified by provided attachmentKey.

Returns
  • a promise that will contain an AttachmentCleanupException in case of error.

public Promise<Unit> deleteAttachmentContainerForIssue (Issue issue)

Delete the container for attachments for a given issue. For file systems, this means the attachment directory for that issue.

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.

public Promise<Unit> deleteTemporaryAttachment (TemporaryAttachmentId temporaryAttachmentId)

Deletes temporary attachment created previously by putTemporaryAttachment(java.io.InputStream, long).

Parameters
temporaryAttachmentId id of temporary attachment

@Nonnull public Option<ErrorCollection> errors ()

Health status for this component. Specifically the errors that cause the attachment subsystem to fail.

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.

public Promise<Boolean> exists (AttachmentKey attachmentKey)

Checks if attachment exists.

Parameters
attachmentKey key of attachment to check for existence
Returns
  • a com.atlassian.util.concurrent.Promise to boolean result, true if attachment exists and false otherwise

public Promise<A> getAttachment (AttachmentKey attachmentKey, Function<InputStream, A> inputStreamProcessor)

Retrieve data for a given attachment.

Parameters
attachmentKey The key of attachment used to identify attachment data
inputStreamProcessor 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 AttachmentRuntimeException in case of error.

public Promise<A> getAttachmentData (AttachmentKey attachmentKey, Function<AttachmentGetData, A> attachmentGetDataProcessor)

Retrieve data for a given attachment. Provides more information to consumer than (@link StreamAttachmentStore#getAttachment)

Parameters
attachmentKey The key of attachment used to identify attachment data
attachmentGetDataProcessor 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 AttachmentRuntimeException in case of error.

public File getAttachmentFile (AttachmentKey attachmentKey)

Returns the physical File for the given Attachment. If you are calling this on multiple attachments for the same issue, consider using the overriden method that passes in the issue. Else, this goes to the database for each call.

Parameters
attachmentKey the the key of the attachment
Returns
  • the file.

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

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

public boolean hasFileSystemAvailable ()

public Promise<Unit> moveAttachment (AttachmentKey oldAttachmentKey, AttachmentKey newAttachmentKey)

Move attachment identified by oldAttachmentKey to be identified by newAttachmentKey and will be not reachable under oldAttachmentKey anymore.

Parameters
oldAttachmentKey the old AttachmentKey
newAttachmentKey the new AttachmentKey

public Promise<Unit> moveTemporaryToAttachment (TemporaryAttachmentId temporaryAttachmentId, AttachmentKey destinationKey)

Moving temporary attachment created by putTemporaryAttachment(java.io.InputStream, long) to real attachment.

Parameters
temporaryAttachmentId id of temporary attachment, returned by putTemporaryAttachment(java.io.InputStream, long)
destinationKey destination key of under which attachment will be identified

public Promise<StoreAttachmentResult> putAttachment (StoreAttachmentBean storeAttachmentBean)

Store attachment data for a given attachment.

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 AttachmentRuntimeException in case of error.

public Promise<TemporaryAttachmentId> putTemporaryAttachment (InputStream inputStream, long size)

Creates temporaryAttachment in store which can be later moved to attachment via moveTemporaryToAttachment(TemporaryAttachmentId, AttachmentKey)

Parameters
inputStream stream to temporary attachment data
size the size of provided stream
Returns
  • returns promise to temporaryAttachmentId