com.atlassian.jira.avatar
Class AvatarServiceImpl

java.lang.Object
  extended by com.atlassian.jira.avatar.AvatarServiceImpl
All Implemented Interfaces:
AvatarService

public class AvatarServiceImpl
extends Object
implements AvatarService

Implementation of the AvatarService.

Since:
v4.3

Constructor Summary
AvatarServiceImpl(UserManager userManager, AvatarManager avatarManager, UserPropertyManager userPropertyManager, VelocityRequestContextFactory velocityRequestContextFactory, ApplicationProperties applicationProperties)
           
 
Method Summary
 boolean canSetCustomUserAvatar(com.atlassian.crowd.embedded.api.User remoteUser, String username)
          Returns a boolean indicating whether the calling user can edit the custom user avatar for the user with the given username.
protected  boolean canViewAvatar(com.atlassian.crowd.embedded.api.User user, Avatar avatar)
          Returns true if the passed in user has permission to view the passed in avatar.
protected  Long configuredAvatarIdFor(com.atlassian.crowd.embedded.api.User user)
          Returns the avatar id that is configured for the given User.
protected  Avatar getAnonymousAvatar()
          Returns the anonymous avatar, if configured.
 Avatar getAvatar(com.atlassian.crowd.embedded.api.User remoteUser, String avatarUserId)
          Returns the Avatar for the given user, if configured.
 URI getAvatarAbsoluteURL(com.atlassian.crowd.embedded.api.User remoteUser, String avatarUserId, Avatar.Size size)
          This is the same as AvatarService.getAvatarURL(com.atlassian.crowd.embedded.api.User, String, com.atlassian.jira.avatar.Avatar.Size) but returns an absolute URL.
 URI getAvatarURL(com.atlassian.crowd.embedded.api.User remoteUser, String avatarUserId)
          Returns the URL for the avatar of the user having the given username for displaying on a page that should be shown for the passed in remoteUser.
 URI getAvatarURL(com.atlassian.crowd.embedded.api.User remoteUser, String avatarUserId, Avatar.Size size)
          Returns the URL for the avatar of the user having the given username for displaying on a page that should be shown for the passed in remoteUser.
 URI getAvatarUrlNoPermCheck(String avatarUserId, Avatar.Size size)
          This is the same as AvatarService.getAvatarURL(com.atlassian.crowd.embedded.api.User, String, com.atlassian.jira.avatar.Avatar.Size) but does no permission checking.
protected  Avatar getDefaultAvatar()
          Returns the default avatar, if configured.
 URI getProjectAvatarAbsoluteURL(Project project, Avatar.Size size)
          Returns the URL for the avatar of the given project.
 URI getProjectAvatarURL(Project project, Avatar.Size size)
          Returns the URL for the avatar of the given project.
 boolean hasCustomUserAvatar(com.atlassian.crowd.embedded.api.User remoteUser, String username)
           
 boolean isGravatarEnabled()
          Returns true if Gravatar support is enabled.
protected  void setConfiguredAvatarIdFor(com.atlassian.crowd.embedded.api.User user, Long avatarId)
          Sets the given avatar id as the configured avatar id for a user.
 void setCustomUserAvatar(com.atlassian.crowd.embedded.api.User remoteUser, String username, Long avatarId)
          Sets a custom avatar for a given user.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AvatarServiceImpl

public AvatarServiceImpl(UserManager userManager,
                         AvatarManager avatarManager,
                         UserPropertyManager userPropertyManager,
                         VelocityRequestContextFactory velocityRequestContextFactory,
                         ApplicationProperties applicationProperties)
Method Detail

getAvatar

public Avatar getAvatar(com.atlassian.crowd.embedded.api.User remoteUser,
                        String avatarUserId)
                 throws AvatarsDisabledException
Description copied from interface: AvatarService
Returns the Avatar for the given user, if configured. If the user does not have a custom avatar, or if the calling user does not have permission to view the Avatar, this method returns the default avatar. If the user does not exist, this method returns the anonymous avatar.

If this method would return the default user avatar but none is configured, or if this method would return the anonymous avatar but none is configured, this method returns null.

Specified by:
getAvatar in interface AvatarService
Parameters:
remoteUser - the User that wants to view an Avatar
avatarUserId - a String containing a username (may have been deleted)
Returns:
an Avatar, or null
Throws:
AvatarsDisabledException - if avatars are disabled

getAvatarURL

public URI getAvatarURL(com.atlassian.crowd.embedded.api.User remoteUser,
                        String avatarUserId)
                 throws AvatarsDisabledException
Description copied from interface: AvatarService
Returns the URL for the avatar of the user having the given username for displaying on a page that should be shown for the passed in remoteUser. This method returns a URL for an avatar with the default size.

If the user does not have a custom avatar, or if the calling user does not have permission to view the Avatar, this method returns the URL of the default avatar. If the user does not exist, this method returns the URL of the anonymous avatar.

Specified by:
getAvatarURL in interface AvatarService
Parameters:
remoteUser - a User object for the currently logged in user
avatarUserId - a String containing a username (may have been deleted)
Returns:
a URL that can be used to display the avatar
Throws:
AvatarsDisabledException - if avatars are disabled
See Also:
AvatarService.getAvatar(com.atlassian.crowd.embedded.api.User, String)

getAvatarURL

public URI getAvatarURL(com.atlassian.crowd.embedded.api.User remoteUser,
                        String avatarUserId,
                        Avatar.Size size)
                 throws AvatarsDisabledException
Description copied from interface: AvatarService
Returns the URL for the avatar of the user having the given username for displaying on a page that should be shown for the passed in remoteUser.

If the user does not have a custom avatar, or if the calling user does not have permission to view the Avatar, this method returns the URL of the default avatar. If the user does not exist, this method returns the URL of the anonymous avatar.

Specified by:
getAvatarURL in interface AvatarService
Parameters:
remoteUser - a User object for the currently logged in user
avatarUserId - a String containing a username (may have been deleted)
size - the size of the avatar to be displayed (if null, the default size is used)
Returns:
a URL that can be used to display the avatar
Throws:
AvatarsDisabledException - if avatars are disabled
See Also:
AvatarService.getAvatar(com.atlassian.crowd.embedded.api.User, String)

getAvatarUrlNoPermCheck

public URI getAvatarUrlNoPermCheck(String avatarUserId,
                                   Avatar.Size size)
                            throws AvatarsDisabledException
Description copied from interface: AvatarService
This is the same as AvatarService.getAvatarURL(com.atlassian.crowd.embedded.api.User, String, com.atlassian.jira.avatar.Avatar.Size) but does no permission checking.

Specified by:
getAvatarUrlNoPermCheck in interface AvatarService
Parameters:
avatarUserId - a String containing a username (may have been deleted)
size - the size of the avatar to be displayed (if null, the default size is used)
Returns:
a URL that can be used to display the avatar
Throws:
AvatarsDisabledException - if avatars are disabled

getAvatarAbsoluteURL

public URI getAvatarAbsoluteURL(com.atlassian.crowd.embedded.api.User remoteUser,
                                String avatarUserId,
                                Avatar.Size size)
                         throws AvatarsDisabledException
Description copied from interface: AvatarService
This is the same as AvatarService.getAvatarURL(com.atlassian.crowd.embedded.api.User, String, com.atlassian.jira.avatar.Avatar.Size) but returns an absolute URL.

Specified by:
getAvatarAbsoluteURL in interface AvatarService
Throws:
AvatarsDisabledException

hasCustomUserAvatar

public boolean hasCustomUserAvatar(com.atlassian.crowd.embedded.api.User remoteUser,
                                   String username)
Specified by:
hasCustomUserAvatar in interface AvatarService

setCustomUserAvatar

public void setCustomUserAvatar(com.atlassian.crowd.embedded.api.User remoteUser,
                                String username,
                                Long avatarId)
                         throws AvatarsDisabledException,
                                NoPermissionException
Description copied from interface: AvatarService
Sets a custom avatar for a given user.

Specified by:
setCustomUserAvatar in interface AvatarService
Parameters:
remoteUser - a User object for the currently logged in user
username - the username of the user whose avatar we will configure
avatarId - the id of the avatar to configure for the user
Throws:
AvatarsDisabledException - if avatars are disabled
NoPermissionException - if the remote user does not have permission to update the given user's avatar
See Also:
AvatarService.canSetCustomUserAvatar(com.atlassian.crowd.embedded.api.User, String)

canSetCustomUserAvatar

public boolean canSetCustomUserAvatar(com.atlassian.crowd.embedded.api.User remoteUser,
                                      String username)
Description copied from interface: AvatarService
Returns a boolean indicating whether the calling user can edit the custom user avatar for the user with the given username.

Specified by:
canSetCustomUserAvatar in interface AvatarService
Parameters:
remoteUser - a User object for the currently logged in user
username - the username of the user whose avatar we will configure
Returns:
a indicating whether the calling user can edit the custom user avatar for another user

getProjectAvatarURL

public URI getProjectAvatarURL(Project project,
                               Avatar.Size size)
Description copied from interface: AvatarService
Returns the URL for the avatar of the given project.

If running in the context of a web request, this will return a URL relative to the server root (ie "/jira/..."). Otherwise, it will return an absolute URL (eg. "http://example.com/jira/...").

Specified by:
getProjectAvatarURL in interface AvatarService
Parameters:
project - the Project of which to get the avatar URL
size - the size of the avatar to be displayed (if null, the default size is used)
Returns:
a URL that can be used to display the avatar

getProjectAvatarAbsoluteURL

public URI getProjectAvatarAbsoluteURL(Project project,
                                       Avatar.Size size)
Description copied from interface: AvatarService
Returns the URL for the avatar of the given project.

This will always return an absolute URL (eg. "http://example.com/jira/...").

Specified by:
getProjectAvatarAbsoluteURL in interface AvatarService
Parameters:
project - the Project of which to get the avatar URL
size - the size of the avatar to be displayed (if null, the default size is used)
Returns:
a URL that can be used to display the avatar

configuredAvatarIdFor

protected Long configuredAvatarIdFor(com.atlassian.crowd.embedded.api.User user)
Returns the avatar id that is configured for the given User. If the user has not configured an avatar, this method returns null.

Parameters:
user - the user whose avatar we want
Returns:
an avatar id, or null
See Also:
AvatarManager.getDefaultAvatarId(com.atlassian.jira.avatar.Avatar.Type), AvatarManager.getAnonymousAvatarId()

isGravatarEnabled

public boolean isGravatarEnabled()
Returns true if Gravatar support is enabled.

Specified by:
isGravatarEnabled in interface AvatarService
Returns:
a boolean indicating whether Gravatar support is on

setConfiguredAvatarIdFor

protected void setConfiguredAvatarIdFor(com.atlassian.crowd.embedded.api.User user,
                                        Long avatarId)
Sets the given avatar id as the configured avatar id for a user.

Parameters:
user - the User whose avatar is being configured
avatarId - the avatar id to configure

canViewAvatar

protected boolean canViewAvatar(com.atlassian.crowd.embedded.api.User user,
                                Avatar avatar)
Returns true if the passed in user has permission to view the passed in avatar. By definition, any user can view the system avatars (e.g. avatars with no owner).

Parameters:
user - a User
avatar - an Avatar
Returns:
a boolean indicating whether the passed in user has permission to view the passed in avatar

getDefaultAvatar

protected Avatar getDefaultAvatar()
Returns the default avatar, if configured. Otherwise returns null.

Returns:
the default Avatar, or null

getAnonymousAvatar

protected Avatar getAnonymousAvatar()
Returns the anonymous avatar, if configured. Otherwise returns null.

Returns:
the anonymous avatar, or null


Copyright © 2002-2013 Atlassian. All Rights Reserved.