public final class ContentDirectoryStructureAttachmentDataFileSystem extends Object implements AttachmentDataFileSystem, AttachmentDataFileSystemInternals
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 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 |
---|
ContentDirectoryStructureAttachmentDataFileSystem(FileLocationResolver rootDir,
DeferredFileDeletionQueue deferredFileDeletionQueue) |
Modifier and Type | Method and Description |
---|---|
File |
containerDirectoryForAttachmentVersions(long latestVersionAttachmentId,
long contentId,
Optional<Long> spaceId)
Get the
File representing the directory that contains all the versions of an attachment |
boolean |
dataExistsForAttachment(AttachmentRef attachment)
Indicates whether the filesystem contains data for the given attachment
|
void |
deleteAllAttachmentVersions(AttachmentRef attachment,
AttachmentRef.Container originalContent)
Delete all data corresponding to all versions of the given attachment
|
void |
deleteSingleAttachmentVersion(AttachmentRef attachment,
AttachmentRef.Container originalContent)
Delete the data corresponding to a single attachment version
|
void |
deleteSingleAttachmentVersion(AttachmentRef attachment,
AttachmentRef.Container originalContent,
AttachmentDataStreamType dataStreamType)
Delete the data of the specified stream type corresponding to a single attachment version
|
AttachmentDataStream |
getAttachmentData(AttachmentRef attachment,
AttachmentDataStreamType dataStreamType)
Fetches the data for a given attachment version and data stream type
|
AttachmentDataStream |
getAttachmentData(AttachmentRef attachment,
AttachmentDataStreamType dataStreamType,
Optional<RangeRequest> range)
Fetches the specified range of data for a given attachment version and data stream type
|
File |
getDirectoryForSpace(Optional<Long> spaceId) |
void |
moveAttachment(AttachmentRef oldAttachment,
AttachmentRef newAttachment,
AttachmentRef.Container newContent)
Move all data relating to one attachment to a new directory corresponding to the given new attachment and
content entity.
|
void |
moveAttachments(AttachmentRef.Container contentEntity,
AttachmentRef.Space oldSpace,
AttachmentRef.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(AttachmentRef sourceAttachmentVersion,
AttachmentRef 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(AttachmentRef attachmentVersion,
AttachmentDataStream attachmentDataStream,
boolean overwrite,
org.springframework.util.unit.DataSize expectedFileSize)
Save new data corresponding to the given attachment.
|
public static final String NON_SPACED_DIRECTORY_NAME
public ContentDirectoryStructureAttachmentDataFileSystem(FileLocationResolver rootDir, DeferredFileDeletionQueue deferredFileDeletionQueue)
public boolean dataExistsForAttachment(AttachmentRef attachment)
AttachmentDataFileSystem
dataExistsForAttachment
in interface AttachmentDataFileSystem
public void moveAttachment(AttachmentRef oldAttachment, AttachmentRef newAttachment, AttachmentRef.Container newContent)
AttachmentDataFileSystem
moveAttachment
in interface AttachmentDataFileSystem
oldAttachment
- 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(AttachmentRef attachmentVersion, AttachmentDataStream attachmentDataStream, boolean overwrite, org.springframework.util.unit.DataSize expectedFileSize)
AttachmentDataFileSystem
saveAttachmentData
in interface AttachmentDataFileSystem
attachmentVersion
- 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.expectedFileSize
- The expected size of the data being writtenpublic File containerDirectoryForAttachmentVersions(long latestVersionAttachmentId, long contentId, Optional<Long> spaceId)
File
representing the directory that contains all the versions of an attachmentcontainerDirectoryForAttachmentVersions
in interface AttachmentDataFileSystemInternals
latestVersionAttachmentId
- 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(AttachmentRef attachment, AttachmentRef.Container originalContent)
This method will remove any empty folders left after removing the attachment data.
deleteAllAttachmentVersions
in interface AttachmentDataFileSystem
attachment
- the attachment for which data should be removedoriginalContent
- the content the attachment belongs topublic void moveDataForAttachmentVersion(AttachmentRef sourceAttachmentVersion, AttachmentRef targetAttachmentVersion)
AttachmentDataFileSystem
moveDataForAttachmentVersion
in interface AttachmentDataFileSystem
sourceAttachmentVersion
- The attachment version containing the datatargetAttachmentVersion
- The attachment version to which the data should be movedpublic void deleteSingleAttachmentVersion(AttachmentRef attachment, AttachmentRef.Container originalContent)
This method will remove any empty folders left after removing the attachment data.
deleteSingleAttachmentVersion
in interface AttachmentDataFileSystem
attachment
- the attachment for which data should be removedoriginalContent
- the content the attachment belongs topublic void deleteSingleAttachmentVersion(AttachmentRef attachment, AttachmentRef.Container originalContent, AttachmentDataStreamType dataStreamType)
AttachmentDataFileSystem
deleteSingleAttachmentVersion
in interface AttachmentDataFileSystem
attachment
- The attachment whose data should be deletedoriginalContent
- The content entity associated with the attachmentdataStreamType
- The attachment stream typepublic File getDirectoryForSpace(Optional<Long> spaceId)
getDirectoryForSpace
in interface AttachmentDataFileSystemInternals
public AttachmentDataStream getAttachmentData(AttachmentRef attachment, AttachmentDataStreamType dataStreamType)
AttachmentDataFileSystem
getAttachmentData
in interface AttachmentDataFileSystem
attachment
- 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(AttachmentRef attachment, AttachmentDataStreamType dataStreamType, Optional<RangeRequest> range)
AttachmentDataFileSystem
getAttachmentData
in interface AttachmentDataFileSystem
attachment
- 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(AttachmentRef.Container contentEntity, AttachmentRef.Space oldSpace, AttachmentRef.Space newSpace)
AttachmentDataFileSystem
moveAttachments
in interface AttachmentDataFileSystem
contentEntity
- 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 AttachmentDataFileSystem
Copyright © 2003–2021 Atlassian. All rights reserved.