de.uka.ipd.consensus.impl
Class UserImpl

java.lang.Object
  extended byde.uka.ipd.consensus.impl.TM4JObjectWrapper
      extended byde.uka.ipd.consensus.impl.UserImpl
All Implemented Interfaces:
Commentatable, Comparable, EventListener, javax.servlet.http.HttpSessionBindingListener, Rateable, Serializable, User

public class UserImpl
extends TM4JObjectWrapper
implements User, javax.servlet.http.HttpSessionBindingListener

TODO

Version:
2006-06-14
Author:
Thomas Much
See Also:
Serialized Form

Field Summary
 
Fields inherited from class de.uka.ipd.consensus.impl.TM4JObjectWrapper
EMPTY_SCOPE
 
Method Summary
 Rating addRating(User rater, double value)
          Adds a rating for the given user to this element.
 void addRole(UserRole role)
          Adds a UserRole to this user's roles.
protected  void change(int passwordHash, String firstname, String lastname, String email, String comment)
           
 int compareTo(Object obj)
           
protected static String extractUsername(String userid)
           
 double getAverageOwnRatingsValue()
          Returns the average value (the arithmetic mean) of all ratings that this user has given to other elements of the ontology.
 double getAverageRatingValue()
          Returns the average value (the arithmetic mean) of all current ratings for this element.
 String getComment()
          Returns the comment of the element.
 String getEmail()
           
 String getFirstname()
           
 String getId()
          Returns the user's id that was computed automatically from the username when the user created his account.
static UserImpl getInstance(OntologyManagerImpl omi, org.tm4j.topicmap.Topic userTopic)
           
static UserImpl getInstance(UserManagerImpl umi, String username, int passwordHash, String firstname, String lastname, String email, double initScore, String comment, String roles)
           
 String getLastname()
           
 Date getLoginTime()
           
 Collection getOwnRatings()
          Returns a collection of all current Rating objects that this user has given to other elements of the ontology.
 int getOwnRatingsCount()
          Returns the number of ratings that this user has given to other elements of the ontology.
 int getPasswordHash()
           
 Rating getRating(User user)
          Returns the rating of the given user for this element.
 Collection getRatings()
          Returns a collection of all current Rating objects (from different users) for this element.
 int getRatingsCount()
          Returns the number of ratings for this element.
 Collection getRoles()
          Returns a collection of UserRole objects that this user is in.
 double getScore()
          Returns this user's score.
 UserManager getUserManager()
          Returns the UserManager instance that manages this user account.
 String getUsername()
          Returns the username that the user has given himself when creating his user account.
protected  org.tm4j.topicmap.Topic getWrappedTopic()
           
protected  void init(int passwordHash, String firstname, String lastname, String email, double initScore, String comment, String roles)
           
 boolean isAdmin()
          Checks if the user is in the admin role.
 boolean isInRole(UserRole role)
          Checks if the user is in the given role.
 boolean isLoggedOn()
          Checks if the user is logged on.
 boolean isSuperAdmin()
           
 void removeRole(UserRole role)
          Removes a UserRole from this user's roles.
 void setComment(User setter, String comment)
          Changes the element's comment.
protected  void setLoggedOn(boolean loggedOn)
           
 void setScore(double score)
          Changes this user's score.
 String toString()
           
 void valueBound(javax.servlet.http.HttpSessionBindingEvent event)
           
 void valueUnbound(javax.servlet.http.HttpSessionBindingEvent event)
           
 
Methods inherited from class de.uka.ipd.consensus.impl.TM4JObjectWrapper
equals, getCache, getLoggingManager, getObjectId, getOccurrence, getOntologyManager, getWrappedObject, hashCode, putCache, wrap, wrap, wrap, wrap, wrap, wrap, wrap
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

getInstance

public static UserImpl getInstance(OntologyManagerImpl omi,
                                   org.tm4j.topicmap.Topic userTopic)

getInstance

public static UserImpl getInstance(UserManagerImpl umi,
                                   String username,
                                   int passwordHash,
                                   String firstname,
                                   String lastname,
                                   String email,
                                   double initScore,
                                   String comment,
                                   String roles)
                            throws Exception
Throws:
Exception

init

protected void init(int passwordHash,
                    String firstname,
                    String lastname,
                    String email,
                    double initScore,
                    String comment,
                    String roles)

change

protected void change(int passwordHash,
                      String firstname,
                      String lastname,
                      String email,
                      String comment)

getWrappedTopic

protected org.tm4j.topicmap.Topic getWrappedTopic()

getUserManager

public UserManager getUserManager()
Description copied from interface: User
Returns the UserManager instance that manages this user account.

Specified by:
getUserManager in interface User
Returns:
the UserManager, never null

getUsername

public String getUsername()
Description copied from interface: User
Returns the username that the user has given himself when creating his user account. This username must be unique within the user database.

Specified by:
getUsername in interface User
Returns:
the username (never empty, never null)
See Also:
User.getId(), UserManager.createUser(String, String, Map), UserManager.getUserByUsername(String)

extractUsername

protected static String extractUsername(String userid)

getId

public String getId()
Description copied from interface: User
Returns the user's id that was computed automatically from the username when the user created his account. The user id must be unique within all elements of the ontology.

Specified by:
getId in interface User
Returns:
the user's id (never empty, never null)
See Also:
User.getUsername(), UserManager.createUser(String, String, Map), UserManager.getUserById(String)

getFirstname

public String getFirstname()

getLastname

public String getLastname()

getEmail

public String getEmail()

getPasswordHash

public int getPasswordHash()

getLoginTime

public Date getLoginTime()

getRatings

public Collection getRatings()
Description copied from interface: Rateable
Returns a collection of all current Rating objects (from different users) for this element. This method exists just for convenience and delegates to one of the getRatings() methods of RatingManager.

Specified by:
getRatings in interface Rateable
Returns:
a possibly empty collection, never null
See Also:
Rating, RatingManager

getAverageRatingValue

public double getAverageRatingValue()
Description copied from interface: Rateable
Returns the average value (the arithmetic mean) of all current ratings for this element.

Specified by:
getAverageRatingValue in interface Rateable
Returns:
the arithmetic mean of all ratings for this element

getRatingsCount

public int getRatingsCount()
Description copied from interface: Rateable
Returns the number of ratings for this element. Each user can have only one current rating for each element, i.e. historical ratings do not count.

Specified by:
getRatingsCount in interface Rateable
Returns:
the number of ratings for this element.

addRating

public Rating addRating(User rater,
                        double value)
                 throws RatingManagerException,
                        DynamicRightsManagerException
Description copied from interface: Rateable
Adds a rating for the given user to this element. If the user has rated the element already, only the rating's value is changed. Otherwise, this method creates and adds a new rating using suitable RatingManager methods.

Specified by:
addRating in interface Rateable
Parameters:
rater - the user who wants to add or change the rating
value - the new value
Returns:
the newly created or the existing but changed rating
Throws:
DynamicRightsManagerException - if the user is not allowed to rate this element
RatingManagerException - if the rating could not be created/changed
See Also:
RatingManager, DynamicRightsManager.mayAddRating(Rating, Rateable)

getRating

public Rating getRating(User user)
Description copied from interface: Rateable
Returns the rating of the given user for this element. This method exists just for convenience and delegates to one of the getRatings() methods of RatingManager.

Specified by:
getRating in interface Rateable
Parameters:
user - the user who's rating shall be returned
Returns:
the rating of the user or null if the user hasn't rated this element yet
See Also:
RatingManager

getAverageOwnRatingsValue

public double getAverageOwnRatingsValue()
Description copied from interface: User
Returns the average value (the arithmetic mean) of all ratings that this user has given to other elements of the ontology. Each element can have only one current rating by one user, i.e. historical ratings do not count.

Specified by:
getAverageOwnRatingsValue in interface User
Returns:
the arithmetic mean of all ratings that this user has given to other elements of the ontology

getOwnRatings

public Collection getOwnRatings()
Description copied from interface: User
Returns a collection of all current Rating objects that this user has given to other elements of the ontology. This method exists just for convenience and delegates to a RatingManager method.

Specified by:
getOwnRatings in interface User
Returns:
a possibly empty collection, never null
See Also:
Rating, RatingManager.getUsersOwnRatings(User)

getOwnRatingsCount

public int getOwnRatingsCount()
Description copied from interface: User
Returns the number of ratings that this user has given to other elements of the ontology. Each element can have only one current rating by one user, i.e. historical ratings do not count.

Specified by:
getOwnRatingsCount in interface User
Returns:
the number of ratings that this user has given to other elements of the ontology.

getComment

public String getComment()
Description copied from interface: Commentatable
Returns the comment of the element.

Specified by:
getComment in interface Commentatable
Returns:
the comment (may be the empty string, but never null)

setComment

public void setComment(User setter,
                       String comment)
                throws OntologyManagerException,
                       DynamicRightsManagerException
Description copied from interface: Commentatable
Changes the element's comment.

Specified by:
setComment in interface Commentatable
Parameters:
setter - the user who wants to change the comment
comment - the new comment (null is treated as an empty string)
Throws:
DynamicRightsManagerException - if the user is not allowed to change the comment
OntologyManagerException - if the comment could not be changed
See Also:
DynamicRightsManager.mayChangeConceptComment(User, Concept), DynamicRightsManager.mayChangeUserComment(User, User)

toString

public String toString()

compareTo

public int compareTo(Object obj)
Specified by:
compareTo in interface Comparable

setScore

public void setScore(double score)
Description copied from interface: User
Changes this user's score. This method is usually called from a ScoringListener.

Specified by:
setScore in interface User
Parameters:
score - the new score (an absolute value, not a delta value!)
See Also:
User.getScore(), ScoringListener

getScore

public double getScore()
Description copied from interface: User
Returns this user's score. The IncentiveManager or a ScoringListener may change the user's score for his actions (e.g. create or rate elements).

Specified by:
getScore in interface User
Returns:
the user's score
See Also:
User.setScore(double), IncentiveManager.getInitialUserScore(), ScoringListener

addRole

public void addRole(UserRole role)
Description copied from interface: User
Adds a UserRole to this user's roles.

Specified by:
addRole in interface User
Parameters:
role - the UserRole to add
See Also:
UserManager.findRole(String)

getRoles

public Collection getRoles()
Description copied from interface: User
Returns a collection of UserRole objects that this user is in.

Specified by:
getRoles in interface User
Returns:
a possibly empty collection, never null
See Also:
UserRole

isInRole

public boolean isInRole(UserRole role)
Description copied from interface: User
Checks if the user is in the given role.

Specified by:
isInRole in interface User
Parameters:
role - the role to check
Returns:
true if the user is in the role, false otherwise
See Also:
UserManager.findRole(String)

removeRole

public void removeRole(UserRole role)
Description copied from interface: User
Removes a UserRole from this user's roles. If the user isn't in the role, this call is ignored.

Specified by:
removeRole in interface User
Parameters:
role - the UserRole to remove
See Also:
UserManager.findRole(String)

isAdmin

public boolean isAdmin()
Description copied from interface: User
Checks if the user is in the admin role.

Specified by:
isAdmin in interface User
Returns:
true if the user is in the admin role, false otherwise

isSuperAdmin

public boolean isSuperAdmin()

isLoggedOn

public boolean isLoggedOn()
Description copied from interface: User
Checks if the user is logged on.

Specified by:
isLoggedOn in interface User
Returns:
true if the user is logged on, false otherwise
See Also:
UserManager.login(String, String), UserManager.logout(User)

setLoggedOn

protected void setLoggedOn(boolean loggedOn)

valueBound

public void valueBound(javax.servlet.http.HttpSessionBindingEvent event)
Specified by:
valueBound in interface javax.servlet.http.HttpSessionBindingListener

valueUnbound

public void valueUnbound(javax.servlet.http.HttpSessionBindingEvent event)
Specified by:
valueUnbound in interface javax.servlet.http.HttpSessionBindingListener