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 |
| Modifier and Type | Method and Description |
|---|---|
com.atlassian.dc.filestore.api.compat.FilesystemPath |
containerPathForAttachmentVersions(long latestVersionAttachmentId,
long contentId,
Long spaceId)
Get the
File representing the directory that contains all the versions of an attachment |
static ContentDirectoryStructureAttachmentDataFileSystem |
create(AttachmentDataStorageLocationResolver rootDir,
DeferredFileDeletionQueue deferredFileDeletionQueue) |
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
|
com.atlassian.dc.filestore.api.compat.FilesystemPath |
getPathForSpace(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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcontainerDirectoryForAttachmentVersions, getDirectoryForSpacepublic static final String NON_SPACED_DIRECTORY_NAME
public static ContentDirectoryStructureAttachmentDataFileSystem create(AttachmentDataStorageLocationResolver rootDir, DeferredFileDeletionQueue deferredFileDeletionQueue)
public boolean dataExistsForAttachment(AttachmentRef attachment)
AttachmentDataFileSystemdataExistsForAttachment in interface AttachmentDataFileSystempublic void moveAttachment(AttachmentRef oldAttachment, AttachmentRef newAttachment, AttachmentRef.Container 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(AttachmentRef attachmentVersion, AttachmentDataStream attachmentDataStream, boolean overwrite, org.springframework.util.unit.DataSize expectedFileSize)
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.expectedFileSize - The expected size of the data being writtenpublic com.atlassian.dc.filestore.api.compat.FilesystemPath containerPathForAttachmentVersions(long latestVersionAttachmentId,
long contentId,
@Nullable
Long spaceId)
File representing the directory that contains all the versions of an attachmentcontainerPathForAttachmentVersions in interface AttachmentDataFileSystemInternalslatestVersionAttachmentId - 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 AttachmentDataFileSystemattachment - the attachment for which data should be removedoriginalContent - the content the attachment belongs topublic void moveDataForAttachmentVersion(AttachmentRef sourceAttachmentVersion, AttachmentRef targetAttachmentVersion)
AttachmentDataFileSystemmoveDataForAttachmentVersion in interface AttachmentDataFileSystemsourceAttachmentVersion - 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 AttachmentDataFileSystemattachment - the attachment for which data should be removedoriginalContent - the content the attachment belongs topublic void deleteSingleAttachmentVersion(AttachmentRef attachment, AttachmentRef.Container originalContent, AttachmentDataStreamType dataStreamType)
AttachmentDataFileSystemdeleteSingleAttachmentVersion in interface AttachmentDataFileSystemattachment - The attachment whose data should be deletedoriginalContent - The content entity associated with the attachmentdataStreamType - The attachment stream typepublic com.atlassian.dc.filestore.api.compat.FilesystemPath getPathForSpace(@Nullable Long spaceId)
getPathForSpace in interface AttachmentDataFileSystemInternalspublic AttachmentDataStream getAttachmentData(AttachmentRef 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(AttachmentRef 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(AttachmentRef.Container contentEntity, AttachmentRef.Space oldSpace, AttachmentRef.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–2022 Atlassian. All rights reserved.