1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package com.xpn.xwiki.plugin.rightsmanager; |
22 |
|
|
23 |
|
import java.text.MessageFormat; |
24 |
|
import java.util.Collection; |
25 |
|
import java.util.Collections; |
26 |
|
import java.util.List; |
27 |
|
import java.util.Map; |
28 |
|
|
29 |
|
import org.slf4j.Logger; |
30 |
|
import org.slf4j.LoggerFactory; |
31 |
|
|
32 |
|
import com.xpn.xwiki.XWikiContext; |
33 |
|
import com.xpn.xwiki.XWikiException; |
34 |
|
import com.xpn.xwiki.plugin.PluginApi; |
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
@version |
40 |
|
@since |
41 |
|
@since |
42 |
|
|
|
|
| 37.8% |
Uncovered Elements: 56 (90) |
Complexity: 26 |
Complexity Density: 0.41 |
|
43 |
|
public class RightsManagerPluginApi extends PluginApi<RightsManagerPlugin> |
44 |
|
{ |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
public static final String CONTEXT_LASTERRORCODE = "lasterrorcode"; |
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
public static final String CONTEXT_LASTEXCEPTION = "lastexception"; |
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
protected static final Logger LOGGER = LoggerFactory.getLogger(RightsManagerPluginApi.class); |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
private RightsManagerRightsApi rightsApi; |
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
private RightsManagerUsersApi usersApi; |
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
private RightsManagerGroupsApi groupsApi; |
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
@param |
79 |
|
@param |
80 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
81 |
22 |
public RightsManagerPluginApi(RightsManagerPlugin plugin, XWikiContext context)... |
82 |
|
{ |
83 |
22 |
super(plugin, context); |
84 |
|
|
85 |
22 |
this.rightsApi = new RightsManagerRightsApi(context); |
86 |
22 |
this.usersApi = new RightsManagerUsersApi(context); |
87 |
22 |
this.groupsApi = new RightsManagerGroupsApi(context); |
88 |
|
} |
89 |
|
|
90 |
|
|
91 |
|
@return |
92 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
93 |
0 |
public RightsManagerRightsApi getRightsApi()... |
94 |
|
{ |
95 |
0 |
return this.rightsApi; |
96 |
|
} |
97 |
|
|
98 |
|
|
99 |
|
@return |
100 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
101 |
2 |
public RightsManagerUsersApi getUsersApi()... |
102 |
|
{ |
103 |
2 |
return this.usersApi; |
104 |
|
} |
105 |
|
|
106 |
|
|
107 |
|
@return |
108 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
109 |
5 |
public RightsManagerGroupsApi getGroupsApi()... |
110 |
|
{ |
111 |
5 |
return this.groupsApi; |
112 |
|
} |
113 |
|
|
114 |
|
|
115 |
|
@link |
116 |
|
|
117 |
|
@param |
118 |
|
@return@link |
119 |
|
|
|
|
| 15% |
Uncovered Elements: 17 (20) |
Complexity: 5 |
Complexity Density: 0.36 |
|
120 |
10 |
static Object[][] createMatchingTable(Map<?, ?> map)... |
121 |
|
{ |
122 |
10 |
if (map == null || map.size() == 0) { |
123 |
10 |
return null; |
124 |
|
} |
125 |
|
|
126 |
0 |
Object[][] table = new Object[map.size()][3]; |
127 |
|
|
128 |
0 |
int i = 0; |
129 |
0 |
for (Map.Entry<?, ?> entry : map.entrySet()) { |
130 |
0 |
table[i][0] = entry.getKey(); |
131 |
|
|
132 |
0 |
if (entry.getValue() instanceof List) { |
133 |
0 |
List<?> typeValue = (List<?>) entry.getValue(); |
134 |
0 |
table[i][1] = typeValue.get(0); |
135 |
0 |
if (typeValue.size() > 1) { |
136 |
0 |
table[i][2] = typeValue.get(1); |
137 |
|
} |
138 |
|
} else { |
139 |
0 |
table[i][2] = entry.getValue(); |
140 |
|
} |
141 |
|
|
142 |
0 |
++i; |
143 |
|
} |
144 |
|
|
145 |
0 |
return table; |
146 |
|
} |
147 |
|
|
148 |
|
|
149 |
|
@link |
150 |
|
|
151 |
|
@param |
152 |
|
@return@link |
153 |
|
|
|
|
| 43.5% |
Uncovered Elements: 13 (23) |
Complexity: 6 |
Complexity Density: 0.4 |
|
154 |
5 |
static Object[][] createOrderTable(List<?> list)... |
155 |
|
{ |
156 |
5 |
if (list == null || list.size() == 0) { |
157 |
0 |
return null; |
158 |
|
} |
159 |
|
|
160 |
5 |
Object[][] table = new Object[list.size()][3]; |
161 |
|
|
162 |
5 |
int i = 0; |
163 |
5 |
for (Object entry : list) { |
164 |
5 |
if (entry instanceof List) { |
165 |
0 |
List<?> fieldParams = (List<?>) entry; |
166 |
0 |
table[i][0] = fieldParams.get(0); |
167 |
0 |
if (fieldParams.size() > 1) { |
168 |
0 |
table[i][1] = fieldParams.get(1); |
169 |
|
} |
170 |
0 |
if (fieldParams.size() > 2) { |
171 |
0 |
table[i][2] = fieldParams.get(2); |
172 |
|
} |
173 |
|
} else { |
174 |
5 |
table[i][0] = entry.toString(); |
175 |
|
} |
176 |
|
|
177 |
5 |
++i; |
178 |
|
} |
179 |
|
|
180 |
5 |
return table; |
181 |
|
} |
182 |
|
|
183 |
|
|
184 |
|
@link@link |
185 |
|
|
186 |
|
@param@link |
187 |
|
@param |
188 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
189 |
0 |
private void logError(String comment, XWikiException e)... |
190 |
|
{ |
191 |
0 |
LOGGER.error(comment, e); |
192 |
|
|
193 |
0 |
this.context.put(CONTEXT_LASTERRORCODE, e.getCode()); |
194 |
0 |
this.context.put(CONTEXT_LASTEXCEPTION, e); |
195 |
|
} |
196 |
|
|
197 |
|
|
198 |
|
|
199 |
|
|
200 |
|
|
201 |
|
|
202 |
|
@param |
203 |
|
@return@link@link |
204 |
|
@throws |
205 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
206 |
0 |
public Collection<String> getAllGroupsNamesForMember(String member) throws XWikiException... |
207 |
|
{ |
208 |
0 |
Collection<String> memberList; |
209 |
|
|
210 |
0 |
try { |
211 |
0 |
memberList = RightsManager.getInstance().getAllGroupsNamesForMember(member, 0, 0, this.context); |
212 |
|
} catch (RightsManagerException e) { |
213 |
0 |
logError(MessageFormat.format("Try to get all groups containing user [{0}]", new Object[] { member }), e); |
214 |
|
|
215 |
0 |
memberList = Collections.emptyList(); |
216 |
|
} |
217 |
|
|
218 |
0 |
return memberList; |
219 |
|
} |
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
|
224 |
|
@param |
225 |
|
@return@link@link |
226 |
|
@throws |
227 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
228 |
0 |
public Collection<String> getAllMembersNamesForGroup(String group) throws XWikiException... |
229 |
|
{ |
230 |
0 |
return getAllMembersNamesForGroup(group, 0, 0); |
231 |
|
} |
232 |
|
|
233 |
|
|
234 |
|
|
235 |
|
|
236 |
|
@param |
237 |
|
@param |
238 |
|
@param |
239 |
|
@return@link@link |
240 |
|
@throws |
241 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
242 |
0 |
public Collection<String> getAllMembersNamesForGroup(String group, int nb, int start) throws XWikiException... |
243 |
|
{ |
244 |
0 |
return getAllMatchedMembersNamesForGroup(group, null, nb, start, null); |
245 |
|
} |
246 |
|
|
247 |
|
|
248 |
|
|
249 |
|
|
250 |
|
@param |
251 |
|
@param |
252 |
|
@param |
253 |
|
@param |
254 |
|
@param |
255 |
|
@return@link@link |
256 |
|
@throws |
257 |
|
@since |
258 |
|
|
|
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
259 |
7 |
public Collection<String> getAllMatchedMembersNamesForGroup(String group, String matchField, int nb, int start,... |
260 |
|
Boolean orderAsc) throws XWikiException |
261 |
|
{ |
262 |
7 |
Collection<String> memberList; |
263 |
|
|
264 |
7 |
try { |
265 |
7 |
memberList = |
266 |
|
RightsManager.getInstance().getAllMatchedMembersNamesForGroup(group, matchField, nb, start, orderAsc, |
267 |
|
this.context); |
268 |
|
} catch (RightsManagerException e) { |
269 |
0 |
logError(MessageFormat.format("Try to get all matched member of group [{0}]", new Object[] { group }), e); |
270 |
|
|
271 |
0 |
memberList = Collections.emptyList(); |
272 |
|
} |
273 |
|
|
274 |
7 |
return memberList; |
275 |
|
} |
276 |
|
|
277 |
|
|
278 |
|
|
279 |
|
|
280 |
|
@param |
281 |
|
@return |
282 |
|
@throws |
283 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
284 |
0 |
public int countAllGroupsNamesForMember(String member) throws XWikiException... |
285 |
|
{ |
286 |
0 |
int count = 0; |
287 |
|
|
288 |
0 |
try { |
289 |
0 |
count = RightsManager.getInstance().countAllGroupsNamesForMember(member, this.context); |
290 |
|
} catch (RightsManagerException e) { |
291 |
0 |
logError("Try to count groups containing provided user", e); |
292 |
|
} |
293 |
|
|
294 |
0 |
return count; |
295 |
|
} |
296 |
|
|
297 |
|
|
298 |
|
|
299 |
|
|
300 |
|
@param |
301 |
|
@return |
302 |
|
@throws |
303 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
304 |
9 |
public int countAllMembersNamesForGroup(String group) throws XWikiException... |
305 |
|
{ |
306 |
9 |
int count = 0; |
307 |
|
|
308 |
9 |
try { |
309 |
9 |
count = RightsManager.getInstance().countAllMembersNamesForGroup(group, this.context); |
310 |
|
} catch (RightsManagerException e) { |
311 |
0 |
logError("Try to count all members provided group contains", e); |
312 |
|
} |
313 |
|
|
314 |
9 |
return count; |
315 |
|
} |
316 |
|
} |