Interface AttachmentManager
-
- All Known Subinterfaces:
AttachmentManagerInternal
- All Known Implementing Classes:
DefaultAttachmentManager
,DelegatorAttachmentManager
,ReadThroughCachingAttachmentManager
@Transactional public interface AttachmentManager
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description void
copyAttachment(Attachment attachment, ContentEntityObject destinationContent)
Copy specified attachment to specified destination content.void
copyAttachments(ContentEntityObject sourceContent, ContentEntityObject destinationContent)
Copy the latest version of all the attachments on the sourceContent to the destinationContent.void
copyAttachments(ContentEntityObject sourceContent, ContentEntityObject destinationContent, SaveContext saveContext)
Copy the latest version of all the attachments on the sourceContent to the destinationContent.int
countLatestVersionsOfAttachments(ContentEntityObject content)
Returns a count of the number of latest versions of attachmentsint
countLatestVersionsOfAttachmentsOnPageSince(ContentEntityObject content, Date since)
Fetches number of attachments changed on a page since a specific timestampint
countLatestVersionsOfAttachmentsWithAnyStatus(ContentEntityObject content)
Returns a count of the number of latest versions of attachments (including trashed)void
deepAttachmentDelete(AttachmentDeleteOptions attachmentDeleteOptions)
Support delete multiple attachments in batchdefault Optional<Attachment>
findAttachmentForDownloadPath(String downloadPath)
Find anAttachment
for the givendownloadPath
.List<Attachment>
getAllVersions(Attachment attachment)
Get all versions of an attachment, starting with the current versionList<Attachment>
getAllVersionsOfAttachments(ContentEntityObject content)
Returns a list of all attachments, old and new.Attachment
getAttachment(long id)
Deprecated.since 7.5.0, useAttachmentService
instead in plugins, or useAttachmentManagerInternal
in core where applicableAttachment
getAttachment(ContentEntityObject content, String attachmentFileName)
Deprecated.since 7.5.0, useAttachmentService
instead in plugins, or useAttachmentManagerInternal
in core where applicableAttachment
getAttachment(ContentEntityObject content, String attachmentFileName, int version)
Deprecated.since 7.5.0, useAttachmentService
instead in plugins, or useAttachmentManagerInternal
in core where applicableAttachmentDao
getAttachmentDao()
Deprecated.since 7.5.0, no replacement, use dependency injection where possibleInputStream
getAttachmentData(Attachment attachment)
Retrieve the data for attachmentInputStream
getAttachmentData(Attachment attachment, Optional<RangeRequest> range)
Retrieve the specified range of data for attachmentString
getAttachmentDownloadPath(ContentEntityObject content, String attachmentFileName)
Get the download path for the most recent version of an attachment with the given name for some contentcom.atlassian.fugue.Maybe<Attachment>
getAttachmentForDownloadPath(String downloadPath)
Deprecated.since 7.0.1.List<Attachment>
getAttachments(List<Long> ids)
Deprecated.since 7.5.0, useAttachmentService
instead in plugins, or useAttachmentManagerInternal
in core where applicableOptional<AttachmentStatisticsDTO>
getAttachmentStatistics()
Fetches statistics about attachmentsAttachmentDataStorageType
getBackingStorageType()
Returns the currently active storage type.AttachmentDao.AttachmentCopier
getCopier(AttachmentManager destination)
Retrieves a AttachmentDao.AttachmentCopier that will allow the attachments from one data store to be copied across to another.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.List<Attachment>
getLatestVersionsOfAttachments(ContentEntityObject content)
Returns a list of only latest versions of attachments.List<Attachment>
getLatestVersionsOfAttachmentsForMultipleCeos(Iterable<? extends ContentEntityObject> contentEntityObjects)
Returns a list of all the latest versions of attachments for all the CEOs providedList<Attachment>
getLatestVersionsOfAttachmentsWithAnyStatus(ContentEntityObject content)
Returns a list of only latest versions of attachments (including trashed).AttachmentDao.AttachmentMigrator
getMigrator(AttachmentManager destination)
Retrieves a AttachmentDao.AttachmentMigrator that will allow the attachments from one data store to be moved across to another.List<Attachment>
getPreviousVersions(Attachment attachment)
Get all non-current versions of an attachment, not including the current version.Map<Long,Long>
getRemappedAttachmentIds()
Gets a list of remapped attachment IDs.void
moveAttachment(Attachment latestVersion, String fileName, ContentEntityObject newContent)
void
removeAttachmentFromServer(Attachment attachment)
Removes an Attachment and its data from the server and data store.void
removeAttachments(List<? extends Attachment> attachments)
Removes the contents of attachments from the servervoid
removeAttachmentVersionFromServer(Attachment attachment)
Removes the given version of the Attachment and its data from the server and data store.void
removeAttachmentVersionFromServerWithoutNotifications(Attachment attachment)
Removes the given version of the Attachment and its data from the server and data store while suppressing notifications.void
removeAttachmentWithoutNotifications(Attachment attachment)
Removes an Attachment and its data from the server while suppressing notifications.void
restore(Attachment attachment)
Restores an attachment from trash.void
saveAttachment(Attachment attachment, @Nullable Attachment previousVersion, InputStream attachmentData)
Saves an Attachment and its datavoid
saveAttachment(Attachment attachment, @Nullable Attachment previousVersion, InputStream attachmentData, SaveContext saveContext)
Saves an Attachment and its data, taking aSaveContext
to allow more useful event handling.void
saveAttachments(List<SavableAttachment> savableAttachments)
Saves multiple attachment and their datavoid
saveAttachments(List<SavableAttachment> savableAttachments, SaveContext saveContext)
Saves multiple attachment and their datavoid
setAttachmentData(Attachment attachment, InputStream attachmentData)
Set the data belonging to attachmentvoid
trash(Attachment attachment)
Moves an attachment to the trash.
-
-
-
Method Detail
-
deepAttachmentDelete
void deepAttachmentDelete(AttachmentDeleteOptions attachmentDeleteOptions)
Support delete multiple attachments in batch- Parameters:
attachmentDeleteOptions
-- Since:
- 7.17.0
-
getAttachment
@Deprecated @Transactional(readOnly=true) Attachment getAttachment(long id)
Deprecated.since 7.5.0, useAttachmentService
instead in plugins, or useAttachmentManagerInternal
in core where applicable- Parameters:
id
-- Returns:
- attachment with id
-
getAttachments
@Deprecated @Transactional(readOnly=true) List<Attachment> getAttachments(List<Long> ids)
Deprecated.since 7.5.0, useAttachmentService
instead in plugins, or useAttachmentManagerInternal
in core where applicableReturns 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:
- attachments matching ids in the list
-
getAllVersionsOfAttachments
@Transactional(readOnly=true) List<Attachment> getAllVersionsOfAttachments(ContentEntityObject content)
Returns a list of all attachments, old and new.
-
getLatestVersionsOfAttachments
@Transactional(readOnly=true) List<Attachment> getLatestVersionsOfAttachments(ContentEntityObject content)
Returns a list of only latest versions of attachments.
-
getLatestVersionsOfAttachmentsForMultipleCeos
@Transactional(readOnly=true) List<Attachment> getLatestVersionsOfAttachmentsForMultipleCeos(Iterable<? extends ContentEntityObject> contentEntityObjects)
Returns a list of all the latest versions of attachments for all the CEOs provided- Parameters:
contentEntityObjects
-- Since:
- 5.9.2
-
getLatestVersionsOfAttachmentsWithAnyStatus
@Transactional(readOnly=true) List<Attachment> getLatestVersionsOfAttachmentsWithAnyStatus(ContentEntityObject content)
Returns a list of only latest versions of attachments (including trashed).
-
countLatestVersionsOfAttachments
int countLatestVersionsOfAttachments(ContentEntityObject content)
Returns a count of the number of latest versions of attachments
-
countLatestVersionsOfAttachmentsWithAnyStatus
int countLatestVersionsOfAttachmentsWithAnyStatus(ContentEntityObject content)
Returns a count of the number of latest versions of attachments (including trashed)
-
countLatestVersionsOfAttachmentsOnPageSince
int countLatestVersionsOfAttachmentsOnPageSince(ContentEntityObject content, Date since)
Fetches number of attachments changed on a page since a specific timestamp- 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
-
getAttachmentStatistics
@Transactional(readOnly=true) Optional<AttachmentStatisticsDTO> getAttachmentStatistics()
Fetches statistics about attachments- Returns:
- an AttachmentStatisticsDTO object with statistics about attachments such as total and current count
- Since:
- 6.11.0
-
getAttachmentData
@Transactional(readOnly=true, noRollbackFor=java.lang.IllegalArgumentException.class) InputStream getAttachmentData(Attachment attachment)
Retrieve the data for attachment- Parameters:
attachment
- the Attachment the data belongs to- Returns:
- InputStream representing the data
- Throws:
RuntimeException
- if the data could not be found
-
getAttachmentData
@Transactional(readOnly=true, noRollbackFor=java.lang.IllegalArgumentException.class) InputStream getAttachmentData(Attachment attachment, Optional<RangeRequest> range)
Retrieve the specified range of data for attachment- Parameters:
attachment
- the Attachment the data belongs torange
- the range of data to retrieve. Seecom.atlassian.filestore.client.api.entity.ByteRanges
- Returns:
- InputStream representing the data
- Throws:
RuntimeException
- if the data could not be found- Since:
- 5.10
-
removeAttachmentFromServer
void removeAttachmentFromServer(Attachment attachment)
Removes an Attachment and its data from the server and data store.- Parameters:
attachment
- the Attachment to remove
-
removeAttachmentWithoutNotifications
void removeAttachmentWithoutNotifications(Attachment attachment)
Removes an Attachment and its data from the server while suppressing notifications. This is useful when you don't want to send notifications when removing the file.- Since:
- 5.8
-
removeAttachmentVersionFromServer
void removeAttachmentVersionFromServer(Attachment attachment)
Removes the given version of the Attachment and its data from the server and data store.In case of the given attachment being the latest version, the previous version (if any) gets removed and the given object impersonates the previous version as the latest version.
- Parameters:
attachment
- the Attachment to remove- Since:
- 4.3
-
removeAttachmentVersionFromServerWithoutNotifications
void removeAttachmentVersionFromServerWithoutNotifications(Attachment attachment)
Removes the given version of the Attachment and its data from the server and data store while suppressing notifications. This is useful when you don't want to send notifications when removing the file.In case of the given attachment being the latest version, the previous version (if any) gets removed and the given object impersonates the previous version as the latest version.
- Parameters:
attachment
- the Attachment to remove
-
removeAttachments
void removeAttachments(List<? extends Attachment> attachments)
Removes the contents of attachments from the server- Parameters:
attachments
- a List of Attachments- See Also:
removeAttachmentFromServer(Attachment)
-
moveAttachment
void moveAttachment(Attachment latestVersion, String fileName, ContentEntityObject newContent)
- Parameters:
latestVersion
- The attachment to be movedfileName
- New name of the filenewContent
- The new contentEntiityObject which will be parent to the attachment
-
copyAttachments
void copyAttachments(ContentEntityObject sourceContent, ContentEntityObject destinationContent, SaveContext saveContext) throws IOException
Copy the latest version of all the attachments on the sourceContent to the destinationContent.- Parameters:
sourceContent
- the content with attachments to be copied.destinationContent
- the content to copy the attachments to.saveContext
- details the circumstances under which the attachments are being copied.- Throws:
IOException
- if there are problems reading or writing attachment data during the copy.- Since:
- 5.10
-
copyAttachments
void copyAttachments(ContentEntityObject sourceContent, ContentEntityObject destinationContent) throws IOException
Copy the latest version of all the attachments on the sourceContent to the destinationContent.- Parameters:
sourceContent
- the content with attachments to be copied.destinationContent
- the content to copy the attachments to.- Throws:
IOException
- if there are problems reading or writing attachment data during the copy.
-
copyAttachment
void copyAttachment(Attachment attachment, ContentEntityObject destinationContent) throws IOException
Copy specified attachment to specified destination content.- Parameters:
attachment
- the attachmentdestinationContent
- the destination- Throws:
IOException
-
getAttachment
@Deprecated @Transactional(readOnly=true) Attachment getAttachment(ContentEntityObject content, String attachmentFileName, int version)
Deprecated.since 7.5.0, useAttachmentService
instead in plugins, or useAttachmentManagerInternal
in core where applicableRetrieve a named attachment from a page- Parameters:
content
- the page the attachment is attached toattachmentFileName
- the filename of the attachment to retrieveversion
- the version of the attachment to retrieve. If you provide a version of 0 or less, you'll get the most recent version, but you should probably use #getAttachment(AbstractPage, String) instead for that purpose instead- Returns:
- the requested attachment, or null if the requested attachment does not exist.
-
getAttachment
@Deprecated @Transactional(readOnly=true) Attachment getAttachment(ContentEntityObject content, String attachmentFileName)
Deprecated.since 7.5.0, useAttachmentService
instead in plugins, or useAttachmentManagerInternal
in core where applicableGet the most recent version of an attachment with a given name for a particular page- Parameters:
content
- the page the attachment is attached toattachmentFileName
- the filename of the attachment to be retrieved- Returns:
- the appropriate attachment, or null if no such attachment exists
-
getAttachmentDownloadPath
@Transactional(readOnly=true) String getAttachmentDownloadPath(ContentEntityObject content, String attachmentFileName)
Get the download path for the most recent version of an attachment with the given name for some content- Parameters:
content
- the content the attachment is attached toattachmentFileName
- the filename of the attachment to be retrieved- Returns:
- the appropriate attachment download path, or null if no such attachment exists
- Since:
- 4.3
-
saveAttachment
void saveAttachment(Attachment attachment, @Nullable Attachment previousVersion, InputStream attachmentData, SaveContext saveContext) throws IOException
Saves an Attachment and its data, taking aSaveContext
to allow more useful event handling.- Parameters:
attachment
- the modified version of the AttachmentpreviousVersion
- the original version of the Attachment (null if new)attachmentData
- an InputStream representing the data of the AttachmentsaveContext
- provides more information about the circumstances of the save- Throws:
IOException
IllegalArgumentException
- if attachment's content is not set
-
saveAttachment
void saveAttachment(Attachment attachment, @Nullable Attachment previousVersion, InputStream attachmentData) throws IOException
Saves an Attachment and its data- Parameters:
attachment
- the modified version of the AttachmentpreviousVersion
- the original version of the Attachment (null if new)attachmentData
- an InputStream representing the data of the Attachment- Throws:
IOException
IllegalArgumentException
- if attachment's content is not set
-
saveAttachments
void saveAttachments(List<SavableAttachment> savableAttachments, SaveContext saveContext) throws IOException
Saves multiple attachment and their data- Parameters:
savableAttachments
- the modified version of the AttachmentsaveContext
- provides more details about saving. If in doubt passDefaultSaveContext.DEFAULT
.- Throws:
IOException
IllegalArgumentException
- if attachment's content is not set
-
saveAttachments
void saveAttachments(List<SavableAttachment> savableAttachments) throws IOException
Saves multiple attachment and their data- Parameters:
savableAttachments
- the modified version of the Attachment- Throws:
IOException
IllegalArgumentException
- if attachment's content is not set
-
setAttachmentData
void setAttachmentData(Attachment attachment, InputStream attachmentData) throws AttachmentDataExistsException
Set the data belonging to attachmentThis method can be used when there is missing data for an Attachment (e.g. during imports) and the data needs to be set manually.
- Parameters:
attachment
- Attachment the data belongs toattachmentData
- the data to be saved- Throws:
AttachmentDataExistsException
- if data for attachment already exists
-
getMigrator
@Transactional(readOnly=true) AttachmentDao.AttachmentMigrator getMigrator(AttachmentManager destination)
Retrieves a AttachmentDao.AttachmentMigrator that will allow the attachments from one data store to be moved across to another.- Parameters:
destination
- the AttachmentManager the data is being moved to- Returns:
- an AttachmentMigrator object
-
getCopier
@Transactional(readOnly=true) AttachmentDao.AttachmentCopier getCopier(AttachmentManager destination)
Retrieves a AttachmentDao.AttachmentCopier that will allow the attachments from one data store to be copied across to another.- Parameters:
destination
- the AttachmentManager the data is being copied to- Returns:
- an AttachmentCopier object
-
getAttachmentDao
@Deprecated @Transactional(readOnly=true) AttachmentDao getAttachmentDao()
Deprecated.since 7.5.0, no replacement, use dependency injection where possibleRetrieves the AttachmentDao for the AttachmentManager- Returns:
- An AttachmentDao instance
-
getAllVersions
@Transactional(readOnly=true) List<Attachment> getAllVersions(Attachment attachment)
Get all versions of an attachment, starting with the current version
-
getPreviousVersions
@Transactional(readOnly=true) List<Attachment> getPreviousVersions(Attachment attachment)
Get all non-current versions of an attachment, not including the current version. (ordered from most recent)- Parameters:
attachment
- the attachment to get all non-current versions for.
-
getLastAddedVersionsOf
@Transactional(readOnly=true) 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
@Transactional(readOnly=true) AttachmentDataStorageType getBackingStorageType()
Returns the currently active storage type.- Since:
- 4.3
- See Also:
AttachmentDao.getBackingStorageType()
-
getAttachmentForDownloadPath
@Deprecated @Transactional(readOnly=true) com.atlassian.fugue.Maybe<Attachment> getAttachmentForDownloadPath(String downloadPath)
Deprecated.since 7.0.1. UsefindAttachmentForDownloadPath(String)
Find anAttachment
for the givendownloadPath
.The path must at least contain the segment produced by
Attachment.getDownloadPath()
, that is /download/attachments/<contentId>/<fileName> where <contentId> identifies a validContentEntityObject
and <fileName> identifies a validAttachment
attached to thatContentEntityObject
.- Parameters:
downloadPath
- the download path identifying anAttachment
.This value is expected to be url encoded, with spaces converted to %20 instead of a '+'- Returns:
- maybe the attachment if the given download path matches the criteria as described above and the referenced objects are known to the system
- Since:
- 5.2
- See Also:
Attachment.getDownloadPath()
-
findAttachmentForDownloadPath
default Optional<Attachment> findAttachmentForDownloadPath(String downloadPath)
Find anAttachment
for the givendownloadPath
.The path must at least contain the segment produced by
Attachment.getDownloadPath()
, that is /download/attachments/<contentId>/<fileName> where <contentId> identifies a validContentEntityObject
and <fileName> identifies a validAttachment
attached to thatContentEntityObject
.- Parameters:
downloadPath
- the download path identifying anAttachment
.This value is expected to be url encoded, with spaces converted to %20 instead of a '+'- Returns:
- maybe the attachment if the given download path matches the criteria as described above and the referenced objects are known to the system
- Since:
- 7.0.1
- See Also:
Attachment.getDownloadPath()
-
getRemappedAttachmentIds
@Transactional(readOnly=true) 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
-
trash
void trash(Attachment attachment)
Moves an attachment to the trash.- Parameters:
attachment
- the attachment to be trashed- Since:
- 5.8
-
restore
void restore(Attachment attachment)
Restores an attachment from trash.- Parameters:
attachment
- the attachment to restore- Since:
- 5.8
-
-