1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.impl.jaxb; |
17 | |
|
18 | |
import org.apache.commons.lang.StringUtils; |
19 | |
import org.joda.time.DateTime; |
20 | |
import org.kuali.rice.core.api.util.jaxb.DateTimeAdapter; |
21 | |
import org.kuali.rice.core.util.jaxb.NameAndNamespacePair; |
22 | |
import org.kuali.rice.core.util.jaxb.NameAndNamespacePairValidatingAdapter; |
23 | |
import org.kuali.rice.kim.api.group.GroupContract; |
24 | |
import org.kuali.rice.kim.api.identity.principal.PrincipalContract; |
25 | |
import org.kuali.rice.kim.api.jaxb.QualificationListAdapter; |
26 | |
import org.kuali.rice.kim.api.role.RoleContract; |
27 | |
import org.kuali.rice.kim.api.role.RoleMemberContract; |
28 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
29 | |
import org.kuali.rice.kim.util.KimConstants.KimUIConstants; |
30 | |
|
31 | |
import javax.xml.bind.Unmarshaller; |
32 | |
import javax.xml.bind.annotation.XmlAccessType; |
33 | |
import javax.xml.bind.annotation.XmlAccessorType; |
34 | |
import javax.xml.bind.annotation.XmlElement; |
35 | |
import javax.xml.bind.annotation.XmlTransient; |
36 | |
import javax.xml.bind.annotation.XmlType; |
37 | |
import javax.xml.bind.annotation.adapters.NormalizedStringAdapter; |
38 | |
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; |
39 | |
import java.io.Serializable; |
40 | |
import java.util.HashMap; |
41 | |
import java.util.Map; |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
@XmlTransient |
50 | |
public abstract class RoleMemberXmlDTO implements Serializable { |
51 | |
|
52 | |
private static final long serialVersionUID = 1L; |
53 | |
|
54 | |
@XmlElement(name="principalId") |
55 | |
@XmlJavaTypeAdapter(NormalizedStringAdapter.class) |
56 | |
private String principalId; |
57 | |
|
58 | |
@XmlElement(name="principalName") |
59 | |
@XmlJavaTypeAdapter(NormalizedStringAdapter.class) |
60 | |
private String principalName; |
61 | |
|
62 | |
@XmlElement(name="groupId") |
63 | |
@XmlJavaTypeAdapter(NormalizedStringAdapter.class) |
64 | |
private String groupId; |
65 | |
|
66 | |
@XmlElement(name="groupName") |
67 | |
@XmlJavaTypeAdapter(NameAndNamespacePairValidatingAdapter.class) |
68 | |
private NameAndNamespacePair groupName; |
69 | |
|
70 | |
@XmlElement(name="roleIdAsMember") |
71 | |
@XmlJavaTypeAdapter(NormalizedStringAdapter.class) |
72 | |
private String roleIdAsMember; |
73 | |
|
74 | |
@XmlElement(name="roleNameAsMember") |
75 | |
@XmlJavaTypeAdapter(NameAndNamespacePairValidatingAdapter.class) |
76 | |
private NameAndNamespacePair roleNameAsMember; |
77 | |
|
78 | |
@XmlElement(name="activeFromDate") |
79 | |
@XmlJavaTypeAdapter(DateTimeAdapter.class) |
80 | |
private DateTime activeFromDate; |
81 | |
|
82 | |
@XmlElement(name="activeToDate") |
83 | |
@XmlJavaTypeAdapter(DateTimeAdapter.class) |
84 | |
private DateTime activeToDate; |
85 | |
|
86 | |
@XmlElement(name="qualifications") |
87 | |
@XmlJavaTypeAdapter(QualificationListAdapter.class) |
88 | |
private Map<String, String> qualifications; |
89 | |
|
90 | |
@XmlTransient |
91 | |
private String memberTypeCode; |
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | 0 | public RoleMemberXmlDTO() {} |
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | 0 | public RoleMemberXmlDTO(RoleMemberContract roleMember, boolean populateMemberId) { |
107 | 0 | if (roleMember == null) { |
108 | 0 | throw new IllegalArgumentException("roleMember cannot be null"); |
109 | |
} |
110 | 0 | this.memberTypeCode = roleMember.getMemberTypeCode(); |
111 | 0 | this.activeFromDate = roleMember.getActiveFromDate(); |
112 | 0 | this.activeToDate = roleMember.getActiveToDate(); |
113 | 0 | this.qualifications = (roleMember.getAttributes() != null) ? roleMember.getAttributes() : new HashMap<String, String>(); |
114 | |
|
115 | 0 | if (KimUIConstants.MEMBER_TYPE_PRINCIPAL_CODE.equals(memberTypeCode)) { |
116 | 0 | if (populateMemberId) { |
117 | 0 | this.principalId = roleMember.getMemberId(); |
118 | |
} |
119 | 0 | PrincipalContract principal = KimApiServiceLocator.getIdentityService().getPrincipal(roleMember.getMemberId()); |
120 | 0 | if (principal == null) { |
121 | 0 | throw new IllegalArgumentException("Cannot find principal with ID \"" + roleMember.getMemberId() + "\""); |
122 | |
} |
123 | 0 | this.principalName = principal.getPrincipalName(); |
124 | 0 | } else if (KimUIConstants.MEMBER_TYPE_GROUP_CODE.equals(memberTypeCode)) { |
125 | 0 | if (populateMemberId) { |
126 | 0 | this.groupId = roleMember.getMemberId(); |
127 | |
} |
128 | 0 | GroupContract group = KimApiServiceLocator.getGroupService().getGroup(roleMember.getMemberId()); |
129 | 0 | if (group == null) { |
130 | 0 | throw new IllegalArgumentException("Cannot find group with ID \"" + roleMember.getMemberId() + "\""); |
131 | |
} |
132 | 0 | this.groupName = new NameAndNamespacePair(group.getNamespaceCode(), group.getName()); |
133 | 0 | } else if (KimUIConstants.MEMBER_TYPE_ROLE_CODE.equals(memberTypeCode)) { |
134 | 0 | if (populateMemberId) { |
135 | 0 | this.roleIdAsMember = roleMember.getMemberId(); |
136 | |
} |
137 | 0 | RoleContract role = KimApiServiceLocator.getRoleService().getRole(roleMember.getMemberId()); |
138 | 0 | if (role == null) { |
139 | 0 | throw new IllegalArgumentException("Cannot find role with ID \"" + roleMember.getMemberId() + "\""); |
140 | |
} |
141 | 0 | this.roleNameAsMember = new NameAndNamespacePair(role.getNamespaceCode(), role.getName()); |
142 | 0 | } else { |
143 | 0 | throw new IllegalArgumentException("Cannot construct a RoleMemberXmlDTO from a role member with an unrecognized member type code of \"" + |
144 | |
memberTypeCode + "\""); |
145 | |
} |
146 | 0 | } |
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
public String getPrincipalId() { |
152 | 0 | return this.principalId; |
153 | |
} |
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
public void setPrincipalId(String principalId) { |
159 | 0 | this.principalId = principalId; |
160 | 0 | } |
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
public String getPrincipalName() { |
166 | 0 | return this.principalName; |
167 | |
} |
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
public void setPrincipalName(String principalName) { |
173 | 0 | this.principalName = principalName; |
174 | 0 | } |
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
public String getGroupId() { |
180 | 0 | return this.groupId; |
181 | |
} |
182 | |
|
183 | |
|
184 | |
|
185 | |
|
186 | |
public void setGroupId(String groupId) { |
187 | 0 | this.groupId = groupId; |
188 | 0 | } |
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
public NameAndNamespacePair getGroupName() { |
194 | 0 | return this.groupName; |
195 | |
} |
196 | |
|
197 | |
|
198 | |
|
199 | |
|
200 | |
public void setGroupName(NameAndNamespacePair groupName) { |
201 | 0 | this.groupName = groupName; |
202 | 0 | } |
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
public String getRoleIdAsMember() { |
208 | 0 | return this.roleIdAsMember; |
209 | |
} |
210 | |
|
211 | |
|
212 | |
|
213 | |
|
214 | |
public void setRoleIdAsMember(String roleIdAsMember) { |
215 | 0 | this.roleIdAsMember = roleIdAsMember; |
216 | 0 | } |
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | |
public NameAndNamespacePair getRoleNameAsMember() { |
222 | 0 | return this.roleNameAsMember; |
223 | |
} |
224 | |
|
225 | |
|
226 | |
|
227 | |
|
228 | |
public void setRoleNameAsMember(NameAndNamespacePair roleNameAsMember) { |
229 | 0 | this.roleNameAsMember = roleNameAsMember; |
230 | 0 | } |
231 | |
|
232 | |
|
233 | |
|
234 | |
|
235 | |
public DateTime getActiveFromDate() { |
236 | 0 | return this.activeFromDate; |
237 | |
} |
238 | |
|
239 | |
|
240 | |
|
241 | |
|
242 | |
public void setActiveFromDate(DateTime activeFromDate) { |
243 | 0 | this.activeFromDate = activeFromDate; |
244 | 0 | } |
245 | |
|
246 | |
|
247 | |
|
248 | |
|
249 | |
public DateTime getActiveToDate() { |
250 | 0 | return this.activeToDate; |
251 | |
} |
252 | |
|
253 | |
|
254 | |
|
255 | |
|
256 | |
public void setActiveToDate(DateTime activeToDate) { |
257 | 0 | this.activeToDate = activeToDate; |
258 | 0 | } |
259 | |
|
260 | |
|
261 | |
|
262 | |
|
263 | |
public Map<String, String> getQualifications() { |
264 | 0 | return this.qualifications; |
265 | |
} |
266 | |
|
267 | |
|
268 | |
|
269 | |
|
270 | |
public void setQualifications(Map<String, String> qualifications) { |
271 | 0 | this.qualifications = qualifications; |
272 | 0 | } |
273 | |
|
274 | |
|
275 | |
|
276 | |
|
277 | |
|
278 | |
|
279 | |
|
280 | |
|
281 | |
|
282 | |
|
283 | |
public String getMemberTypeCode() { |
284 | 0 | if (memberTypeCode == null) { |
285 | 0 | boolean foundMemberInfo = false; |
286 | |
|
287 | 0 | if (StringUtils.isNotBlank(principalId) || StringUtils.isNotBlank(principalName)) { |
288 | 0 | memberTypeCode = KimUIConstants.MEMBER_TYPE_PRINCIPAL_CODE; |
289 | 0 | foundMemberInfo = true; |
290 | |
} |
291 | |
|
292 | 0 | if (StringUtils.isNotBlank(groupId) || groupName != null) { |
293 | 0 | if (foundMemberInfo) { |
294 | 0 | memberTypeCode = null; |
295 | 0 | throw new IllegalStateException("Cannot have a role member that is simultaneously populated with member principal, member group, and/or member role information"); |
296 | |
} |
297 | 0 | memberTypeCode = KimUIConstants.MEMBER_TYPE_GROUP_CODE; |
298 | 0 | foundMemberInfo = true; |
299 | |
} |
300 | |
|
301 | 0 | if (StringUtils.isNotBlank(roleIdAsMember) || roleNameAsMember != null) { |
302 | 0 | if (foundMemberInfo) { |
303 | 0 | memberTypeCode = null; |
304 | 0 | throw new IllegalStateException("Cannot have a role member that is simultaneously populated with member principal, member group, and/or member role information"); |
305 | |
} |
306 | 0 | memberTypeCode = KimUIConstants.MEMBER_TYPE_ROLE_CODE; |
307 | 0 | foundMemberInfo = true; |
308 | |
} |
309 | |
} |
310 | 0 | return this.memberTypeCode; |
311 | |
} |
312 | |
|
313 | |
|
314 | |
|
315 | |
|
316 | |
|
317 | |
|
318 | |
|
319 | |
|
320 | |
|
321 | |
public String getMemberId() { |
322 | 0 | if (KimUIConstants.MEMBER_TYPE_PRINCIPAL_CODE.equals(getMemberTypeCode())) { |
323 | 0 | return principalId; |
324 | 0 | } else if (KimUIConstants.MEMBER_TYPE_GROUP_CODE.equals(getMemberTypeCode())) { |
325 | 0 | return groupId; |
326 | 0 | } else if (KimUIConstants.MEMBER_TYPE_ROLE_CODE.equals(getMemberTypeCode())) { |
327 | 0 | return roleIdAsMember; |
328 | |
} |
329 | 0 | return null; |
330 | |
} |
331 | |
|
332 | |
|
333 | |
|
334 | |
|
335 | |
|
336 | |
|
337 | |
|
338 | |
|
339 | |
|
340 | |
public String getMemberName() { |
341 | 0 | if (KimUIConstants.MEMBER_TYPE_PRINCIPAL_CODE.equals(getMemberTypeCode())) { |
342 | 0 | return principalName; |
343 | 0 | } else if (KimUIConstants.MEMBER_TYPE_GROUP_CODE.equals(getMemberTypeCode())) { |
344 | 0 | return (groupName != null) ? groupName.getName() : null; |
345 | 0 | } else if (KimUIConstants.MEMBER_TYPE_ROLE_CODE.equals(getMemberTypeCode())) { |
346 | 0 | return (roleNameAsMember != null) ? roleNameAsMember.getName() : null; |
347 | |
} |
348 | 0 | return null; |
349 | |
} |
350 | |
|
351 | |
|
352 | |
|
353 | |
|
354 | |
|
355 | |
|
356 | |
|
357 | |
|
358 | |
|
359 | |
|
360 | |
public String getMemberNamespaceCode() { |
361 | 0 | if (KimUIConstants.MEMBER_TYPE_PRINCIPAL_CODE.equals(getMemberTypeCode())) { |
362 | 0 | return null; |
363 | 0 | } else if (KimUIConstants.MEMBER_TYPE_GROUP_CODE.equals(getMemberTypeCode())) { |
364 | 0 | return (groupName != null) ? groupName.getName() : null; |
365 | 0 | } else if (KimUIConstants.MEMBER_TYPE_ROLE_CODE.equals(getMemberTypeCode())) { |
366 | 0 | return (roleNameAsMember != null) ? roleNameAsMember.getName() : null; |
367 | |
} |
368 | 0 | return null; |
369 | |
} |
370 | |
|
371 | |
|
372 | |
|
373 | |
|
374 | |
|
375 | |
|
376 | |
|
377 | |
public abstract String getRoleId(); |
378 | |
|
379 | |
|
380 | |
|
381 | |
|
382 | |
|
383 | |
|
384 | |
|
385 | |
|
386 | |
@XmlAccessorType(XmlAccessType.FIELD) |
387 | |
@XmlType(name="StandaloneRoleMemberType", propOrder={ |
388 | |
"roleId", "roleNameAndNamespace", "principalId", "principalName", "groupId", "groupName", "roleIdAsMember", |
389 | |
"roleNameAsMember", "activeFromDate", "activeToDate", "qualifications" |
390 | |
}) |
391 | |
public static class OutsideOfRole extends RoleMemberXmlDTO { |
392 | |
|
393 | |
private static final long serialVersionUID = 1L; |
394 | |
|
395 | |
@XmlElement(name="roleId") |
396 | |
@XmlJavaTypeAdapter(NormalizedStringAdapter.class) |
397 | |
private String roleId; |
398 | |
|
399 | |
@XmlElement(name="roleName") |
400 | |
@XmlJavaTypeAdapter(NameAndNamespacePairValidatingAdapter.class) |
401 | |
private NameAndNamespacePair roleNameAndNamespace; |
402 | |
|
403 | |
public OutsideOfRole() { |
404 | 0 | super(); |
405 | 0 | } |
406 | |
|
407 | |
public OutsideOfRole(RoleMemberContract roleMember, boolean populateMemberId) { |
408 | 0 | super(roleMember, populateMemberId); |
409 | 0 | this.roleId = roleMember.getRoleId(); |
410 | 0 | RoleContract tempRole = KimApiServiceLocator.getRoleService().getRole(roleId); |
411 | 0 | if (tempRole == null) { |
412 | 0 | throw new IllegalArgumentException("Cannot find role with ID \"" + roleId + "\""); |
413 | |
} |
414 | 0 | this.roleNameAndNamespace = new NameAndNamespacePair(tempRole.getNamespaceCode(), tempRole.getName()); |
415 | 0 | } |
416 | |
|
417 | |
|
418 | |
|
419 | |
|
420 | |
@Override |
421 | |
public String getRoleId() { |
422 | 0 | return roleId; |
423 | |
} |
424 | |
|
425 | |
|
426 | |
|
427 | |
|
428 | |
public void setRoleId(String roleId) { |
429 | 0 | this.roleId = roleId; |
430 | 0 | } |
431 | |
|
432 | |
|
433 | |
|
434 | |
|
435 | |
public NameAndNamespacePair getRoleNameAndNamespace() { |
436 | 0 | return this.roleNameAndNamespace; |
437 | |
} |
438 | |
|
439 | |
|
440 | |
|
441 | |
|
442 | |
public void setRoleNameAndNamespace(NameAndNamespacePair roleNameAndNamespace) { |
443 | 0 | this.roleNameAndNamespace = roleNameAndNamespace; |
444 | 0 | } |
445 | |
|
446 | |
|
447 | |
|
448 | |
|
449 | |
|
450 | |
|
451 | |
public String getRoleName() { |
452 | 0 | return (roleNameAndNamespace != null) ? roleNameAndNamespace.getName() : null; |
453 | |
} |
454 | |
|
455 | |
|
456 | |
|
457 | |
|
458 | |
|
459 | |
|
460 | |
public String getRoleNamespaceCode() { |
461 | 0 | return (roleNameAndNamespace != null) ? roleNameAndNamespace.getNamespaceCode() : null; |
462 | |
} |
463 | |
} |
464 | |
|
465 | |
|
466 | |
|
467 | |
|
468 | |
|
469 | |
|
470 | |
|
471 | |
|
472 | |
@XmlAccessorType(XmlAccessType.FIELD) |
473 | |
@XmlType(name="RoleMemberType", propOrder={ |
474 | |
"principalId", "principalName", "groupId", "groupName", "roleIdAsMember", |
475 | |
"roleNameAsMember", "activeFromDate", "activeToDate", "qualifications" |
476 | |
}) |
477 | |
public static class WithinRole extends RoleMemberXmlDTO { |
478 | |
|
479 | |
private static final long serialVersionUID = 1L; |
480 | |
|
481 | |
@XmlTransient |
482 | |
private String roleId; |
483 | |
|
484 | |
public WithinRole() { |
485 | 0 | super(); |
486 | 0 | } |
487 | |
|
488 | |
public WithinRole(RoleMemberContract roleMember, boolean populateMemberId) { |
489 | 0 | super(roleMember, populateMemberId); |
490 | 0 | this.roleId = roleMember.getRoleId(); |
491 | 0 | } |
492 | |
|
493 | |
void beforeUnmarshal(Unmarshaller unmarshaller, Object parent) { |
494 | 0 | if (parent instanceof RoleMembersXmlDTO.WithinRole) { |
495 | 0 | this.roleId = ((RoleMembersXmlDTO.WithinRole)parent).getRoleId(); |
496 | |
} |
497 | 0 | } |
498 | |
|
499 | |
|
500 | |
|
501 | |
|
502 | |
@Override |
503 | |
public String getRoleId() { |
504 | 0 | return roleId; |
505 | |
} |
506 | |
|
507 | |
} |
508 | |
} |