de.uka.ipd.consensus.impl
Class SQLRatingManagerImpl

java.lang.Object
  extended byde.uka.ipd.consensus.foundation.AbstractConsensusFoundationModule
      extended byde.uka.ipd.consensus.impl.SQLRatingManagerImpl
All Implemented Interfaces:
ConsensusFoundationManager, ConsensusFoundationModule, RatingManager

public class SQLRatingManagerImpl
extends AbstractConsensusFoundationModule
implements RatingManager

TODO

Version:
2006-06-14
Author:
Thomas Much

Field Summary
static String NEUTRAL
           
static String NO
           
static String YES
           
 
Constructor Summary
SQLRatingManagerImpl()
           
 
Method Summary
 void addRating(Association rated, Rating rating)
          Adds the given rating to the given association.
 void addRating(Attribute rated, Rating rating)
          Adds the given rating to the given attribute.
 void addRating(Topic rated, Rating rating)
          Adds the given rating to the given topic.
 void addRating(User rated, Rating rating)
          Adds the given rating to the given user.
 void addRatingListener(RatingListener listener)
          Registers a new RatingListener.
protected  void changeRatingComment(SQLRatingImpl rating, String comment)
           
protected  void changeRatingValue(SQLRatingImpl rating, double newval, double oldval, long newdate, long olddate, long newrateddate, long oldrateddate, String oldcomment)
           
 boolean changesAllowed()
          With this method the RatingManager signals if ratings, once added, can be changed afterwards.
 Rating createRating(User creator, double value)
          Creates a new rating with the given user as the creator ("owner" of the rating).
 void deleteRatings(Association association)
          If an association is deleted permanently from the ontology, this method can be used to remove the ratings that were added to the association, too (including historical values).
 void deleteRatings(Attribute attribute)
          If an attribute is deleted permanently from the ontology, this method can be used to remove the ratings that were added to the attribute, too (including historical values).
 void deleteRatings(Topic topic)
          If a topic is deleted permanently from the ontology, this method can be used to remove the ratings that were added to the topic, too (including historical values).
 void deleteRatings(User user)
          If a user is deleted permanently from the ontology and user database, this method can be used to remove the ratings that were added to the user, too (including historical values).
 double getAverageRatingValue(Association association)
          Returns the average (arithmetic mean) of all ratings for the given association.
 double getAverageRatingValue(Attribute attribute)
          Returns the average (arithmetic mean) of all ratings for the given attribute.
 double getAverageRatingValue(Topic topic)
          Returns the average (arithmetic mean) of all ratings for the given topic.
 double getAverageRatingValue(User user)
          Returns the average (arithmetic mean) of all ratings that other users have added to the given user.
protected  Collection getHistory(SQLRatingImpl rating)
           
 Rating getRating(Association association, User rater)
          Returns the rating object that the given user has added to the given association (or null if the user hasn't rated the association yet).
 Rating getRating(Attribute attribute, User rater)
          Returns the rating object that the given user has added to the given attribute (or null if the user hasn't rated the attribute yet).
 Rating getRating(Topic topic, User rater)
          Returns the rating object that the given user has added to the given topic (or null if the user hasn't rated the topic yet).
 Rating getRating(User user, User rater)
          Returns the rating object that the given user (parameter "rater") has added to another user (parameter "user") - or null if the user hasn't rated the other user yet.
 Collection getRatings(Association association)
          Returns a collection of all Rating objects that have been added to the given association.
 Collection getRatings(Attribute attribute)
          Returns a collection of all Rating objects that have been added to the given attribute.
 Collection getRatings(Topic topic)
          Returns a collection of all Rating objects that have been added to the given topic.
 Collection getRatings(User user)
          Returns a collection of all Rating objects that have been added by other users to the given user.
 int getRatingsCount(Association association)
          Returns the number of ratings that have been added to the given association.
 int getRatingsCount(Attribute attribute)
          Returns the number of ratings that have been added to the given attribute.
 int getRatingsCount(Topic topic)
          Returns the number of ratings that have been added to the given topic.
 int getRatingsCount(User user)
          Returns the number of ratings that have been added by other users to the given user.
 double getUsersAverageOwnRatingsValue(User user)
          Returns the average (arithmetic mean) of all ratings that the given user has added to other rateable elements.
 Collection getUsersOwnRatings(User user)
          returns all (TODO) user's ratings, newest first
 int getUsersOwnRatingsCount(User user)
          Returns the number of ratings that the given user has added to other rateable elements.
 String getVersion()
          Returns a version string of the implementation of this module.
 void init(Properties config, LoggingManager logging, UserManager users, OntologyManager ontology)
          This method is called by the ConsensusFoundation constructor to initialize the RatingManager.
 void initCompleted(Properties config, ConsensusFoundationManager cfm)
          This method is called by the ConsensusFoundation constructor after all available modules have been initialized (i.e. their init() method has been called).
 String ratingValueToString(double value)
          As applications will have to store rating values as strings (e.g. in the presentation layer), this method converts a rating value into a string.
 void removeRating(User remover, Rating rating)
          Removes a rating and its history if it is assigned to a rateable element (otherwise this call is ignored).
 void removeRatingListener(RatingListener listener)
          Removes a RatingListener, if it is registered with the RatingManager (otherwise this call is ignored).
 void shutdown()
          Called by ConsensusFoundation.shutdown() when the application shuts down.
 double stringToRatingValue(String str)
          Converts a string returned by ratingValueToString() back into a rating value.
 
Methods inherited from class de.uka.ipd.consensus.foundation.AbstractConsensusFoundationModule
finalize, getConsensusFoundationManager, getDynamicRightsManager, getEvolutionManager, getIncentiveManager, getLoggingManager, getOntologyManager, getRatingManager, getUserManager
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.uka.ipd.consensus.foundation.ConsensusFoundationModule
getConsensusFoundationManager
 

Field Detail

NO

public static final String NO
See Also:
Constant Field Values

YES

public static final String YES
See Also:
Constant Field Values

NEUTRAL

public static final String NEUTRAL
See Also:
Constant Field Values
Constructor Detail

SQLRatingManagerImpl

public SQLRatingManagerImpl()
Method Detail

init

public void init(Properties config,
                 LoggingManager logging,
                 UserManager users,
                 OntologyManager ontology)
          throws Exception
Description copied from interface: RatingManager

This method is called by the ConsensusFoundation constructor to initialize the RatingManager.

Specified by:
init in interface RatingManager
Parameters:
config - all entries from ConsensusFoundation.properties
logging - the successfully initialized LoggingManager instance
users - the the successfully initialized UserManager instance
ontology - the the successfully initialized OntologyManager instance
Throws:
Exception - if any error occurs (startup of the application is aborted in this case)
See Also:
ConsensusFoundation.ConsensusFoundation()

initCompleted

public void initCompleted(Properties config,
                          ConsensusFoundationManager cfm)
                   throws Exception
Description copied from interface: ConsensusFoundationModule
This method is called by the ConsensusFoundation constructor after all available modules have been initialized (i.e. their init() method has been called). Here a module can perform some final initialization that is dependant on other modules.

Specified by:
initCompleted in interface ConsensusFoundationModule
Overrides:
initCompleted in class AbstractConsensusFoundationModule
Throws:
Exception

shutdown

public void shutdown()
Description copied from interface: ConsensusFoundationModule
Called by ConsensusFoundation.shutdown() when the application shuts down.

When implementing this method make sure that the shutdown code is executed only once even if this method is called multiple times.

Specified by:
shutdown in interface ConsensusFoundationModule
Overrides:
shutdown in class AbstractConsensusFoundationModule

changesAllowed

public boolean changesAllowed()
Description copied from interface: RatingManager
With this method the RatingManager signals if ratings, once added, can be changed afterwards.

Specified by:
changesAllowed in interface RatingManager
Returns:
true if existing ratings can be changed, false otherwise

ratingValueToString

public String ratingValueToString(double value)
Description copied from interface: RatingManager
As applications will have to store rating values as strings (e.g. in the presentation layer), this method converts a rating value into a string. If the RatingManager supports discrete values, this method should try to return suitable string for these concrete values instead of simply turning the value number into a string (e.g. "YES", "NO", "NEUTRAL" instead of "1", "-1", "0").

The values are intended to be valid until application shutdown only and may not be compatible between different implementations of the RatingManager interface!

return the given rating value converted to a suitable string

Specified by:
ratingValueToString in interface RatingManager
See Also:
Rating.getValue(), RatingManager.stringToRatingValue(String)

stringToRatingValue

public double stringToRatingValue(String str)
Description copied from interface: RatingManager
Converts a string returned by ratingValueToString() back into a rating value.

If an unknown string is given, Rating.NEUTRAL should be returned.

Specified by:
stringToRatingValue in interface RatingManager
Parameters:
str - the string to be converted
Returns:
the converted rating value
See Also:
Rating.setValue(double), Rating.NEUTRAL, RatingManager.ratingValueToString(double)

createRating

public Rating createRating(User creator,
                           double value)
                    throws RatingManagerException,
                           DynamicRightsManagerException
Description copied from interface: RatingManager
Creates a new rating with the given user as the creator ("owner" of the rating). The rating is not assigned to any rateable element yet, this is done using the various addRating() methods or - better - the Rateable interface.

Specified by:
createRating in interface RatingManager
Parameters:
creator - the user who wants to create the rating
value - the value for the newly created rating (-1..1, including both values)
Returns:
the newly created rating
Throws:
RatingManagerException - if the rating could not be created
DynamicRightsManagerException - if the user is not allowed to create ratings
See Also:
Rateable.addRating(User, double), DynamicRightsManager.mayCreateRating(User)

getHistory

protected Collection getHistory(SQLRatingImpl rating)

changeRatingValue

protected void changeRatingValue(SQLRatingImpl rating,
                                 double newval,
                                 double oldval,
                                 long newdate,
                                 long olddate,
                                 long newrateddate,
                                 long oldrateddate,
                                 String oldcomment)

changeRatingComment

protected void changeRatingComment(SQLRatingImpl rating,
                                   String comment)

getUsersOwnRatings

public Collection getUsersOwnRatings(User user)
returns all (TODO) user's ratings, newest first

Specified by:
getUsersOwnRatings in interface RatingManager
Parameters:
user - the user from whom the ratings are returned
Returns:
a possibly empty collection, never null
See Also:
Rating, User.getOwnRatings()

getUsersAverageOwnRatingsValue

public double getUsersAverageOwnRatingsValue(User user)
Description copied from interface: RatingManager
Returns the average (arithmetic mean) of all ratings that the given user has added to other rateable elements.

Only current ratings are taken into account, not historical ones.

Specified by:
getUsersAverageOwnRatingsValue in interface RatingManager
Parameters:
user - the user from whose ratings the average rating value shall be computed
Returns:
the arithmetic mean of all ratings or Rating.NEUTRAL if the user hasn't rated other elements yet
See Also:
Rating.NEUTRAL, User.getAverageOwnRatingsValue()

getUsersOwnRatingsCount

public int getUsersOwnRatingsCount(User user)
Description copied from interface: RatingManager
Returns the number of ratings that the given user has added to other rateable elements.

Only current ratings are taken into account, not historical ones.

Specified by:
getUsersOwnRatingsCount in interface RatingManager
Parameters:
user - the user from whom the number of ratings shall be returned
Returns:
the number of ratings the given user has added to other elements
See Also:
User.getOwnRatingsCount()

removeRating

public void removeRating(User remover,
                         Rating rating)
                  throws RatingManagerException,
                         DynamicRightsManagerException
Description copied from interface: RatingManager
Removes a rating and its history if it is assigned to a rateable element (otherwise this call is ignored).

Specified by:
removeRating in interface RatingManager
Parameters:
remover - the user who wants to remove the rating
rating - the rating to be removed
Throws:
RatingManagerException - if the rating could not be removed
DynamicRightsManagerException - if the user is not allowed to remove the rating
See Also:
Rating.getRateable(), DynamicRightsManager.mayRemoveRating(User, Rating)

getRating

public Rating getRating(Topic topic,
                        User rater)
Description copied from interface: RatingManager
Returns the rating object that the given user has added to the given topic (or null if the user hasn't rated the topic yet).

Specified by:
getRating in interface RatingManager
Parameters:
topic - the topic from which the rating is returned
rater - the user who added the rating
Returns:
the Rating object or null
See Also:
Rateable.getRating(User)

getRating

public Rating getRating(Attribute attribute,
                        User rater)
Description copied from interface: RatingManager
Returns the rating object that the given user has added to the given attribute (or null if the user hasn't rated the attribute yet).

Specified by:
getRating in interface RatingManager
Parameters:
attribute - the attribute from which the rating is returned
rater - the user who added the rating
Returns:
the Rating object or null
See Also:
Rateable.getRating(User)

getRating

public Rating getRating(Association association,
                        User rater)
Description copied from interface: RatingManager
Returns the rating object that the given user has added to the given association (or null if the user hasn't rated the association yet).

Specified by:
getRating in interface RatingManager
Parameters:
association - the association from which the rating is returned
rater - the user who added the rating
Returns:
the Rating object or null
See Also:
Rateable.getRating(User)

getRating

public Rating getRating(User user,
                        User rater)
Description copied from interface: RatingManager
Returns the rating object that the given user (parameter "rater") has added to another user (parameter "user") - or null if the user hasn't rated the other user yet.

Specified by:
getRating in interface RatingManager
Parameters:
user - the user from which the rating is returned
rater - the user who added the rating
Returns:
the Rating object or null
See Also:
Rateable.getRating(User)

getRatings

public Collection getRatings(Topic topic)
Description copied from interface: RatingManager
Returns a collection of all Rating objects that have been added to the given topic.

Only current ratings are taken into account, not historical ones.

Specified by:
getRatings in interface RatingManager
Parameters:
topic - the topic for which the ratings are returned
Returns:
a possibly empty collection, never null
See Also:
Rating, Rateable.getRatings()

getRatings

public Collection getRatings(Attribute attribute)
Description copied from interface: RatingManager
Returns a collection of all Rating objects that have been added to the given attribute.

Only current ratings are taken into account, not historical ones.

Specified by:
getRatings in interface RatingManager
Parameters:
attribute - the attribute for which the ratings are returned
Returns:
a possibly empty collection, never null
See Also:
Rating, Rateable.getRatings()

getRatings

public Collection getRatings(Association association)
Description copied from interface: RatingManager
Returns a collection of all Rating objects that have been added to the given association.

Only current ratings are taken into account, not historical ones.

Specified by:
getRatings in interface RatingManager
Parameters:
association - the association for which the ratings are returned
Returns:
a possibly empty collection, never null
See Also:
Rating, Rateable.getRatings()

getRatings

public Collection getRatings(User user)
Description copied from interface: RatingManager
Returns a collection of all Rating objects that have been added by other users to the given user.

Only current ratings are taken into account, not historical ones.

Specified by:
getRatings in interface RatingManager
Parameters:
user - the user for whom the ratings are returned
Returns:
a possibly empty collection, never null
See Also:
Rating, Rateable.getRatings()

getRatingsCount

public int getRatingsCount(Association association)
Description copied from interface: RatingManager
Returns the number of ratings that have been added to the given association.

Only current ratings are taken into account, not historical ones.

Specified by:
getRatingsCount in interface RatingManager
Parameters:
association - the association for which the number of ratings shall be returned
Returns:
the number of ratings for the given association
See Also:
Rateable.getRatingsCount()

getRatingsCount

public int getRatingsCount(Attribute attribute)
Description copied from interface: RatingManager
Returns the number of ratings that have been added to the given attribute.

Only current ratings are taken into account, not historical ones.

Specified by:
getRatingsCount in interface RatingManager
Parameters:
attribute - the attribute for which the number of ratings shall be returned
Returns:
the number of ratings for the given attribute
See Also:
Rateable.getRatingsCount()

getRatingsCount

public int getRatingsCount(Topic topic)
Description copied from interface: RatingManager
Returns the number of ratings that have been added to the given topic.

Only current ratings are taken into account, not historical ones.

Specified by:
getRatingsCount in interface RatingManager
Parameters:
topic - the topic for which the number of ratings shall be returned
Returns:
the number of ratings for the given topic
See Also:
Rateable.getRatingsCount()

getRatingsCount

public int getRatingsCount(User user)
Description copied from interface: RatingManager
Returns the number of ratings that have been added by other users to the given user.

Only current ratings are taken into account, not historical ones.

Specified by:
getRatingsCount in interface RatingManager
Parameters:
user - the user for whom the number of ratings shall be returned
Returns:
the number of other user's ratings for the given user
See Also:
Rateable.getRatingsCount()

getAverageRatingValue

public double getAverageRatingValue(Association association)
Description copied from interface: RatingManager
Returns the average (arithmetic mean) of all ratings for the given association.

Only current ratings are taken into account, not historical ones.

Specified by:
getAverageRatingValue in interface RatingManager
Parameters:
association - the association for which the average rating value shall be computed
Returns:
the arithmetic mean of all ratings or Rating.NEUTRAL if the association isn't rated yet
See Also:
Rating.NEUTRAL, Rateable.getAverageRatingValue()

getAverageRatingValue

public double getAverageRatingValue(Attribute attribute)
Description copied from interface: RatingManager
Returns the average (arithmetic mean) of all ratings for the given attribute.

Only current ratings are taken into account, not historical ones.

Specified by:
getAverageRatingValue in interface RatingManager
Parameters:
attribute - the attribute for which the average rating value shall be computed
Returns:
the arithmetic mean of all ratings or Rating.NEUTRAL if the attribute isn't rated yet
See Also:
Rating.NEUTRAL, Rateable.getAverageRatingValue()

getAverageRatingValue

public double getAverageRatingValue(Topic topic)
Description copied from interface: RatingManager
Returns the average (arithmetic mean) of all ratings for the given topic.

Only current ratings are taken into account, not historical ones.

Specified by:
getAverageRatingValue in interface RatingManager
Parameters:
topic - the topic for which the average rating value shall be computed
Returns:
the arithmetic mean of all ratings or Rating.NEUTRAL if the topic isn't rated yet
See Also:
Rating.NEUTRAL, Rateable.getAverageRatingValue()

getAverageRatingValue

public double getAverageRatingValue(User user)
Description copied from interface: RatingManager
Returns the average (arithmetic mean) of all ratings that other users have added to the given user.

Only current ratings are taken into account, not historical ones.

Specified by:
getAverageRatingValue in interface RatingManager
Parameters:
user - the user for whom the average rating value shall be computed
Returns:
the arithmetic mean of all ratings or Rating.NEUTRAL if the user isn't rated yet
See Also:
Rating.NEUTRAL, Rateable.getAverageRatingValue()

addRating

public void addRating(Topic rated,
                      Rating rating)
               throws RatingManagerException,
                      DynamicRightsManagerException
Description copied from interface: RatingManager
Adds the given rating to the given topic.

The implementation must ensure that each rating can be added to one rateable element only, that each user can rate each topic only once and that historical ratings cannot be added at all.

Specified by:
addRating in interface RatingManager
Parameters:
rated - the topic to which the rating will be added
rating - the rating to be added
Throws:
DynamicRightsManagerException - if the user is not allowed to add the rating
RatingManagerException - if the rating cannot be added to the given topic
See Also:
Rating.isHistorical(), DynamicRightsManager.mayAddRating(Rating, Rateable), Rateable.addRating(User, double)

addRating

public void addRating(Attribute rated,
                      Rating rating)
               throws RatingManagerException,
                      DynamicRightsManagerException
Description copied from interface: RatingManager
Adds the given rating to the given attribute.

The implementation must ensure that each rating can be added to one rateable element only, that each user can rate each attribute only once and that historical ratings cannot be added at all.

Specified by:
addRating in interface RatingManager
Parameters:
rated - the attribute to which the rating will be added
rating - the rating to be added
Throws:
DynamicRightsManagerException - if the user is not allowed to add the rating
RatingManagerException - if the rating cannot be added to the given attribute
See Also:
Rating.isHistorical(), DynamicRightsManager.mayAddRating(Rating, Rateable), Rateable.addRating(User, double)

addRating

public void addRating(Association rated,
                      Rating rating)
               throws RatingManagerException,
                      DynamicRightsManagerException
Description copied from interface: RatingManager
Adds the given rating to the given association.

The implementation must ensure that each rating can be added to one rateable element only, that each user can rate each association only once and that historical ratings cannot be added at all.

Specified by:
addRating in interface RatingManager
Parameters:
rated - the association to which the rating will be added
rating - the rating to be added
Throws:
RatingManagerException - if the rating cannot be added to the given association
DynamicRightsManagerException - if the user is not allowed to add the rating
See Also:
Rating.isHistorical(), DynamicRightsManager.mayAddRating(Rating, Rateable), Rateable.addRating(User, double)

addRating

public void addRating(User rated,
                      Rating rating)
               throws RatingManagerException,
                      DynamicRightsManagerException
Description copied from interface: RatingManager
Adds the given rating to the given user.

The implementation must ensure that each rating can be added to one rateable element only, that each user can rate each other user only once and that historical ratings cannot be added at all.

Specified by:
addRating in interface RatingManager
Parameters:
rated - the user to which the rating will be added
rating - the rating to be added
Throws:
RatingManagerException - if the rating cannot be added to the given user
DynamicRightsManagerException - if the user (who created the rating) is not allowed to add the rating to the given user
See Also:
Rating.isHistorical(), DynamicRightsManager.mayAddRating(Rating, Rateable), Rateable.addRating(User, double)

deleteRatings

public void deleteRatings(Topic topic)
                   throws RatingManagerException
Description copied from interface: RatingManager
If a topic is deleted permanently from the ontology, this method can be used to remove the ratings that were added to the topic, too (including historical values).

This method will be used by the EvolutionManager.

Specified by:
deleteRatings in interface RatingManager
Parameters:
topic - the topic object for which the corresponding ratings shall be deleted
Throws:
RatingManagerException - if the ratings could not be deleted
See Also:
EvolutionManager.deleteTopic(User, Topic), EvolutionManager.deleteTopicAndSubtopics(User, Topic)

deleteRatings

public void deleteRatings(Attribute attribute)
                   throws RatingManagerException
Description copied from interface: RatingManager
If an attribute is deleted permanently from the ontology, this method can be used to remove the ratings that were added to the attribute, too (including historical values).

This method will be used by the EvolutionManager.

Specified by:
deleteRatings in interface RatingManager
Parameters:
attribute - the attribute object for which the corresponding ratings shall be deleted
Throws:
RatingManagerException - if the ratings could not be deleted
See Also:
EvolutionManager.deleteAttribute(User, Topic, Attribute)

deleteRatings

public void deleteRatings(Association association)
                   throws RatingManagerException
Description copied from interface: RatingManager
If an association is deleted permanently from the ontology, this method can be used to remove the ratings that were added to the association, too (including historical values).

This method will be used by the EvolutionManager.

Specified by:
deleteRatings in interface RatingManager
Parameters:
association - the association object for which the corresponding ratings shall be deleted
Throws:
RatingManagerException - if the ratings could not be deleted
See Also:
EvolutionManager.deleteAssociation(User, Association)

deleteRatings

public void deleteRatings(User user)
                   throws RatingManagerException
Description copied from interface: RatingManager
If a user is deleted permanently from the ontology and user database, this method can be used to remove the ratings that were added to the user, too (including historical values).

This method will be used by the UserManager.

Specified by:
deleteRatings in interface RatingManager
Parameters:
user - the user object for which the corresponding ratings shall be deleted
Throws:
RatingManagerException - if the ratings could not be deleted
See Also:
UserManager.deleteUser(User, String)

addRatingListener

public void addRatingListener(RatingListener listener)
Description copied from interface: RatingManager
Registers a new RatingListener.

Specified by:
addRatingListener in interface RatingManager
Parameters:
listener - the RatingListener to be added

removeRatingListener

public void removeRatingListener(RatingListener listener)
Description copied from interface: RatingManager
Removes a RatingListener, if it is registered with the RatingManager (otherwise this call is ignored).

Specified by:
removeRatingListener in interface RatingManager
Parameters:
listener - the RatingListener to be removed

getVersion

public String getVersion()
Description copied from interface: ConsensusFoundationModule
Returns a version string of the implementation of this module.

Specified by:
getVersion in interface ConsensusFoundationModule
Returns:
the version of the module's implementation