@Role
@Unstable
public interface RatingsManager
Modifier and Type | Interface and Description |
---|---|
static class |
RatingsManager.RatingQueryField
The fields to be used for performing queries on Ratings.
|
Modifier and Type | Method and Description |
---|---|
long |
countRatings(Map<RatingsManager.RatingQueryField,Object> queryParameters)
Retrieve the number of ratings matching the given parameters but without retrieving them directly.
|
AverageRating |
getAverageRating(org.xwiki.model.reference.EntityReference entityReference)
Retrieve the average rating information of the given reference.
|
String |
getIdentifier() |
RatingsConfiguration |
getRatingConfiguration() |
List<Rating> |
getRatings(Map<RatingsManager.RatingQueryField,Object> queryParameters,
int offset,
int limit,
RatingsManager.RatingQueryField orderBy,
boolean asc)
Retrieve the list of ratings based on the given query parameters.
|
int |
getScale() |
long |
moveRatings(org.xwiki.model.reference.EntityReference oldReference,
org.xwiki.model.reference.EntityReference newReference)
Update all ratings concerning the given reference to point to the new reference.
|
AverageRating |
recomputeAverageRating(org.xwiki.model.reference.EntityReference entityReference)
Compute back the average rating for all the ratings existing for the given reference.
|
boolean |
removeRating(String ratingIdentifier)
Remove a rating based on its identifier.
|
long |
removeRatings(org.xwiki.model.reference.EntityReference entityReference)
Remove all ratings concerning the given reference.
|
Rating |
saveRating(org.xwiki.model.reference.EntityReference reference,
org.xwiki.user.UserReference user,
int vote)
Save and return a
Rating information. |
void |
saveRating(Rating rating)
This method performs a direct save of the rating specified in parameter.
|
void |
setIdentifier(String identifier)
Allows to set the identifier of the manager.
|
void |
setRatingConfiguration(RatingsConfiguration configuration)
Allows to set the configuration of the manager.
|
String getIdentifier()
void setIdentifier(String identifier)
RatingsManagerFactory
.identifier
- the identifier to be set.int getScale()
void setRatingConfiguration(RatingsConfiguration configuration)
RatingsManagerFactory
.configuration
- the configuration to be set.RatingsConfiguration getRatingConfiguration()
Rating saveRating(org.xwiki.model.reference.EntityReference reference, org.xwiki.user.UserReference user, int vote) throws RatingsException
Rating
information.
If an existing rating has already been saved by the same user on the same reference, then this method updates the
existing value.
This method should check that the given vote matches the scale of the manager.
It should also take into account the RatingsConfiguration.isZeroStored()
configuration to handle case when
the vote is equal to 0. The method returns null if the vote is equal to 0 and the configuration doesn't allow
to store it, but it might perform storage side effect (such as removing a previous Rating
information).
This method also handles the computation of AverageRating
if the
RatingsConfiguration.isAverageStored()
configuration is set to true.
Note that this method should also handle sending the appropriate
CreatedRatingEvent
and UpdatedRatingEvent
.reference
- the entity for which to save a rating value.user
- the user who performs the rating.vote
- the actual vote to be saved.RatingsException
- in case of problem for saving the rating.List<Rating> getRatings(Map<RatingsManager.RatingQueryField,Object> queryParameters, int offset, int limit, RatingsManager.RatingQueryField orderBy, boolean asc) throws RatingsException
String.valueOf(Object)
. Only the ratings of the current manager are
retrieved even if the store is shared.queryParameters
- the map of parameters to rely on for query the ratings.offset
- the offset where to start getting results.limit
- the limit number of results to retrieve.orderBy
- the field to use for sorting the results.asc
- if true
, use ascending order for sorting, else use descending order.limit
ratings results.RatingsException
- in case of problem for querying the ratings.long countRatings(Map<RatingsManager.RatingQueryField,Object> queryParameters) throws RatingsException
String.valueOf(Object)
. Only the ratings of the current manager are
retrieved even if the store is shared.queryParameters
- the map of parameters to rely on for query the ratings.RatingsException
- in case of problem during the query.boolean removeRating(String ratingIdentifier) throws RatingsException
AverageRating
if the
RatingsConfiguration.isAverageStored()
is enabled.ratingIdentifier
- the identifier of the rating to remove.true
if a rating is deleted, false
if no rating with the given identifier can be found.RatingsException
- in case of problem during the query.long removeRatings(org.xwiki.model.reference.EntityReference entityReference) throws RatingsException
entityReference
- the reference used as a criteria for filtering ratings reference or parents.RatingsException
- in case of problem during the query.@Unstable long moveRatings(org.xwiki.model.reference.EntityReference oldReference, org.xwiki.model.reference.EntityReference newReference) throws RatingsException
oldReference
- the old reference to be updated.newReference
- the new reference.RatingsException
- in case of problem during the query.AverageRating getAverageRating(org.xwiki.model.reference.EntityReference entityReference) throws RatingsException
entityReference
- the reference for which to retrieve the average rating information.RatingsException
- in case of problem during the query.void saveRating(Rating rating) throws RatingsException
RatingsConfiguration.isZeroStored()
option and does not
compute back the average. Finally no event is triggered when using this method.
For those to be taken into account, please check saveRating(EntityReference, UserReference, int)
.rating
- a rating object to be saved.RatingsException
AverageRating recomputeAverageRating(org.xwiki.model.reference.EntityReference entityReference) throws RatingsException
entityReference
- the reference for which to compute back the ratings.RatingsException
- in case of errors.Copyright © 2004–2021 XWiki. All rights reserved.