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