com.atlassian.jira.avatar
Class AvatarManagerImpl

java.lang.Object
  extended by com.atlassian.jira.avatar.AvatarManagerImpl
All Implemented Interfaces:
AvatarManager

public class AvatarManagerImpl
extends Object
implements AvatarManager

Manager for Avatars.

Since:
v4.0

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.atlassian.jira.avatar.AvatarManager
AvatarManager.ImageSize
 
Field Summary
 
Fields inherited from interface com.atlassian.jira.avatar.AvatarManager
AVATAR_IMAGE_FORMAT, AVATAR_IMAGE_FORMAT_FULL, USER_AVATAR_ID_KEY
 
Constructor Summary
AvatarManagerImpl(AvatarStore store, JiraHome jiraHome, ApplicationProperties applicationProperties, PermissionManager permissionManager)
           
 
Method Summary
 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(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, Project owner, 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.
 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.
 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.
 Long getDefaultAvatarId(Avatar.Type ofType)
          Gets the default avatar for the given type.
 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, Project owner)
          Determines if the remoteUser provided has permission to edit avatars of a certain type for the owner provided.
 boolean hasPermissionToEdit(com.atlassian.crowd.embedded.api.User 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 hasPermissionToView(ApplicationUser remoteUser, ApplicationUser user)
          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 hasPermissionToView(com.atlassian.crowd.embedded.api.User 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 isAvatarOwner(Avatar avatar, String ownerId)
          Tells whether the given avatar is owned by the given ownerId.
 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 dataProcessor.
 void update(Avatar avatar)
          Saves the avatar as an updated version of the avatar with the same id that is already in the database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AvatarManagerImpl

public AvatarManagerImpl(AvatarStore store,
                         JiraHome jiraHome,
                         ApplicationProperties applicationProperties,
                         PermissionManager permissionManager)
Method Detail

getById

public Avatar getById(Long avatarId)
Description copied from interface: AvatarManager
Retrieve the avatar with the given id.

Specified by:
getById in interface AvatarManager
Parameters:
avatarId - must not be null.
Returns:
the Avatar if there is one or null if not.

delete

public boolean delete(Long avatarId)
Description copied from interface: AvatarManager
Delete the avatar with the given id and the file on disk.

Specified by:
delete in interface AvatarManager
Parameters:
avatarId - must not be null.
Returns:
true only if there was an avatar with the given id which was deleted.

delete

public boolean delete(Long avatarId,
                      boolean alsoDeleteAvatarFile)
Description copied from interface: AvatarManager
Delete the avatar with the given id.

Specified by:
delete in interface AvatarManager
Parameters:
avatarId - must not be null.
alsoDeleteAvatarFile - if false, the avatar file will be left on disk.
Returns:
true only if there was an avatar with the given id which was deleted.

update

public void update(Avatar avatar)
Description copied from interface: AvatarManager
Saves the avatar as an updated version of the avatar with the same id that is already in the database.

Specified by:
update in interface AvatarManager
Parameters:
avatar - must not be null.

create

public Avatar create(Avatar avatar)
Description copied from interface: AvatarManager
Creates a database record for the given avatar. Use the return value as the persistent avatar, not the one you passed in.

Specified by:
create in interface AvatarManager
Parameters:
avatar - must not be null, must have a null id.
Returns:
the created avatar which has an assigned id.

create

public Avatar create(Avatar avatar,
                     InputStream imageData,
                     Selection croppingSelection)
              throws DataAccessException,
                     IOException
Description copied from interface: AvatarManager
Creates a database record for the given avatar and uses the content of the InputStream as the image. Use the return value as the persistent avatar, not the one you passed in.

Specified by:
create in interface AvatarManager
Parameters:
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.
Returns:
the created avatar which has an assigned id.
Throws:
DataAccessException - if there is a back-end database problem.
IOException

create

public Avatar create(String fileName,
                     String contentType,
                     Project owner,
                     InputStream imageData,
                     Selection croppingSelection)
              throws DataAccessException,
                     IOException
Description copied from interface: AvatarManager
Creates a database record for the given avatar and uses the content of the InputStream as the image. Use the return value as the persistent avatar, not the one you passed in.

Specified by:
create in interface AvatarManager
Parameters:
fileName - the name of the avatar
contentType - MIME content type for the avatar
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 image
Returns:
the created avatar which has an assigned id
Throws:
DataAccessException - if there is a back-end database problem.
IOException

create

public Avatar create(String fileName,
                     String contentType,
                     ApplicationUser owner,
                     InputStream imageData,
                     Selection croppingSelection)
              throws DataAccessException,
                     IOException
Description copied from interface: AvatarManager
Creates a database record for the given avatar and uses the content of the InputStream as the image. Use the return value as the persistent avatar, not the one you passed in.

Specified by:
create in interface AvatarManager
Parameters:
fileName - the name of the avatar
contentType - MIME content type for the avatar
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 image
Returns:
the created avatar which has an assigned id
Throws:
DataAccessException - if there is a back-end database problem.
IOException

getAvatarBaseDirectory

public File getAvatarBaseDirectory()
Description copied from interface: AvatarManager
Returns the directory for storing avatars.

Specified by:
getAvatarBaseDirectory in interface AvatarManager
Returns:
the directory.

getAllSystemAvatars

public List<Avatar> getAllSystemAvatars(Avatar.Type type)
Description copied from interface: AvatarManager
Provides a list of all system avatars.

Specified by:
getAllSystemAvatars in interface AvatarManager
Parameters:
type - The type of system avatars to return
Returns:
the system avatars.

getCustomAvatarsForOwner

public List<Avatar> getCustomAvatarsForOwner(Avatar.Type type,
                                             String ownerId)
Description copied from interface: AvatarManager
Provides a list of all avatars that are of the given type which have the given owner.

Specified by:
getCustomAvatarsForOwner in interface AvatarManager
Parameters:
type - the desired type of the avatars to retrieve.
ownerId - the id of the owner, matches the type (project id or user key).
Returns:
all the avatars that have the given type and owner, never null.

isAvatarOwner

public boolean isAvatarOwner(Avatar avatar,
                             String ownerId)
Description copied from interface: AvatarManager
Tells whether the given avatar is owned by the given ownerId.

Specified by:
isAvatarOwner in interface AvatarManager
Parameters:
avatar - the avatar to check, must not be null.
ownerId - the ownerId to check, must not be null.
Returns:
true only if the given ownerId is the ownerId of the given avatar.

readAvatarData

public void readAvatarData(Avatar avatar,
                           AvatarManager.ImageSize size,
                           Consumer<InputStream> dataAccessor)
                    throws IOException
Description copied from interface: AvatarManager
Provides read-only access to the data of the avatar image as an InputStream passed to the provided dataProcessor. The InputStream is closed after the dataProcessor completes. The dataProcessor is immediately invoked on the data for the avatar.

Specified by:
readAvatarData in interface AvatarManager
Parameters:
avatar - the avatar for which the data is to be processed.
size - the size to return for this avatar
dataAccessor - something to read the data.
Throws:
IOException - if an IOException occurs in the dataProcessor or in acquiring the InputStream for the avatar.

getDefaultAvatarId

public Long getDefaultAvatarId(Avatar.Type ofType)
Description copied from interface: AvatarManager
Gets the default avatar for the given type.

Specified by:
getDefaultAvatarId in interface AvatarManager
Parameters:
ofType - the Avatar type.
Returns:
the default Avatar.

getAnonymousAvatarId

public Long getAnonymousAvatarId()
Description copied from interface: AvatarManager
Gets the avatar id to use to represent an unknown or anonymous user

Specified by:
getAnonymousAvatarId in interface AvatarManager
Returns:
the avatar id for an anonymous user

hasPermissionToView

public boolean hasPermissionToView(com.atlassian.crowd.embedded.api.User remoteUser,
                                   Avatar.Type type,
                                   String ownerId)
Description copied from interface: AvatarManager
Determines if the remoteUser provided has permission to view avatars of a certain type for the owner provided. For project avatars, this method checks that the user is either and admin, project admin or has browse permission for the owner project. For user avatars, the method checks that the remoteUser has use permission for JIRA or the remoteUser and avatar owner are the same person

Specified by:
hasPermissionToView in interface AvatarManager
Parameters:
remoteUser - The remote user trying to view an avatar
type - The type of avatar
ownerId - The owner id of the avatar being viewed (project id or user key)
Returns:
true if the remote user has permission to view avatars owned by the owner provided.

hasPermissionToView

public boolean hasPermissionToView(ApplicationUser remoteUser,
                                   Project project)
Description copied from interface: AvatarManager
Determines if the remoteUser provided has permission to view avatars of a certain type for the owner provided. For project avatars, this method checks that the user is either and admin, project admin or has browse permission for the owner project. For user avatars, the method checks that the remoteUser has use permission for JIRA or the remoteUser and avatar owner are the same person

Specified by:
hasPermissionToView in interface AvatarManager
Parameters:
remoteUser - The remote user trying to view an avatar
project - The owner of the avatar being viewed
Returns:
true if the remote user has permission to view avatars owned by the owner provided.

hasPermissionToView

public boolean hasPermissionToView(ApplicationUser remoteUser,
                                   ApplicationUser user)
Description copied from interface: AvatarManager
Determines if the remoteUser provided has permission to view avatars of a certain type for the owner provided. For project avatars, this method checks that the user is either and admin, project admin or has browse permission for the owner project. For user avatars, the method checks that the remoteUser has use permission for JIRA or the remoteUser and avatar owner are the same person

Specified by:
hasPermissionToView in interface AvatarManager
Parameters:
remoteUser - The remote user trying to view an avatar
user - The owner of the avatar being viewed
Returns:
true if the remote user has permission to view avatars owned by the owner provided.

hasPermissionToEdit

public boolean hasPermissionToEdit(com.atlassian.crowd.embedded.api.User remoteUser,
                                   Avatar.Type type,
                                   String ownerId)
Description copied from interface: AvatarManager
Determines if the remoteUser provided has permission to edit avatars of a certain type for the owner provided. For project avatars, this method checks that the user is either and admin or project admin for the owner project. For user avatars, the method checks that the remoteUser has admin permissions for JIRA or the remoteUser and avatar owner are the same person. If external user management is enabled this method returns false

Specified by:
hasPermissionToEdit in interface AvatarManager
Parameters:
remoteUser - The remote user trying to edit an avatar
type - The type of avatar
ownerId - The owner id of the avatar being edited (project id or user key)
Returns:
true if the remote user has permission to edit avatars owned by the owner provided.

hasPermissionToEdit

public boolean hasPermissionToEdit(ApplicationUser remoteUser,
                                   ApplicationUser owner)
Description copied from interface: AvatarManager
Determines if the remoteUser provided has permission to edit avatars of a certain type for the owner provided. For project avatars, this method checks that the user is either and admin or project admin for the owner project. For user avatars, the method checks that the remoteUser has admin permissions for JIRA or the remoteUser and avatar owner are the same person. If external user management is enabled this method returns false

Specified by:
hasPermissionToEdit in interface AvatarManager
Parameters:
remoteUser - The remote user trying to edit an avatar
owner - The owner of the avatar being edited
Returns:
true if the remote user has permission to edit avatars owned by the owner provided.

hasPermissionToEdit

public boolean hasPermissionToEdit(ApplicationUser remoteUser,
                                   Project owner)
Description copied from interface: AvatarManager
Determines if the remoteUser provided has permission to edit avatars of a certain type for the owner provided. For project avatars, this method checks that the user is either and admin or project admin for the owner project. For user avatars, the method checks that the remoteUser has admin permissions for JIRA or the remoteUser and avatar owner are the same person. If external user management is enabled this method returns false

Specified by:
hasPermissionToEdit in interface AvatarManager
Parameters:
remoteUser - The remote user trying to edit an avatar
owner - The owner of the avatar being edited
Returns:
true if the remote user has permission to edit avatars owned by the owner provided.


Copyright © 2002-2013 Atlassian. All Rights Reserved.