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.classes; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.Collections; |
24 |
|
import java.util.HashMap; |
25 |
|
import java.util.List; |
26 |
|
import java.util.Map; |
27 |
|
|
28 |
|
import org.apache.commons.lang3.StringUtils; |
29 |
|
import org.dom4j.Element; |
30 |
|
import org.slf4j.Logger; |
31 |
|
import org.slf4j.LoggerFactory; |
32 |
|
import org.xwiki.model.reference.EntityReference; |
33 |
|
|
34 |
|
import com.xpn.xwiki.XWikiContext; |
35 |
|
import com.xpn.xwiki.XWikiException; |
36 |
|
import com.xpn.xwiki.doc.merge.MergeConfiguration; |
37 |
|
import com.xpn.xwiki.doc.merge.MergeResult; |
38 |
|
import com.xpn.xwiki.objects.BaseProperty; |
39 |
|
import com.xpn.xwiki.objects.LargeStringProperty; |
40 |
|
import com.xpn.xwiki.objects.meta.PropertyMetaClass; |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
@version |
46 |
|
|
|
|
| 54.5% |
Uncovered Elements: 35 (77) |
Complexity: 26 |
Complexity Density: 0.57 |
|
47 |
|
public class UsersClass extends ListClass |
48 |
|
{ |
49 |
|
|
50 |
|
private static final Logger LOGGER = LoggerFactory.getLogger(UsersClass.class); |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
private static final String META_PROPERTY_USES_LIST = "usesList"; |
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
@param |
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
63 |
587 |
public UsersClass(PropertyMetaClass metaClass)... |
64 |
|
{ |
65 |
587 |
super("userslist", "Users List", metaClass); |
66 |
|
|
67 |
587 |
setSize(20); |
68 |
587 |
setDisplayType("input"); |
69 |
587 |
setPicker(true); |
70 |
|
} |
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
75 |
587 |
public UsersClass()... |
76 |
|
{ |
77 |
587 |
this(null); |
78 |
|
} |
79 |
|
|
|
|
| 50% |
Uncovered Elements: 2 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
80 |
2 |
@Override... |
81 |
|
public List<String> getList(XWikiContext context) |
82 |
|
{ |
83 |
|
|
84 |
|
|
85 |
2 |
try { |
86 |
2 |
return (List<String>) context.getWiki().getGroupService(context) |
87 |
|
.getAllMatchedUsers(null, false, 0, 0, null, context); |
88 |
|
} catch (XWikiException e) { |
89 |
0 |
LOGGER.warn("Failed to retrieve the list of users.", e); |
90 |
0 |
return Collections.emptyList(); |
91 |
|
} |
92 |
|
} |
93 |
|
|
|
|
| 81.8% |
Uncovered Elements: 2 (11) |
Complexity: 3 |
Complexity Density: 0.33 |
|
94 |
1 |
@Override... |
95 |
|
public Map<String, ListItem> getMap(XWikiContext context) |
96 |
|
{ |
97 |
|
|
98 |
|
|
99 |
1 |
Map<String, ListItem> result; |
100 |
1 |
List<String> users = getList(context); |
101 |
1 |
if (users != null && users.size() > 0) { |
102 |
1 |
result = new HashMap<String, ListItem>(); |
103 |
1 |
for (String userName : users) { |
104 |
|
|
105 |
1 |
String prettyUserName = context.getWiki().getUserName(userName, null, false, context); |
106 |
1 |
result.put(userName, new ListItem(userName, prettyUserName)); |
107 |
|
} |
108 |
|
} else { |
109 |
0 |
result = Collections.EMPTY_MAP; |
110 |
|
} |
111 |
1 |
return result; |
112 |
|
} |
113 |
|
|
114 |
|
|
115 |
|
@return |
116 |
|
|
117 |
|
@deprecated |
118 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
119 |
0 |
@Deprecated... |
120 |
|
public boolean isUsesList() |
121 |
|
{ |
122 |
0 |
return getIntValue(META_PROPERTY_USES_LIST) == 1; |
123 |
|
} |
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
@param |
130 |
|
|
131 |
|
@deprecated |
132 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
133 |
0 |
@Deprecated... |
134 |
|
public void setUsesList(boolean usesList) |
135 |
|
{ |
136 |
0 |
setIntValue(META_PROPERTY_USES_LIST, usesList ? 1 : 0); |
137 |
|
} |
138 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
139 |
244 |
@Override... |
140 |
|
public BaseProperty newProperty() |
141 |
|
{ |
142 |
244 |
BaseProperty property = new LargeStringProperty(); |
143 |
244 |
property.setName(getName()); |
144 |
244 |
return property; |
145 |
|
} |
146 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
147 |
236 |
@Override... |
148 |
|
public BaseProperty fromString(String value) |
149 |
|
{ |
150 |
236 |
BaseProperty prop = newProperty(); |
151 |
236 |
prop.setValue(value); |
152 |
236 |
return prop; |
153 |
|
} |
154 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
155 |
2 |
@Override... |
156 |
|
public BaseProperty fromStringArray(String[] strings) |
157 |
|
{ |
158 |
2 |
List<String> list = new ArrayList<String>(); |
159 |
5 |
for (int i = 0; i < strings.length; i++) { |
160 |
3 |
if (!StringUtils.isBlank(strings[i])) { |
161 |
2 |
list.add(strings[i]); |
162 |
|
} |
163 |
|
} |
164 |
2 |
BaseProperty prop = newProperty(); |
165 |
2 |
prop.setValue(StringUtils.join(list, ',')); |
166 |
2 |
return prop; |
167 |
|
} |
168 |
|
|
169 |
|
|
170 |
|
@param |
171 |
|
@param |
172 |
|
@return |
173 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
174 |
0 |
public String getText(String value, XWikiContext context)... |
175 |
|
{ |
176 |
0 |
return context.getWiki().getUserName(value, null, false, context); |
177 |
|
} |
178 |
|
|
179 |
|
|
180 |
|
|
181 |
|
|
182 |
|
@param |
183 |
|
@return |
184 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
185 |
241 |
public static List<String> getListFromString(String value)... |
186 |
|
{ |
187 |
241 |
return getListFromString(value, ",", false); |
188 |
|
} |
189 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
190 |
0 |
@Override... |
191 |
|
public BaseProperty newPropertyfromXML(Element ppcel) |
192 |
|
{ |
193 |
0 |
String value = ppcel.getText(); |
194 |
0 |
return fromString(value); |
195 |
|
} |
196 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
197 |
0 |
@Override... |
198 |
|
public List<String> toList(BaseProperty<?> property) |
199 |
|
{ |
200 |
0 |
List<String> selectlist; |
201 |
|
|
202 |
0 |
if (property == null) { |
203 |
0 |
selectlist = Collections.emptyList(); |
204 |
|
} else { |
205 |
0 |
selectlist = getListFromString((String) property.getValue()); |
206 |
|
} |
207 |
|
|
208 |
0 |
return selectlist; |
209 |
|
} |
210 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 5 |
Complexity Density: 1.67 |
|
211 |
0 |
@Override... |
212 |
|
public void fromList(BaseProperty<?> property, List<String> list) |
213 |
|
{ |
214 |
0 |
if (isMultiSelect()) { |
215 |
0 |
property.setValue(list != null ? StringUtils.join(list, ',') : null); |
216 |
|
} else { |
217 |
0 |
property.setValue(list != null && !list.isEmpty() ? list.get(0) : null); |
218 |
|
} |
219 |
|
} |
220 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
221 |
0 |
@Override... |
222 |
|
public <T extends EntityReference> void mergeProperty(BaseProperty<T> currentProperty, |
223 |
|
BaseProperty<T> previousProperty, BaseProperty<T> newProperty, MergeConfiguration configuration, |
224 |
|
XWikiContext xcontext, MergeResult mergeResult) |
225 |
|
{ |
226 |
|
|
227 |
0 |
mergeNotOrderedListProperty(currentProperty, previousProperty, newProperty, configuration, xcontext, |
228 |
|
mergeResult); |
229 |
|
} |
230 |
|
} |