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.kuali.rice.core.api.CoreConstants; |
24 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
25 | |
import org.kuali.rice.core.api.mo.ModelObjectComplete; |
26 | |
import org.kuali.rice.core.util.AttributeSet; |
27 | |
import org.kuali.rice.core.util.jaxb.SqlTimestampAdapter; |
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.sql.Timestamp; |
38 | |
import java.util.ArrayList; |
39 | |
import java.util.Collection; |
40 | |
import java.util.List; |
41 | |
|
42 | |
@XmlRootElement(name = RoleMember.Constants.ROOT_ELEMENT_NAME) |
43 | |
@XmlAccessorType(XmlAccessType.NONE) |
44 | |
@XmlType(name = RoleMember.Constants.TYPE_NAME, propOrder = { |
45 | |
RoleMember.Elements.ROLE_MEMBER_ID, |
46 | |
RoleMember.Elements.ROLE_ID, |
47 | |
RoleMember.Elements.QUALIFIER, |
48 | |
RoleMember.Elements.ROLE_RESPONSIBILITY_ACTIONS, |
49 | |
RoleMember.Elements.MEMBER_ID, |
50 | |
RoleMember.Elements.MEMBER_TYPE_CODE, |
51 | |
CoreConstants.CommonElements.ACTIVE_FROM_DATE, |
52 | |
CoreConstants.CommonElements.ACTIVE_TO_DATE, |
53 | |
CoreConstants.CommonElements.ACTIVE, |
54 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
55 | |
}) |
56 | 6 | public class RoleMember implements RoleMemberContract, ModelObjectComplete { |
57 | |
|
58 | |
private static final long serialVersionUID = 1L; |
59 | |
|
60 | |
@XmlElement(name = Elements.ROLE_MEMBER_ID) |
61 | |
private final String roleMemberId; |
62 | |
|
63 | |
@XmlElement(name = Elements.ROLE_ID) |
64 | |
private final String roleId; |
65 | |
|
66 | |
@XmlElement(name = Elements.QUALIFIER) |
67 | |
private final AttributeSet qualifier; |
68 | |
|
69 | |
@XmlElement(name = Elements.ROLE_RESPONSIBILITY_ACTIONS) |
70 | |
private final List<RoleResponsibilityAction> roleResponsibilityActions; |
71 | |
|
72 | |
@XmlElement(name = Elements.MEMBER_ID) |
73 | |
private final String memberId; |
74 | |
|
75 | |
@XmlElement(name = Elements.MEMBER_TYPE_CODE) |
76 | |
private final String memberTypeCode; |
77 | |
|
78 | |
@XmlJavaTypeAdapter(SqlTimestampAdapter.class) |
79 | |
@XmlElement(name = CoreConstants.CommonElements.ACTIVE_FROM_DATE) |
80 | |
private final Timestamp activeFromDate; |
81 | |
|
82 | |
@XmlJavaTypeAdapter(SqlTimestampAdapter.class) |
83 | |
@XmlElement(name = CoreConstants.CommonElements.ACTIVE_TO_DATE) |
84 | |
private final Timestamp activeToDate; |
85 | |
|
86 | |
@XmlElement(name = CoreConstants.CommonElements.ACTIVE) |
87 | |
private final boolean active; |
88 | |
|
89 | 7 | @SuppressWarnings("unused") |
90 | |
@XmlAnyElement |
91 | |
private final Collection<Element> _futureElements = null; |
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
@SuppressWarnings("unused") |
97 | 1 | private RoleMember() { |
98 | 1 | roleMemberId = null; |
99 | 1 | roleId = null; |
100 | 1 | qualifier = null; |
101 | 1 | roleResponsibilityActions = null; |
102 | 1 | memberId = null; |
103 | 1 | memberTypeCode = null; |
104 | 1 | activeFromDate = null; |
105 | 1 | activeToDate = null; |
106 | 1 | active = false; |
107 | 1 | } |
108 | |
|
109 | 6 | private RoleMember(Builder b) { |
110 | 6 | roleMemberId = b.getRoleMemberId(); |
111 | 6 | roleId = b.getRoleId(); |
112 | 6 | qualifier = b.getQualifier(); |
113 | |
|
114 | 6 | List<RoleResponsibilityAction> roleResponsibilityActions = new ArrayList<RoleResponsibilityAction>(); |
115 | 6 | if (!CollectionUtils.isEmpty(b.getRoleRspActions())) { |
116 | 0 | for (RoleResponsibilityAction.Builder rraBuilder : b.getRoleRspActions()) { |
117 | 0 | roleResponsibilityActions.add(rraBuilder.build()); |
118 | |
} |
119 | |
} |
120 | 6 | this.roleResponsibilityActions = roleResponsibilityActions; |
121 | |
|
122 | 6 | memberId = b.getMemberId(); |
123 | 6 | memberTypeCode = b.getMemberTypeCode(); |
124 | 6 | activeFromDate = b.getActiveFromDate(); |
125 | 6 | activeToDate = b.getActiveToDate(); |
126 | 6 | active = b.isActive(); |
127 | 6 | } |
128 | |
|
129 | |
|
130 | |
public String getMemberId() { |
131 | 2 | return this.memberId; |
132 | |
} |
133 | |
|
134 | |
public String getMemberTypeCode() { |
135 | 2 | return this.memberTypeCode; |
136 | |
} |
137 | |
|
138 | |
|
139 | |
public String getRoleMemberId() { |
140 | 2 | return this.roleMemberId; |
141 | |
} |
142 | |
|
143 | |
public String getRoleId() { |
144 | 2 | return this.roleId; |
145 | |
} |
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
public AttributeSet getQualifier() { |
151 | 2 | return this.qualifier; |
152 | |
} |
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
public List<RoleResponsibilityAction> getRoleRspActions() { |
158 | 2 | return this.roleResponsibilityActions; |
159 | |
} |
160 | |
|
161 | |
public Timestamp getActiveFromDate() { |
162 | 2 | return activeFromDate; |
163 | |
} |
164 | |
|
165 | |
public Timestamp getActiveToDate() { |
166 | 2 | return activeToDate; |
167 | |
} |
168 | |
|
169 | |
@Override |
170 | |
public boolean isActive(Timestamp activeAsOfDate) { |
171 | 3 | return (activeFromDate.before(activeAsOfDate) && activeToDate.after(activeAsOfDate)); |
172 | |
} |
173 | |
|
174 | |
@Override |
175 | |
public int hashCode() { |
176 | 0 | return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
177 | |
} |
178 | |
|
179 | |
@Override |
180 | |
public boolean equals(Object obj) { |
181 | 1 | return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
182 | |
} |
183 | |
|
184 | |
@Override |
185 | |
public String toString() { |
186 | 0 | return ToStringBuilder.reflectionToString(this); |
187 | |
} |
188 | |
|
189 | |
@Override |
190 | |
public boolean isActive() { |
191 | 0 | return active; |
192 | |
} |
193 | |
|
194 | |
|
195 | 16 | public static final class Builder implements ModelBuilder, RoleMemberContract, ModelObjectComplete { |
196 | |
|
197 | |
private String roleMemberId; |
198 | |
private String roleId; |
199 | |
private AttributeSet qualifier; |
200 | |
private List<RoleResponsibilityAction.Builder> roleRspActions; |
201 | |
private String memberId; |
202 | |
private String memberTypeCode; |
203 | |
private Timestamp activeFromDate; |
204 | |
private Timestamp activeToDate; |
205 | 10 | private boolean active = true; |
206 | |
|
207 | |
|
208 | |
public static Builder create(String roleId, String roleMemberId, String memberId, |
209 | |
String memberTypeCode, Timestamp activeFromDate, Timestamp activeToDate, AttributeSet qualifier) { |
210 | 9 | Builder b = new Builder(); |
211 | 9 | b.setRoleId(roleId); |
212 | 9 | b.setRoleMemberId(roleMemberId); |
213 | 9 | b.setMemberId(memberId); |
214 | 9 | b.setMemberTypeCode(memberTypeCode); |
215 | 9 | b.setActiveFromDate(activeFromDate); |
216 | 9 | b.setActiveToDate(activeToDate); |
217 | 9 | b.setQualifier(qualifier); |
218 | 9 | return b; |
219 | |
} |
220 | |
|
221 | |
public static Builder create(RoleMemberContract contract) { |
222 | 1 | Builder b = new Builder(); |
223 | 1 | b.setRoleMemberId(contract.getRoleMemberId()); |
224 | 1 | b.setRoleId(contract.getRoleId()); |
225 | 1 | b.setQualifier(contract.getQualifier()); |
226 | |
|
227 | 1 | List<RoleResponsibilityAction.Builder> rraBuilders = new ArrayList<RoleResponsibilityAction.Builder>(); |
228 | 1 | if (!CollectionUtils.isEmpty(contract.getRoleRspActions())) { |
229 | 0 | for (RoleResponsibilityActionContract rrac : contract.getRoleRspActions()) { |
230 | 0 | rraBuilders.add(RoleResponsibilityAction.Builder.create(rrac)); |
231 | |
} |
232 | |
} |
233 | 1 | b.setRoleRspActions(rraBuilders); |
234 | |
|
235 | 1 | b.setMemberId(contract.getMemberId()); |
236 | 1 | b.setMemberTypeCode(contract.getMemberTypeCode()); |
237 | 1 | b.setActiveFromDate(contract.getActiveFromDate()); |
238 | 1 | b.setActiveToDate(contract.getActiveToDate()); |
239 | 1 | return b; |
240 | |
} |
241 | |
|
242 | |
public RoleMember build() { |
243 | 6 | return new RoleMember(this); |
244 | |
} |
245 | |
|
246 | |
public String getRoleMemberId() { |
247 | 6 | return roleMemberId; |
248 | |
} |
249 | |
|
250 | |
public void setRoleMemberId(String roleMemberId) { |
251 | 10 | this.roleMemberId = roleMemberId; |
252 | 10 | } |
253 | |
|
254 | |
public String getRoleId() { |
255 | 6 | return roleId; |
256 | |
} |
257 | |
|
258 | |
public void setRoleId(String roleId) { |
259 | 10 | this.roleId = roleId; |
260 | 10 | } |
261 | |
|
262 | |
public AttributeSet getQualifier() { |
263 | 6 | return qualifier; |
264 | |
} |
265 | |
|
266 | |
public void setQualifier(AttributeSet qualifier) { |
267 | 10 | this.qualifier = qualifier; |
268 | 10 | } |
269 | |
|
270 | |
public List<RoleResponsibilityAction.Builder> getRoleRspActions() { |
271 | 6 | return roleRspActions; |
272 | |
} |
273 | |
|
274 | |
public void setRoleRspActions(List<RoleResponsibilityAction.Builder> roleRspActions) { |
275 | 1 | this.roleRspActions = roleRspActions; |
276 | 1 | } |
277 | |
|
278 | |
public String getMemberId() { |
279 | 6 | return memberId; |
280 | |
} |
281 | |
|
282 | |
public void setMemberId(String memberId) { |
283 | 12 | if (StringUtils.isBlank(memberId)) { |
284 | 2 | throw new IllegalArgumentException("memberId may not be null"); |
285 | |
} |
286 | 10 | this.memberId = memberId; |
287 | 10 | } |
288 | |
|
289 | |
public String getMemberTypeCode() { |
290 | 6 | return memberTypeCode; |
291 | |
} |
292 | |
|
293 | |
public void setMemberTypeCode(String memberTypeCode) { |
294 | 12 | if (StringUtils.isBlank(memberTypeCode)) { |
295 | 2 | throw new IllegalArgumentException("memberTypeCode may not be null"); |
296 | |
} |
297 | 10 | this.memberTypeCode = memberTypeCode; |
298 | 10 | } |
299 | |
|
300 | |
public Timestamp getActiveFromDate() { |
301 | 6 | return activeFromDate; |
302 | |
} |
303 | |
|
304 | |
public void setActiveFromDate(Timestamp activeFromDate) { |
305 | 10 | this.activeFromDate = activeFromDate; |
306 | 10 | } |
307 | |
|
308 | |
public Timestamp getActiveToDate() { |
309 | 6 | return activeToDate; |
310 | |
} |
311 | |
|
312 | |
public void setActiveToDate(Timestamp activeToDate) { |
313 | 10 | this.activeToDate = activeToDate; |
314 | 10 | } |
315 | |
|
316 | |
@Override |
317 | |
public boolean isActive(Timestamp activeAsOfDate) { |
318 | 0 | return (activeFromDate.before(activeAsOfDate) && activeToDate.after(activeAsOfDate)); |
319 | |
} |
320 | |
|
321 | |
@Override |
322 | |
public boolean isActive() { |
323 | 6 | return active; |
324 | |
} |
325 | |
|
326 | |
public void setActive(boolean active) { |
327 | 0 | this.active = active; |
328 | 0 | } |
329 | |
|
330 | |
@Override |
331 | |
public int hashCode() { |
332 | 0 | return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
333 | |
} |
334 | |
|
335 | |
@Override |
336 | |
public boolean equals(Object obj) { |
337 | 0 | return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
338 | |
} |
339 | |
|
340 | |
@Override |
341 | |
public String toString() { |
342 | 0 | return ToStringBuilder.reflectionToString(this); |
343 | |
} |
344 | |
|
345 | |
|
346 | |
} |
347 | |
|
348 | |
|
349 | |
|
350 | |
|
351 | |
|
352 | 0 | static class Elements { |
353 | |
final static String ROLE_MEMBER_ID = "roleMemberId"; |
354 | |
final static String ROLE_ID = "roleId"; |
355 | |
final static String QUALIFIER = "qualifier"; |
356 | |
final static String ROLE_RESPONSIBILITY_ACTIONS = "roleResponsibilityActions"; |
357 | |
final static String MEMBER_ID = "memberId"; |
358 | |
final static String MEMBER_TYPE_CODE = "memberTypeCode"; |
359 | |
} |
360 | |
|
361 | |
|
362 | |
|
363 | |
|
364 | 0 | static class Constants { |
365 | |
final static String ROOT_ELEMENT_NAME = "roleMember"; |
366 | |
final static String TYPE_NAME = "RoleMemberType"; |
367 | 1 | final static String[] HASH_CODE_EQUALS_EXCLUDE = {CoreConstants.CommonElements.FUTURE_ELEMENTS}; |
368 | |
} |
369 | |
} |