1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.ratings; |
21 |
|
|
22 |
|
import javax.inject.Inject; |
23 |
|
import javax.inject.Singleton; |
24 |
|
|
25 |
|
import org.slf4j.Logger; |
26 |
|
import org.xwiki.component.annotation.Component; |
27 |
|
import org.xwiki.component.manager.ComponentLookupException; |
28 |
|
import org.xwiki.component.manager.ComponentManager; |
29 |
|
import org.xwiki.context.Execution; |
30 |
|
import org.xwiki.model.reference.DocumentReference; |
31 |
|
|
32 |
|
import com.xpn.xwiki.XWiki; |
33 |
|
import com.xpn.xwiki.XWikiContext; |
34 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
35 |
|
import com.xpn.xwiki.objects.BaseProperty; |
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
@version |
41 |
|
@since |
42 |
|
|
43 |
|
@Component |
44 |
|
@Singleton |
45 |
|
|
|
|
| 69.2% |
Uncovered Elements: 8 (26) |
Complexity: 10 |
Complexity Density: 0.59 |
|
46 |
|
public class ConfiguredRatingsManagerProvider implements ConfiguredProvider<RatingsManager> |
47 |
|
{ |
48 |
|
@Inject |
49 |
|
private Logger logger; |
50 |
|
|
51 |
|
@Inject |
52 |
|
private Execution execution; |
53 |
|
|
54 |
|
@Inject |
55 |
|
private ComponentManager componentManager; |
56 |
|
|
57 |
|
@Inject |
58 |
|
private RatingsConfiguration ratingsConfiguration; |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
@return |
64 |
|
@throws |
65 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
66 |
12 |
protected XWikiContext getXWikiContext()... |
67 |
|
{ |
68 |
12 |
return (XWikiContext) execution.getContext().getProperty("xwikicontext"); |
69 |
|
} |
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
@return |
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
76 |
12 |
protected XWiki getXWiki()... |
77 |
|
{ |
78 |
12 |
return getXWikiContext().getWiki(); |
79 |
|
} |
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
@param |
86 |
|
@return |
87 |
|
|
|
|
| 61.9% |
Uncovered Elements: 8 (21) |
Complexity: 8 |
Complexity Density: 0.53 |
|
88 |
12 |
@Override... |
89 |
|
public RatingsManager get(DocumentReference documentRef) |
90 |
|
{ |
91 |
12 |
String defaultHint = "default"; |
92 |
12 |
String ratingsHint = |
93 |
|
getXWiki().Param( |
94 |
|
RatingsManager.RATINGS_CONFIG_PARAM_PREFIX + RatingsManager.RATINGS_CONFIG_FIELDNAME_MANAGER_HINT, |
95 |
|
defaultHint); |
96 |
|
|
97 |
12 |
try { |
98 |
12 |
XWikiDocument configurationDocument = ratingsConfiguration.getConfigurationDocument(documentRef); |
99 |
12 |
if (!configurationDocument.isNew() |
100 |
|
&& configurationDocument.getXObject(RatingsManager.RATINGS_CONFIG_CLASSREFERENCE) != null) { |
101 |
12 |
BaseProperty prop = |
102 |
|
(BaseProperty) configurationDocument.getXObject(RatingsManager.RATINGS_CONFIG_CLASSREFERENCE).get( |
103 |
|
RatingsManager.RATINGS_CONFIG_CLASS_FIELDNAME_MANAGER_HINT); |
104 |
12 |
String hint = (prop == null) ? null : (String) prop.getValue(); |
105 |
12 |
ratingsHint = (hint == null) ? ratingsHint : hint; |
106 |
|
} |
107 |
|
} catch (Exception e) { |
108 |
0 |
logger.error("Cannot read ratings config", e); |
109 |
|
} |
110 |
|
|
111 |
12 |
try { |
112 |
12 |
return componentManager.getInstance(RatingsManager.class, ratingsHint); |
113 |
|
} catch (ComponentLookupException e) { |
114 |
|
|
115 |
0 |
logger.error("Error loading ratings manager component for hint " + ratingsHint, e); |
116 |
0 |
try { |
117 |
0 |
return componentManager.getInstance(RatingsManager.class, defaultHint); |
118 |
|
} catch (ComponentLookupException e1) { |
119 |
0 |
return null; |
120 |
|
} |
121 |
|
} |
122 |
|
} |
123 |
|
} |