1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.kim.api.group; |
18 | |
|
19 | |
import org.apache.commons.collections.CollectionUtils; |
20 | |
import org.apache.commons.lang.StringUtils; |
21 | |
import org.apache.commons.lang.builder.EqualsBuilder; |
22 | |
import org.apache.commons.lang.builder.HashCodeBuilder; |
23 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
24 | |
import org.kuali.rice.core.api.CoreConstants; |
25 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
26 | |
import org.kuali.rice.core.api.mo.ModelObjectComplete; |
27 | |
import org.kuali.rice.kim.api.person.Person; |
28 | |
import org.w3c.dom.Element; |
29 | |
|
30 | |
import javax.xml.bind.annotation.XmlAccessType; |
31 | |
import javax.xml.bind.annotation.XmlAccessorType; |
32 | |
import javax.xml.bind.annotation.XmlAnyElement; |
33 | |
import javax.xml.bind.annotation.XmlElement; |
34 | |
import javax.xml.bind.annotation.XmlRootElement; |
35 | |
import javax.xml.bind.annotation.XmlType; |
36 | |
import java.io.Serializable; |
37 | |
import java.util.ArrayList; |
38 | |
import java.util.Collection; |
39 | |
import java.util.Collections; |
40 | |
import java.util.HashSet; |
41 | |
import java.util.List; |
42 | |
import java.util.Set; |
43 | |
|
44 | |
@XmlRootElement(name = Group.Constants.ROOT_ELEMENT_NAME) |
45 | |
@XmlAccessorType(XmlAccessType.NONE) |
46 | |
@XmlType(name = Group.Constants.TYPE_NAME, propOrder = { |
47 | |
Group.Elements.ID, |
48 | |
Group.Elements.NAMESPACE_CODE, |
49 | |
Group.Elements.NAME, |
50 | |
Group.Elements.DESCRIPTION, |
51 | |
Group.Elements.KIM_TYPE_ID, |
52 | |
Group.Elements.MEMBERS, |
53 | |
Group.Elements.ATTRIBUTES, |
54 | |
Group.Elements.ACTIVE, |
55 | |
CoreConstants.CommonElements.VERSION_NUMBER, |
56 | |
CoreConstants.CommonElements.OBJECT_ID, |
57 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
58 | |
}) |
59 | |
public final class Group implements GroupContract, ModelObjectComplete { |
60 | |
@XmlElement(name = Elements.ID, required = true) |
61 | |
private final String id; |
62 | |
|
63 | |
@XmlElement(name = Elements.NAMESPACE_CODE, required = true) |
64 | |
private final String namespaceCode; |
65 | |
|
66 | |
@XmlElement(name = Elements.NAME, required = true) |
67 | |
private final String name; |
68 | |
|
69 | |
@XmlElement(name = Elements.DESCRIPTION, required = false) |
70 | |
private final String description; |
71 | |
|
72 | |
@XmlElement(name = Elements.KIM_TYPE_ID, required = true) |
73 | |
private final String kimTypeId; |
74 | |
|
75 | |
@XmlElement(name = Elements.MEMBERS, required = false) |
76 | |
private final List<GroupMember> members; |
77 | |
|
78 | |
@XmlElement(name = Elements.ATTRIBUTES, required = false) |
79 | |
private final List<GroupAttribute> attributes; |
80 | |
|
81 | |
@XmlElement(name = Elements.ACTIVE, required = false) |
82 | |
private final boolean active; |
83 | |
|
84 | |
@XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) |
85 | |
private final Long versionNumber; |
86 | |
|
87 | |
@XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false) |
88 | |
private final String objectId; |
89 | |
|
90 | 4 | @SuppressWarnings("unused") |
91 | |
@XmlAnyElement |
92 | |
private final Collection<Element> _futureElements = null; |
93 | |
|
94 | 3 | private Group() { |
95 | 3 | this.id = null; |
96 | 3 | this.namespaceCode = null; |
97 | 3 | this.name = null; |
98 | 3 | this.description = null; |
99 | 3 | this.kimTypeId = null; |
100 | 3 | this.members = null; |
101 | 3 | this.attributes = null; |
102 | 3 | this.versionNumber = null; |
103 | 3 | this.objectId = null; |
104 | 3 | this.active = false; |
105 | 3 | } |
106 | |
|
107 | 1 | public Group(Builder builder) { |
108 | 1 | id = builder.getId(); |
109 | 1 | namespaceCode = builder.getNamespaceCode(); |
110 | 1 | name = builder.getName(); |
111 | 1 | description = builder.getDescription(); |
112 | 1 | kimTypeId = builder.getKimTypeId(); |
113 | 1 | members = new ArrayList<GroupMember>(); |
114 | 1 | if (!CollectionUtils.isEmpty(builder.getMembers())) { |
115 | 1 | for (GroupMember.Builder member : builder.getMembers()) { |
116 | 2 | members.add(member.build()); |
117 | |
} |
118 | |
} |
119 | 1 | attributes = new ArrayList<GroupAttribute>(); |
120 | 1 | if (!CollectionUtils.isEmpty(builder.getAttributes())) { |
121 | 1 | for (GroupAttribute.Builder attribute : builder.getAttributes()) { |
122 | 2 | attributes.add(attribute.build()); |
123 | |
} |
124 | |
} |
125 | 1 | versionNumber = builder.getVersionNumber(); |
126 | 1 | objectId = builder.getObjectId(); |
127 | 1 | active = builder.isActive(); |
128 | 1 | } |
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | 1 | public static class Builder implements GroupContract, ModelBuilder, Serializable { |
135 | |
private String id; |
136 | |
private String namespaceCode; |
137 | |
private String name; |
138 | |
private String description; |
139 | |
private String kimTypeId; |
140 | |
private List<GroupMember.Builder> members; |
141 | |
private List<GroupAttribute.Builder> attributes; |
142 | |
private boolean active; |
143 | |
private Long versionNumber; |
144 | |
private String objectId; |
145 | |
|
146 | 1 | private Builder(String id, String namespaceCode, String name, String kimTypeId) { |
147 | 1 | setId(id); |
148 | 1 | setNamespaceCode(namespaceCode); |
149 | 1 | setName(name); |
150 | 1 | setKimTypeId(kimTypeId); |
151 | 1 | } |
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
public static Builder create(String id, String namespaceCode, String name, String kimTypeId) { |
157 | 0 | return new Builder(id, namespaceCode, name, kimTypeId); |
158 | |
} |
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
public static Builder create(GroupContract contract) { |
164 | 1 | Builder builder = new Builder(contract.getId(), contract.getNamespaceCode(), contract.getName(), contract.getKimTypeId()); |
165 | 1 | builder.setDescription(contract.getDescription()); |
166 | |
|
167 | 1 | List<GroupMember.Builder> groupMemberBuilders = new ArrayList<GroupMember.Builder>(); |
168 | 1 | for (GroupMemberContract memberContract : contract.getMembers()) { |
169 | 2 | GroupMember.Builder memberBuilder = GroupMember.Builder.create(memberContract); |
170 | 2 | groupMemberBuilders.add(memberBuilder); |
171 | 2 | } |
172 | 1 | builder.setMembers(groupMemberBuilders); |
173 | |
|
174 | 1 | List<GroupAttribute.Builder> groupAttributeBuilders = new ArrayList<GroupAttribute.Builder>(); |
175 | 1 | for (GroupAttributeContract attributeContract : contract.getAttributes()) { |
176 | 2 | GroupAttribute.Builder attributeBuilder = GroupAttribute.Builder.create(attributeContract); |
177 | 2 | groupAttributeBuilders.add(attributeBuilder); |
178 | 2 | } |
179 | 1 | builder.setAttributes(groupAttributeBuilders); |
180 | |
|
181 | 1 | builder.setActive(contract.isActive()); |
182 | 1 | builder.setVersionNumber(contract.getVersionNumber()); |
183 | 1 | builder.setObjectId(contract.getObjectId()); |
184 | 1 | return builder; |
185 | |
} |
186 | |
|
187 | |
@Override |
188 | |
public String getId() { |
189 | 1 | return id; |
190 | |
} |
191 | |
|
192 | |
public void setId(String id) { |
193 | 1 | if (StringUtils.isEmpty(id)) { |
194 | 0 | throw new IllegalArgumentException("id is blank"); |
195 | |
} |
196 | 1 | this.id = id; |
197 | 1 | } |
198 | |
|
199 | |
@Override |
200 | |
public String getNamespaceCode() { |
201 | 1 | return namespaceCode; |
202 | |
} |
203 | |
|
204 | |
public void setNamespaceCode(String namespaceCode) { |
205 | 1 | if (StringUtils.isEmpty(namespaceCode)) { |
206 | 0 | throw new IllegalArgumentException("namespaceCode is blank"); |
207 | |
} |
208 | 1 | this.namespaceCode = namespaceCode; |
209 | 1 | } |
210 | |
|
211 | |
@Override |
212 | |
public String getName() { |
213 | 1 | return name; |
214 | |
} |
215 | |
|
216 | |
public void setName(String name) { |
217 | 1 | if (StringUtils.isEmpty(name)) { |
218 | 0 | throw new IllegalArgumentException("name is blank"); |
219 | |
} |
220 | 1 | this.name = name; |
221 | 1 | } |
222 | |
|
223 | |
@Override |
224 | |
public String getDescription() { |
225 | 1 | return description; |
226 | |
} |
227 | |
|
228 | |
public void setDescription(String description) { |
229 | 1 | this.description = description; |
230 | 1 | } |
231 | |
|
232 | |
@Override |
233 | |
public String getKimTypeId() { |
234 | 1 | return kimTypeId; |
235 | |
} |
236 | |
|
237 | |
public void setKimTypeId(String kimTypeId) { |
238 | 1 | if (StringUtils.isEmpty(kimTypeId)) { |
239 | 0 | throw new IllegalArgumentException("kimTypeId is blank"); |
240 | |
} |
241 | 1 | this.kimTypeId = kimTypeId; |
242 | 1 | } |
243 | |
|
244 | |
@Override |
245 | |
public List<GroupMember.Builder> getMembers() { |
246 | 2 | return members; |
247 | |
} |
248 | |
|
249 | |
public void setMembers(List<GroupMember.Builder> members) { |
250 | 1 | this.members = members; |
251 | 1 | } |
252 | |
|
253 | |
|
254 | |
public List<Person> getPersonMembers() { |
255 | 0 | return null; |
256 | |
} |
257 | |
|
258 | |
|
259 | |
public List<Group> getGroupMembers() { |
260 | 0 | return null; |
261 | |
} |
262 | |
|
263 | |
@Override |
264 | |
public List<GroupAttribute.Builder> getAttributes() { |
265 | 2 | return attributes; |
266 | |
} |
267 | |
|
268 | |
public void setAttributes(List<GroupAttribute.Builder> attributes) { |
269 | 1 | this.attributes = attributes; |
270 | 1 | } |
271 | |
|
272 | |
@Override |
273 | |
public boolean isActive() { |
274 | 1 | return active; |
275 | |
} |
276 | |
|
277 | |
public void setActive(boolean active) { |
278 | 1 | this.active = active; |
279 | 1 | } |
280 | |
|
281 | |
@Override |
282 | |
public Long getVersionNumber() { |
283 | 1 | return versionNumber; |
284 | |
} |
285 | |
|
286 | |
public void setVersionNumber(Long versionNumber) { |
287 | 1 | this.versionNumber = versionNumber; |
288 | 1 | } |
289 | |
|
290 | |
@Override |
291 | |
public String getObjectId() { |
292 | 1 | return objectId; |
293 | |
} |
294 | |
|
295 | |
public void setObjectId(String objectId) { |
296 | 1 | this.objectId = objectId; |
297 | 1 | } |
298 | |
|
299 | |
@Override |
300 | |
public Group build() { |
301 | 1 | return new Group(this); |
302 | |
} |
303 | |
} |
304 | |
|
305 | |
@Override |
306 | |
public int hashCode() { |
307 | 0 | return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
308 | |
} |
309 | |
|
310 | |
@Override |
311 | |
public boolean equals(Object obj) { |
312 | 1 | return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
313 | |
} |
314 | |
|
315 | |
@Override |
316 | |
public String toString() { |
317 | 0 | return ToStringBuilder.reflectionToString(this); |
318 | |
} |
319 | |
|
320 | |
@Override |
321 | |
public String getId() { |
322 | 1 | return id; |
323 | |
} |
324 | |
|
325 | |
@Override |
326 | |
public String getNamespaceCode() { |
327 | 1 | return namespaceCode; |
328 | |
} |
329 | |
|
330 | |
@Override |
331 | |
public String getName() { |
332 | 1 | return name; |
333 | |
} |
334 | |
|
335 | |
@Override |
336 | |
public String getDescription() { |
337 | 0 | return description; |
338 | |
} |
339 | |
|
340 | |
@Override |
341 | |
public String getKimTypeId() { |
342 | 0 | return kimTypeId; |
343 | |
} |
344 | |
|
345 | |
@Override |
346 | |
public List<GroupMember> getMembers() { |
347 | 17 | return Collections.unmodifiableList(members); |
348 | |
} |
349 | |
|
350 | |
|
351 | |
public List<Person> getPersonMembers() { |
352 | 0 | List<Person> personMembers = new ArrayList(); |
353 | 0 | for (GroupMember member : members) { |
354 | |
|
355 | |
|
356 | |
|
357 | |
|
358 | |
} |
359 | 0 | return Collections.unmodifiableList(personMembers); |
360 | |
} |
361 | |
|
362 | |
|
363 | |
public List<Group> getGroupMembers() { |
364 | 0 | List groupMembers = new ArrayList(); |
365 | 0 | for (GroupMember member : members) { |
366 | |
|
367 | |
|
368 | |
|
369 | |
|
370 | |
} |
371 | 0 | return Collections.unmodifiableList(groupMembers); |
372 | |
} |
373 | |
|
374 | |
@Override |
375 | |
public List<GroupAttribute> getAttributes() { |
376 | 15 | return attributes; |
377 | |
} |
378 | |
|
379 | |
@Override |
380 | |
public boolean isActive() { |
381 | 1 | return active; |
382 | |
} |
383 | |
|
384 | |
@Override |
385 | |
public Long getVersionNumber() { |
386 | 1 | return versionNumber; |
387 | |
} |
388 | |
|
389 | |
@Override |
390 | |
public String getObjectId() { |
391 | 1 | return objectId; |
392 | |
} |
393 | |
|
394 | |
|
395 | |
|
396 | |
|
397 | 0 | static class Constants { |
398 | |
final static String ROOT_ELEMENT_NAME = "group"; |
399 | |
final static String TYPE_NAME = "GroupType"; |
400 | 1 | final static String[] HASH_CODE_EQUALS_EXCLUDE = {CoreConstants.CommonElements.FUTURE_ELEMENTS}; |
401 | |
} |
402 | |
|
403 | |
|
404 | |
|
405 | |
|
406 | |
|
407 | 0 | static class Elements { |
408 | |
final static String ID = "id"; |
409 | |
final static String NAMESPACE_CODE = "namespaceCode"; |
410 | |
final static String NAME = "name"; |
411 | |
final static String DESCRIPTION = "description"; |
412 | |
final static String KIM_TYPE_ID = "kimTypeId"; |
413 | |
final static String ATTRIBUTES = "attributes"; |
414 | |
final static String MEMBERS = "members"; |
415 | |
final static String ACTIVE = "active"; |
416 | |
} |
417 | |
} |