public class HierarchicalMultiStreamAttachmentDataFileSystem extends Object implements AttachmentDataFileSystem
AttachmentDataFileSystem which stores the
attachment data as files on a filesystem, using the standard File API.
The files are stored within a hierarchical directory structure that incorporates the IDs of the space, content entity
and attachment IDs to which the attachment data belongs to. Data corresponding to each version of the attachment are
stored, as are different "streams" of data for each version (see AttachmentDataStreamType.
For attachments belonging to "spaced" content entities (e.g. pages, blogs), the directory structure is described by the following pattern: "h1/h2/spaceId/h3/h4/contentId/attachmentId/attachmentFile"
where h1 and h2 are hashcodes generated from the spaceId, h3 and h4 are hashcodes generated from the contentId,
and attachmentFile represents a combination of the attachment version and the data stream type. For
backwards compatibility with HierarchicalFileSystemAttachmentDataDao,
attachment files of type AttachmentDataStreamType.RAW_BINARY have a filename of just the numeric
attachment version. For other stream types, the filename is "version.streamType" (e.g. "1.extracted_text").
For "non-spaced" entity attachments (e.g. user profile pictures), a simpler but similar structure is used: "nonspaced/h3/h4/contentId/attachmentId/attachmentFile"
| Modifier and Type | Field and Description |
|---|---|
static String |
NON_SPACED_DIRECTORY_NAME |
| Constructor and Description |
|---|
HierarchicalMultiStreamAttachmentDataFileSystem(FileLocationResolver rootDir)
Deprecated.
Since 5.7.1. Inject the hierarchicalMultiStreamAttachmentDataFileSystem bean instead.
|
HierarchicalMultiStreamAttachmentDataFileSystem(FileLocationResolver rootDir,
DeferredFileDeletionQueue deferredFileDeletionQueue) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
copyAttachmentData(Attachment sourceAttachment,
Attachment destAttachment) |
boolean |
dataExistsForAttachment(Attachment attachment)
Indicates whether the filesystem contains data for the given attachment
|
void |
deleteAllAttachmentVersions(Attachment attachment,
ContentEntityObject contentEntity)
Delete all data corresponding to all versions of the given attachment
|
void |
deleteSingleAttachmentVersion(Attachment attachment,
ContentEntityObject originalContent)
Delete the data corresponding to a single attachment version
|
AttachmentDataStream |
getAttachmentData(Attachment attachment,
AttachmentDataStreamType dataStreamType)
Fetches the data for a given attachment version and data stream type
|
AttachmentDataStream |
getAttachmentData(Attachment attachment,
AttachmentDataStreamType dataStreamType,
Optional<RangeRequest> range)
Fetches the specified range of data for a given attachment version and data stream type
|
File |
getContainerDirectoryForAttachmentVersions(long latestVersionAttachmentId,
long contentId,
com.atlassian.fugue.Maybe<Long> spaceId)
Get the
File representing the directory that contains all the versions of an attachment |
void |
moveAttachment(Attachment oldAttachment,
Attachment newAttachment,
ContentEntityObject newContent)
Move all data relating to one attachment to a new directory corresponding to the given new attachment and
content entity.
|
void |
moveAttachments(ContentEntityObject contentEntity,
Space oldSpace,
Space newSpace)
Move all data for all versions of all attachments corresponding to the given content entity in the given
space, to the same entity in a different space.
|
void |
moveDataForAttachmentVersion(Attachment sourceAttachmentVersion,
Attachment targetAttachmentVersion)
Move the data associated with one attachment version, to being associated with a different attachment version
|
void |
prepareForMigrationTo()
In this implementation, we want to make sure the attachments directory is empty,
otherwise we will have attachments or files that don't belong.
|
boolean |
saveAttachmentData(Attachment attachmentVersion,
AttachmentDataStream attachmentDataStream,
boolean overwrite)
Save new data corresponding to the given attachment.
|
public static final String NON_SPACED_DIRECTORY_NAME
@Deprecated public HierarchicalMultiStreamAttachmentDataFileSystem(FileLocationResolver rootDir)
public HierarchicalMultiStreamAttachmentDataFileSystem(FileLocationResolver rootDir, DeferredFileDeletionQueue deferredFileDeletionQueue)
public boolean dataExistsForAttachment(Attachment attachment)
AttachmentDataFileSystemdataExistsForAttachment in interface AttachmentDataFileSystempublic void moveAttachment(Attachment oldAttachment, Attachment newAttachment, ContentEntityObject newContent)
AttachmentDataFileSystemmoveAttachment in interface AttachmentDataFileSystemoldAttachment - The attachment whose data is to be movednewAttachment - The attachment to which the data should be moved tonewContent - The content entity corresponding to the new attachmentpublic boolean saveAttachmentData(Attachment attachmentVersion, AttachmentDataStream attachmentDataStream, boolean overwrite)
AttachmentDataFileSystemsaveAttachmentData in interface AttachmentDataFileSystemattachmentVersion - The attachment to which the data should be associatedattachmentDataStream - The new dataoverwrite - If true, any existing data will be overwritten. If false, does nothing if data already exists.public boolean copyAttachmentData(Attachment sourceAttachment, Attachment destAttachment)
copyAttachmentData in interface AttachmentDataFileSystemsourceAttachment - source attachmentdestAttachment - dest attachmentpublic File getContainerDirectoryForAttachmentVersions(long latestVersionAttachmentId, long contentId, com.atlassian.fugue.Maybe<Long> spaceId)
File representing the directory that contains all the versions of an attachmentlatestVersionAttachmentId - this should be the ID of the latest version or the directory will not existcontentId - the ID of the content containing the attachmentspaceId - the ID of the space the content belongs toFile representing the directory that contains all the versions of an attachmentpublic void deleteAllAttachmentVersions(Attachment attachment, ContentEntityObject contentEntity)
This method will remove any empty folders left after removing the attachment data.
deleteAllAttachmentVersions in interface AttachmentDataFileSystemattachment - the attachment for which data should be removedcontentEntity - the content the attachment belongs topublic void moveDataForAttachmentVersion(Attachment sourceAttachmentVersion, Attachment targetAttachmentVersion)
AttachmentDataFileSystemmoveDataForAttachmentVersion in interface AttachmentDataFileSystemsourceAttachmentVersion - The attachment version containing the datatargetAttachmentVersion - The attachment version to which the data should be movedpublic void deleteSingleAttachmentVersion(Attachment attachment, ContentEntityObject originalContent)
This method will remove any empty folders left after removing the attachment data.
deleteSingleAttachmentVersion in interface AttachmentDataFileSystemattachment - the attachment for which data should be removedoriginalContent - the content the attachment belongs topublic AttachmentDataStream getAttachmentData(Attachment attachment, AttachmentDataStreamType dataStreamType)
AttachmentDataFileSystemgetAttachmentData in interface AttachmentDataFileSystemattachment - The attachment version for which the data is to be fetcheddataStreamType - The type of the data stream to be fetchedAttachmentDataStream containing the resultpublic AttachmentDataStream getAttachmentData(Attachment attachment, AttachmentDataStreamType dataStreamType, Optional<RangeRequest> range)
AttachmentDataFileSystemgetAttachmentData in interface AttachmentDataFileSystemattachment - The attachment version for which the data is to be fetcheddataStreamType - The type of the data stream to be fetchedrange - The range of the data stream to be fetchedAttachmentDataStream containing the resultpublic void moveAttachments(ContentEntityObject contentEntity, Space oldSpace, Space newSpace)
AttachmentDataFileSystemmoveAttachments in interface AttachmentDataFileSystemcontentEntity - The content entity whose attachment data is to be movedoldSpace - The original space of the content entitynewSpace - The new space of the content entitypublic void prepareForMigrationTo()
We also want to make sure the attachments directory actually exists, prior to moving data across.
It is the responsibility of the action performing the migration to warn the user about this.
prepareForMigrationTo in interface AttachmentDataFileSystemCopyright © 2003–2016 Atlassian. All rights reserved.