com.atlassian.confluence.pages.persistence.dao.filesystem
Class HierarchicalMultiStreamAttachmentDataFileSystem

java.lang.Object
  extended by com.atlassian.confluence.pages.persistence.dao.filesystem.HierarchicalMultiStreamAttachmentDataFileSystem

public class HierarchicalMultiStreamAttachmentDataFileSystem
extends Object

An implementation of 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"

Since:
5.5

Field Summary
static String NON_SPACED_DIRECTORY_NAME
           
 
Constructor Summary
HierarchicalMultiStreamAttachmentDataFileSystem(FileLocationResolver rootDir)
          Deprecated. Since 5.7.1. Inject the hierarchicalMultiStreamAttachmentDataFileSystem bean instead.
HierarchicalMultiStreamAttachmentDataFileSystem(FileLocationResolver rootDir, DeferredFileDeletionQueue deferredFileDeletionQueue)
           
 
Method Summary
 boolean dataExistsForAttachment(Attachment attachment)
          Indicates whether the filesystem contains data for the given attachment
 void deleteAllAttachmentVersions(Attachment attachment, ContentEntityObject originalContent)
          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
 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
 boolean saveAttachmentData(Attachment attachmentVersion, AttachmentDataStream attachmentDataStream, boolean overwrite)
          Save new data corresponding to the given attachment.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NON_SPACED_DIRECTORY_NAME

public static final String NON_SPACED_DIRECTORY_NAME
See Also:
Constant Field Values
Constructor Detail

HierarchicalMultiStreamAttachmentDataFileSystem

@Deprecated
public HierarchicalMultiStreamAttachmentDataFileSystem(FileLocationResolver rootDir)
Deprecated. Since 5.7.1. Inject the hierarchicalMultiStreamAttachmentDataFileSystem bean instead.

Do not use this. Consumers used to create their own HierarchicalMultiStreamAttachmentDataFileSystem but no longer need to as it is now a bean.


HierarchicalMultiStreamAttachmentDataFileSystem

public HierarchicalMultiStreamAttachmentDataFileSystem(FileLocationResolver rootDir,
                                                       DeferredFileDeletionQueue deferredFileDeletionQueue)
Method Detail

dataExistsForAttachment

public boolean dataExistsForAttachment(Attachment attachment)
Indicates whether the filesystem contains data for the given attachment


moveAttachment

public 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.

Parameters:
oldAttachment - The attachment whose data is to be moved
newAttachment - The attachment to which the data should be moved to
newContent - The content entity corresponding to the new attachment

saveAttachmentData

public boolean saveAttachmentData(Attachment attachmentVersion,
                                  AttachmentDataStream attachmentDataStream,
                                  boolean overwrite)
Save new data corresponding to the given attachment.

Parameters:
attachmentVersion - The attachment to which the data should be associated
attachmentDataStream - The new data
overwrite - If true, any existing data will be overwritten. If false, does nothing if data already exists.
Returns:
true if the data was written, false otherwise (e.g. no overwrite)

getContainerDirectoryForAttachmentVersions

public 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

Parameters:
latestVersionAttachmentId - this should be the ID of the latest version or the directory will not exist
contentId - the ID of the content containing the attachment
spaceId - the ID of the space the content belongs to
Returns:
the File representing the directory that contains all the versions of an attachment
Since:
5.7

deleteAllAttachmentVersions

public void deleteAllAttachmentVersions(Attachment attachment,
                                        ContentEntityObject originalContent)
Delete all data corresponding to all versions of the given attachment

Parameters:
attachment - the attachment whose data is to be deleted
originalContent - The content entity associated with the attachment

moveDataForAttachmentVersion

public void moveDataForAttachmentVersion(Attachment sourceAttachmentVersion,
                                         Attachment targetAttachmentVersion)
Move the data associated with one attachment version, to being associated with a different attachment version

Parameters:
sourceAttachmentVersion - The attachment version containing the data
targetAttachmentVersion - The attachment version to which the data should be moved

deleteSingleAttachmentVersion

public void deleteSingleAttachmentVersion(Attachment attachment,
                                          ContentEntityObject originalContent)
Delete the data corresponding to a single attachment version

Parameters:
attachment - The attachment whose data should be deleted
originalContent - The content entity associated with the attachment

getAttachmentData

public AttachmentDataStream getAttachmentData(Attachment attachment,
                                              AttachmentDataStreamType dataStreamType)
Fetches the data for a given attachment version and data stream type

Parameters:
attachment - The attachment version for which the data is to be fetched
dataStreamType - The type of the data stream to be fetched
Returns:
The AttachmentDataStream containing the result

moveAttachments

public 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.

Parameters:
contentEntity - The content entity whose attachment data is to be moved
oldSpace - The original space of the content entity
newSpace - The new space of the content entity


Copyright © 2003–2015 Atlassian. All rights reserved.