Package com.atlassian.jira.user
Class ApplicationUsers
java.lang.Object
com.atlassian.jira.user.ApplicationUsers
Contains utility methods for getting an
ApplicationUser
from a directory User
.- Since:
- v5.1.1
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ApplicationUser
Gets theApplicationUser
in anull
-safe manner.static ApplicationUser
from
(com.atlassian.crowd.embedded.api.User user) Obtains an ApplicationUser for the given directory User.static List<ApplicationUser>
Performsnull
-safe conversion of a collection of directory users to correspondingApplicationUser
objects.static List<ApplicationUser>
from
(Collection<com.atlassian.crowd.embedded.api.User> users) Performsnull
-safe conversion of a collection of directory users to correspondingApplicationUser
objects.static String
getKeyFor
(com.atlassian.crowd.embedded.api.User user) Gets the user key for the given directory User.static String
getKeyFor
(ApplicationUser user) Get the key from the given user in a null-safe mannerstatic com.atlassian.crowd.embedded.api.User
Does a null-safe conversion from an application user to a directory user.static List<com.atlassian.crowd.embedded.api.User>
toDirectoryUsers
(Collection<ApplicationUser> applicationUsers) Performsnull
-safe conversion of a collection of application users to corresponding directoryUser
objects.
-
Constructor Details
-
ApplicationUsers
public ApplicationUsers()
-
-
Method Details
-
from
Obtains an ApplicationUser for the given directory User.- Parameters:
user
- the directory User- Returns:
- the Application User, or
null
if the incoming user isnull
. - Throws:
IllegalStateException
- ifuser
is notnull
, but theUserKeyService
has no mapping for itsusername
. This should not occur during normal operation, as all users are assigned keys during the upgrade to v6.0 or when the user is created.
-
getKeyFor
Gets the user key for the given directory User.This is a
null
-safe shorthand forApplicationUsers.from(user).getKey()
- Parameters:
user
- the directory User- Returns:
- the application user Key for the given directory
User
, ornull
if the incoming user isnull
or has no mapping in theUserKeyService
-
getKeyFor
Get the key from the given user in a null-safe manner- Parameters:
user
- the user (possibly null)- Returns:
- the key of the given user, or null if the user is null
-
toDirectoryUser
@Nullable public static com.atlassian.crowd.embedded.api.User toDirectoryUser(@Nullable ApplicationUser user) Does a null-safe conversion from an application user to a directory user.- Parameters:
user
- the ApplicationUser- Returns:
- the corresponding Directory user
-
from
@Nullable public static List<ApplicationUser> from(@Nullable Collection<com.atlassian.crowd.embedded.api.User> users) Performsnull
-safe conversion of a collection of directory users to correspondingApplicationUser
objects.- Parameters:
users
- the users to transform (may benull
and may containnull
- Returns:
- a list of application users
- Throws:
IllegalStateException
- if any of the users exists in the crowd directory but has no mapping in theUserKeyService
(see comments forfrom(User)
).
-
from
@Nullable public static List<ApplicationUser> from(@Nullable Iterable<com.atlassian.crowd.embedded.api.User> users) Performsnull
-safe conversion of a collection of directory users to correspondingApplicationUser
objects.- Parameters:
users
- the users to transform (may benull
and may containnull
- Returns:
- a list of application users
- Throws:
IllegalStateException
- if any of the users exists in the crowd directory but has no mapping in theUserKeyService
(see comments forfrom(User)
).
-
toDirectoryUsers
@Nullable public static List<com.atlassian.crowd.embedded.api.User> toDirectoryUsers(@Nullable Collection<ApplicationUser> applicationUsers) Performsnull
-safe conversion of a collection of application users to corresponding directoryUser
objects.- Parameters:
applicationUsers
- the users to transform (may benull
and may containnull
- Returns:
- a list of directory users
-
byKey
Gets theApplicationUser
in anull
-safe manner. This is a convenient shorthand forComponentAccessor.getUserManager().getUserByKey(key))
. PreferUserManager.getUserByKey(String)
when theUserManager
is already available.- Parameters:
key
- the user's key- Returns:
- the corresponding user, or
null
if no user exists with that key.
-