Class DiskAvatarRepository

    • Field Detail

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