public class AvatarManagerImpl extends Object implements AvatarManager
AvatarManager.ImageSizeAVATAR_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,
AvatarManagerStats avatarManagerStats) |
| 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, AvatarManagerStats avatarManagerStats)
public Avatar getById(Long avatarId)
AvatarManagergetById in interface AvatarManageravatarId - must not be null.public Avatar getByIdTagged(Long avatarId)
AvatarManagergetByIdTagged in interface AvatarManageravatarId - must not be null.public boolean delete(Long avatarId)
AvatarManagerdelete in interface AvatarManageravatarId - must not be null.public boolean delete(Long avatarId, boolean alsoDeleteAvatarFile)
AvatarManagerdelete in interface AvatarManageravatarId - must not be null.alsoDeleteAvatarFile - if false, the avatar file will be left on disk.public void update(Avatar avatar)
AvatarManagerupdate in interface AvatarManageravatar - must not be null.@Nonnull public Avatar create(Avatar avatar)
AvatarManagercreate in interface AvatarManageravatar - must not be null, must have a null id.@Nonnull public Avatar create(Avatar avatar, InputStream imageData, Selection croppingSelection) throws DataAccessException, IOException
AvatarManagercreate in interface AvatarManageravatar - 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
AvatarManagercreate in interface AvatarManageravatarType - 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
AvatarManagercreate in interface AvatarManagericonType - 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
AvatarManagercreate in interface AvatarManagerfileName - 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
AvatarManagercreate in interface AvatarManagerfileName - 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
AvatarManagercreate in interface AvatarManagerfileName - 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()
AvatarManagergetAvatarBaseDirectory in interface AvatarManager@Nonnull public List<Avatar> getAllSystemAvatars(Avatar.Type type)
AvatarManagergetAllSystemAvatars in interface AvatarManagertype - The type of system avatars to return@Nonnull public List<Avatar> getAllSystemAvatars(IconType iconType)
AvatarManagergetAllSystemAvatars in interface AvatarManagericonType - The type of system avatars to return@Nonnull public List<Avatar> getCustomAvatarsForOwner(Avatar.Type type, String ownerId)
AvatarManagergetCustomAvatarsForOwner in interface AvatarManagertype - 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)
AvatarManagergetCustomAvatarsForOwner in interface AvatarManagericonType - 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)
AvatarManagerisAvatarOwner in interface AvatarManageravatar - 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
AvatarManagerInputStream 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 AvatarManageravatar - 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
AvatarManagerInputStream 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 AvatarManageravatar - 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
AvatarManagerInputStream 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 AvatarManageravatar - 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)
AvatarManagergetDefaultAvatarId in interface AvatarManagerofType - the Avatar type.public Long getDefaultAvatarId(@Nonnull IconType iconType)
AvatarManagergetDefaultAvatarId in interface AvatarManagericonType - the Icon type.public Avatar getDefaultAvatar(IconType iconType)
AvatarManagergetDefaultAvatar in interface AvatarManagericonType - the Icon type.public boolean isValidIconType(@Nonnull IconType iconType)
AvatarManagerisValidIconType in interface AvatarManagericonType - The icon type to check.public Long getAnonymousAvatarId()
AvatarManagergetAnonymousAvatarId in interface AvatarManagerpublic boolean hasPermissionToView(ApplicationUser remoteUser, Avatar.Type type, String ownerId)
AvatarManagerhasPermissionToView in interface AvatarManagerremoteUser - 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)
AvatarManagerhasPermissionToView in interface AvatarManagerremoteUser - The remote user trying to view an avatarproject - The owner of the avatar being viewedpublic boolean hasPermissionToView(ApplicationUser remoteUser, ApplicationUser owner)
AvatarManagerhasPermissionToView in interface AvatarManagerremoteUser - The remote user trying to view an avatarowner - The owner of the avatar being viewedpublic boolean hasPermissionToEdit(ApplicationUser remoteUser, Avatar.Type type, String ownerId)
AvatarManagerhasPermissionToEdit in interface AvatarManagerremoteUser - 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)
AvatarManagerhasPermissionToEdit in interface AvatarManagerremoteUser - The remote user trying to edit an avatarowner - The owner of the avatar being editedpublic boolean hasPermissionToEdit(ApplicationUser remoteUser, Project owner)
AvatarManagerhasPermissionToEdit in interface AvatarManagerremoteUser - 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)
AvatarManageruserCanView in interface AvatarManagerremoteUser - 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)
AvatarManageruserCanDelete in interface AvatarManagerremoteUser - 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)
AvatarManageruserCanCreateFor in interface AvatarManagerremoteUser - 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)
AvatarManagerAvatarManager.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 AvatarManageravatar - Avatarsize - Avatar sizeCopyright © 2002-2023 Atlassian. All Rights Reserved.