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
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void applyRating​(ScriptNode node, float rating, java.lang.String ratingSchemeName)
      Applies the given rating to the specified node using the specified ratingScheme.
      float getAverageRating​(ScriptNode node, java.lang.String ratingSchemeName)
      Gets the average (mean) rating by all users on the specified node in the specified scheme.
      float getMax​(java.lang.String ratingSchemeName)
      Gets the maximum allowed rating for the specified rating scheme.
      float getMin​(java.lang.String ratingSchemeName)
      Gets the minimum allowed rating for the specified rating scheme.
      float getRating​(ScriptNode node, java.lang.String ratingSchemeName)
      Gets the rating applied to the specified node in the specified scheme by the currently authenticated user.
      java.util.Date getRatingAppliedAt​(ScriptNode node, java.lang.String ratingSchemeName)
      Gets the rating applied date for the specified node in the specified scheme by the currently authenticated user.
      java.lang.String[] getRatingSchemeNames()
      Gets the names for rating schemes currently in the system.
      int getRatingsCount​(ScriptNode node, java.lang.String ratingSchemeName)
      Gets the number of ratings applied to the specified node by all users in the specified scheme.
      float getTotalRating​(ScriptNode node, java.lang.String ratingSchemeName)
      Gets the total (sum) rating by all users on the specified node in the specified scheme.
      boolean isSelfRatingAllowed​(java.lang.String ratingSchemeName)
      This method checks whether self-rating is allowed for the specified rating scheme.
      void removeRating​(ScriptNode node, java.lang.String ratingSchemeName)
      Removes any rating by the current user in the specified scheme from the specified noderef.
      void setServiceRegistry​(ServiceRegistry serviceRegistry)
      Set the service registry
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ScriptRatingService

        public ScriptRatingService()
    • Method Detail

      • setServiceRegistry

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

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

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

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

        public boolean isSelfRatingAllowed​(java.lang.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,
                                java.lang.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:
        getMin(String), getMax(String)
      • removeRating

        public void removeRating​(ScriptNode node,
                                 java.lang.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,
                               java.lang.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 java.util.Date getRatingAppliedAt​(ScriptNode node,
                                                 java.lang.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,
                                   java.lang.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,
                                    java.lang.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,
                                      java.lang.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