org.olat.core.commons.services.commentAndRating
Class UserRatingsManager

java.lang.Object
  extended by org.olat.core.logging.LogDelegator
      extended by org.olat.core.commons.services.commentAndRating.UserRatingsManager
Direct Known Subclasses:
UserRatingsManagerImpl

public abstract class UserRatingsManager
extends LogDelegator

Description:
The user ratings manager provides methods to rate any given OLATResourceable object. To use this manager, make sure a proper implementation for the bean 'org.olat.core.commons.services.commentAndRating.UserRatingsManager' is defined in the spring configuration.

Initial Date: 23.11.2009

Author:
gnaegi

Constructor Summary
UserRatingsManager()
           
 
Method Summary
abstract  java.lang.Float calculateRatingAverage()
           
abstract  java.lang.Long countRatings()
           
abstract  UserRating createRating(Identity creator, int ratingValue)
          Create a new rating for the configured resource
abstract  int deleteAllRatings()
          Delete all ratings for the configured resource and sub path
abstract  int deleteAllRatingsIgnoringSubPath()
          Delete all ratingsfor the configured resource while ignoring the sub path.
abstract  int deleteRating(UserRating rating)
          Delete a rating
static UserRatingsManager getInstance(OLATResourceable ores, java.lang.String subpath)
          Factory method to create a ratings manager for the given OLATResourceable.
abstract  UserRating getRating(Identity identity)
          Get the rating for the configured user
 void init(OLATResourceable ores, java.lang.String subpath)
          Helper method to set the olat resource for this manager
abstract  UserRating reloadRating(UserRating rating)
          Reload the given user rating with the most recent version from the database
abstract  UserRating updateRating(UserRating rating, int newRatingValue)
          Update a rating.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UserRatingsManager

public UserRatingsManager()
Method Detail

getInstance

public static final UserRatingsManager getInstance(OLATResourceable ores,
                                                   java.lang.String subpath)
Factory method to create a ratings manager for the given OLATResourceable. Note that this manager is statefully initialized with the OLATResourceable.

Parameters:
ores - The olat resourceable that provides a typename and a type id
subpath - an optional string that defines any subpath. Use this when your ores is not specific enough
Returns:

init

public void init(OLATResourceable ores,
                 java.lang.String subpath)
Helper method to set the olat resource for this manager

Parameters:
ores -
subpath -

countRatings

public abstract java.lang.Long countRatings()
Returns:
The number of ratings for the configured resource. 0 if no ratings are available.

calculateRatingAverage

public abstract java.lang.Float calculateRatingAverage()
Returns:
The average of ratings for the configured resource. 0 if no ratings are available.

createRating

public abstract UserRating createRating(Identity creator,
                                        int ratingValue)
Create a new rating for the configured resource

Parameters:
creator - The user who is rating
ratingValue - The rating
Returns:

getRating

public abstract UserRating getRating(Identity identity)
Get the rating for the configured user

Parameters:
identity -
Returns:
The users rating or NULL

reloadRating

public abstract UserRating reloadRating(UserRating rating)
Reload the given user rating with the most recent version from the database

Returns:
the reloaded user rating or NULL if the rating does not exist anymore

updateRating

public abstract UserRating updateRating(UserRating rating,
                                        int newRatingValue)
Update a rating. This will first reload the comment object and then update this new object to reduce stale object issues. Make sure you replace your object in your datamodel with the returned user comment object.

Parameters:
rating - The rating which should be updated
rewRatingValue - The updated rating value
Returns:
the updated rating object. Might be a different object than the rating given as attribute or NULL if the rating has been deleted in the meantime and could not be updated at all.

deleteRating

public abstract int deleteRating(UserRating rating)
Delete a rating

Parameters:
rating -
int - number of deleted ratings

deleteAllRatings

public abstract int deleteAllRatings()
Delete all ratings for the configured resource and sub path

Returns:
the number of deleted comments

deleteAllRatingsIgnoringSubPath

public abstract int deleteAllRatingsIgnoringSubPath()
Delete all ratingsfor the configured resource while ignoring the sub path. Use this to delete all ratings e.g. from a blog for all blog posts in one query

Returns: