public class AvatarManagerImpl extends Object implements AvatarManager
AvatarManager.ImageSize
AVATAR_IMAGE_FORMAT, AVATAR_IMAGE_FORMAT_FULL, AVATAR_IMAGE_FORMAT_SVG, PNG_CONTENT_TYPE, SVG_CONTENT_TYPE, USER_AVATAR_ID_KEY
Constructor and Description |
---|
AvatarManagerImpl(AvatarStore store,
ApplicationProperties applicationProperties,
GlobalPermissionManager globalPermissionManager,
AvatarTagger avatarTagger,
AvatarImageDataStorage avatarImageDataStorage,
PermissionManager permissionManager,
com.atlassian.event.api.EventPublisher eventPublisher,
IconTypeDefinitionFactory iconTypeFactory,
RequestCacheFactory requestCacheFactory,
AvatarTranscoder avatarTranscoder) |
Modifier and Type | Method and Description |
---|---|
Avatar |
create(Avatar.Type avatarType,
String owningObjectId,
AvatarImageDataProvider imageDataProvider)
Creates a database record for the given avatar and uses the content of the InputStream as the image.
|
Avatar |
create(Avatar avatar)
Creates a database record for the given avatar.
|
Avatar |
create(Avatar avatar,
InputStream imageData,
Selection croppingSelection)
Creates a database record for the given avatar and uses the content of the InputStream as the image.
|
Avatar |
create(IconType iconType,
IconOwningObjectId owningObjectId,
AvatarImageDataProvider imageDataProvider)
Creates a database record for the given avatar and uses the content of the InputStream as the image.
|
Avatar |
create(String fileName,
String contentType,
ApplicationUser owner,
InputStream imageData,
Selection croppingSelection)
Creates a database record for the given avatar and uses the content of the InputStream as the image.
|
Avatar |
create(String fileName,
String contentType,
IconType iconType,
IconOwningObjectId owner,
InputStream imageData,
Selection croppingSelection)
Creates a database record for the given avatar and uses the content of the InputStream as the image.
|
Avatar |
create(String fileName,
String contentType,
Project project,
InputStream imageData,
Selection croppingSelection)
Creates a database record for the given avatar and uses the content of the InputStream as the image.
|
boolean |
delete(Long avatarId)
Delete the avatar with the given id and the file on disk.
|
boolean |
delete(Long avatarId,
boolean alsoDeleteAvatarFile)
Delete the avatar with the given id.
|
List<Avatar> |
getAllSystemAvatars(Avatar.Type type)
Provides a list of all system avatars.
|
List<Avatar> |
getAllSystemAvatars(IconType iconType)
Provides a list of all system avatars.
|
Long |
getAnonymousAvatarId()
Gets the avatar id to use to represent an unknown or anonymous user
|
File |
getAvatarBaseDirectory()
Returns the directory for storing avatars.
|
Avatar |
getById(Long avatarId)
Retrieve the avatar with the given id.
|
Avatar |
getByIdTagged(Long avatarId)
Retrieve the avatar with the given id,
ensuring the avatar file is tagged with metadata identifying the image came from JIRA.
|
List<Avatar> |
getCustomAvatarsForOwner(Avatar.Type type,
String ownerId)
Provides a list of all avatars that are of the given type which have the given owner.
|
List<Avatar> |
getCustomAvatarsForOwner(IconType iconType,
String ownerId)
Provides a list of all avatars that are of the given type which have the given owner.
|
Avatar |
getDefaultAvatar(IconType iconType)
Gets the default avatar for the given type.
|
Long |
getDefaultAvatarId(Avatar.Type ofType)
Gets the default avatar ID for the given type.
|
Long |
getDefaultAvatarId(IconType iconType)
Gets the default avatar ID for the given type.
|
boolean |
hasImage(Avatar avatar,
Avatar.Size size)
Checks if valid image exists for avatar and image can be consumed by
AvatarManager.readAvatarData(Avatar, Avatar.Size, AvatarFormatPolicy, MediaConsumer) . |
boolean |
hasPermissionToEdit(ApplicationUser remoteUser,
ApplicationUser owner)
Determines if the remoteUser provided has permission to edit avatars of a certain type for the owner provided.
|
boolean |
hasPermissionToEdit(ApplicationUser remoteUser,
Avatar.Type type,
String ownerId)
Determines if the remoteUser provided has permission to edit avatars of a certain type for the owner provided.
|
boolean |
hasPermissionToEdit(ApplicationUser remoteUser,
Project owner)
Determines if the remoteUser provided has permission to edit avatars of a certain type for the owner provided.
|
boolean |
hasPermissionToView(ApplicationUser remoteUser,
ApplicationUser owner)
Determines if the remoteUser provided has permission to view avatars of a certain type for the owner provided.
|
boolean |
hasPermissionToView(ApplicationUser remoteUser,
Avatar.Type type,
String ownerId)
Determines if the remoteUser provided has permission to view avatars of a certain type for the owner provided.
|
boolean |
hasPermissionToView(ApplicationUser remoteUser,
Project project)
Determines if the remoteUser provided has permission to view avatars of a certain type for the owner provided.
|
boolean |
isAvatarOwner(Avatar avatar,
String ownerId)
Tells whether the given avatar is owned by the given ownerId.
|
static boolean |
isAvatarTranscodeable(Avatar avatar) |
static boolean |
isSvgContentType(String mimeType) |
boolean |
isValidIconType(IconType iconType)
Check if this is a valid icon type.
|
void |
readAvatarData(Avatar avatar,
Avatar.Size size,
AvatarFormatPolicy avatarFormatPolicy,
MediaConsumer mediaConsumer)
Provides read-only access to the data of the avatar image as an
InputStream passed to the
provided dataAccessor. |
void |
readAvatarData(Avatar avatar,
Avatar.Size size,
Consumer<InputStream> dataAccessor)
Provides read-only access to the data of the avatar image as an
InputStream passed to the
provided dataAccessor. |
void |
readAvatarData(Avatar avatar,
AvatarManager.ImageSize size,
Consumer<InputStream> dataAccessor)
Provides read-only access to the data of the avatar image as an
InputStream passed to the
provided dataAccessor. |
void |
update(Avatar avatar)
Saves the avatar as an updated version of the avatar with the same id that is already in the database.
|
boolean |
userCanCreateFor(ApplicationUser remoteUser,
IconType iconType,
IconOwningObjectId owningObjectId)
Check if the user could create an avatar for this owning object.
|
boolean |
userCanDelete(ApplicationUser remoteUser,
Avatar icon)
Check if the user can delete the icon.
|
boolean |
userCanView(ApplicationUser remoteUser,
Avatar icon)
Check if the user can view the icon.
|
public AvatarManagerImpl(AvatarStore store, ApplicationProperties applicationProperties, GlobalPermissionManager globalPermissionManager, AvatarTagger avatarTagger, AvatarImageDataStorage avatarImageDataStorage, PermissionManager permissionManager, com.atlassian.event.api.EventPublisher eventPublisher, IconTypeDefinitionFactory iconTypeFactory, RequestCacheFactory requestCacheFactory, AvatarTranscoder avatarTranscoder)
public Avatar getById(Long avatarId)
AvatarManager
getById
in interface AvatarManager
avatarId
- must not be null.public Avatar getByIdTagged(Long avatarId)
AvatarManager
getByIdTagged
in interface AvatarManager
avatarId
- must not be null.public boolean delete(Long avatarId)
AvatarManager
delete
in interface AvatarManager
avatarId
- must not be null.public boolean delete(Long avatarId, boolean alsoDeleteAvatarFile)
AvatarManager
delete
in interface AvatarManager
avatarId
- must not be null.alsoDeleteAvatarFile
- if false, the avatar file will be left on disk.public void update(Avatar avatar)
AvatarManager
update
in interface AvatarManager
avatar
- must not be null.@Nonnull public Avatar create(Avatar avatar)
AvatarManager
create
in interface AvatarManager
avatar
- must not be null, must have a null id.@Nonnull public Avatar create(Avatar avatar, InputStream imageData, Selection croppingSelection) throws DataAccessException, IOException
AvatarManager
create
in interface AvatarManager
avatar
- must not be null, must have a null id.imageData
- the data of the original avatar image.croppingSelection
- the cropping selection for the image or null to take whole image.DataAccessException
- if there is a back-end database problem.IOException
@Nonnull public Avatar create(Avatar.Type avatarType, @Nonnull String owningObjectId, @Nonnull AvatarImageDataProvider imageDataProvider) throws IOException
AvatarManager
create
in interface AvatarManager
avatarType
- type of new avatar to create.owningObjectId
- id of object (project/user/issuetype) to which this avatar is connected to.imageDataProvider
- provider of image dataIOException
- if there are arrors when processing image dataCroppingAvatarImageDataProviderFactory
@Nonnull public Avatar create(@Nonnull IconType iconType, @Nonnull IconOwningObjectId owningObjectId, @Nonnull AvatarImageDataProvider imageDataProvider) throws IOException
AvatarManager
create
in interface AvatarManager
iconType
- type of new avatar to create.owningObjectId
- id of object (project/user/issuetype) to which this avatar is connected to.imageDataProvider
- provider of image dataIOException
- if there are arrors when processing image dataCroppingAvatarImageDataProviderFactory
@Nonnull public Avatar create(String fileName, String contentType, IconType iconType, IconOwningObjectId owner, InputStream imageData, Selection croppingSelection) throws DataAccessException, IOException
AvatarManager
create
in interface AvatarManager
fileName
- the name of the avatarcontentType
- MIME content type for the avatariconType
- The type of avatar to create.owner
- The object that will own the icon.imageData
- the data of the original avatar image (it will be automatically closed)croppingSelection
- the cropping selection for the image or null to take whole imageIOException
- If there was a problem consuming the image data, or a problem storing the image data.DataAccessException
@Nonnull public Avatar create(String fileName, String contentType, Project project, InputStream imageData, Selection croppingSelection) throws DataAccessException, IOException
AvatarManager
create
in interface AvatarManager
fileName
- the name of the avatarcontentType
- MIME content type for the avatarimageData
- the data of the original avatar image (it will be automatically closed)croppingSelection
- the cropping selection for the image or null to take whole imageDataAccessException
- if there is a back-end database problem.IOException
@Nonnull public Avatar create(String fileName, String contentType, ApplicationUser owner, InputStream imageData, Selection croppingSelection) throws DataAccessException, IOException
AvatarManager
create
in interface AvatarManager
fileName
- the name of the avatarcontentType
- MIME content type for the avatarimageData
- the data of the original avatar image (it will be automatically closed)croppingSelection
- the cropping selection for the image or null to take whole imageDataAccessException
- if there is a back-end database problem.IOException
@Nonnull public File getAvatarBaseDirectory()
AvatarManager
getAvatarBaseDirectory
in interface AvatarManager
@Nonnull public List<Avatar> getAllSystemAvatars(Avatar.Type type)
AvatarManager
getAllSystemAvatars
in interface AvatarManager
type
- The type of system avatars to return@Nonnull public List<Avatar> getAllSystemAvatars(IconType iconType)
AvatarManager
getAllSystemAvatars
in interface AvatarManager
iconType
- The type of system avatars to return@Nonnull public List<Avatar> getCustomAvatarsForOwner(Avatar.Type type, String ownerId)
AvatarManager
getCustomAvatarsForOwner
in interface AvatarManager
type
- the desired type of the avatars to retrieve.ownerId
- the id of the owner, matches the type (project id or user key).@Nonnull public List<Avatar> getCustomAvatarsForOwner(IconType iconType, String ownerId)
AvatarManager
getCustomAvatarsForOwner
in interface AvatarManager
iconType
- the desired type of the avatars to retrieve.ownerId
- the id of the owner, matches the type (project id or user key).public boolean isAvatarOwner(Avatar avatar, String ownerId)
AvatarManager
isAvatarOwner
in interface AvatarManager
avatar
- the avatar to check, must not be null.ownerId
- the ownerId to check, must not be null.public void readAvatarData(Avatar avatar, AvatarManager.ImageSize size, Consumer<InputStream> dataAccessor) throws IOException
AvatarManager
InputStream
passed to the
provided dataAccessor. The InputStream is closed after the dataAccessor completes. The dataAccessor is
immediately invoked on the data for the avatar.readAvatarData
in interface AvatarManager
avatar
- the avatar for which the data is to be processed.size
- the size to return for this avatardataAccessor
- something to read the data.IOException
- if an IOException occurs in the dataAccessor or in acquiring the InputStream for the
avatar.AvatarManager.readAvatarData(Avatar, Avatar.Size, AvatarFormatPolicy, MediaConsumer)
public void readAvatarData(@Nonnull Avatar avatar, @Nonnull Avatar.Size size, @Nonnull Consumer<InputStream> dataAccessor) throws IOException
AvatarManager
InputStream
passed to the
provided dataAccessor. The InputStream is closed after the dataAccessor completes. The dataAccessor is
immediately invoked on the data for the avatar.
This is equivalent to calling AvatarManager.readAvatarData(Avatar, Avatar.Size, AvatarFormatPolicy, MediaConsumer)
with
AvatarFormatPolicy.createOriginalDataPolicy()
as the requested type and Optional.empty()
as type Accessor.
readAvatarData
in interface AvatarManager
avatar
- the avatar for which the data is to be processed.size
- the size to return for this avatardataAccessor
- something to read the data.IOException
- if an IOException occurs in the dataAccessor or in acquiring the InputStream for the
avatar.AvatarManager.readAvatarData(Avatar, Avatar.Size, AvatarFormatPolicy, MediaConsumer)
public void readAvatarData(@Nonnull Avatar avatar, @Nonnull Avatar.Size size, @Nonnull AvatarFormatPolicy avatarFormatPolicy, @Nonnull MediaConsumer mediaConsumer) throws IOException
AvatarManager
InputStream
passed to the
provided dataAccessor. The InputStream is closed after the dataAccessor completes. The dataAccessor is
immediately invoked on the data for the avatar.
The format that the image will be served in, is determined by the AvatarFormatPolicy
that is provided
as a parameter. This should be used to set the content type of the data being provided to the @Consumer
. If the parameters are non-strict, it will be a best attempt, and to know which content type
has been used please provide a typeAccessor.
readAvatarData
in interface AvatarManager
avatar
- the avatar for which the data is to be processed.size
- the size to return for this avataravatarFormatPolicy
- the requested format for avatar data.mediaConsumer
- consumer that will read the data.IOException
- if an IOException occurs in the dataAccessor or in acquiring the InputStream for the
avatar.public Long getDefaultAvatarId(Avatar.Type ofType)
AvatarManager
getDefaultAvatarId
in interface AvatarManager
ofType
- the Avatar type.public Long getDefaultAvatarId(@Nonnull IconType iconType)
AvatarManager
getDefaultAvatarId
in interface AvatarManager
iconType
- the Icon type.public Avatar getDefaultAvatar(IconType iconType)
AvatarManager
getDefaultAvatar
in interface AvatarManager
iconType
- the Icon type.public boolean isValidIconType(@Nonnull IconType iconType)
AvatarManager
isValidIconType
in interface AvatarManager
iconType
- The icon type to check.public Long getAnonymousAvatarId()
AvatarManager
getAnonymousAvatarId
in interface AvatarManager
public boolean hasPermissionToView(ApplicationUser remoteUser, Avatar.Type type, String ownerId)
AvatarManager
hasPermissionToView
in interface AvatarManager
remoteUser
- The remote user trying to view an avatartype
- The type of avatarownerId
- The owner id of the avatar being viewed (project id or user key)public boolean hasPermissionToView(ApplicationUser remoteUser, Project project)
AvatarManager
hasPermissionToView
in interface AvatarManager
remoteUser
- The remote user trying to view an avatarproject
- The owner of the avatar being viewedpublic boolean hasPermissionToView(ApplicationUser remoteUser, ApplicationUser owner)
AvatarManager
hasPermissionToView
in interface AvatarManager
remoteUser
- The remote user trying to view an avatarowner
- The owner of the avatar being viewedpublic boolean hasPermissionToEdit(ApplicationUser remoteUser, Avatar.Type type, String ownerId)
AvatarManager
hasPermissionToEdit
in interface AvatarManager
remoteUser
- The remote user trying to edit an avatartype
- The type of avatarownerId
- The owner id of the avatar being edited (project id or user key)public boolean hasPermissionToEdit(ApplicationUser remoteUser, ApplicationUser owner)
AvatarManager
hasPermissionToEdit
in interface AvatarManager
remoteUser
- The remote user trying to edit an avatarowner
- The owner of the avatar being editedpublic boolean hasPermissionToEdit(ApplicationUser remoteUser, Project owner)
AvatarManager
hasPermissionToEdit
in interface AvatarManager
remoteUser
- The remote user trying to edit an avatarowner
- The owner of the avatar being editedpublic static boolean isSvgContentType(String mimeType)
public boolean userCanView(@Nullable ApplicationUser remoteUser, @Nonnull Avatar icon)
AvatarManager
userCanView
in interface AvatarManager
remoteUser
- user whose permissions should be used. Null means anonymous access.icon
- The icon that the user wishes to access.public boolean userCanDelete(@Nullable ApplicationUser remoteUser, @Nonnull Avatar icon)
AvatarManager
userCanDelete
in interface AvatarManager
remoteUser
- user whose permissions should be used. Null means anonymous access.icon
- The icon that the user wishes to delete.public boolean userCanCreateFor(@Nullable ApplicationUser remoteUser, @Nonnull IconType iconType, @Nonnull IconOwningObjectId owningObjectId)
AvatarManager
userCanCreateFor
in interface AvatarManager
remoteUser
- user whose permissions should be used. Null means anonymous access.iconType
- The type of icon the user is trying to create.owningObjectId
- id of the object to which this avatar is connected to. This helps set the scope for
the provider of the IconType
to determine permissions for icons that
have not been created yet.public boolean hasImage(@Nonnull Avatar avatar, @Nonnull Avatar.Size size)
AvatarManager
AvatarManager.readAvatarData(Avatar, Avatar.Size, AvatarFormatPolicy, MediaConsumer)
.
An example of avatar with invalid image would be avatar with its image removed from the filesystem.hasImage
in interface AvatarManager
avatar
- Avatarsize
- Avatar sizeCopyright © 2002-2021 Atlassian. All Rights Reserved.