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