1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.wiki.user.internal; |
21 |
|
|
22 |
|
import javax.inject.Named; |
23 |
|
import javax.inject.Singleton; |
24 |
|
|
25 |
|
import org.xwiki.component.annotation.Component; |
26 |
|
import org.xwiki.model.EntityType; |
27 |
|
import org.xwiki.model.reference.EntityReference; |
28 |
|
import org.xwiki.wiki.user.MembershipType; |
29 |
|
import org.xwiki.wiki.user.UserScope; |
30 |
|
|
31 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
32 |
|
import com.xpn.xwiki.internal.mandatory.AbstractMandatoryDocumentInitializer; |
33 |
|
import com.xpn.xwiki.objects.classes.BaseClass; |
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
@since |
39 |
|
@version |
40 |
|
|
41 |
|
@Component |
42 |
|
@Named("WikiManager.WikiUserClass") |
43 |
|
@Singleton |
|
|
| 88.9% |
Uncovered Elements: 2 (18) |
Complexity: 4 |
Complexity Density: 0.33 |
|
44 |
|
public class WikiUserClassDocumentInitializer extends AbstractMandatoryDocumentInitializer |
45 |
|
{ |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
public static final String DOCUMENT_NAME = "WikiUserClass"; |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
public static final String DOCUMENT_SPACE = "WikiManager"; |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
public static final EntityReference CONFIGURATION_CLASS = new EntityReference(DOCUMENT_NAME, EntityType.DOCUMENT, |
60 |
|
new EntityReference(DOCUMENT_SPACE, EntityType.SPACE)); |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
public static final String DEFAULT_FIELDS_SEPARATOR = "|"; |
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
public static final String FIELD_MEMBERSHIPTYPE = "membershipType"; |
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
public static final String FIELDPN_MEMBERSHIPTYPE = "Membership Type"; |
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
public static final String FIELDL_MEMBERSHIPTYPE = MembershipType.OPEN.name().toLowerCase() |
81 |
|
+ DEFAULT_FIELDS_SEPARATOR + MembershipType.REQUEST.name().toLowerCase() + DEFAULT_FIELDS_SEPARATOR |
82 |
|
+ MembershipType.INVITE.name().toLowerCase(); |
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
public static final String FIELDDT_MEMBERSHIPTYPE = "radio"; |
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
public static final String FIELD_USERSCOPE = "userScope"; |
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
public static final String FIELDPN_USERSCOPE = "User scope"; |
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
public static final String FIELDDT_USERSCOPE = FIELDDT_MEMBERSHIPTYPE; |
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
public static final String FIELDL_USERSCOPE = UserScope.GLOBAL_ONLY.name().toLowerCase() |
108 |
|
+ DEFAULT_FIELDS_SEPARATOR + UserScope.LOCAL_ONLY.name().toLowerCase() + DEFAULT_FIELDS_SEPARATOR |
109 |
|
+ UserScope.LOCAL_AND_GLOBAL.name().toLowerCase(); |
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
114 |
2 |
public WikiUserClassDocumentInitializer()... |
115 |
|
{ |
116 |
2 |
super(DOCUMENT_SPACE, DOCUMENT_NAME); |
117 |
|
} |
118 |
|
|
|
|
| 86.7% |
Uncovered Elements: 2 (15) |
Complexity: 3 |
Complexity Density: 0.27 |
|
119 |
6 |
@Override... |
120 |
|
public boolean updateDocument(XWikiDocument document) |
121 |
|
{ |
122 |
6 |
boolean needsUpdate = false; |
123 |
|
|
124 |
|
|
125 |
6 |
BaseClass baseClass = document.getXClass(); |
126 |
|
|
127 |
6 |
needsUpdate |= baseClass.addStaticListField(FIELD_MEMBERSHIPTYPE, FIELDPN_MEMBERSHIPTYPE, |
128 |
|
MembershipType.values().length, false, FIELDL_MEMBERSHIPTYPE, FIELDDT_MEMBERSHIPTYPE); |
129 |
6 |
needsUpdate |= baseClass.addStaticListField(FIELD_USERSCOPE, FIELDPN_USERSCOPE, |
130 |
|
UserScope.values().length, false, FIELDL_USERSCOPE, FIELDDT_USERSCOPE); |
131 |
|
|
132 |
|
|
133 |
6 |
if (!document.isHidden()) { |
134 |
6 |
document.setHidden(true); |
135 |
6 |
needsUpdate = true; |
136 |
|
} |
137 |
|
|
138 |
|
|
139 |
6 |
if (document.isNew()) { |
140 |
6 |
needsUpdate |= setClassDocumentFields(document, "Wiki User Class"); |
141 |
6 |
document.setContent(document.getContent() + "\n\nClass that represents the wiki configuration" |
142 |
|
+ " about users."); |
143 |
|
} |
144 |
|
|
145 |
6 |
return needsUpdate; |
146 |
|
} |
147 |
|
} |