Class ApplicationUsers

java.lang.Object
com.atlassian.jira.user.ApplicationUsers

public final class ApplicationUsers extends Object
Contains utility methods for getting an ApplicationUser from a directory User.
Since:
v5.1.1
  • Constructor Details

    • ApplicationUsers

      public ApplicationUsers()
  • Method Details

    • from

      @Nullable public static ApplicationUser from(@Nullable com.atlassian.crowd.embedded.api.User user)
      Obtains an ApplicationUser for the given directory User.
      Parameters:
      user - the directory User
      Returns:
      the Application User, or null if the incoming user is null.
      Throws:
      IllegalStateException - if user is not null, but the UserKeyService has no mapping for its username. 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

      @Nullable public static String getKeyFor(@Nullable com.atlassian.crowd.embedded.api.User user)
      Gets the user key for the given directory User.

      This is a null-safe shorthand for

           ApplicationUsers.from(user).getKey()
       
      Parameters:
      user - the directory User
      Returns:
      the application user Key for the given directory User, or null if the incoming user is null or has no mapping in the UserKeyService
    • getKeyFor

      @Nullable public static String getKeyFor(@Nullable ApplicationUser user)
      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)
      Performs null-safe conversion of a collection of directory users to corresponding ApplicationUser objects.
      Parameters:
      users - the users to transform (may be null and may contain null
      Returns:
      a list of application users
      Throws:
      IllegalStateException - if any of the users exists in the crowd directory but has no mapping in the UserKeyService (see comments for from(User)).
    • from

      @Nullable public static List<ApplicationUser> from(@Nullable Iterable<com.atlassian.crowd.embedded.api.User> users)
      Performs null-safe conversion of a collection of directory users to corresponding ApplicationUser objects.
      Parameters:
      users - the users to transform (may be null and may contain null
      Returns:
      a list of application users
      Throws:
      IllegalStateException - if any of the users exists in the crowd directory but has no mapping in the UserKeyService (see comments for from(User)).
    • toDirectoryUsers

      @Nullable public static List<com.atlassian.crowd.embedded.api.User> toDirectoryUsers(@Nullable Collection<ApplicationUser> applicationUsers)
      Performs null-safe conversion of a collection of application users to corresponding directory User objects.
      Parameters:
      applicationUsers - the users to transform (may be null and may contain null
      Returns:
      a list of directory users
    • byKey

      @Nullable public static ApplicationUser byKey(@Nullable String key)
      Gets the ApplicationUser in a null-safe manner. This is a convenient shorthand for ComponentAccessor.getUserManager().getUserByKey(key)). Prefer UserManager.getUserByKey(String) when the UserManager is already available.
      Parameters:
      key - the user's key
      Returns:
      the corresponding user, or null if no user exists with that key.