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