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