1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.ratings.internal; |
21 |
|
|
22 |
|
import javax.inject.Inject; |
23 |
|
import javax.inject.Named; |
24 |
|
import javax.inject.Singleton; |
25 |
|
|
26 |
|
import org.xwiki.bridge.event.DocumentUpdatingEvent; |
27 |
|
import org.xwiki.component.annotation.Component; |
28 |
|
import org.xwiki.observation.AbstractEventListener; |
29 |
|
import org.xwiki.observation.ObservationContext; |
30 |
|
import org.xwiki.observation.event.Event; |
31 |
|
import org.xwiki.ratings.RatingsManager; |
32 |
|
import org.xwiki.ratings.UpdatingRatingEvent; |
33 |
|
|
34 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
35 |
|
import com.xpn.xwiki.objects.BaseObject; |
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
@version |
41 |
|
@since |
42 |
|
|
43 |
|
@Component |
44 |
|
@Singleton |
45 |
|
@Named("AverageRatingProtectionListener") |
|
|
| 41.2% |
Uncovered Elements: 10 (17) |
Complexity: 5 |
Complexity Density: 0.56 |
|
46 |
|
public class AverageRatingProtectionListener extends AbstractEventListener |
47 |
|
{ |
48 |
|
private static final UpdatingRatingEvent PARENT = new UpdatingRatingEvent(); |
49 |
|
|
50 |
|
@Inject |
51 |
|
private ObservationContext observationContext; |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
56 |
2 |
public AverageRatingProtectionListener()... |
57 |
|
{ |
58 |
2 |
super("AverageRatingProtectionListener", new DocumentUpdatingEvent()); |
59 |
|
} |
60 |
|
|
|
|
| 28.6% |
Uncovered Elements: 10 (14) |
Complexity: 4 |
Complexity Density: 0.5 |
|
61 |
41 |
@Override... |
62 |
|
public void onEvent(Event event, Object source, Object data) |
63 |
|
{ |
64 |
41 |
XWikiDocument document = (XWikiDocument) source; |
65 |
41 |
BaseObject ratingObject = document.getXObject(RatingsManager.AVERAGE_RATINGS_CLASSREFERENCE); |
66 |
|
|
67 |
41 |
if (ratingObject != null) { |
68 |
|
|
69 |
0 |
if (!this.observationContext.isIn(PARENT)) { |
70 |
0 |
XWikiDocument previousDocument = document.getOriginalDocument(); |
71 |
0 |
BaseObject previousObject = previousDocument.getXObject(RatingsManager.AVERAGE_RATINGS_CLASSREFERENCE); |
72 |
|
|
73 |
0 |
if (previousObject != null) { |
74 |
0 |
ratingObject.apply(previousObject, true); |
75 |
|
} |
76 |
|
} |
77 |
|
} |
78 |
|
} |
79 |
|
} |