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

    Constructors
    Constructor
    Description
    DiskAvatarRepository(BambooHomeLocator bambooHomeLocator, com.opensymphony.xwork2.TextProvider textProvider)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    delete(@NotNull AvatarType type, @NotNull String avatarId)
    Deletes any stored avatars for the specified object and type.
    long
    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.
    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.
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • AVATARS_PATH

      public static final String AVATARS_PATH
      The path where avatars should be stored.
      See Also:
    • 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:
    • 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:
    • FILE_EXTENSION

      public static final String FILE_EXTENSION
      The file extension applied to stored avatars.
      See Also:
    • 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:
  • 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 interface AvatarRepository
      Parameters:
      type - the type of object to retrieve a default avatar for
      size - 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 interface AvatarRepository
      Parameters:
      type - the type of object associated with the provided ID
      avatarId - the object's ID
      size - 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 interface AvatarRepository
      Parameters:
      type - the type of object associated with the provided ID
      avatarId - the object's ID
      supplier - 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 interface AvatarRepository
      Parameters:
      type - the type of object associated with the provided ID
      avatarId - 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 interface AvatarRepository
      Parameters:
      type - the type of object associated with the provided ID
      avatarId - 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 interface AvatarRepository
      Parameters:
      type - the type of object associated with the provided ID
      oldId - the object's old ID
      newId - 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 calling AvatarRepository.store(com.atlassian.bamboo.avatar.AvatarType, java.lang.String, com.atlassian.bamboo.avatar.AvatarSupplier) will result in an AvatarStoreException.
      Specified by:
      getMaxSize in interface AvatarRepository
      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 interface AvatarRepository
      Parameters:
      type - the type of the object to retrieve a version for
      id - 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