1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.api.common.delegate;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.joda.time.DateTime;
20 import org.kuali.rice.core.api.CoreConstants;
21 import org.kuali.rice.core.api.membership.MemberType;
22 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
23 import org.kuali.rice.core.api.mo.ModelBuilder;
24 import org.kuali.rice.core.api.mo.common.active.InactivatableFromToUtils;
25 import org.kuali.rice.core.api.util.jaxb.DateTimeAdapter;
26 import org.kuali.rice.core.api.util.jaxb.MapStringStringAdapter;
27 import org.kuali.rice.kim.api.KimConstants;
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 javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
37 import java.io.Serializable;
38 import java.util.Collection;
39 import java.util.Map;
40
41 @XmlRootElement(name = DelegateMember.Constants.ROOT_ELEMENT_NAME)
42 @XmlAccessorType(XmlAccessType.NONE)
43 @XmlType(name = DelegateMember.Constants.TYPE_NAME, propOrder = {
44 DelegateMember.Elements.DELEGATION_MEMBER_ID,
45 DelegateMember.Elements.DELEGATION_ID,
46 DelegateMember.Elements.MEMBER_ID,
47 DelegateMember.Elements.ROLE_MEMBER_ID,
48 DelegateMember.Elements.TYPE_CODE,
49 DelegateMember.Elements.ATTRIBUTES,
50 CoreConstants.CommonElements.ACTIVE_FROM_DATE,
51 CoreConstants.CommonElements.ACTIVE_TO_DATE,
52 CoreConstants.CommonElements.VERSION_NUMBER,
53 CoreConstants.CommonElements.FUTURE_ELEMENTS
54 })
55 public final class DelegateMember extends AbstractDataTransferObject
56 implements DelegateMemberContract {
57
58 @XmlElement(name = Elements.DELEGATION_MEMBER_ID, required = true)
59 private final String delegationMemberId;
60
61 @XmlElement(name = Elements.DELEGATION_ID, required = false)
62 private final String delegationId;
63
64 @XmlElement(name = Elements.MEMBER_ID, required = false)
65 private final String memberId;
66
67 @XmlElement(name = Elements.ROLE_MEMBER_ID, required = false)
68 private final String roleMemberId;
69
70 @XmlElement(name = Elements.TYPE_CODE, required = false)
71 private final String typeCode;
72
73 @XmlElement(name = Elements.ATTRIBUTES, required = false)
74 @XmlJavaTypeAdapter(value = MapStringStringAdapter.class)
75 private final Map<String, String> attributes;
76
77 @XmlJavaTypeAdapter(DateTimeAdapter.class)
78 @XmlElement(name = CoreConstants.CommonElements.ACTIVE_FROM_DATE)
79 private final DateTime activeFromDate;
80
81 @XmlJavaTypeAdapter(DateTimeAdapter.class)
82 @XmlElement(name = CoreConstants.CommonElements.ACTIVE_TO_DATE)
83 private final DateTime activeToDate;
84
85 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER)
86 private final Long versionNumber;
87
88 @SuppressWarnings("unused")
89 @XmlAnyElement
90 private final Collection<Element> _futureElements = null;
91
92
93
94
95 @SuppressWarnings("unused")
96 private DelegateMember() {
97 this.delegationMemberId = null;
98 this.delegationId = null;
99 this.memberId = null;
100 this.roleMemberId = null;
101 this.typeCode = null;
102 this.versionNumber = null;
103 this.activeFromDate = null;
104 this.activeToDate = null;
105 this.attributes = null;
106 }
107
108 private DelegateMember(Builder builder) {
109 this.delegationMemberId = builder.getDelegationMemberId();
110 this.delegationId = builder.getDelegationId();
111 this.memberId = builder.getMemberId();
112 this.roleMemberId = builder.getRoleMemberId();
113 this.typeCode = builder.getType().getCode();
114 this.versionNumber = builder.getVersionNumber();
115 this.activeFromDate = builder.getActiveFromDate();
116 this.activeToDate = builder.getActiveToDate();
117 this.attributes = builder.getAttributes();
118 }
119
120
121 @Override
122 public String getDelegationMemberId() {
123 return this.delegationMemberId;
124 }
125
126 @Override
127 public String getDelegationId() {
128 return this.delegationId;
129 }
130
131 @Override
132 public MemberType getType() {
133 return MemberType.fromCode(this.typeCode);
134 }
135
136 @Override
137 public String getRoleMemberId() {
138 return this.roleMemberId;
139 }
140
141 @Override
142 public String getMemberId() {
143 return this.memberId;
144 }
145
146 @Override
147 public Long getVersionNumber() {
148 return this.versionNumber;
149 }
150
151 @Override
152 public DateTime getActiveFromDate() {
153 return activeFromDate;
154 }
155
156 @Override
157 public DateTime getActiveToDate() {
158 return activeToDate;
159 }
160
161
162
163
164 @Override
165 public Map<String, String> getAttributes() {
166 return this.attributes;
167 }
168
169 @Override
170 public boolean isActive(DateTime activeAsOfDate) {
171 return InactivatableFromToUtils.isActive(activeFromDate, activeToDate, activeAsOfDate);
172 }
173
174 @Override
175 public boolean isActive() {
176 return InactivatableFromToUtils.isActive(activeFromDate, activeToDate, null);
177 }
178
179
180
181
182 public static final class Builder implements Serializable, ModelBuilder, DelegateMemberContract {
183
184 private String delegationMemberId;
185 private String delegationId;
186 private String memberId;
187 private String roleMemberId;
188 private MemberType type;
189 private Map<String, String> attributes;
190 private DateTime activeFromDate;
191 private DateTime activeToDate;
192 private Long versionNumber;
193
194 private Builder() {
195
196 }
197
198 public static Builder create() {
199 return new Builder();
200 }
201
202 public static Builder create(DelegateMemberContract contract) {
203 if (contract == null) {
204 throw new IllegalArgumentException("contract was null");
205 }
206 Builder builder = create();
207 builder.setDelegationMemberId(contract.getDelegationMemberId());
208 builder.setDelegationId(contract.getDelegationId());
209 builder.setMemberId(contract.getMemberId());
210 builder.setRoleMemberId(contract.getRoleMemberId());
211 builder.setAttributes(contract.getAttributes());
212 builder.setType(contract.getType());
213 builder.setActiveFromDate(contract.getActiveFromDate());
214 builder.setActiveToDate(contract.getActiveToDate());
215 builder.setVersionNumber(contract.getVersionNumber());
216 return builder;
217 }
218
219 public DelegateMember build() {
220 if (StringUtils.isEmpty(this.delegationMemberId) || this.versionNumber == null) {
221 throw new IllegalStateException("Required fields of delegationMemberId and versionNumber set to valid non-null" +
222 " values before calling build()");
223 }
224 return new DelegateMember(this);
225 }
226
227 @Override
228 public String getDelegationMemberId() {
229 return this.delegationMemberId;
230 }
231
232 public void setDelegationMemberId(String delegationMemberId) {
233 if (StringUtils.isEmpty(delegationMemberId)) {
234 throw new IllegalArgumentException("delegationMemberId is a required field and cannot be null or blank");
235 }
236 this.delegationMemberId = delegationMemberId;
237 }
238
239 public String getDelegationId() {
240 return delegationId;
241 }
242
243 public void setDelegationId(String delegationId) {
244 this.delegationId = delegationId;
245 }
246
247 public String getMemberId() {
248 return memberId;
249 }
250
251 public void setMemberId(String memberId) {
252 this.memberId = memberId;
253 }
254
255 public String getRoleMemberId() {
256 return roleMemberId;
257 }
258
259 public void setRoleMemberId(String roleMemberId) {
260 this.roleMemberId = roleMemberId;
261 }
262
263 public MemberType getType() {
264 return type;
265 }
266
267 public void setType(MemberType type) {
268 this.type = type;
269 }
270
271 @Override
272 public Map<String, String> getAttributes() {
273 return this.attributes;
274 }
275
276 public void setAttributes(Map<String, String> attributes) {
277 this.attributes = attributes;
278 }
279
280 @Override
281 public Long getVersionNumber() {
282 return versionNumber;
283 }
284
285 public void setVersionNumber(Long versionNumber) {
286 if (versionNumber == null) {
287 throw new IllegalArgumentException("versionNumber is required and must be non-null");
288 }
289 this.versionNumber = versionNumber;
290 }
291
292 @Override
293 public DateTime getActiveFromDate() {
294 return activeFromDate;
295 }
296
297 public void setActiveFromDate(DateTime activeFromDate) {
298 this.activeFromDate = activeFromDate;
299 }
300
301 @Override
302 public DateTime getActiveToDate() {
303 return activeToDate;
304 }
305
306 public void setActiveToDate(DateTime activeToDate) {
307 this.activeToDate = activeToDate;
308 }
309
310 @Override
311 public boolean isActive(DateTime activeAsOfDate) {
312 return InactivatableFromToUtils.isActive(activeFromDate, activeToDate, activeAsOfDate);
313 }
314
315 @Override
316 public boolean isActive() {
317 return InactivatableFromToUtils.isActive(activeFromDate, activeToDate, null);
318 }
319 }
320
321
322
323
324 static class Constants {
325
326 final static String ROOT_ELEMENT_NAME = "delegateMember";
327 final static String TYPE_NAME = "DelegateMemberType";
328
329 }
330
331
332
333
334 static class Elements {
335 final static String DELEGATION_MEMBER_ID = "delegationMemberId";
336 final static String ROLE_ID = "roleId";
337 final static String DELEGATION_ID = "delegationId";
338 final static String MEMBER_ID = "memberId";
339 final static String ATTRIBUTES = "attributes";
340 final static String ROLE_MEMBER_ID = "roleMemberId";
341 final static String TYPE_CODE = "typeCode";
342 }
343
344 public static class Cache {
345 public static final String NAME = KimConstants.Namespaces.KIM_NAMESPACE_2_0 + "/" + DelegateMember.Constants.TYPE_NAME;
346 }
347 }