1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.extension.script; |
21 |
|
|
22 |
|
import java.util.Collection; |
23 |
|
|
24 |
|
import javax.inject.Inject; |
25 |
|
import javax.inject.Named; |
26 |
|
import javax.inject.Singleton; |
27 |
|
|
28 |
|
import org.xwiki.component.annotation.Component; |
29 |
|
import org.xwiki.extension.ExtensionId; |
30 |
|
import org.xwiki.extension.ResolveException; |
31 |
|
import org.xwiki.extension.rating.ExtensionRating; |
32 |
|
import org.xwiki.extension.repository.ExtensionRepository; |
33 |
|
import org.xwiki.extension.repository.ExtensionRepositoryManager; |
34 |
|
import org.xwiki.extension.repository.rating.Ratable; |
35 |
|
import org.xwiki.extension.version.Version; |
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
@version |
41 |
|
@since |
42 |
|
|
43 |
|
@Component |
44 |
|
@Named(ExtensionManagerScriptService.ROLEHINT + '.' + ExtensionRatingScriptService.ID) |
45 |
|
@Singleton |
|
|
| 0% |
Uncovered Elements: 27 (27) |
Complexity: 8 |
Complexity Density: 0.38 |
|
46 |
|
public class ExtensionRatingScriptService extends AbstractExtensionScriptService |
47 |
|
{ |
48 |
|
|
49 |
|
@link |
50 |
|
|
51 |
|
public static final String ID = "rating"; |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
@Inject |
57 |
|
private ExtensionRepositoryManager repositoryManager; |
58 |
|
|
59 |
|
|
60 |
|
@return |
61 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
62 |
0 |
private Collection<ExtensionRepository> getRepositories()... |
63 |
|
{ |
64 |
0 |
return this.repositoryManager.getRepositories(); |
65 |
|
} |
66 |
|
|
67 |
|
|
68 |
|
@param |
69 |
|
@return |
70 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
71 |
0 |
public ExtensionRating getRating(ExtensionId extensionId)... |
72 |
|
{ |
73 |
0 |
setError(null); |
74 |
|
|
75 |
0 |
try { |
76 |
0 |
return getRating(extensionId.getId(), extensionId.getVersion()); |
77 |
|
} catch (Exception e) { |
78 |
0 |
setError(e); |
79 |
|
} |
80 |
|
|
81 |
0 |
return null; |
82 |
|
} |
83 |
|
|
84 |
|
|
85 |
|
@param |
86 |
|
@param |
87 |
|
@return |
88 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
89 |
0 |
public ExtensionRating getRating(String extensionId, Version extensionVersion)... |
90 |
|
{ |
91 |
0 |
setError(null); |
92 |
|
|
93 |
0 |
try { |
94 |
0 |
return getRating(extensionId, extensionVersion.getValue()); |
95 |
|
} catch (Exception e) { |
96 |
0 |
setError(e); |
97 |
|
} |
98 |
|
|
99 |
0 |
return null; |
100 |
|
} |
101 |
|
|
102 |
|
|
103 |
|
@param |
104 |
|
@param |
105 |
|
@return |
106 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0.3 |
|
107 |
0 |
public ExtensionRating getRating(String extensionId, String extensionVersion)... |
108 |
|
{ |
109 |
0 |
setError(null); |
110 |
|
|
111 |
0 |
Collection<ExtensionRepository> repositories = getRepositories(); |
112 |
0 |
for (ExtensionRepository repository : repositories) { |
113 |
0 |
if (repository instanceof Ratable) { |
114 |
0 |
try { |
115 |
0 |
setError(null); |
116 |
0 |
return ((Ratable) repository).getRating(extensionId, extensionVersion); |
117 |
|
} catch (ResolveException e) { |
118 |
0 |
setError(e); |
119 |
|
|
120 |
0 |
continue; |
121 |
|
} |
122 |
|
} |
123 |
|
} |
124 |
|
|
125 |
0 |
return null; |
126 |
|
} |
127 |
|
} |