Class ScriptRatingService

All Implemented Interfaces:
org.alfresco.processor.ProcessorExtension, Scopeable

public class ScriptRatingService extends BaseScopableProcessorExtension
Script object representing the rating service.
Since:
3.4
Author:
Neil McErlean
  • Constructor Details

    • ScriptRatingService

      public ScriptRatingService()
  • Method Details

    • setServiceRegistry

      public void setServiceRegistry(ServiceRegistry serviceRegistry)
      Set the service registry
      Parameters:
      serviceRegistry - the service registry.
    • getRatingSchemeNames

      public String[] getRatingSchemeNames()
      Gets the names for rating schemes currently in the system.
      Returns:
      String[]
    • getMin

      public float getMin(String ratingSchemeName)
      Gets the minimum allowed rating for the specified rating scheme.
      Parameters:
      ratingSchemeName - String
      Returns:
      float
    • getMax

      public float getMax(String ratingSchemeName)
      Gets the maximum allowed rating for the specified rating scheme.
      Parameters:
      ratingSchemeName - String
      Returns:
      float
    • isSelfRatingAllowed

      public boolean isSelfRatingAllowed(String ratingSchemeName)
      This method checks whether self-rating is allowed for the specified rating scheme. If self-rating is allowed in the specified scheme, then the cm:creator of a node can apply a rating, otherwise they cannot.
      Parameters:
      ratingSchemeName - the rating scheme bean name.
      Returns:
      true if users can rate their own content, else false.
    • applyRating

      public void applyRating(ScriptNode node, float rating, String ratingSchemeName)
      Applies the given rating to the specified node using the specified ratingScheme. It is the responsibility of the caller to ensure that the rating scheme exists and that the rating is within the limits defined for that scheme.

      Furthermore, only one rating scheme per user per target node is supported. Any attempt by one user to apply a second rating in a different scheme will result in a RatingServiceException.

      Parameters:
      node - ScriptNode
      rating - float
      ratingSchemeName - String
      Throws:
      RatingServiceException
      See Also:
    • removeRating

      public void removeRating(ScriptNode node, String ratingSchemeName)
      Removes any rating by the current user in the specified scheme from the specified noderef.
      Parameters:
      node - ScriptNode
      ratingSchemeName - String
    • getRating

      public float getRating(ScriptNode node, String ratingSchemeName)
      Gets the rating applied to the specified node in the specified scheme by the currently authenticated user.
      Parameters:
      node - ScriptNode
      ratingSchemeName - String
      Returns:
      rating if there is one, else -1. TODO -1 could be a valid rating.
    • getRatingAppliedAt

      public Date getRatingAppliedAt(ScriptNode node, String ratingSchemeName)
      Gets the rating applied date for the specified node in the specified scheme by the currently authenticated user.
      Parameters:
      node - ScriptNode
      ratingSchemeName - String
      Returns:
      rating applied date if there is one, else null
    • getRatingsCount

      public int getRatingsCount(ScriptNode node, String ratingSchemeName)
      Gets the number of ratings applied to the specified node by all users in the specified scheme.
      Parameters:
      node - ScriptNode
      ratingSchemeName - String
      Returns:
      int
    • getTotalRating

      public float getTotalRating(ScriptNode node, String ratingSchemeName)
      Gets the total (sum) rating by all users on the specified node in the specified scheme.
      Parameters:
      node - ScriptNode
      ratingSchemeName - String
      Returns:
      float
    • getAverageRating

      public float getAverageRating(ScriptNode node, String ratingSchemeName)
      Gets the average (mean) rating by all users on the specified node in the specified scheme.
      Parameters:
      node - ScriptNode
      ratingSchemeName - * @param ratingSchemeName String
      Returns:
      float