Package com.atlassian.bamboo.avatar
Class DiskAvatarRepository
java.lang.Object
com.atlassian.bamboo.avatar.DiskAvatarRepository
- All Implemented Interfaces:
AvatarRepository
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The format in which all avatars are stored (regardless of what type of image is uploaded).static final String
The path where avatars should be stored.static final String
The file extension applied to stored avatars.static final String
The filename used to store original avatars.static final int
Marker constant for retrieving the original avatar as it was provided, without any resizing applied. -
Constructor Summary
ConstructorDescriptionDiskAvatarRepository
(BambooHomeLocator bambooHomeLocator, com.opensymphony.xwork2.TextProvider textProvider) -
Method Summary
Modifier and TypeMethodDescriptionvoid
delete
(@NotNull AvatarType type, @NotNull String avatarId) Deletes any stored avatars for the specified object and type.int
delete
(@NotNull AvatarType type, @NotNull Set<String> idsToSkip, long lastModificationTimeStamp) Deletes any stored avatars for the specified type that IDs are not in the IDs to skip collection and that last modification occurred before the specified timestamp.long
Retrieves the configured file size limit for stored avatars.getVersionId
(@NotNull AvatarType type, @NotNull String id) Retrieves a version identifier for the avatar with the specified object and type.boolean
isStored
(@NotNull AvatarType type, @NotNull String avatarId) Retrieves a flag indicating whether an avatar has been stored for the specified object and type.@Nullable CacheableAvatarSupplier
load
(@NotNull AvatarType type, @NotNull String avatarId, int size) Retrieves the current avatar for the specified object and type, or a null if no avatar has been stored.@NotNull CacheableAvatarSupplier
loadDefault
(@NotNull AvatarType type, int size) Loads a default avatar for the specified type in an approximation of the requested size.void
move
(@NotNull AvatarType type, @NotNull String oldId, @NotNull String newId) Moves any stored avatars for the specified object and type from the old ID to the new ID.static int
normalizeSize
(int size) Normalises the specified size to a finite set of potential sizes, effectively constraining the number of resized avatars that will be created from a given original.void
store
(@NotNull AvatarType type, @NotNull String avatarId, @NotNull AvatarSupplier supplier) Stores the provided avatar for the specified object and type.
-
Field Details
-
AVATARS_PATH
The path where avatars should be stored.- See Also:
-
ORIGINAL_SIZE
public static final int ORIGINAL_SIZEMarker constant for retrieving the original avatar as it was provided, without any resizing applied.- See Also:
-
AVATAR_FORMAT
The format in which all avatars are stored (regardless of what type of image is uploaded).- See Also:
-
FILE_EXTENSION
The file extension applied to stored avatars.- See Also:
-
ORIGINAL_FILE
The filename used to store original avatars. This name is consistent to simplify retrieving the original avatar for any given type and ID for use in resizing.- See Also:
-
-
Constructor Details
-
DiskAvatarRepository
@Inject public DiskAvatarRepository(BambooHomeLocator bambooHomeLocator, com.opensymphony.xwork2.TextProvider textProvider)
-
-
Method Details
-
loadDefault
@NotNull public @NotNull CacheableAvatarSupplier loadDefault(@NotNull @NotNull AvatarType type, int size) Description copied from interface:AvatarRepository
Loads a default avatar for the specified type in an approximation of the requested size. Default avatars are only available in a fixed set of sizes, and dynamic sizes are not created, so the request size is normalized into that set.- Specified by:
loadDefault
in interfaceAvatarRepository
- Parameters:
type
- the type of object to retrieve a default avatar forsize
- the size to retrieve the avatar in- Returns:
- a supplier for accessing the requested default avatar
-
load
@Nullable public @Nullable CacheableAvatarSupplier load(@NotNull @NotNull AvatarType type, @NotNull @NotNull String avatarId, int size) Description copied from interface:AvatarRepository
Retrieves the current avatar for the specified object and type, or a null if no avatar has been stored.- Specified by:
load
in interfaceAvatarRepository
- Parameters:
type
- the type of object associated with the provided IDavatarId
- the object's IDsize
- the size to retrieve the avatar in- Returns:
- a supplier for accessing the requested avatar
-
store
public void store(@NotNull @NotNull AvatarType type, @NotNull @NotNull String avatarId, @NotNull @NotNull AvatarSupplier supplier) Description copied from interface:AvatarRepository
Stores the provided avatar for the specified object and type.The file size for the avatar image is not checked by the repository. That restriction is expected to be applied at the system's edges (REST, SpringMVC, etc.).
- Specified by:
store
in interfaceAvatarRepository
- Parameters:
type
- the type of object associated with the provided IDavatarId
- the object's IDsupplier
- a supplier providing access to the avatar data
-
isStored
Description copied from interface:AvatarRepository
Retrieves a flag indicating whether an avatar has been stored for the specified object and type.- Specified by:
isStored
in interfaceAvatarRepository
- Parameters:
type
- the type of object associated with the provided IDavatarId
- the object's ID- Returns:
true
if a local avatar exists for the specified object; otherwise,false
-
delete
Description copied from interface:AvatarRepository
Deletes any stored avatars for the specified object and type. This removes the original as well as any scaled copies that have been created based on requested sizes.- Specified by:
delete
in interfaceAvatarRepository
- Parameters:
type
- the type of object associated with the provided IDavatarId
- the object's ID
-
delete
public int delete(@NotNull @NotNull AvatarType type, @NotNull @NotNull Set<String> idsToSkip, long lastModificationTimeStamp) Description copied from interface:AvatarRepository
Deletes any stored avatars for the specified type that IDs are not in the IDs to skip collection and that last modification occurred before the specified timestamp. This removes the original as well as any scaled copies that have been created based on requested sizes.- Specified by:
delete
in interfaceAvatarRepository
- Parameters:
type
- the type of object associated with the provided IDidsToSkip
- the avatar ids for which the deletion will be skippedlastModificationTimeStamp
- edge for last modification comparison- Returns:
- number of removed avatar directories
-
move
public void move(@NotNull @NotNull AvatarType type, @NotNull @NotNull String oldId, @NotNull @NotNull String newId) Description copied from interface:AvatarRepository
Moves any stored avatars for the specified object and type from the old ID to the new ID.- Specified by:
move
in interfaceAvatarRepository
- Parameters:
type
- the type of object associated with the provided IDoldId
- the object's old IDnewId
- the object's new ID
-
getMaxSize
public long getMaxSize()Description copied from interface:AvatarRepository
Retrieves the configured file size limit for stored avatars. Avatars which are larger than this on disk cannot be stored, and callingAvatarRepository.store(com.atlassian.bamboo.avatar.AvatarType, java.lang.String, com.atlassian.bamboo.avatar.AvatarSupplier)
will result in anAvatarStoreException
.- Specified by:
getMaxSize
in interfaceAvatarRepository
- Returns:
- the configured file size limit for stored avatars
-
getVersionId
@NotNull public @NotNull Optional<Long> getVersionId(@NotNull @NotNull AvatarType type, @NotNull @NotNull String id) Description copied from interface:AvatarRepository
Retrieves a version identifier for the avatar with the specified object and type.- Specified by:
getVersionId
in interfaceAvatarRepository
- Parameters:
type
- the type of the object to retrieve a version forid
- the Object's ID- Returns:
- a version identifier for the avatar identified by the id and type, which will change only when the underlying avatar is modified
-
normalizeSize
public static int normalizeSize(int size) Normalises the specified size to a finite set of potential sizes, effectively constraining the number of resized avatars that will be created from a given original.Note: Any negative size results in
ORIGINAL_SIZE
, which is a marker value used to retrieve the original avatar as it was provided.- Parameters:
size
- the requested size- Returns:
- the normalised size
-