1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.ratings

File RatingsManager.java

 

Code metrics

0
0
0
1
296
68
0
-
-
0
-

Classes

Class Line # Actions
RatingsManager 33 0 - 0 0
-1.0 -
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.ratings;
21   
22    import java.util.List;
23   
24    import org.xwiki.component.annotation.Role;
25    import org.xwiki.model.reference.DocumentReference;
26    import org.xwiki.model.reference.LocalDocumentReference;
27   
28    /**
29    * @version $Id: e023a330a2d110103ad816cfbdd08bcde478fd33 $
30    * @since 6.4M3
31    */
32    @Role
 
33    public interface RatingsManager
34    {
35    public static final String RATINGS_CLASSPAGE = "RatingsClass";
36   
37    public static final String RATINGS_CLASSNAME = "XWiki." + RATINGS_CLASSPAGE;
38   
39    public static final LocalDocumentReference RATINGS_CLASSREFERENCE = new LocalDocumentReference("XWiki",
40    RATINGS_CLASSPAGE);
41   
42    public static final String AVERAGE_RATINGS_CLASSPAGE = "AverageRatingsClass";
43   
44    public static final String AVERAGE_RATINGS_CLASSNAME = "XWiki." + AVERAGE_RATINGS_CLASSPAGE;
45   
46    public static final LocalDocumentReference AVERAGE_RATINGS_CLASSREFERENCE = new LocalDocumentReference("XWiki",
47    AVERAGE_RATINGS_CLASSPAGE);
48   
49    public static final String RATING_CLASS_FIELDNAME_DATE = "date";
50   
51    public static final String RATING_CLASS_FIELDNAME_AUTHOR = "author";
52   
53    public static final String RATING_CLASS_FIELDNAME_VOTE = "vote";
54   
55    public static final String RATING_CLASS_FIELDNAME_PARENT = "parent";
56   
57    public static final String AVERAGERATING_CLASS_FIELDNAME_NBVOTES = "nbvotes";
58   
59    public static final String AVERAGERATING_CLASS_FIELDNAME_AVERAGEVOTE = "averagevote";
60   
61    public static final String AVERAGERATING_CLASS_FIELDNAME_AVERAGEVOTE_METHOD = "method";
62   
63    public static final String RATING_REPUTATION_METHOD_BALANCED = "balanced";
64   
65    public static final String RATING_REPUTATION_METHOD_AVERAGE = "average";
66   
67    public static final String RATING_REPUTATION_METHOD_DEFAULT = "average";
68   
69    public static final String RATINGS_CONFIG_PARAM_PREFIX = "xwiki.ratings.";
70   
71    public static final String RATINGS_CONFIG_GLOBAL_PAGE = "XWiki.RatingsConfig";
72   
73    public static final LocalDocumentReference RATINGS_CONFIG_GLOBAL_REFERENCE = new LocalDocumentReference("XWiki",
74    "RatingsConfig");
75   
76    public static final String RATINGS_CONFIG_SPACE_PAGE = "WebPreferences";
77   
78    public static final LocalDocumentReference RATINGS_CONFIG_CLASSREFERENCE = new LocalDocumentReference("XWiki",
79    "RatingsConfigClass");
80   
81    public static final String RATINGS_CONFIG_CLASS_FIELDNAME_MANAGER_HINT = "managerHint";
82   
83    public static final String RATINGS_CONFIG_CLASS_FIELDNAME_STORAGE_SPACE = "storageSpace";
84   
85    public static final String RATINGS_CONFIG_CLASS_FIELDNAME_STORAGE_SEPARATE_SPACES = "storageSeparateSpaces";
86   
87    public static final String RATINGS_CONFIG_CLASS_FIELDNAME_STORE_AVERAGE_RATING = "storeAverageRating";
88   
89    public static final String RATINGS_CONFIG_CLASS_FIELDNAME_REPUTATION = "reputation";
90   
91    public static final String RATINGS_CONFIG_CLASS_FIELDNAME_REPUTATION_STORED = "reputationStored";
92   
93    public static final String RATINGS_CONFIG_CLASS_FIELDNAME_REPUTATION_METHOD = "reputationMethod";
94   
95    public static final String RATINGS_CONFIG_CLASS_FIELDNAME_REPUTATION_ALGORITHM_HINT = "reputationAlgorithmHint";
96   
97    public static final String RATINGS_CONFIG_CLASS_FIELDNAME_REPUTATION_CUSTOM_ALGORITHM = "reputationCustomAlgorithm";
98   
99    public static final String RATINGS_CONFIG_FIELDNAME_MANAGER_HINT = "managerHint";
100   
101    public static final String RATINGS_CONFIG_FIELDNAME_REPUTATIONALGORITHM_HINT = "reputationAlgorithmHint";
102   
103    /**
104    * Gets the ratings class.
105    *
106    * @return the XWiki document representing the RatingsClass
107    */
108    String getRatingsClassName();
109   
110    /**
111    * Gets a list of ratings
112    *
113    * @param documentRef the document to which the ratings belong to
114    * @param start the offset from where to fetch the ratings
115    * @param count how may ratings to fetch
116    * @param asc sort the results in ascending order or not
117    * @return a list of Rating objects
118    * @throws RatingsException when an error occurs while fetching the list of ratings
119    */
120    List<Rating> getRatings(DocumentReference documentRef, int start, int count, boolean asc) throws RatingsException;
121   
122    /**
123    * Gets a rating based on its id.
124    *
125    * @param ratingId the id of a certain rating
126    * @return a Rating object containing all the rating information
127    * @throws RatingsException when an error occurs while fetching the rating
128    */
129    Rating getRating(String ratingId) throws RatingsException;
130   
131    /**
132    * Gets a rating based on a document and the id of the rating.
133    *
134    * @param documentRef the document to which the rating belongs to
135    * @param id the id of a certain rating
136    * @return a Rating object containing all the rating information
137    * @throws RatingsException when an error occurs while fetching the rating
138    */
139    Rating getRating(DocumentReference documentRef, int id) throws RatingsException;
140   
141    /**
142    * Gets a rating based on a document and user.
143    *
144    * @param documentRef the document to which the rating belongs to
145    * @param user the author of the rating
146    * @return a Rating object containing all the rating information
147    * @throws RatingsException when an error occurs while fetching the rating
148    */
149    Rating getRating(DocumentReference documentRef, DocumentReference user) throws RatingsException;
150   
151    /**
152    * Sets a rating based on a document, user and vote.
153    *
154    * @param documentRef the document to which the rating belongs to
155    * @param author the author of the rating
156    * @param vote the author's vote
157    * @return a Rating object containing all the rating information
158    * @throws RatingsException when an error occurs while setting the rating
159    */
160    Rating setRating(DocumentReference documentRef, DocumentReference author, int vote) throws RatingsException;
161   
162    /**
163    * Removes a rating.
164    *
165    * @param rating the rating to be removed
166    * @return whether the action was successful or not
167    * @throws RatingsException when an error occurs while removing the rating
168    */
169    boolean removeRating(Rating rating) throws RatingsException;
170   
171    /**
172    * Checks if the average rating stored in the rated document as an object or is it kept in memory.
173    *
174    * @return answer to: is the average rating stored?
175    */
176    boolean isAverageRatingStored(DocumentReference documentRef);
177   
178    /**
179    * Checks if the user reputation stored in a document or is it kept in memory.
180    *
181    * @return answer to: is user reputation kept in memory?
182    */
183    boolean isReputationStored(DocumentReference documentRef);
184   
185    /**
186    * Checks if to calculate the user reputation or not.
187    *
188    * @return answer to: calculate the user reputation or not?
189    */
190    boolean hasReputation(DocumentReference documentRef);
191   
192    /**
193    * Gets or calculates the user reputation.
194    *
195    * @param username person to calculate the reputation for
196    * @return AverageRating of the voter
197    */
198    AverageRating getUserReputation(DocumentReference username) throws ReputationException;
199   
200    /**
201    * Updates user reputation.
202    *
203    * @param author the user for which to update the reputation
204    * @param voterRating the users current reputation
205    */
206    void updateUserReputation(DocumentReference author, AverageRating voterRating) throws RatingsException;
207   
208    /**
209    * Gets the default methods of calculating the user reputation.
210    *
211    * @return the default methods of calculating the user reputation
212    */
213    String[] getDefaultReputationMethods(DocumentReference documentRef);
214   
215    /**
216    * Gets the average rating for a document using the default average rating calculation method.
217    *
218    * @param documentRef the document for which to calculate the average rating
219    * @return the calculated average rating
220    * @throws RatingsException when an error occurs while fetching the average rating
221    */
222    AverageRating getAverageRating(DocumentReference documentRef) throws RatingsException;
223   
224    /**
225    * Gets the average rating calculated by the specified method.
226    *
227    * @param documentRef the document for which to get the average rating
228    * @param method the method of calculating the average rating
229    * @throws RatingsException when encountering an error while fetching the average rating
230    */
231    AverageRating getAverageRating(DocumentReference documentRef, String method) throws RatingsException;
232   
233    /**
234    * Gets the average rating with the option to store it if it's not yet stored.
235    *
236    * @param documentRef the document for which to get the average rating
237    * @param method the method of calculating the average rating
238    * @param create create the average rating object on the rated document if stored ratings is active
239    * @throws RatingsException when encountering an error while fetching the average rating
240    */
241    AverageRating getAverageRating(DocumentReference documentRef, String method, boolean create)
242    throws RatingsException;
243   
244    /**
245    * Gets the average rating for a SQL query.
246    *
247    * @param fromsql the from clause of the SQL query
248    * @param wheresql the where clause of the SQL query
249    * @return the calculated average rating
250    * @throws RatingsException when an error occurs while fetching the average rating
251    */
252    AverageRating getAverageRatingFromQuery(String fromsql, String wheresql) throws RatingsException;
253   
254    /**
255    * Gets the average rating for a SQL query with specifying the average rating calculation method.
256    *
257    * @param fromsql the from clause of the SQL query
258    * @param wheresql the where clause of the SQL query
259    * @param method the method used to calculate the average rating
260    * @return the calculated average rating
261    * @throws RatingsException when an error occurs while fetching the average rating
262    */
263    AverageRating getAverageRatingFromQuery(String fromsql, String wheresql, String method) throws RatingsException;
264   
265    /**
266    * Calculates the average rating.
267    *
268    * @param documentRef the document for which to calculate the average rating
269    * @param method the method of calculating the average rating
270    * @return the calculated average rating
271    * @throws RatingsException when an error occurs while calculating the average rating
272    */
273    AverageRating calcAverageRating(DocumentReference documentRef, String method) throws RatingsException;
274   
275    /**
276    * Updates the average rating. This is done only if the average rating is stored.
277    *
278    * @param documentRef the document for which to update the average rating
279    * @param rating the new rating which was performed
280    * @param oldVote the value of the old rating
281    * @param method the method of calculating the average rating
282    * @throws RatingsException when an error occurred while updating the average rating
283    */
284    void updateAverageRating(DocumentReference documentRef, Rating rating, int oldVote, String method)
285    throws RatingsException;
286   
287    /**
288    * Updates the average rating of a document.
289    *
290    * @param documentRef the document being rated
291    * @param rating the new rating
292    * @param oldVote the old vote
293    * @throws RatingsException when an error occurs while updating the average rating
294    */
295    void updateAverageRatings(DocumentReference documentRef, Rating rating, int oldVote) throws RatingsException;
296    }