1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.api.role;
17
18 import org.apache.commons.collections.CollectionUtils;
19 import org.apache.commons.lang.StringUtils;
20 import org.apache.commons.lang.builder.EqualsBuilder;
21 import org.apache.commons.lang.builder.HashCodeBuilder;
22 import org.apache.commons.lang.builder.ToStringBuilder;
23 import org.joda.time.DateTime;
24 import org.kuali.rice.core.api.CoreConstants;
25 import org.kuali.rice.core.api.membership.MemberType;
26 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
27 import org.kuali.rice.core.api.mo.ModelBuilder;
28 import org.kuali.rice.core.api.mo.ModelObjectComplete;
29 import org.kuali.rice.core.api.mo.common.active.InactivatableFromToUtils;
30 import org.kuali.rice.core.api.util.jaxb.DateTimeAdapter;
31 import org.kuali.rice.core.api.util.jaxb.MapStringStringAdapter;
32 import org.kuali.rice.kim.api.KimConstants;
33 import org.w3c.dom.Element;
34
35 import javax.xml.bind.annotation.XmlAccessType;
36 import javax.xml.bind.annotation.XmlAccessorType;
37 import javax.xml.bind.annotation.XmlAnyElement;
38 import javax.xml.bind.annotation.XmlElement;
39 import javax.xml.bind.annotation.XmlElementWrapper;
40 import javax.xml.bind.annotation.XmlRootElement;
41 import javax.xml.bind.annotation.XmlType;
42 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
43 import java.util.ArrayList;
44 import java.util.Collection;
45 import java.util.List;
46 import java.util.Map;
47
48 @XmlRootElement(name = RoleMember.Constants.ROOT_ELEMENT_NAME)
49 @XmlAccessorType(XmlAccessType.NONE)
50 @XmlType(name = RoleMember.Constants.TYPE_NAME, propOrder = {
51 RoleMember.Elements.ID,
52 RoleMember.Elements.ROLE_ID,
53 RoleMember.Elements.ATTRIBUTES,
54 RoleMember.Elements.ROLE_RESPONSIBILITY_ACTIONS,
55 RoleMember.Elements.MEMBER_ID,
56 RoleMember.Elements.TYPE_CODE,
57 RoleMember.Elements.MEMBER_NAME,
58 RoleMember.Elements.MEMBER_NAMESPACE_CODE,
59 CoreConstants.CommonElements.ACTIVE_FROM_DATE,
60 CoreConstants.CommonElements.ACTIVE_TO_DATE,
61 CoreConstants.CommonElements.VERSION_NUMBER,
62 CoreConstants.CommonElements.OBJECT_ID,
63 CoreConstants.CommonElements.FUTURE_ELEMENTS
64 })
65 public class RoleMember extends AbstractDataTransferObject implements RoleMemberContract {
66
67 private static final long serialVersionUID = 1L;
68
69 @XmlElement(name = Elements.ID, required = false)
70 private final String id;
71
72 @XmlElement(name = Elements.ROLE_ID, required = true)
73 private final String roleId;
74
75 @XmlElement(name = Elements.ATTRIBUTES, required = false)
76 @XmlJavaTypeAdapter(value = MapStringStringAdapter.class)
77 private final Map<String, String> attributes;
78
79 @XmlElementWrapper(name = Elements.ROLE_RESPONSIBILITY_ACTIONS, required = false)
80 @XmlElement(name = Elements.ROLE_RESPONSIBILITY_ACTION, required = false)
81 private final List<RoleResponsibilityAction> roleResponsibilityActions;
82
83 @XmlElement(name = Elements.MEMBER_ID, required = true)
84 private final String memberId;
85
86 @XmlElement(name = Elements.TYPE_CODE, required = true)
87 private final String typeCode;
88
89 @XmlElement(name = Elements.MEMBER_NAME, required = true)
90 private final String memberName;
91
92 @XmlElement(name = Elements.MEMBER_NAMESPACE_CODE, required = true)
93 private final String memberNamespaceCode;
94
95 @XmlJavaTypeAdapter(DateTimeAdapter.class)
96 @XmlElement(name = CoreConstants.CommonElements.ACTIVE_FROM_DATE, required = false)
97 private final DateTime activeFromDate;
98
99 @XmlJavaTypeAdapter(DateTimeAdapter.class)
100 @XmlElement(name = CoreConstants.CommonElements.ACTIVE_TO_DATE, required = false)
101 private final DateTime activeToDate;
102
103 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
104 private final Long versionNumber;
105
106 @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
107 private final String objectId;
108
109 @SuppressWarnings("unused")
110 @XmlAnyElement
111 private final Collection<Element> _futureElements = null;
112
113
114
115
116 @SuppressWarnings("unused")
117 private RoleMember() {
118 id = null;
119 roleId = null;
120 attributes = null;
121 roleResponsibilityActions = null;
122 memberId = null;
123 typeCode = null;
124 memberName = null;
125 memberNamespaceCode = null;
126 activeFromDate = null;
127 activeToDate = null;
128 this.versionNumber = null;
129 this.objectId = null;
130 }
131
132 private RoleMember(Builder b) {
133 id = b.getId();
134 roleId = b.getRoleId();
135 attributes = b.getAttributes();
136
137 List<RoleResponsibilityAction> roleResponsibilityActions = new ArrayList<RoleResponsibilityAction>();
138 if (!CollectionUtils.isEmpty(b.getRoleRspActions())) {
139 for (RoleResponsibilityAction.Builder rraBuilder : b.getRoleRspActions()) {
140 roleResponsibilityActions.add(rraBuilder.build());
141 }
142 }
143 this.roleResponsibilityActions = roleResponsibilityActions;
144
145 memberId = b.getMemberId();
146 typeCode = b.getType().getCode();
147 memberName = b.getMemberName();
148 memberNamespaceCode = b.getMemberNamespaceCode();
149 activeFromDate = b.getActiveFromDate();
150 activeToDate = b.getActiveToDate();
151 versionNumber = b.getVersionNumber();
152 objectId = b.getObjectId();
153 }
154
155 @Override
156 public String getMemberId() {
157 return this.memberId;
158 }
159
160 @Override
161 public MemberType getType() {
162 return MemberType.fromCode(this.typeCode);
163 }
164
165 @Override
166 public String getId() {
167 return this.id;
168 }
169
170 @Override
171 public String getRoleId() {
172 return this.roleId;
173 }
174
175
176
177
178 @Override
179 public Map<String, String> getAttributes() {
180 return this.attributes;
181 }
182
183
184
185
186 @Override
187 public List<RoleResponsibilityAction> getRoleRspActions() {
188 return this.roleResponsibilityActions;
189 }
190
191 @Override
192 public DateTime getActiveFromDate() {
193 return activeFromDate;
194 }
195
196 @Override
197 public DateTime getActiveToDate() {
198 return activeToDate;
199 }
200
201 @Override
202 public boolean isActive(DateTime activeAsOfDate) {
203 return InactivatableFromToUtils.isActive(activeFromDate, activeToDate, activeAsOfDate);
204 }
205
206 @Override
207 public boolean isActive() {
208 return InactivatableFromToUtils.isActive(activeFromDate, activeToDate, null);
209 }
210
211 @Override
212 public Long getVersionNumber() {
213 return versionNumber;
214 }
215
216 @Override
217 public String getObjectId() {
218 return objectId;
219 }
220
221 @Override
222 public String getMemberName() {
223 return memberName;
224 }
225
226 @Override
227 public String getMemberNamespaceCode() {
228 return memberNamespaceCode;
229 }
230
231
232 public static final class Builder implements ModelBuilder, RoleMemberContract, ModelObjectComplete {
233
234 private String id;
235 private String roleId;
236 private Map<String, String> attributes;
237 private List<RoleResponsibilityAction.Builder> roleRspActions;
238 private String memberId;
239 private MemberType type;
240 private DateTime activeFromDate;
241 private DateTime activeToDate;
242 private Long versionNumber;
243 private String objectId;
244 private String memberName;
245 private String memberNamespaceCode;
246
247 private Builder(String roleId, String memberId, MemberType type) {
248 setRoleId(roleId);
249 setMemberId(memberId);
250 setType(type);
251 }
252
253 public static Builder create(String roleId, String id, String memberId,
254 MemberType memberType, DateTime activeFromDate, DateTime activeToDate, Map<String, String> attributes,String memberName,String memberNamespaceCode) {
255 Builder b = new Builder(roleId, memberId, memberType);
256 b.setId(id);
257 b.setActiveFromDate(activeFromDate);
258 b.setActiveToDate(activeToDate);
259 b.setAttributes(attributes);
260 b.setMemberName(memberName);
261 b.setMemberNamespaceCode(memberNamespaceCode);
262 return b;
263 }
264
265 public static Builder create(RoleMemberContract contract) {
266 Builder b = new Builder(contract.getRoleId(), contract.getMemberId(), contract.getType());
267 b.setId(contract.getId());
268 b.setAttributes(contract.getAttributes());
269
270 List<RoleResponsibilityAction.Builder> rraBuilders = new ArrayList<RoleResponsibilityAction.Builder>();
271 if (!CollectionUtils.isEmpty(contract.getRoleRspActions())) {
272 for (RoleResponsibilityActionContract rrac : contract.getRoleRspActions()) {
273 rraBuilders.add(RoleResponsibilityAction.Builder.create(rrac));
274 }
275 }
276 b.setRoleRspActions(rraBuilders);
277
278 b.setActiveFromDate(contract.getActiveFromDate());
279 b.setActiveToDate(contract.getActiveToDate());
280 b.setMemberName(contract.getMemberName());
281 b.setMemberNamespaceCode(contract.getMemberNamespaceCode());
282 b.setVersionNumber(contract.getVersionNumber());
283 b.setObjectId(contract.getObjectId());
284 return b;
285 }
286
287 @Override
288 public RoleMember build() {
289 return new RoleMember(this);
290 }
291
292 @Override
293 public String getId() {
294 return id;
295 }
296
297 public void setId(String id) {
298 this.id = id;
299 }
300
301 @Override
302 public String getRoleId() {
303 return roleId;
304 }
305
306 public void setRoleId(String roleId) {
307 if (StringUtils.isEmpty(roleId)) {
308 throw new IllegalArgumentException("roleId is empty");
309 }
310 this.roleId = roleId;
311 }
312
313 @Override
314 public Map<String, String> getAttributes() {
315 return attributes;
316 }
317
318 public void setAttributes(Map<String, String> attributes) {
319 this.attributes = attributes;
320 }
321
322 @Override
323 public List<RoleResponsibilityAction.Builder> getRoleRspActions() {
324 return roleRspActions;
325 }
326
327 public void setRoleRspActions(List<RoleResponsibilityAction.Builder> roleRspActions) {
328 this.roleRspActions = roleRspActions;
329 }
330
331 @Override
332 public String getMemberId() {
333 return memberId;
334 }
335
336 public void setMemberId(String memberId) {
337 if (StringUtils.isBlank(memberId)) {
338 throw new IllegalArgumentException("memberId may not be null");
339 }
340 this.memberId = memberId;
341 }
342
343 @Override
344 public MemberType getType() {
345 return type;
346 }
347
348 @Override
349 public String getMemberName() {
350 return memberName;
351 }
352
353 public void setMemberName(String memberName){
354 this.memberName = memberName;
355 }
356 @Override
357 public String getMemberNamespaceCode() {
358 return memberNamespaceCode;
359 }
360
361 public void setMemberNamespaceCode(String memberNamespaceCode){
362 this.memberNamespaceCode = memberNamespaceCode;
363 }
364 public void setType(final MemberType type) {
365 if (type == null) {
366 throw new IllegalArgumentException("type is null");
367 }
368 this.type = type;
369 }
370
371 @Override
372 public DateTime getActiveFromDate() {
373 return activeFromDate;
374 }
375
376 public void setActiveFromDate(DateTime activeFromDate) {
377 this.activeFromDate = activeFromDate;
378 }
379
380 @Override
381 public DateTime getActiveToDate() {
382 return activeToDate;
383 }
384
385 public void setActiveToDate(DateTime activeToDate) {
386 this.activeToDate = activeToDate;
387 }
388
389 @Override
390 public boolean isActive(DateTime activeAsOfDate) {
391 return InactivatableFromToUtils.isActive(activeFromDate, activeToDate, activeAsOfDate);
392 }
393
394 @Override
395 public boolean isActive() {
396 return InactivatableFromToUtils.isActive(activeFromDate, activeToDate, null);
397 }
398
399 @Override
400 public Long getVersionNumber() {
401 return versionNumber;
402 }
403
404 public void setVersionNumber(final Long versionNumber) {
405 this.versionNumber = versionNumber;
406 }
407
408 @Override
409 public String getObjectId() {
410 return objectId;
411 }
412
413 public void setObjectId(final String objectId) {
414 this.objectId = objectId;
415 }
416
417 @Override
418 public int hashCode() {
419 return HashCodeBuilder.reflectionHashCode(this);
420 }
421
422 @Override
423 public boolean equals(Object obj) {
424 return EqualsBuilder.reflectionEquals(obj, this);
425 }
426
427 @Override
428 public String toString() {
429 return ToStringBuilder.reflectionToString(this);
430 }
431 }
432
433
434
435
436
437 static class Elements {
438 final static String ID = "id";
439 final static String ROLE_ID = "roleId";
440 final static String ATTRIBUTES = "attributes";
441 final static String ROLE_RESPONSIBILITY_ACTIONS = "roleResponsibilityActions";
442 final static String ROLE_RESPONSIBILITY_ACTION = "roleResponsibilityAction";
443 final static String MEMBER_ID = "memberId";
444 final static String TYPE_CODE = "typeCode";
445 final static String MEMBER_NAME = "memberName";
446 final static String MEMBER_NAMESPACE_CODE = "memberNamespaceCode";
447 }
448
449
450
451
452 static class Constants {
453 final static String ROOT_ELEMENT_NAME = "roleMember";
454 final static String TYPE_NAME = "RoleMemberType";
455 }
456
457 public static class Cache {
458 public static final String NAME = KimConstants.Namespaces.KIM_NAMESPACE_2_0 + "/" + RoleMember.Constants.TYPE_NAME;
459 }
460 }