Package com.atlassian.bamboo.avatar
Class DiskAvatarRepository
- java.lang.Object
-
- com.atlassian.bamboo.avatar.DiskAvatarRepository
-
- All Implemented Interfaces:
AvatarRepository
public class DiskAvatarRepository extends Object implements AvatarRepository
-
-
Field Summary
Fields Modifier and Type Field Description static String
AVATAR_FORMAT
The format in which all avatars are stored (regardless of what type of image is uploaded).static String
AVATARS_PATH
The path where avatars should be stored.static String
FILE_EXTENSION
The file extension applied to stored avatars.static String
ORIGINAL_FILE
The filename used to store original avatars.static int
ORIGINAL_SIZE
Marker constant for retrieving the original avatar as it was provided, without any resizing applied.
-
Constructor Summary
Constructors Constructor Description DiskAvatarRepository(BambooHomeLocator bambooHomeLocator, com.opensymphony.xwork2.TextProvider textProvider)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
delete(@NotNull AvatarType type, @NotNull String avatarId)
Deletes any stored avatars for the specified object and type.long
getMaxSize()
Retrieves the configured file size limit for stored avatars.@NotNull Optional<Long>
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 Detail
-
AVATARS_PATH
public static final String AVATARS_PATH
The path where avatars should be stored.- See Also:
- Constant Field Values
-
ORIGINAL_SIZE
public static final int ORIGINAL_SIZE
Marker constant for retrieving the original avatar as it was provided, without any resizing applied.- See Also:
- Constant Field Values
-
AVATAR_FORMAT
public static final String AVATAR_FORMAT
The format in which all avatars are stored (regardless of what type of image is uploaded).- See Also:
- Constant Field Values
-
FILE_EXTENSION
public static final String FILE_EXTENSION
The file extension applied to stored avatars.- See Also:
- Constant Field Values
-
ORIGINAL_FILE
public static final String 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:
- Constant Field Values
-
-
Constructor Detail
-
DiskAvatarRepository
@Inject public DiskAvatarRepository(BambooHomeLocator bambooHomeLocator, com.opensymphony.xwork2.TextProvider textProvider)
-
-
Method Detail
-
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
public boolean isStored(@NotNull @NotNull AvatarType type, @NotNull @NotNull String avatarId)
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
public void delete(@NotNull @NotNull AvatarType type, @NotNull @NotNull String avatarId)
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
-
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
-
-