Class LikeScriptService

java.lang.Object
org.xwiki.like.script.LikeScriptService
All Implemented Interfaces:
org.xwiki.script.service.ScriptService

@Component @Singleton @Named("like") public class LikeScriptService extends Object implements org.xwiki.script.service.ScriptService
Script service for manipulating Like informations.
Since:
12.7RC1
Version:
$Id: 57644d90838603a88197a6f698a0582febdf4d0c $
  • Constructor Details

    • LikeScriptService

      public LikeScriptService()
  • Method Details

    • isAuthorized

      public boolean isAuthorized(EntityReference entityReference)
      Check if current user is allowed to use Like on the given reference. Note that we explicitely deny the right for guests.
      Parameters:
      entityReference - the reference on which to use like.
      Returns:
      true only if current user is not guest and has Like right on the reference.
    • displayButton

      public boolean displayButton(EntityReference entityReference)
      Check if the display button should be displayed: should be true if the like feature is enabled (see LikeConfiguration.isEnabled()) and if current user is authorized to use like (see isAuthorized(EntityReference)) or if the configuration is set to always display it (see LikeConfiguration.alwaysDisplayButton()).
      Parameters:
      entityReference - the reference for which to display the button
      Returns:
      true only if the button should be displayed.
    • isEnabled

      public boolean isEnabled()
      Returns:
      true if the Like feature is enabled.
      Since:
      13.1RC1
    • like

      public Optional<Long> like(EntityReference entityReference)
      Perform a like on the given reference with the current user, only if allowed.
      Parameters:
      entityReference - the reference on which to perform a like.
      Returns:
      the new number of likes if the operation succeeded, else return an empty optional.
    • unlike

      public Optional<Long> unlike(EntityReference entityReference)
      Perform a unlike on the given reference with the current user, only if allowed.
      Parameters:
      entityReference - the reference on which to perform a like.
      Returns:
      the new number of likes if the operation succeeded, else return an empty optional.
    • getLikes

      public Optional<Long> getLikes(EntityReference entityReference)
      Retrieve like information for the given reference.
      Parameters:
      entityReference - the reference for which to retrieve like information.
      Returns:
      the number of likes, or an empty optional in case of problem.
    • getUserLikes

      public List<EntityReference> getUserLikes(UserReference userReference, int offset, int limit)
      Retrieve likes performed by the given user.
      Parameters:
      userReference - the user for whom to retrieve likes.
      offset - the offset used for pagination.
      limit - the limit used for pagination.
      Returns:
      a list of liked references.
    • countUserLikes

      public Optional<Long> countUserLikes(UserReference userReference)
      Count the number of likes performed by the given user.
      Parameters:
      userReference - the user for whom to count likes.
      Returns:
      the number of likes performed.
      Since:
      12.9RC1
    • isLiked

      public boolean isLiked(EntityReference entityReference)
      Determine if the current user already liked the given reference.
      Parameters:
      entityReference - the reference for which to check if the current liked it or not already.
      Returns:
      true if the entity has been already liked.
    • getLikers

      public List<UserReference> getLikers(EntityReference target, int offset, int limit)
      Return the likers of a reference.
      Parameters:
      target - the reference being liked.
      offset - the start offset for pagination.
      limit - the limit of results for pagination.
      Returns:
      a list of user references who liked the reference.
      Since:
      12.8RC1