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