com.atlassian.jira.usercompatibility
Class UserCompatibilityHelper

java.lang.Object
  extended by com.atlassian.jira.usercompatibility.UserCompatibilityHelper

public class UserCompatibilityHelper
extends java.lang.Object

Helper class containing utility methods for plugins which supports both JIRA 6.0 and older. In this case, cannot use directly a new ApplicationUser interface introduced in JIRA 6.0. This class contains methods which can be used to perform type-safe operations.


Constructor Summary
UserCompatibilityHelper()
           
 
Method Summary
static UserWithKey convertUserObject(java.lang.Object userObject)
          Converts given userObject into UserWithKey.
static java.lang.String getKeyForUser(com.atlassian.crowd.embedded.api.User user)
          Returns unique key, which e.g.
static com.atlassian.crowd.embedded.api.User getUserForKey(java.lang.String key)
          Returns User object based on specified key.
static boolean isUserObject(java.lang.Object object)
          Tells whether given object represents a user and can be passed to convertUserObject(Object).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UserCompatibilityHelper

public UserCompatibilityHelper()
Method Detail

convertUserObject

public static UserWithKey convertUserObject(java.lang.Object userObject)
Converts given userObject into UserWithKey.

This method was introduced as an answer for different return value from com.atlassian.jira.issue.fields.CustomFields containing users in JIRA 6.0. In such case, com.atlassian.jira.issue.fields.CustomField returns User in JIRA < 6.0, and ApplicationUser in JIRA >= 6.0

Parameters:
userObject - object representing User
Returns:
UserWithKey object containg unique user's key and User object itself.
Throws:
java.lang.IllegalArgumentException - when given userObject has unknown type
ApplicationUserUtilAccessException - when necessary class/method cannot be accessed

getKeyForUser

public static java.lang.String getKeyForUser(com.atlassian.crowd.embedded.api.User user)
Returns unique key, which e.g. can be stored in persistent storage, for given User.

For plugin which supports only JIRA >= 6.0 it is highly recommended to use com.atlassian.jira.user.ApplicationUsers#getKeyFor(com.atlassian.crowd.embedded.api.User) directly

Parameters:
user - the directory User
Returns:
unique Key for given user
Throws:
ApplicationUserUtilAccessException - when necessary class/method cannot be accessed

getUserForKey

public static com.atlassian.crowd.embedded.api.User getUserForKey(java.lang.String key)
Returns User object based on specified key.

This method should be used as an opposite of UserCompabilityHelper#getKeyForUser(com.atlassian.crowd.embedded.api.User) for finding users based on string, e.g. stored in persistent storage. For plugin which supports only JIRA >= 6.0 it is highly recommended to use UserManager#getUserByKey(String) directly.

Warning:
Principal.getName() of returned user can be not equal to given key.

Parameters:
key - User's key
Returns:
User object for given key
Throws:
ApplicationUserUtilAccessException - when necessary class/method cannot be accessed

isUserObject

public static boolean isUserObject(java.lang.Object object)
Tells whether given object represents a user and can be passed to convertUserObject(Object).

This method was introduced as an answer for different return value from com.atlassian.jira.issue.fields.CustomFields containing users in JIRA 6.0. In such case, com.atlassian.jira.issue.fields.CustomField returns User in JIRA < 6.0, and ApplicationUser in JIRA >= 6.0

Parameters:
object - object possibly representing a User
Returns:
true if object can be passed to convertUserObject(Object).
Throws:
ApplicationUserUtilAccessException - when necessary class/method cannot be accessed


Copyright © 2013 Atlassian. All Rights Reserved.