1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.objects; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.Arrays; |
24 |
|
import java.util.Collection; |
25 |
|
import java.util.Collections; |
26 |
|
import java.util.Date; |
27 |
|
import java.util.HashMap; |
28 |
|
import java.util.HashSet; |
29 |
|
import java.util.Iterator; |
30 |
|
import java.util.LinkedHashMap; |
31 |
|
import java.util.List; |
32 |
|
import java.util.Map; |
33 |
|
import java.util.Set; |
34 |
|
|
35 |
|
import org.apache.commons.lang3.StringUtils; |
36 |
|
import org.dom4j.Element; |
37 |
|
import org.slf4j.Logger; |
38 |
|
import org.slf4j.LoggerFactory; |
39 |
|
import org.xwiki.model.EntityType; |
40 |
|
import org.xwiki.model.reference.DocumentReference; |
41 |
|
import org.xwiki.model.reference.DocumentReferenceResolver; |
42 |
|
import org.xwiki.model.reference.EntityReference; |
43 |
|
import org.xwiki.model.reference.EntityReferenceResolver; |
44 |
|
|
45 |
|
import com.xpn.xwiki.XWikiContext; |
46 |
|
import com.xpn.xwiki.XWikiException; |
47 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
48 |
|
import com.xpn.xwiki.doc.merge.MergeConfiguration; |
49 |
|
import com.xpn.xwiki.doc.merge.MergeResult; |
50 |
|
import com.xpn.xwiki.objects.classes.BaseClass; |
51 |
|
import com.xpn.xwiki.objects.classes.PropertyClass; |
52 |
|
import com.xpn.xwiki.web.Utils; |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
@version |
63 |
|
|
|
|
| 56.6% |
Uncovered Elements: 223 (514) |
Complexity: 145 |
Complexity Density: 0.47 |
|
64 |
|
public abstract class BaseCollection<R extends EntityReference> extends BaseElement<R> |
65 |
|
implements ObjectInterface, Cloneable |
66 |
|
{ |
67 |
|
private static final Logger LOGGER = LoggerFactory.getLogger(BaseCollection.class); |
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
private EntityReference xClassReference; |
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
private DocumentReference xClassReferenceCache; |
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
protected Map<String, Object> fields = new LinkedHashMap<String, Object>(); |
89 |
|
|
90 |
|
protected List<Object> fieldsToRemove = new ArrayList<>(); |
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
protected int number; |
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
protected EntityReferenceResolver<String> relativeEntityReferenceResolver; |
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
protected DocumentReferenceResolver<EntityReference> currentReferenceDocumentReferenceResolver; |
112 |
|
|
113 |
|
|
114 |
|
@return |
115 |
|
|
116 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
117 |
4927 |
protected EntityReferenceResolver<String> getRelativeEntityReferenceResolver()... |
118 |
|
{ |
119 |
4927 |
if (this.relativeEntityReferenceResolver == null) { |
120 |
4928 |
this.relativeEntityReferenceResolver = Utils.getComponent(EntityReferenceResolver.TYPE_STRING, "relative"); |
121 |
|
} |
122 |
|
|
123 |
4927 |
return this.relativeEntityReferenceResolver; |
124 |
|
} |
125 |
|
|
126 |
|
|
127 |
|
@return |
128 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
129 |
86265 |
protected DocumentReferenceResolver<EntityReference> getCurrentReferenceDocumentReferenceResolver()... |
130 |
|
{ |
131 |
86268 |
if (this.currentReferenceDocumentReferenceResolver == null) { |
132 |
14542 |
this.currentReferenceDocumentReferenceResolver = |
133 |
|
Utils.getComponent(DocumentReferenceResolver.TYPE_REFERENCE, "current"); |
134 |
|
} |
135 |
|
|
136 |
86271 |
return this.currentReferenceDocumentReferenceResolver; |
137 |
|
} |
138 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
139 |
112593 |
public int getNumber()... |
140 |
|
{ |
141 |
112592 |
return this.number; |
142 |
|
} |
143 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
144 |
106279 |
public void setNumber(int number)... |
145 |
|
{ |
146 |
106276 |
this.number = number; |
147 |
|
} |
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
@link |
152 |
|
|
153 |
|
@param |
154 |
|
@see |
155 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
156 |
0 |
public void addPropertyForRemoval(PropertyInterface field)... |
157 |
|
{ |
158 |
0 |
getFieldsToRemove().add(field); |
159 |
|
} |
160 |
|
|
161 |
|
|
162 |
|
|
163 |
|
|
164 |
|
@since |
165 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
166 |
256052 |
public DocumentReference getXClassReference()... |
167 |
|
{ |
168 |
256041 |
if (this.xClassReferenceCache == null && getRelativeXClassReference() != null) { |
169 |
86268 |
this.xClassReferenceCache = getCurrentReferenceDocumentReferenceResolver() |
170 |
|
.resolve(getRelativeXClassReference(), getDocumentReference()); |
171 |
|
} |
172 |
|
|
173 |
256053 |
return this.xClassReferenceCache; |
174 |
|
} |
175 |
|
|
176 |
|
|
177 |
|
|
178 |
|
|
179 |
|
@since |
180 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
181 |
331570 |
public EntityReference getRelativeXClassReference()... |
182 |
|
{ |
183 |
331570 |
return this.xClassReference; |
184 |
|
} |
185 |
|
|
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
@deprecated@link |
190 |
|
|
|
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
191 |
17260 |
@Deprecated... |
192 |
|
public String getClassName() |
193 |
|
{ |
194 |
17260 |
String xClassAsString; |
195 |
17260 |
if (getXClassReference() != null) { |
196 |
17260 |
xClassAsString = getLocalEntityReferenceSerializer().serialize(getXClassReference()); |
197 |
|
} else { |
198 |
0 |
xClassAsString = ""; |
199 |
|
} |
200 |
17260 |
return xClassAsString; |
201 |
|
} |
202 |
|
|
203 |
|
|
204 |
|
|
205 |
|
|
206 |
|
|
207 |
|
|
208 |
|
|
209 |
|
@param |
210 |
|
@since |
211 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
212 |
155424 |
public void setXClassReference(EntityReference xClassReference)... |
213 |
|
{ |
214 |
|
|
215 |
155426 |
EntityReference ref = xClassReference; |
216 |
|
|
217 |
155426 |
if (ref != null) { |
218 |
52627 |
EntityReference wiki = xClassReference.extractReference(EntityType.WIKI); |
219 |
52627 |
if (wiki != null) { |
220 |
6709 |
ref = xClassReference.removeParent(wiki); |
221 |
|
} |
222 |
|
} |
223 |
|
|
224 |
155426 |
this.xClassReference = ref; |
225 |
155425 |
this.xClassReferenceCache = null; |
226 |
|
} |
227 |
|
|
228 |
|
|
229 |
|
|
230 |
|
|
231 |
|
@deprecated@link |
232 |
|
|
|
|
| 77.8% |
Uncovered Elements: 2 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
233 |
4907 |
@Deprecated... |
234 |
|
public void setClassName(String name) |
235 |
|
{ |
236 |
4906 |
EntityReference xClassReference = null; |
237 |
4906 |
if (!StringUtils.isEmpty(name)) { |
238 |
|
|
239 |
|
|
240 |
|
|
241 |
4907 |
if (!"internal".equals(name)) { |
242 |
4907 |
xClassReference = getRelativeEntityReferenceResolver().resolve(name, EntityType.DOCUMENT); |
243 |
|
} |
244 |
|
} |
245 |
4906 |
setXClassReference(xClassReference); |
246 |
|
} |
247 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
248 |
2293988 |
@Override... |
249 |
|
public PropertyInterface safeget(String name) |
250 |
|
{ |
251 |
2294003 |
return (PropertyInterface) getFields().get(name); |
252 |
|
} |
253 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
254 |
12069 |
@Override... |
255 |
|
public PropertyInterface get(String name) throws XWikiException |
256 |
|
{ |
257 |
12066 |
return safeget(name); |
258 |
|
} |
259 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
260 |
1077800 |
@Override... |
261 |
|
public void safeput(String name, PropertyInterface property) |
262 |
|
{ |
263 |
1077816 |
addField(name, property); |
264 |
1077942 |
if (property instanceof BaseProperty) { |
265 |
1019575 |
((BaseProperty) property).setObject(this); |
266 |
1019569 |
((BaseProperty) property).setName(name); |
267 |
|
} |
268 |
|
} |
269 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
270 |
0 |
@Override... |
271 |
|
public void put(String name, PropertyInterface property) throws XWikiException |
272 |
|
{ |
273 |
0 |
safeput(name, property); |
274 |
|
} |
275 |
|
|
276 |
|
|
277 |
|
@since |
278 |
|
|
|
|
| 92.3% |
Uncovered Elements: 1 (13) |
Complexity: 5 |
Complexity Density: 0.56 |
|
279 |
39604 |
@Override... |
280 |
|
public BaseClass getXClass(XWikiContext context) |
281 |
|
{ |
282 |
39603 |
BaseClass baseClass = null; |
283 |
|
|
284 |
39603 |
if ((context == null) || (context.getWiki() == null)) { |
285 |
1 |
return baseClass; |
286 |
|
} |
287 |
|
|
288 |
39604 |
DocumentReference classReference = getXClassReference(); |
289 |
|
|
290 |
39603 |
if (classReference != null) { |
291 |
39549 |
try { |
292 |
39549 |
baseClass = context.getWiki().getXClass(classReference, context); |
293 |
|
} catch (Exception e) { |
294 |
0 |
LOGGER.error("Failed to get class [" + classReference + "]", e); |
295 |
|
} |
296 |
|
} |
297 |
|
|
298 |
39604 |
return baseClass; |
299 |
|
} |
300 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
301 |
1206278 |
public String getStringValue(String name)... |
302 |
|
{ |
303 |
1206287 |
BaseProperty prop = (BaseProperty) safeget(name); |
304 |
1206327 |
if (prop == null || prop.getValue() == null) { |
305 |
10427 |
return ""; |
306 |
|
} else { |
307 |
1195905 |
return prop.getValue().toString(); |
308 |
|
} |
309 |
|
} |
310 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
311 |
637 |
public String getLargeStringValue(String name)... |
312 |
|
{ |
313 |
637 |
return getStringValue(name); |
314 |
|
} |
315 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
316 |
343255 |
public void setStringValue(String name, String value)... |
317 |
|
{ |
318 |
343258 |
BaseStringProperty property = (BaseStringProperty) safeget(name); |
319 |
343276 |
if (property == null) { |
320 |
178169 |
property = new StringProperty(); |
321 |
|
} |
322 |
343261 |
property.setName(name); |
323 |
343250 |
property.setValue(value); |
324 |
343258 |
safeput(name, property); |
325 |
|
} |
326 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
327 |
226 |
public void setLargeStringValue(String name, String value)... |
328 |
|
{ |
329 |
226 |
BaseStringProperty property = (BaseStringProperty) safeget(name); |
330 |
226 |
if (property == null) { |
331 |
224 |
property = new LargeStringProperty(); |
332 |
|
} |
333 |
226 |
property.setName(name); |
334 |
226 |
property.setValue(value); |
335 |
226 |
safeput(name, property); |
336 |
|
} |
337 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
338 |
329673 |
public int getIntValue(String name)... |
339 |
|
{ |
340 |
329675 |
return getIntValue(name, 0); |
341 |
|
} |
342 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
343 |
335263 |
public int getIntValue(String name, int default_value)... |
344 |
|
{ |
345 |
335267 |
try { |
346 |
335273 |
NumberProperty prop = (NumberProperty) safeget(name); |
347 |
335272 |
if (prop == null) { |
348 |
22422 |
return default_value; |
349 |
|
} else { |
350 |
312850 |
return ((Number) prop.getValue()).intValue(); |
351 |
|
} |
352 |
|
} catch (Exception e) { |
353 |
24 |
return default_value; |
354 |
|
} |
355 |
|
} |
356 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
357 |
346309 |
public void setIntValue(String name, int value)... |
358 |
|
{ |
359 |
346309 |
NumberProperty property = new IntegerProperty(); |
360 |
346308 |
property.setName(name); |
361 |
346308 |
property.setValue(value); |
362 |
346305 |
safeput(name, property); |
363 |
|
} |
364 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
365 |
0 |
public long getLongValue(String name)... |
366 |
|
{ |
367 |
0 |
try { |
368 |
0 |
NumberProperty prop = (NumberProperty) safeget(name); |
369 |
0 |
if (prop == null) { |
370 |
0 |
return 0; |
371 |
|
} else { |
372 |
0 |
return ((Number) prop.getValue()).longValue(); |
373 |
|
} |
374 |
|
} catch (Exception e) { |
375 |
0 |
return 0; |
376 |
|
} |
377 |
|
} |
378 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
379 |
1 |
public void setLongValue(String name, long value)... |
380 |
|
{ |
381 |
1 |
NumberProperty property = new LongProperty(); |
382 |
1 |
property.setName(name); |
383 |
1 |
property.setValue(value); |
384 |
1 |
safeput(name, property); |
385 |
|
} |
386 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
387 |
0 |
public float getFloatValue(String name)... |
388 |
|
{ |
389 |
0 |
try { |
390 |
0 |
NumberProperty prop = (NumberProperty) safeget(name); |
391 |
0 |
if (prop == null) { |
392 |
0 |
return 0; |
393 |
|
} else { |
394 |
0 |
return ((Number) prop.getValue()).floatValue(); |
395 |
|
} |
396 |
|
} catch (Exception e) { |
397 |
0 |
return 0; |
398 |
|
} |
399 |
|
} |
400 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
401 |
0 |
public void setFloatValue(String name, float value)... |
402 |
|
{ |
403 |
0 |
NumberProperty property = new FloatProperty(); |
404 |
0 |
property.setName(name); |
405 |
0 |
property.setValue(new Float(value)); |
406 |
0 |
safeput(name, property); |
407 |
|
} |
408 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
409 |
0 |
public double getDoubleValue(String name)... |
410 |
|
{ |
411 |
0 |
try { |
412 |
0 |
NumberProperty prop = (NumberProperty) safeget(name); |
413 |
0 |
if (prop == null) { |
414 |
0 |
return 0; |
415 |
|
} else { |
416 |
0 |
return ((Number) prop.getValue()).doubleValue(); |
417 |
|
} |
418 |
|
} catch (Exception e) { |
419 |
0 |
return 0; |
420 |
|
} |
421 |
|
} |
422 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
423 |
0 |
public void setDoubleValue(String name, double value)... |
424 |
|
{ |
425 |
0 |
NumberProperty property = new DoubleProperty(); |
426 |
0 |
property.setName(name); |
427 |
0 |
property.setValue(new Double(value)); |
428 |
0 |
safeput(name, property); |
429 |
|
} |
430 |
|
|
|
|
| 87.5% |
Uncovered Elements: 1 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
431 |
4 |
public Date getDateValue(String name)... |
432 |
|
{ |
433 |
4 |
try { |
434 |
4 |
DateProperty prop = (DateProperty) safeget(name); |
435 |
4 |
if (prop == null) { |
436 |
3 |
return null; |
437 |
|
} else { |
438 |
1 |
return (Date) prop.getValue(); |
439 |
|
} |
440 |
|
} catch (Exception e) { |
441 |
0 |
return null; |
442 |
|
} |
443 |
|
} |
444 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
445 |
4 |
public void setDateValue(String name, Date value)... |
446 |
|
{ |
447 |
4 |
DateProperty property = new DateProperty(); |
448 |
4 |
property.setName(name); |
449 |
4 |
property.setValue(value); |
450 |
4 |
safeput(name, property); |
451 |
|
} |
452 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
453 |
0 |
public Set<?> getSetValue(String name)... |
454 |
|
{ |
455 |
0 |
ListProperty prop = (ListProperty) safeget(name); |
456 |
0 |
if (prop == null) { |
457 |
0 |
return new HashSet<Object>(); |
458 |
|
} else { |
459 |
0 |
return new HashSet<Object>((Collection<?>) prop.getValue()); |
460 |
|
} |
461 |
|
} |
462 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
463 |
0 |
public void setSetValue(String name, Set<?> value)... |
464 |
|
{ |
465 |
0 |
ListProperty property = new ListProperty(); |
466 |
0 |
property.setValue(value); |
467 |
0 |
safeput(name, property); |
468 |
|
} |
469 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
470 |
541 |
public List getListValue(String name)... |
471 |
|
{ |
472 |
541 |
ListProperty prop = (ListProperty) safeget(name); |
473 |
541 |
if (prop == null) { |
474 |
242 |
return new ArrayList(); |
475 |
|
} else { |
476 |
299 |
return (List) prop.getValue(); |
477 |
|
} |
478 |
|
} |
479 |
|
|
|
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
480 |
108 |
public void setStringListValue(String name, List value)... |
481 |
|
{ |
482 |
108 |
ListProperty property = (ListProperty) safeget(name); |
483 |
108 |
if (property == null) { |
484 |
108 |
property = new StringListProperty(); |
485 |
|
} |
486 |
108 |
property.setValue(value); |
487 |
108 |
safeput(name, property); |
488 |
|
} |
489 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
490 |
20 |
public void setDBStringListValue(String name, List value)... |
491 |
|
{ |
492 |
20 |
ListProperty property = (ListProperty) safeget(name); |
493 |
20 |
if (property == null) { |
494 |
9 |
property = new DBStringListProperty(); |
495 |
|
} |
496 |
20 |
property.setValue(value); |
497 |
20 |
safeput(name, property); |
498 |
|
} |
499 |
|
|
500 |
|
|
501 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
502 |
2597091 |
private Map<String, Object> getFields()... |
503 |
|
{ |
504 |
2597094 |
return this.fields; |
505 |
|
} |
506 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
507 |
134144 |
public void setFields(Map fields)... |
508 |
|
{ |
509 |
134139 |
this.fields = fields; |
510 |
|
} |
511 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
512 |
4030704 |
public PropertyInterface getField(String name)... |
513 |
|
{ |
514 |
4030712 |
return (PropertyInterface) this.fields.get(name); |
515 |
|
} |
516 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
517 |
1093403 |
public void addField(String name, PropertyInterface element)... |
518 |
|
{ |
519 |
1093401 |
this.fields.put(name, element); |
520 |
|
|
521 |
1093500 |
if (element instanceof BaseElement) { |
522 |
1093501 |
((BaseElement) element).setOwnerDocument(getOwnerDocument()); |
523 |
|
} |
524 |
|
} |
525 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
526 |
124 |
public void removeField(String name)... |
527 |
|
{ |
528 |
124 |
Object field = safeget(name); |
529 |
124 |
if (field != null) { |
530 |
7 |
this.fields.remove(name); |
531 |
7 |
this.fieldsToRemove.add(field); |
532 |
|
} |
533 |
|
} |
534 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
535 |
33127 |
public Collection getFieldList()... |
536 |
|
{ |
537 |
33127 |
return this.fields.values(); |
538 |
|
} |
539 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
540 |
662636 |
public Set<String> getPropertyList()... |
541 |
|
{ |
542 |
662635 |
return this.fields.keySet(); |
543 |
|
} |
544 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
545 |
86680 |
public Object[] getProperties()... |
546 |
|
{ |
547 |
86680 |
return getFields().values().toArray(); |
548 |
|
} |
549 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
550 |
138 |
public String[] getPropertyNames()... |
551 |
|
{ |
552 |
138 |
return getFields().keySet().toArray(new String[0]); |
553 |
|
} |
554 |
|
|
555 |
|
|
556 |
|
|
557 |
|
|
558 |
|
|
|
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 2 |
Complexity Density: 0.29 |
|
559 |
86531 |
public Iterator getSortedIterator()... |
560 |
|
{ |
561 |
86531 |
Iterator it = null; |
562 |
86531 |
try { |
563 |
|
|
564 |
86531 |
List propList = Arrays.asList(getProperties()); |
565 |
|
|
566 |
|
|
567 |
86531 |
Collections.sort(propList, new ElementComparator()); |
568 |
|
|
569 |
|
|
570 |
86531 |
it = propList.iterator(); |
571 |
|
} catch (ClassCastException ccex) { |
572 |
|
|
573 |
|
|
574 |
0 |
it = getFieldList().iterator(); |
575 |
|
} |
576 |
|
|
577 |
86531 |
return it; |
578 |
|
} |
579 |
|
|
|
|
| 81.2% |
Uncovered Elements: 6 (32) |
Complexity: 8 |
Complexity Density: 0.44 |
|
580 |
7813 |
@Override... |
581 |
|
public boolean equals(Object coll) |
582 |
|
{ |
583 |
|
|
584 |
7813 |
if (this == coll) { |
585 |
0 |
return true; |
586 |
|
} |
587 |
|
|
588 |
7813 |
if (!super.equals(coll)) { |
589 |
25 |
return false; |
590 |
|
} |
591 |
7788 |
BaseCollection collection = (BaseCollection) coll; |
592 |
7788 |
if (collection.getXClassReference() == null) { |
593 |
7761 |
if (getXClassReference() != null) { |
594 |
0 |
return false; |
595 |
|
} |
596 |
27 |
} else if (!collection.getXClassReference().equals(getXClassReference())) { |
597 |
0 |
return false; |
598 |
|
} |
599 |
|
|
600 |
7788 |
if (getFields().size() != collection.getFields().size()) { |
601 |
4 |
return false; |
602 |
|
} |
603 |
|
|
604 |
7784 |
for (Map.Entry<String, Object> entry : getFields().entrySet()) { |
605 |
58917 |
Object prop = entry.getValue(); |
606 |
58917 |
Object prop2 = collection.getFields().get(entry.getKey()); |
607 |
58917 |
if (!prop.equals(prop2)) { |
608 |
2 |
return false; |
609 |
|
} |
610 |
|
} |
611 |
|
|
612 |
7782 |
return true; |
613 |
|
} |
614 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
|
615 |
134134 |
@Override... |
616 |
|
public BaseCollection clone() |
617 |
|
{ |
618 |
134135 |
BaseCollection collection = (BaseCollection) super.clone(); |
619 |
134139 |
collection.setXClassReference(getRelativeXClassReference()); |
620 |
134140 |
collection.setNumber(getNumber()); |
621 |
134139 |
Map fields = getFields(); |
622 |
134140 |
Map cfields = new HashMap(); |
623 |
134137 |
for (Object objEntry : fields.entrySet()) { |
624 |
873207 |
Map.Entry entry = (Map.Entry) objEntry; |
625 |
873217 |
PropertyInterface prop = (PropertyInterface) ((BaseElement) entry.getValue()).clone(); |
626 |
873214 |
prop.setObject(collection); |
627 |
873198 |
cfields.put(entry.getKey(), prop); |
628 |
|
} |
629 |
134140 |
collection.setFields(cfields); |
630 |
|
|
631 |
134140 |
return collection; |
632 |
|
} |
633 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
634 |
0 |
public void merge(BaseObject object)... |
635 |
|
{ |
636 |
0 |
Iterator itfields = object.getPropertyList().iterator(); |
637 |
0 |
while (itfields.hasNext()) { |
638 |
0 |
String name = (String) itfields.next(); |
639 |
0 |
if (safeget(name) == null) { |
640 |
0 |
safeput(name, (PropertyInterface) ((BaseElement) object.safeget(name)).clone()); |
641 |
|
} |
642 |
|
} |
643 |
|
} |
644 |
|
|
|
|
| 0% |
Uncovered Elements: 68 (68) |
Complexity: 20 |
Complexity Density: 0.59 |
|
645 |
0 |
public List<ObjectDiff> getDiff(Object oldObject, XWikiContext context)... |
646 |
|
{ |
647 |
0 |
ArrayList<ObjectDiff> difflist = new ArrayList<ObjectDiff>(); |
648 |
0 |
BaseCollection oldCollection = (BaseCollection) oldObject; |
649 |
|
|
650 |
0 |
for (Object key : this.getFields().keySet()) { |
651 |
0 |
String propertyName = (String) key; |
652 |
0 |
BaseProperty newProperty = (BaseProperty) this.getFields().get(propertyName); |
653 |
0 |
BaseProperty oldProperty = (BaseProperty) oldCollection.getFields().get(propertyName); |
654 |
0 |
BaseClass bclass = getXClass(context); |
655 |
0 |
PropertyClass pclass = (PropertyClass) ((bclass == null) ? null : bclass.getField(propertyName)); |
656 |
0 |
String propertyType = (pclass == null) ? "" : pclass.getClassType(); |
657 |
|
|
658 |
0 |
if (oldProperty == null) { |
659 |
|
|
660 |
0 |
if ((newProperty != null) && (!newProperty.toText().equals(""))) { |
661 |
0 |
if (pclass != null) { |
662 |
0 |
String newPropertyValue = (newProperty.getValue() instanceof String) ? newProperty.toText() |
663 |
|
: pclass.displayView(propertyName, this, context); |
664 |
0 |
difflist.add(new ObjectDiff(getXClassReference(), getNumber(), "", |
665 |
|
ObjectDiff.ACTION_PROPERTYADDED, propertyName, propertyType, "", newPropertyValue)); |
666 |
|
} |
667 |
|
} |
668 |
0 |
} else if (!oldProperty.toText().equals(((newProperty == null) ? "" : newProperty.toText()))) { |
669 |
|
|
670 |
0 |
if (pclass != null) { |
671 |
|
|
672 |
0 |
String newPropertyValue = (newProperty.getValue() instanceof String) ? newProperty.toText() |
673 |
|
: pclass.displayView(propertyName, this, context); |
674 |
0 |
String oldPropertyValue = (oldProperty.getValue() instanceof String) ? oldProperty.toText() |
675 |
|
: pclass.displayView(propertyName, oldCollection, context); |
676 |
0 |
difflist |
677 |
|
.add(new ObjectDiff(getXClassReference(), getNumber(), "", ObjectDiff.ACTION_PROPERTYCHANGED, |
678 |
|
propertyName, propertyType, oldPropertyValue, newPropertyValue)); |
679 |
|
} else { |
680 |
|
|
681 |
0 |
difflist |
682 |
|
.add(new ObjectDiff(getXClassReference(), getNumber(), "", ObjectDiff.ACTION_PROPERTYCHANGED, |
683 |
|
propertyName, propertyType, oldProperty.toText(), newProperty.toText())); |
684 |
|
} |
685 |
|
} |
686 |
|
} |
687 |
|
|
688 |
|
|
689 |
0 |
for (Object key : oldCollection.getFields().keySet()) { |
690 |
0 |
String propertyName = (String) key; |
691 |
0 |
BaseProperty newProperty = (BaseProperty) this.getFields().get(propertyName); |
692 |
0 |
BaseProperty oldProperty = (BaseProperty) oldCollection.getFields().get(propertyName); |
693 |
0 |
BaseClass bclass = getXClass(context); |
694 |
0 |
PropertyClass pclass = (PropertyClass) ((bclass == null) ? null : bclass.getField(propertyName)); |
695 |
0 |
String propertyType = (pclass == null) ? "" : pclass.getClassType(); |
696 |
|
|
697 |
0 |
if (newProperty == null) { |
698 |
|
|
699 |
0 |
if ((oldProperty != null) && (!oldProperty.toText().equals(""))) { |
700 |
0 |
if (pclass != null) { |
701 |
|
|
702 |
0 |
String oldPropertyValue = (oldProperty.getValue() instanceof String) ? oldProperty.toText() |
703 |
|
: pclass.displayView(propertyName, oldCollection, context); |
704 |
0 |
difflist.add(new ObjectDiff(oldCollection.getXClassReference(), oldCollection.getNumber(), "", |
705 |
|
ObjectDiff.ACTION_PROPERTYREMOVED, propertyName, propertyType, oldPropertyValue, "")); |
706 |
|
} else { |
707 |
|
|
708 |
0 |
difflist.add(new ObjectDiff(oldCollection.getXClassReference(), oldCollection.getNumber(), "", |
709 |
|
ObjectDiff.ACTION_PROPERTYREMOVED, propertyName, propertyType, oldProperty.toText(), "")); |
710 |
|
} |
711 |
|
} |
712 |
|
} |
713 |
|
} |
714 |
|
|
715 |
0 |
return difflist; |
716 |
|
} |
717 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
718 |
4483 |
public List getFieldsToRemove()... |
719 |
|
{ |
720 |
4483 |
return this.fieldsToRemove; |
721 |
|
} |
722 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
723 |
0 |
public void setFieldsToRemove(List fieldsToRemove)... |
724 |
|
{ |
725 |
0 |
this.fieldsToRemove = fieldsToRemove; |
726 |
|
} |
727 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
728 |
0 |
@Override... |
729 |
|
public Element toXML() |
730 |
|
{ |
731 |
0 |
return super.toXML(); |
732 |
|
} |
733 |
|
|
734 |
|
|
735 |
|
@deprecated@link |
736 |
|
|
|
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 5 |
Complexity Density: 0.33 |
|
737 |
0 |
@Override... |
738 |
|
@Deprecated |
739 |
|
public Element toXML(BaseClass bclass) |
740 |
|
{ |
741 |
|
|
742 |
0 |
XWikiContext xcontext = getXWikiContext(); |
743 |
|
|
744 |
0 |
BaseClass currentBaseClass; |
745 |
0 |
DocumentReference classReference; |
746 |
0 |
if (bclass != null && xcontext != null) { |
747 |
0 |
classReference = bclass.getDocumentReference(); |
748 |
0 |
currentBaseClass = xcontext.getBaseClass(bclass.getDocumentReference()); |
749 |
0 |
xcontext.addBaseClass(bclass); |
750 |
|
} else { |
751 |
0 |
classReference = null; |
752 |
0 |
currentBaseClass = null; |
753 |
|
} |
754 |
|
|
755 |
0 |
try { |
756 |
0 |
return super.toXML(); |
757 |
|
} finally { |
758 |
0 |
if (classReference != null) { |
759 |
0 |
if (currentBaseClass != null) { |
760 |
0 |
xcontext.addBaseClass(currentBaseClass); |
761 |
|
} else { |
762 |
0 |
xcontext.removeBaseClass(classReference); |
763 |
|
} |
764 |
|
} |
765 |
|
} |
766 |
|
} |
767 |
|
|
768 |
|
|
769 |
|
|
770 |
|
|
771 |
|
@link |
772 |
|
|
773 |
|
@return |
774 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
775 |
0 |
public String toXMLString()... |
776 |
|
{ |
777 |
0 |
return toXMLString(true); |
778 |
|
} |
779 |
|
|
780 |
|
|
781 |
|
@since |
782 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
783 |
40 |
public Map<String, Object> getCustomMappingMap() throws XWikiException... |
784 |
|
{ |
785 |
40 |
Map<String, Object> map = new HashMap<String, Object>(); |
786 |
40 |
for (String name : this.fields.keySet()) { |
787 |
394 |
BaseProperty property = (BaseProperty) get(name); |
788 |
394 |
map.put(name, property.getCustomMappingValue()); |
789 |
|
} |
790 |
40 |
map.put("id", getId()); |
791 |
|
|
792 |
40 |
return map; |
793 |
|
} |
794 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
795 |
263591 |
@Override... |
796 |
|
public void setDocumentReference(DocumentReference reference) |
797 |
|
{ |
798 |
263594 |
super.setDocumentReference(reference); |
799 |
|
|
800 |
|
|
801 |
|
|
802 |
263581 |
this.xClassReferenceCache = null; |
803 |
|
} |
804 |
|
|
|
|
| 35.7% |
Uncovered Elements: 36 (56) |
Complexity: 14 |
Complexity Density: 0.47 |
|
805 |
55 |
@Override... |
806 |
|
public void merge(ElementInterface previousElement, ElementInterface newElement, MergeConfiguration configuration, |
807 |
|
XWikiContext context, MergeResult mergeResult) |
808 |
|
{ |
809 |
55 |
BaseCollection<R> previousCollection = (BaseCollection<R>) previousElement; |
810 |
55 |
BaseCollection<R> newCollection = (BaseCollection<R>) newElement; |
811 |
|
|
812 |
55 |
List<ObjectDiff> classDiff = newCollection.getDiff(previousCollection, context); |
813 |
55 |
for (ObjectDiff diff : classDiff) { |
814 |
1 |
PropertyInterface propertyResult = getField(diff.getPropName()); |
815 |
1 |
PropertyInterface previousProperty = previousCollection.getField(diff.getPropName()); |
816 |
1 |
PropertyInterface newProperty = newCollection.getField(diff.getPropName()); |
817 |
|
|
818 |
1 |
if (diff.getAction() == ObjectDiff.ACTION_PROPERTYADDED) { |
819 |
0 |
if (propertyResult == null) { |
820 |
|
|
821 |
0 |
safeput(diff.getPropName(), |
822 |
0 |
configuration.isProvidedVersionsModifiables() ? newProperty : newProperty.clone()); |
823 |
0 |
mergeResult.setModified(true); |
824 |
0 |
} else if (!propertyResult.equals(newProperty)) { |
825 |
|
|
826 |
0 |
mergeResult.getLog().error("Collision found on property [{}]", newProperty.getReference()); |
827 |
|
} |
828 |
1 |
} else if (diff.getAction() == ObjectDiff.ACTION_PROPERTYREMOVED) { |
829 |
0 |
if (propertyResult != null) { |
830 |
0 |
if (propertyResult.equals(previousProperty)) { |
831 |
|
|
832 |
0 |
removeField(diff.getPropName()); |
833 |
0 |
mergeResult.setModified(true); |
834 |
|
} else { |
835 |
|
|
836 |
|
|
837 |
0 |
mergeResult.getLog().error("Collision found on property [{}]", previousProperty.getReference()); |
838 |
|
} |
839 |
|
} else { |
840 |
|
|
841 |
0 |
mergeResult.getLog().warn("Property [{}] already removed", previousProperty.getReference()); |
842 |
|
} |
843 |
1 |
} else if (diff.getAction() == ObjectDiff.ACTION_PROPERTYCHANGED) { |
844 |
1 |
if (propertyResult != null) { |
845 |
1 |
if (propertyResult.equals(previousProperty)) { |
846 |
|
|
847 |
1 |
safeput(diff.getPropName(), |
848 |
1 |
configuration.isProvidedVersionsModifiables() ? newProperty : newProperty.clone()); |
849 |
1 |
mergeResult.setModified(true); |
850 |
0 |
} else if (!propertyResult.equals(newProperty)) { |
851 |
|
|
852 |
0 |
mergeField(propertyResult, previousProperty, newProperty, configuration, context, mergeResult); |
853 |
|
} |
854 |
|
} else { |
855 |
|
|
856 |
|
|
857 |
0 |
mergeResult.getLog().warn("Collision found on property [{}]", newProperty.getReference()); |
858 |
|
|
859 |
0 |
safeput(diff.getPropName(), |
860 |
0 |
configuration.isProvidedVersionsModifiables() ? newProperty : newProperty.clone()); |
861 |
0 |
mergeResult.setModified(true); |
862 |
|
} |
863 |
|
} |
864 |
|
} |
865 |
|
} |
866 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
867 |
0 |
protected void mergeField(PropertyInterface currentElement, ElementInterface previousElement,... |
868 |
|
ElementInterface newElement, MergeConfiguration configuration, XWikiContext context, MergeResult mergeResult) |
869 |
|
{ |
870 |
0 |
currentElement.merge(previousElement, newElement, configuration, context, mergeResult); |
871 |
|
} |
872 |
|
|
|
|
| 70% |
Uncovered Elements: 9 (30) |
Complexity: 5 |
Complexity Density: 0.23 |
|
873 |
12 |
@Override... |
874 |
|
public boolean apply(ElementInterface newElement, boolean clean) |
875 |
|
{ |
876 |
12 |
boolean modified = false; |
877 |
|
|
878 |
12 |
BaseCollection<R> newCollection = (BaseCollection<R>) newElement; |
879 |
|
|
880 |
12 |
if (clean) { |
881 |
|
|
882 |
12 |
List<String> fieldsToDelete = new ArrayList<String>(this.fields.size()); |
883 |
12 |
for (String key : this.fields.keySet()) { |
884 |
35 |
if (newCollection.safeget(key) == null) { |
885 |
0 |
fieldsToDelete.add(key); |
886 |
|
} |
887 |
|
} |
888 |
|
|
889 |
12 |
for (String key : fieldsToDelete) { |
890 |
0 |
removeField(key); |
891 |
0 |
modified = true; |
892 |
|
} |
893 |
|
} |
894 |
|
|
895 |
|
|
896 |
12 |
for (Map.Entry<String, Object> entry : newCollection.fields.entrySet()) { |
897 |
37 |
PropertyInterface field = (PropertyInterface) this.fields.get(entry.getKey()); |
898 |
37 |
PropertyInterface newField = (PropertyInterface) entry.getValue(); |
899 |
|
|
900 |
37 |
if (field == null) { |
901 |
|
|
902 |
2 |
safeput(entry.getKey(), newField); |
903 |
2 |
modified = true; |
904 |
35 |
} else if (field.getClass() != newField.getClass()) { |
905 |
|
|
906 |
0 |
removeField(entry.getKey()); |
907 |
0 |
safeput(entry.getKey(), newField); |
908 |
0 |
modified = true; |
909 |
|
} else { |
910 |
|
|
911 |
35 |
modified |= field.apply(newField, clean); |
912 |
|
} |
913 |
|
} |
914 |
|
|
915 |
12 |
return modified; |
916 |
|
} |
917 |
|
|
918 |
|
|
919 |
|
|
920 |
|
|
921 |
|
@param |
922 |
|
@since |
923 |
|
|
|
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
924 |
595985 |
@Override... |
925 |
|
public void setOwnerDocument(XWikiDocument ownerDocument) |
926 |
|
{ |
927 |
595986 |
super.setOwnerDocument(ownerDocument); |
928 |
|
|
929 |
595982 |
for (String propertyName : getPropertyList()) { |
930 |
3988842 |
PropertyInterface property = getField(propertyName); |
931 |
3988773 |
if (property instanceof BaseElement) { |
932 |
3988838 |
((BaseElement) property).setOwnerDocument(ownerDocument); |
933 |
|
} |
934 |
|
} |
935 |
|
} |
936 |
|
} |