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

File StoredAverageRating.java

 

Coverage histogram

../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

0
12
8
1
103
59
9
0.75
1.5
8
1.12

Classes

Class Line # Actions
StoredAverageRating 36 12 0% 9 20
0.00%
 

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.internal;
21   
22    import org.xwiki.ratings.AverageRating;
23    import org.xwiki.ratings.RatingsException;
24    import org.xwiki.ratings.RatingsManager;
25   
26    import com.xpn.xwiki.XWikiContext;
27    import com.xpn.xwiki.XWikiException;
28    import com.xpn.xwiki.doc.XWikiDocument;
29    import com.xpn.xwiki.objects.BaseObject;
30   
31    /**
32    * @version $Id: 6b4d70ba79e539122174b32bcbc4e19f043367f4 $
33    * @see AverageRating
34    * @since 6.4M3
35    */
 
36    public class StoredAverageRating implements AverageRating
37    {
38    private XWikiDocument document;
39   
40    private BaseObject object;
41   
42    private XWikiContext context;
43   
44    /**
45    * StoredAverageRating constructor.
46    *
47    * @param document the document with which the rating is associated
48    * @param ratingObject the Rating object
49    * @param context the context
50    */
 
51  0 toggle public StoredAverageRating(XWikiDocument document, BaseObject ratingObject, XWikiContext context)
52    {
53  0 this.document = document;
54  0 this.context = context;
55  0 this.object = ratingObject;
56    }
57   
 
58  0 toggle @Override
59    public int getNbVotes()
60    {
61  0 return object.getIntValue(RatingsManager.AVERAGERATING_CLASS_FIELDNAME_NBVOTES);
62    }
63   
 
64  0 toggle @Override
65    public void setNbVotes(int nbVotes)
66    {
67  0 object.setIntValue(RatingsManager.AVERAGERATING_CLASS_FIELDNAME_NBVOTES, nbVotes);
68    }
69   
 
70  0 toggle @Override
71    public float getAverageVote()
72    {
73  0 return object.getFloatValue(RatingsManager.AVERAGERATING_CLASS_FIELDNAME_AVERAGEVOTE);
74    }
75   
 
76  0 toggle @Override
77    public void setAverageVote(float averageVote)
78    {
79  0 object.setFloatValue(RatingsManager.AVERAGERATING_CLASS_FIELDNAME_AVERAGEVOTE, averageVote);
80    }
81   
 
82  0 toggle @Override
83    public String getMethod()
84    {
85  0 return object.getStringValue(RatingsManager.AVERAGERATING_CLASS_FIELDNAME_AVERAGEVOTE_METHOD);
86    }
87   
 
88  0 toggle @Override
89    public void setMethod(String method)
90    {
91  0 object.setStringValue(RatingsManager.AVERAGERATING_CLASS_FIELDNAME_AVERAGEVOTE_METHOD, method);
92    }
93   
 
94  0 toggle @Override
95    public void save() throws RatingsException
96    {
97  0 try {
98  0 context.getWiki().saveDocument(document, "Update rating", true, context);
99    } catch (XWikiException e) {
100  0 throw new RatingsException(e);
101    }
102    }
103    }