1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.internal.mandatory; |
21 |
|
|
22 |
|
import javax.inject.Inject; |
23 |
|
import javax.inject.Named; |
24 |
|
import javax.inject.Provider; |
25 |
|
import javax.inject.Singleton; |
26 |
|
|
27 |
|
import org.slf4j.Logger; |
28 |
|
import org.xwiki.component.annotation.Component; |
29 |
|
import org.xwiki.model.reference.DocumentReference; |
30 |
|
import org.xwiki.model.reference.EntityReference; |
31 |
|
import org.xwiki.model.reference.LocalDocumentReference; |
32 |
|
import org.xwiki.wiki.descriptor.WikiDescriptorManager; |
33 |
|
|
34 |
|
import com.xpn.xwiki.XWiki; |
35 |
|
import com.xpn.xwiki.XWikiContext; |
36 |
|
import com.xpn.xwiki.XWikiException; |
37 |
|
import com.xpn.xwiki.doc.MandatoryDocumentInitializer; |
38 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
39 |
|
import com.xpn.xwiki.objects.BaseObject; |
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
@version |
45 |
|
@since |
46 |
|
|
47 |
|
@Component |
48 |
|
@Singleton |
49 |
|
@Named("XWiki.XWikiAllGroup") |
|
|
| 97.1% |
Uncovered Elements: 1 (34) |
Complexity: 8 |
Complexity Density: 0.36 |
|
50 |
|
public class XWikiAllGroupDocumentInitializer implements MandatoryDocumentInitializer |
51 |
|
{ |
52 |
|
private static final String DOCUMENT_NAME = "XWikiAllGroup"; |
53 |
|
|
54 |
|
private static final String CLASS_NAME = "XWikiGroups"; |
55 |
|
|
56 |
|
@Inject |
57 |
|
private WikiDescriptorManager wikiDescriptorManager; |
58 |
|
|
59 |
|
@Inject |
60 |
|
private Provider<XWikiContext> xcontextProvider; |
61 |
|
|
62 |
|
@Inject |
63 |
|
private Logger logger; |
64 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
65 |
116 |
@Override... |
66 |
|
public EntityReference getDocumentReference() |
67 |
|
{ |
68 |
116 |
return new LocalDocumentReference(XWiki.SYSTEM_SPACE, DOCUMENT_NAME); |
69 |
|
} |
70 |
|
|
|
|
| 96.8% |
Uncovered Elements: 1 (31) |
Complexity: 7 |
Complexity Density: 0.33 |
|
71 |
117 |
@Override... |
72 |
|
public boolean updateDocument(XWikiDocument document) |
73 |
|
{ |
74 |
117 |
boolean needsUpdate = false; |
75 |
|
|
76 |
|
|
77 |
117 |
LocalDocumentReference classReference = new LocalDocumentReference(XWiki.SYSTEM_SPACE, CLASS_NAME); |
78 |
|
|
79 |
|
|
80 |
117 |
if (document.getCreatorReference() == null) { |
81 |
38 |
document.setCreatorReference(new DocumentReference(wikiDescriptorManager.getMainWikiId(), |
82 |
|
XWiki.SYSTEM_SPACE, "superadmin")); |
83 |
38 |
needsUpdate = true; |
84 |
|
} |
85 |
|
|
86 |
|
|
87 |
117 |
if (document.getAuthorReference() == null) { |
88 |
38 |
document.setAuthorReference(document.getCreatorReference()); |
89 |
38 |
needsUpdate = true; |
90 |
|
} |
91 |
|
|
92 |
|
|
93 |
117 |
if (document.getParentReference() == null) { |
94 |
38 |
document.setParentReference(classReference); |
95 |
38 |
needsUpdate = true; |
96 |
|
} |
97 |
|
|
98 |
|
|
99 |
117 |
if (!document.isHidden()) { |
100 |
38 |
document.setHidden(true); |
101 |
38 |
needsUpdate = true; |
102 |
|
} |
103 |
|
|
104 |
|
|
105 |
117 |
if (document.getXObject(classReference) == null) { |
106 |
38 |
try { |
107 |
38 |
BaseObject obj = document.newXObject(classReference, xcontextProvider.get()); |
108 |
38 |
obj.setStringValue("member", ""); |
109 |
38 |
needsUpdate = true; |
110 |
|
} catch (XWikiException e) { |
111 |
0 |
logger.error( |
112 |
|
String.format("Impossible to add an object to the document XWiki.XWikiAllGroups in the wiki [%s].", |
113 |
|
document.getDocumentReference().getWikiReference().getName()), e); |
114 |
|
} |
115 |
|
} |
116 |
|
|
117 |
117 |
return needsUpdate; |
118 |
|
} |
119 |
|
} |