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.io.Serializable; |
23 |
|
import java.util.ArrayList; |
24 |
|
import java.util.List; |
25 |
|
import java.util.UUID; |
26 |
|
|
27 |
|
import org.dom4j.Element; |
28 |
|
import org.xwiki.model.EntityType; |
29 |
|
import org.xwiki.model.reference.DocumentReference; |
30 |
|
import org.xwiki.model.reference.DocumentReferenceResolver; |
31 |
|
import org.xwiki.model.reference.EntityReference; |
32 |
|
import org.xwiki.model.reference.SpaceReference; |
33 |
|
|
34 |
|
import com.xpn.xwiki.XWikiContext; |
35 |
|
import com.xpn.xwiki.XWikiException; |
36 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
37 |
|
import com.xpn.xwiki.doc.merge.MergeConfiguration; |
38 |
|
import com.xpn.xwiki.doc.merge.MergeResult; |
39 |
|
import com.xpn.xwiki.objects.classes.BaseClass; |
40 |
|
import com.xpn.xwiki.objects.classes.PropertyClass; |
41 |
|
import com.xpn.xwiki.web.Utils; |
42 |
|
|
|
|
| 76.3% |
Uncovered Elements: 46 (194) |
Complexity: 63 |
Complexity Density: 0.58 |
|
43 |
|
public class BaseObject extends BaseCollection<BaseObjectReference> implements ObjectInterface, Serializable, Cloneable |
44 |
|
{ |
45 |
|
private String guid = UUID.randomUUID().toString(); |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
private DocumentReferenceResolver<String> currentMixedDocumentReferenceResolver2; |
53 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
54 |
4857 |
private DocumentReferenceResolver<String> getCurrentMixedDocumentReferenceResolver()... |
55 |
|
{ |
56 |
4857 |
if (this.currentMixedDocumentReferenceResolver2 == null) { |
57 |
4856 |
this.currentMixedDocumentReferenceResolver2 = |
58 |
|
Utils.getComponent(DocumentReferenceResolver.TYPE_STRING, "currentmixed"); |
59 |
|
} |
60 |
|
|
61 |
4857 |
return this.currentMixedDocumentReferenceResolver2; |
62 |
|
} |
63 |
|
|
64 |
|
|
65 |
|
@inheritDoc |
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
@deprecated@link |
71 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
72 |
17090 |
@Deprecated... |
73 |
|
@Override |
74 |
|
public String getName() |
75 |
|
{ |
76 |
17090 |
return super.getName(); |
77 |
|
} |
78 |
|
|
79 |
|
|
80 |
|
@inheritDoc |
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
@deprecated@link |
86 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
87 |
4859 |
@Deprecated... |
88 |
|
@Override |
89 |
|
public void setName(String name) |
90 |
|
{ |
91 |
4859 |
DocumentReference reference = getDocumentReference(); |
92 |
|
|
93 |
4856 |
if (reference != null) { |
94 |
2 |
EntityReference relativeReference = getRelativeEntityReferenceResolver().resolve(name, EntityType.DOCUMENT); |
95 |
2 |
reference = new DocumentReference(relativeReference.extractReference(EntityType.DOCUMENT).getName(), |
96 |
|
new SpaceReference(relativeReference.extractReference(EntityType.SPACE).getName(), |
97 |
|
reference.getParent().getParent())); |
98 |
|
} else { |
99 |
4857 |
reference = getCurrentMixedDocumentReferenceResolver().resolve(name); |
100 |
|
} |
101 |
4860 |
setDocumentReference(reference); |
102 |
|
} |
103 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
104 |
21095 |
@Override... |
105 |
|
protected BaseObjectReference createReference() |
106 |
|
{ |
107 |
21092 |
BaseObjectReference reference; |
108 |
|
|
109 |
21095 |
if (getXClassReference() != null && getDocumentReference() != null) { |
110 |
21092 |
reference = new BaseObjectReference(getXClassReference(), getNumber(), getDocumentReference()); |
111 |
|
} else { |
112 |
2 |
reference = null; |
113 |
|
} |
114 |
|
|
115 |
21092 |
return reference; |
116 |
|
} |
117 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
118 |
85505 |
@Override... |
119 |
|
public void setNumber(int number) |
120 |
|
{ |
121 |
85506 |
super.setNumber(number); |
122 |
|
|
123 |
|
|
124 |
85499 |
this.referenceCache = null; |
125 |
|
} |
126 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
127 |
52626 |
@Override... |
128 |
|
public void setXClassReference(EntityReference xClassReference) |
129 |
|
{ |
130 |
52627 |
super.setXClassReference(xClassReference); |
131 |
|
|
132 |
|
|
133 |
52626 |
this.referenceCache = null; |
134 |
|
} |
135 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
136 |
0 |
public void displayHidden(StringBuffer buffer, String name, String prefix, XWikiContext context)... |
137 |
|
{ |
138 |
0 |
((PropertyClass) getXClass(context).get(name)).displayHidden(buffer, name, prefix, this, context); |
139 |
|
} |
140 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
141 |
0 |
public void displayView(StringBuffer buffer, String name, String prefix, XWikiContext context)... |
142 |
|
{ |
143 |
0 |
((PropertyClass) getXClass(context).get(name)).displayView(buffer, name, prefix, this, context); |
144 |
|
} |
145 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
146 |
0 |
public void displayEdit(StringBuffer buffer, String name, String prefix, XWikiContext context)... |
147 |
|
{ |
148 |
0 |
((PropertyClass) getXClass(context).get(name)).displayEdit(buffer, name, prefix, this, context); |
149 |
|
} |
150 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
151 |
0 |
public String displayHidden(String name, String prefix, XWikiContext context)... |
152 |
|
{ |
153 |
0 |
StringBuffer buffer = new StringBuffer(); |
154 |
0 |
((PropertyClass) getXClass(context).get(name)).displayHidden(buffer, name, prefix, this, context); |
155 |
|
|
156 |
0 |
return buffer.toString(); |
157 |
|
} |
158 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
159 |
0 |
public String displayView(String name, String prefix, XWikiContext context)... |
160 |
|
{ |
161 |
0 |
StringBuffer buffer = new StringBuffer(); |
162 |
0 |
((PropertyClass) getXClass(context).get(name)).displayView(buffer, name, prefix, this, context); |
163 |
|
|
164 |
0 |
return buffer.toString(); |
165 |
|
} |
166 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
167 |
0 |
public String displayEdit(String name, String prefix, XWikiContext context)... |
168 |
|
{ |
169 |
0 |
StringBuffer buffer = new StringBuffer(); |
170 |
0 |
((PropertyClass) getXClass(context).get(name)).displayEdit(buffer, name, prefix, this, context); |
171 |
|
|
172 |
0 |
return buffer.toString(); |
173 |
|
} |
174 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
175 |
0 |
public String displayHidden(String name, XWikiContext context)... |
176 |
|
{ |
177 |
0 |
return displayHidden(name, "", context); |
178 |
|
} |
179 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
180 |
0 |
public String displayView(String name, XWikiContext context)... |
181 |
|
{ |
182 |
0 |
return displayView(name, "", context); |
183 |
|
} |
184 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
185 |
0 |
public String displayEdit(String name, XWikiContext context)... |
186 |
|
{ |
187 |
0 |
return displayEdit(name, "", context); |
188 |
|
} |
189 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
190 |
31336 |
@Override... |
191 |
|
public BaseObject clone() |
192 |
|
{ |
193 |
31333 |
BaseObject object = (BaseObject) super.clone(); |
194 |
31338 |
object.setGuid(getGuid()); |
195 |
|
|
196 |
31338 |
return object; |
197 |
|
} |
198 |
|
|
199 |
|
|
200 |
|
@link |
201 |
|
|
202 |
|
|
203 |
|
@since |
204 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
205 |
134 |
public BaseObject duplicate()... |
206 |
|
{ |
207 |
134 |
BaseObject object = clone(); |
208 |
|
|
209 |
134 |
object.setGuid(UUID.randomUUID().toString()); |
210 |
|
|
211 |
134 |
return object; |
212 |
|
} |
213 |
|
|
214 |
|
|
215 |
|
@since |
216 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
217 |
102 |
public BaseObject duplicate(DocumentReference documentReference)... |
218 |
|
{ |
219 |
102 |
BaseObject object = duplicate(); |
220 |
102 |
object.setDocumentReference(documentReference); |
221 |
102 |
return object; |
222 |
|
} |
223 |
|
|
|
|
| 84.6% |
Uncovered Elements: 2 (13) |
Complexity: 4 |
Complexity Density: 0.57 |
|
224 |
142 |
@Override... |
225 |
|
public boolean equals(Object obj) |
226 |
|
{ |
227 |
|
|
228 |
142 |
if (this == obj) { |
229 |
114 |
return true; |
230 |
|
} |
231 |
|
|
232 |
28 |
if (!super.equals(obj)) { |
233 |
4 |
return false; |
234 |
|
} |
235 |
|
|
236 |
24 |
if (getNumber() != ((BaseObject) obj).getNumber()) { |
237 |
0 |
return false; |
238 |
|
} |
239 |
|
|
240 |
24 |
return true; |
241 |
|
} |
242 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
243 |
0 |
@Override... |
244 |
|
public void fromXML(Element oel) throws XWikiException |
245 |
|
{ |
246 |
0 |
super.fromXML(oel); |
247 |
|
} |
248 |
|
|
|
|
| 98.4% |
Uncovered Elements: 1 (63) |
Complexity: 20 |
Complexity Density: 0.65 |
|
249 |
779 |
@Override... |
250 |
|
public List<ObjectDiff> getDiff(Object oldEntity, XWikiContext context) |
251 |
|
{ |
252 |
779 |
ArrayList<ObjectDiff> difflist = new ArrayList<ObjectDiff>(); |
253 |
779 |
BaseObject oldObject = (BaseObject) oldEntity; |
254 |
|
|
255 |
779 |
for (String propertyName : this.getPropertyList()) { |
256 |
3415 |
BaseProperty newProperty = (BaseProperty) this.getField(propertyName); |
257 |
3415 |
BaseProperty oldProperty = (BaseProperty) oldObject.getField(propertyName); |
258 |
3415 |
BaseClass bclass = getXClass(context); |
259 |
3415 |
PropertyClass pclass = (PropertyClass) ((bclass == null) ? null : bclass.getField(propertyName)); |
260 |
3415 |
String propertyType = (pclass == null) ? "" : pclass.getClassType(); |
261 |
|
|
262 |
3415 |
if (oldProperty == null) { |
263 |
|
|
264 |
504 |
if ((newProperty != null) && (!newProperty.toText().equals(""))) { |
265 |
207 |
String newPropertyValue = (newProperty.getValue() instanceof String || pclass == null) |
266 |
|
? newProperty.toText() : pclass.displayView(propertyName, this, context); |
267 |
207 |
difflist.add(new ObjectDiff(getXClassReference(), getNumber(), getGuid(), |
268 |
|
ObjectDiff.ACTION_PROPERTYADDED, propertyName, propertyType, "", newPropertyValue)); |
269 |
|
} |
270 |
2911 |
} else if (!oldProperty.toText().equals(((newProperty == null) ? "" : newProperty.toText()))) { |
271 |
|
|
272 |
113 |
if (pclass != null) { |
273 |
|
|
274 |
108 |
String newPropertyValue = (newProperty.getValue() instanceof String) ? newProperty.toText() |
275 |
|
: pclass.displayView(propertyName, this, context); |
276 |
108 |
String oldPropertyValue = (oldProperty.getValue() instanceof String) ? oldProperty.toText() |
277 |
|
: pclass.displayView(propertyName, oldObject, context); |
278 |
108 |
difflist.add( |
279 |
|
new ObjectDiff(getXClassReference(), getNumber(), getGuid(), ObjectDiff.ACTION_PROPERTYCHANGED, |
280 |
|
propertyName, propertyType, oldPropertyValue, newPropertyValue)); |
281 |
|
} else { |
282 |
|
|
283 |
5 |
difflist.add( |
284 |
|
new ObjectDiff(getXClassReference(), getNumber(), getGuid(), ObjectDiff.ACTION_PROPERTYCHANGED, |
285 |
|
propertyName, propertyType, oldProperty.toText(), newProperty.toText())); |
286 |
|
} |
287 |
|
} |
288 |
|
} |
289 |
|
|
290 |
|
|
291 |
779 |
for (String propertyName : oldObject.getPropertyList()) { |
292 |
3001 |
BaseProperty newProperty = (BaseProperty) this.getField(propertyName); |
293 |
3001 |
BaseProperty oldProperty = (BaseProperty) oldObject.getField(propertyName); |
294 |
3001 |
BaseClass bclass = getXClass(context); |
295 |
3001 |
PropertyClass pclass = (PropertyClass) ((bclass == null) ? null : bclass.getField(propertyName)); |
296 |
3001 |
String propertyType = (pclass == null) ? "" : pclass.getClassType(); |
297 |
|
|
298 |
3001 |
if (newProperty == null) { |
299 |
|
|
300 |
90 |
if ((oldProperty != null) && (!oldProperty.toText().equals(""))) { |
301 |
63 |
if (pclass != null) { |
302 |
|
|
303 |
19 |
String oldPropertyValue = (oldProperty.getValue() instanceof String) ? oldProperty.toText() |
304 |
|
: pclass.displayView(propertyName, oldObject, context); |
305 |
19 |
difflist.add( |
306 |
|
new ObjectDiff(oldObject.getXClassReference(), oldObject.getNumber(), oldObject.getGuid(), |
307 |
|
ObjectDiff.ACTION_PROPERTYREMOVED, propertyName, propertyType, oldPropertyValue, "")); |
308 |
|
} else { |
309 |
|
|
310 |
44 |
difflist.add(new ObjectDiff(oldObject.getXClassReference(), oldObject.getNumber(), |
311 |
|
oldObject.getGuid(), ObjectDiff.ACTION_PROPERTYREMOVED, propertyName, propertyType, |
312 |
|
oldProperty.toText(), "")); |
313 |
|
} |
314 |
|
} |
315 |
|
} |
316 |
|
} |
317 |
|
|
318 |
779 |
return difflist; |
319 |
|
} |
320 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
321 |
6612 |
public com.xpn.xwiki.api.Object newObjectApi(BaseObject obj, XWikiContext context)... |
322 |
|
{ |
323 |
6611 |
return new com.xpn.xwiki.api.Object(obj, context); |
324 |
|
} |
325 |
|
|
|
|
| 90% |
Uncovered Elements: 2 (20) |
Complexity: 7 |
Complexity Density: 0.58 |
|
326 |
666 |
public void set(String fieldname, java.lang.Object value, XWikiContext context)... |
327 |
|
{ |
328 |
666 |
BaseClass bclass = getXClass(context); |
329 |
666 |
PropertyClass pclass = (PropertyClass) bclass.get(fieldname); |
330 |
666 |
BaseProperty prop = (BaseProperty) safeget(fieldname); |
331 |
666 |
if ((value instanceof String) && (pclass != null)) { |
332 |
593 |
prop = pclass.fromString((String) value); |
333 |
|
} else { |
334 |
73 |
if ((prop == null) && (pclass != null)) { |
335 |
62 |
prop = pclass.newProperty(); |
336 |
|
} |
337 |
73 |
if (prop != null) { |
338 |
73 |
prop.setValue(value); |
339 |
|
} |
340 |
|
} |
341 |
|
|
342 |
666 |
if (prop != null) { |
343 |
666 |
prop.setOwnerDocument(getOwnerDocument()); |
344 |
666 |
safeput(fieldname, prop); |
345 |
|
} |
346 |
|
} |
347 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
348 |
58633 |
public String getGuid()... |
349 |
|
{ |
350 |
58632 |
return this.guid; |
351 |
|
} |
352 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
353 |
44423 |
public void setGuid(String guid)... |
354 |
|
{ |
355 |
44423 |
this.guid = guid; |
356 |
|
} |
357 |
|
|
358 |
|
|
359 |
|
|
360 |
|
|
361 |
|
@param |
362 |
|
@since |
363 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
364 |
104010 |
@Override... |
365 |
|
public void setOwnerDocument(XWikiDocument ownerDocument) |
366 |
|
{ |
367 |
104010 |
super.setOwnerDocument(ownerDocument); |
368 |
|
|
369 |
104013 |
if (this.ownerDocument != null) { |
370 |
103895 |
setDocumentReference(this.ownerDocument.getDocumentReference()); |
371 |
|
} |
372 |
|
} |
373 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 4 |
Complexity Density: 0.44 |
|
374 |
0 |
@Override... |
375 |
|
protected void mergeField(PropertyInterface currentElement, ElementInterface previousElement, |
376 |
|
ElementInterface newElement, MergeConfiguration configuration, XWikiContext context, MergeResult mergeResult) |
377 |
|
{ |
378 |
0 |
BaseClass baseClass = getXClass(context); |
379 |
0 |
if (baseClass != null) { |
380 |
0 |
PropertyClass propertyClass = (PropertyClass) baseClass.get(currentElement.getName()); |
381 |
0 |
if (propertyClass != null) { |
382 |
0 |
try { |
383 |
0 |
propertyClass.mergeProperty((BaseProperty) currentElement, (BaseProperty) previousElement, |
384 |
|
(BaseProperty) newElement, configuration, context, mergeResult); |
385 |
|
} catch (Exception e) { |
386 |
0 |
mergeResult.getLog().error("Failed to merge field [{}]", currentElement.getName(), e); |
387 |
|
} |
388 |
|
|
389 |
0 |
return; |
390 |
|
} |
391 |
|
} |
392 |
|
|
393 |
0 |
super.mergeField(currentElement, previousElement, newElement, configuration, context, mergeResult); |
394 |
|
} |
395 |
|
} |