Interface AttachmentDao
-
- All Known Subinterfaces:
AttachmentDaoInternal
- All Known Implementing Classes:
AbstractDelegatingAttachmentDao
,AbstractHibernateAttachmentDao
,NonTransactionalHibernateAttachmentDao
,ReadThroughCachingAttachmentDao
,TransactionalHibernateAttachmentDao
public interface AttachmentDao
This interface defines the methods for classes acting as a DAO at the level of meta-data storage for Attachments.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
AttachmentDao.AttachmentCopier
static interface
AttachmentDao.AttachmentMigrator
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description void
afterMigrationFrom()
Perform any tasks necessary after Attachment data has been moved from this data store to another.int
countLatestVersionsOfAttachments(ContentEntityObject content)
int
countLatestVersionsOfAttachmentsOnPageSince(ContentEntityObject content, Date since)
int
countLatestVersionsOfAttachmentsWithAnyStatus(ContentEntityObject content)
List<Attachment>
findAll()
Retrieves the latest versions of all AttachmentsList<Attachment>
findAllVersions(Attachment attachment)
Iterator<Attachment>
findLatestVersionsIterator()
Retrieves the latest versions of all Attachments and returns an Iterator to the results.Attachment
getAttachment(ContentEntityObject content, String fileName, int version)
Return the attachment on the specified content with the given filename and version.InputStream
getAttachmentData(Attachment attachment)
Retrieves the InputStream representing the data for attachmentInputStream
getAttachmentData(Attachment attachment, Optional<RangeRequest> range)
Retrieves the InputStream representing the specified range of data for attachmentOptional<AttachmentStatisticsDTO>
getAttachmentStatistics()
Fetches statistics about attachmentsAttachmentDataStorageType
getBackingStorageType()
Returns the backing storage type.Attachment
getById(long id)
Returns the attachment with the given persistent ID.List<Attachment>
getByIds(List<Long> ids)
Returns a list of attachments matching the given list of IDs.AttachmentDao.AttachmentCopier
getCopier(AttachmentDao destinationDao)
Get a copier object to copy attachments between data storesAttachmentDataDao
getDataDao()
List<Attachment>
getLastAddedVersionsOf(Attachment attachment)
Retrieves all the last added versions for each user who has added a version of the attachment That is, if a user has added multiple versions, only the latest added version will be added to the list returned.Attachment
getLatestAttachment(ContentEntityObject content, String fileName)
Return the latest version of the attachment on the specified content with the given filename.List<Attachment>
getLatestVersionsOfAttachments(ContentEntityObject ceo)
Retrieves the latest versions of all attachments to ceoPageResponse<Attachment>
getLatestVersionsOfAttachments(ContentEntityObject ceo, LimitedRequest pageRequest, com.google.common.base.Predicate<? super Attachment> predicate)
Deprecated.since 7.0.1.List<Attachment>
getLatestVersionsOfAttachmentsForMultipleCeos(Iterable<? extends ContentEntityObject> contentEntityObjects)
Retrieves the latest versions of all attachments for all CEOs providedList<Attachment>
getLatestVersionsOfAttachmentsWithAnyStatus(ContentEntityObject ceo)
Retrieves the latest versions of all attachments to ceo (including trashed)AttachmentDao.AttachmentMigrator
getMigrator(AttachmentDao destinationDao)
Get a migrator object to migrate attachments between attachment datastores.Map<Long,Long>
getRemappedAttachmentIds()
Gets a list of remapped attachment IDs.boolean
isAttachmentPresent(Attachment attachment)
Check that an attachment existsvoid
moveAttachment(Attachment attachment, Attachment oldAttachment, ContentEntityObject newContent)
Moves an Attachment to a new file name or content objectvoid
prepareForMigrationTo()
Prepare the data store for a migration from another type of data store.void
removeAttachmentFromServer(Attachment attachment)
Removes attachment (and all of its versions)void
removeAttachmentVersionFromServer(Attachment attachment)
Removes an attachment versionvoid
replaceAttachmentData(Attachment attachment, InputStream attachmentData)
Sets the attachment data for attachmentvoid
saveNewAttachment(Attachment attachment, InputStream attachmentData)
Saves a new attachmentvoid
saveNewAttachmentVersion(Attachment attachment, Attachment previousVersion, InputStream attachmentData)
Saves a new version of attachmentvoid
updateAttachment(Attachment attachment)
Update an existing attachment without creating a new version
-
-
-
Method Detail
-
getLatestVersionsOfAttachments
List<Attachment> getLatestVersionsOfAttachments(ContentEntityObject ceo)
Retrieves the latest versions of all attachments to ceo- Parameters:
ceo
- the content to look up attachments- Returns:
- a List of Attachment objects
- See Also:
countLatestVersionsOfAttachments(com.atlassian.confluence.core.ContentEntityObject)
-
getLatestVersionsOfAttachmentsForMultipleCeos
List<Attachment> getLatestVersionsOfAttachmentsForMultipleCeos(Iterable<? extends ContentEntityObject> contentEntityObjects)
Retrieves the latest versions of all attachments for all CEOs provided- Parameters:
contentEntityObjects
- CEOs to retrieve attachements for- Returns:
- a List of Attachment objects
- Since:
- 5.9.2
-
getLatestVersionsOfAttachmentsWithAnyStatus
List<Attachment> getLatestVersionsOfAttachmentsWithAnyStatus(ContentEntityObject ceo)
Retrieves the latest versions of all attachments to ceo (including trashed)- Parameters:
ceo
- the content to look up attachments- Returns:
- a List of Attachment objects
- See Also:
countLatestVersionsOfAttachments(com.atlassian.confluence.core.ContentEntityObject)
-
getLatestVersionsOfAttachments
@Deprecated PageResponse<Attachment> getLatestVersionsOfAttachments(ContentEntityObject ceo, LimitedRequest pageRequest, com.google.common.base.Predicate<? super Attachment> predicate)
Deprecated.Retrieves a paginated list of the latest version of attachments to the ceo filtered by the predicate- Parameters:
ceo
- the content to find attachments onpageRequest
- the pagination requestpredicate
- a predicate to filter the results by- Returns:
- a paginated list of attachments
-
countLatestVersionsOfAttachments
int countLatestVersionsOfAttachments(ContentEntityObject content)
- Parameters:
content
- the content object- Returns:
- the number of current attachments on a content object
- See Also:
getLatestVersionsOfAttachments(com.atlassian.confluence.core.ContentEntityObject)
-
countLatestVersionsOfAttachmentsWithAnyStatus
int countLatestVersionsOfAttachmentsWithAnyStatus(ContentEntityObject content)
- Parameters:
content
- the content object- Returns:
- the number of current attachments on a content object (including trashed)
-
countLatestVersionsOfAttachmentsOnPageSince
int countLatestVersionsOfAttachmentsOnPageSince(ContentEntityObject content, Date since)
- Parameters:
content
- the content objectsince
- the date of earliest change- Returns:
- the number of attachments on a content object (including trashed) changed since
- Since:
- 7.3.0
- See Also:
getLatestVersionsOfAttachmentsForMultipleCeos(Iterable)
-
getAttachmentStatistics
Optional<AttachmentStatisticsDTO> getAttachmentStatistics()
Fetches statistics about attachments- Returns:
- an AttachmentStatisticsDTO with statistics about attachments such as total and current count
- Since:
- 6.11.0
-
findAll
List<Attachment> findAll()
Retrieves the latest versions of all AttachmentsUse of this method is discouraged when there are a large amount of Attachments.
- Returns:
- A List of Attachment objects
- See Also:
findLatestVersionsIterator()
-
findLatestVersionsIterator
Iterator<Attachment> findLatestVersionsIterator()
Retrieves the latest versions of all Attachments and returns an Iterator to the results.- Returns:
- Iterator to the results
-
getAttachmentData
InputStream getAttachmentData(Attachment attachment) throws AttachmentDataNotFoundException
Retrieves the InputStream representing the data for attachment- Parameters:
attachment
- the attachment whose data will be returned- Returns:
- InputStream of the data
- Throws:
AttachmentDataNotFoundException
- if the data could not be found
-
getAttachmentData
InputStream getAttachmentData(Attachment attachment, Optional<RangeRequest> range) throws AttachmentDataNotFoundException
Retrieves the InputStream representing the specified range of data for attachment- Parameters:
attachment
- the attachment whose data will be returnedrange
- the range of data to retrieve. Seecom.atlassian.filestore.client.api.entity.ByteRanges
- Returns:
- InputStream of the data
- Throws:
AttachmentDataNotFoundException
- if the data could not be found
-
saveNewAttachment
void saveNewAttachment(Attachment attachment, InputStream attachmentData)
Saves a new attachment- Parameters:
attachment
- the Attachment to be savedattachmentData
- the attachment data to be saved
-
saveNewAttachmentVersion
void saveNewAttachmentVersion(Attachment attachment, Attachment previousVersion, InputStream attachmentData)
Saves a new version of attachment- Parameters:
attachment
- the Attachment to be savedpreviousVersion
- the previous version of the AttachmentattachmentData
- the attachment data to be saved
-
isAttachmentPresent
boolean isAttachmentPresent(Attachment attachment)
Check that an attachment exists- Parameters:
attachment
- the Attachment to be checked
-
moveAttachment
void moveAttachment(Attachment attachment, Attachment oldAttachment, ContentEntityObject newContent)
Moves an Attachment to a new file name or content objectThis method assumes that the filename and/or content of the attachment (and its previous versions) have already been updated.
- Parameters:
attachment
- the Attachment to be movedoldAttachment
- the Attachment before it has been updatednewContent
- the new content attachment belongs to- Throws:
IllegalArgumentException
- if attachment is not the latest version
-
removeAttachmentFromServer
void removeAttachmentFromServer(Attachment attachment)
Removes attachment (and all of its versions)- Parameters:
attachment
- the Attachment to be removed
-
removeAttachmentVersionFromServer
void removeAttachmentVersionFromServer(Attachment attachment)
Removes an attachment version- Parameters:
attachment
- the Attachment version to be removed- Since:
- 4.2
-
replaceAttachmentData
void replaceAttachmentData(Attachment attachment, InputStream attachmentData)
Sets the attachment data for attachmentThis method will overwrite any existing data for the attachment version.
- Parameters:
attachment
- Attachment the data belongs toattachmentData
- the data to save
-
getMigrator
AttachmentDao.AttachmentMigrator getMigrator(AttachmentDao destinationDao)
Get a migrator object to migrate attachments between attachment datastores.To be used when switching datastore implementations
- Parameters:
destinationDao
- dao to move attachments to- Returns:
- A migrator
-
getCopier
AttachmentDao.AttachmentCopier getCopier(AttachmentDao destinationDao)
Get a copier object to copy attachments between data storesThe source data store will remain untouched
- Parameters:
destinationDao
- dao to copy attachments to- Returns:
- A copier
-
prepareForMigrationTo
void prepareForMigrationTo()
Prepare the data store for a migration from another type of data store.Classes implementing this method will perform any tasks necessary to allow the data store to be used. These tasks may assume that users are locked out of the system.
- Throws:
RuntimeException
- if there was a problem
-
afterMigrationFrom
void afterMigrationFrom()
Perform any tasks necessary after Attachment data has been moved from this data store to another. These tasks may assume that users are locked out of the system.- Throws:
RuntimeException
- if there was a problem
-
findAllVersions
List<Attachment> findAllVersions(Attachment attachment)
-
getById
Attachment getById(long id)
Returns the attachment with the given persistent ID. Returns null if no such attachment exists.- Parameters:
id
- the persistent ID of the attachment to retrieve- Returns:
- the attachment with the given ID, or null if no attachment exists with the provided ID.
- Since:
- 3.0
-
getByIds
List<Attachment> getByIds(List<Long> ids)
Returns a list of attachments matching the given list of IDs. Returns an empty list if no such attachments exist. In the case where some IDs exist and some don't, only the existing Attachments will be returned.- Parameters:
ids
- list of IDs to retrieve- Returns:
- the attachments with the given IDs, or an empty list if no attachments exist with the provided IDs.
- Since:
- 5.7
-
getAttachment
Attachment getAttachment(ContentEntityObject content, String fileName, int version) throws IllegalArgumentException
Return the attachment on the specified content with the given filename and version. Returns null if no such attachment exists.Note: unlike
AttachmentManager.getAttachment(ContentEntityObject, String, int)
, this method does not accept zero as a special flag to indicate the latest version of an attachment. To retrieve the latest version of an attachment, usegetLatestAttachment(ContentEntityObject, String)
.- Parameters:
content
- the content to find the attachment onfileName
- the file name of the attachment, treated case-insensitivelyversion
- the version of the attachment- Returns:
- the attachment with the given name and version attached to that content, or null if the attachment does not exist.
- Throws:
IllegalArgumentException
- if the content or fileName is null- Since:
- 3.0
-
getLatestAttachment
Attachment getLatestAttachment(ContentEntityObject content, String fileName) throws IllegalArgumentException
Return the latest version of the attachment on the specified content with the given filename. Returns null if no attachment with that name on the content exists.- Parameters:
content
- the content to find the attachment onfileName
- the file name of the attachment- Returns:
- the latest version of attachment with the given name attached to that content, or null if the attachment does not exist.
- Throws:
IllegalArgumentException
- if the content or fileName is null- Since:
- 3.0
-
getLastAddedVersionsOf
List<Attachment> getLastAddedVersionsOf(Attachment attachment)
Retrieves all the last added versions for each user who has added a version of the attachment That is, if a user has added multiple versions, only the latest added version will be added to the list returned. Result will be sorted with the earliest version coming first.- Parameters:
attachment
- attachment (must be the latest version)- Returns:
- the last added versions for each user who has added a version of the attachment
- Throws:
IllegalArgumentException
- if the attachment is not the latest version or null
-
getBackingStorageType
AttachmentDataStorageType getBackingStorageType()
Returns the backing storage type.- Returns:
- the backing storage type
- Since:
- 4.3
- See Also:
AttachmentDataDao.getStorageType()
-
updateAttachment
void updateAttachment(Attachment attachment)
Update an existing attachment without creating a new version- Parameters:
attachment
-- Since:
- 5.7
-
getRemappedAttachmentIds
Map<Long,Long> getRemappedAttachmentIds()
Gets a list of remapped attachment IDs. The key is the old ID and the value is the new ID.- Returns:
- A map where the key is the original ID and the value is the new ID.
- Since:
- 5.7.1
-
getDataDao
AttachmentDataDao getDataDao()
-
-