1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.api.group;
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 = GroupMember.Constants.ROOT_ELEMENT_NAME)
40 @XmlAccessorType(XmlAccessType.NONE)
41 @XmlType(name = GroupMember.Constants.TYPE_NAME, propOrder = {
42 GroupMember.Elements.ID,
43 GroupMember.Elements.GROUP_ID,
44 GroupMember.Elements.MEMBER_ID,
45 GroupMember.Elements.TYPE_CODE,
46 CoreConstants.CommonElements.ACTIVE_FROM_DATE,
47 CoreConstants.CommonElements.ACTIVE_TO_DATE,
48 CoreConstants.CommonElements.VERSION_NUMBER,
49 CoreConstants.CommonElements.OBJECT_ID,
50 CoreConstants.CommonElements.FUTURE_ELEMENTS
51 })
52 public class GroupMember extends AbstractDataTransferObject implements GroupMemberContract {
53
54 @XmlElement(name = Elements.ID, required = false)
55 private final String id;
56
57 @XmlElement(name = Elements.GROUP_ID, required = true)
58 private final String groupId;
59
60 @XmlElement(name = Elements.MEMBER_ID, required = true)
61 private final String memberId;
62
63 @XmlElement(name = Elements.TYPE_CODE, required = true)
64 private final String typeCode;
65
66 @XmlElement(name = CoreConstants.CommonElements.ACTIVE_FROM_DATE, required = false)
67 @XmlJavaTypeAdapter(DateTimeAdapter.class)
68 private final DateTime activeFromDate;
69
70 @XmlElement(name = CoreConstants.CommonElements.ACTIVE_TO_DATE, required = false)
71 @XmlJavaTypeAdapter(DateTimeAdapter.class)
72 private final DateTime activeToDate;
73
74 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
75 private final Long versionNumber;
76
77 @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
78 private final String objectId;
79
80 @SuppressWarnings("unused")
81 @XmlAnyElement
82 private final Collection<Element> _futureElements = null;
83
84 private GroupMember() {
85 this.id = null;
86 this.groupId = null;
87 this.memberId = null;
88 this.typeCode = null;
89 this.versionNumber = null;
90 this.objectId = null;
91 this.activeFromDate = null;
92 this.activeToDate = null;
93 }
94
95
96 public GroupMember(Builder builder) {
97 this.id = builder.getId();
98 this.groupId = builder.getGroupId();
99 this.memberId = builder.getMemberId();
100 this.typeCode = builder.getType().getCode();
101 this.versionNumber = builder.getVersionNumber();
102 this.objectId = builder.getObjectId();
103 this.activeFromDate = builder.getActiveFromDate();
104 this.activeToDate = builder.getActiveToDate();
105 }
106
107 @Override
108 public String getId() {
109 return id;
110 }
111
112 @Override
113 public String getGroupId() {
114 return groupId;
115 }
116
117 @Override
118 public String getMemberId() {
119 return memberId;
120 }
121
122 @Override
123 public MemberType getType() {
124 return MemberType.fromCode(typeCode);
125 }
126
127 @Override
128 public DateTime getActiveFromDate() {
129 return activeFromDate;
130 }
131
132 @Override
133 public DateTime getActiveToDate() {
134 return activeToDate;
135 }
136
137 @Override
138 public Long getVersionNumber() {
139 return versionNumber;
140 }
141
142 @Override
143 public String getObjectId() {
144 return objectId;
145 }
146
147 @Override
148 public boolean isActive(DateTime activeAsOf) {
149 return InactivatableFromToUtils.isActive(activeFromDate, activeToDate, activeAsOf);
150 }
151
152 @Override
153 public boolean isActive() {
154 return InactivatableFromToUtils.isActive(activeFromDate, activeToDate, null);
155 }
156
157 public static class Builder implements GroupMemberContract, ModelBuilder, Serializable {
158 private String id;
159 private String groupId;
160 private String memberId;
161 private MemberType type;
162 private DateTime activeFromDate;
163 private DateTime activeToDate;
164 private Long versionNumber;
165 private String objectId;
166
167 private Builder(String groupId, String memberId, MemberType type) {
168 setGroupId(groupId);
169 setMemberId(memberId);
170 setType(type);
171 }
172
173
174
175
176 public static Builder create(String groupId, String memberId, MemberType type) {
177 return new Builder(groupId, memberId, type);
178 }
179
180
181
182
183 public static Builder create(GroupMemberContract contract) {
184 if (contract == null) {
185 throw new IllegalArgumentException("contract was null");
186 }
187 Builder builder = new Builder(contract.getGroupId(), contract.getMemberId(), contract.getType());
188 builder.setId(contract.getId());
189 builder.setActiveFromDate(contract.getActiveFromDate());
190 builder.setActiveToDate(contract.getActiveToDate());
191 builder.setVersionNumber(contract.getVersionNumber());
192 builder.setObjectId(contract.getObjectId());
193 return builder;
194 }
195
196 @Override
197 public String getId() {
198 return id;
199 }
200
201 public void setId(final String id) {
202 if (StringUtils.isWhitespace(id)) {
203 throw new IllegalArgumentException("id is blank");
204 }
205 this.id = id;
206 }
207
208 @Override
209 public String getGroupId() {
210 return groupId;
211 }
212
213 public void setGroupId(final String groupId) {
214 if (StringUtils.isEmpty(groupId)) {
215 throw new IllegalArgumentException("groupId is empty");
216 }
217 this.groupId = groupId;
218 }
219
220 @Override
221 public String getMemberId() {
222 return memberId;
223 }
224
225 public void setMemberId(final String memberId) {
226 if (StringUtils.isEmpty(memberId)) {
227 throw new IllegalArgumentException("memberId is empty");
228 }
229 this.memberId = memberId;
230 }
231
232 @Override
233 public MemberType getType() {
234 return type;
235 }
236
237 public void setType(final MemberType type) {
238 if (type == null) {
239 throw new IllegalArgumentException("type is null");
240 }
241 this.type = type;
242 }
243
244 @Override
245 public DateTime getActiveFromDate() {
246 return activeFromDate;
247 }
248
249 public void setActiveFromDate(final DateTime activeFromDate) {
250 this.activeFromDate = activeFromDate;
251 }
252
253 @Override
254 public DateTime getActiveToDate() {
255 return activeToDate;
256 }
257
258 public void setActiveToDate(final DateTime activeToDate) {
259 this.activeToDate = activeToDate;
260 }
261
262 @Override
263 public Long getVersionNumber() {
264 return versionNumber;
265 }
266
267 public void setVersionNumber(final Long versionNumber) {
268 this.versionNumber = versionNumber;
269 }
270
271 @Override
272 public String getObjectId() {
273 return objectId;
274 }
275
276 public void setObjectId(final String objectId) {
277 this.objectId = objectId;
278 }
279
280 @Override
281 public boolean isActive(DateTime activeAsOf) {
282 return InactivatableFromToUtils.isActive(activeFromDate, activeToDate, activeAsOf);
283 }
284
285 @Override
286 public boolean isActive() {
287 return InactivatableFromToUtils.isActive(activeFromDate, activeToDate, null);
288 }
289
290 @Override
291 public GroupMember build() {
292 return new GroupMember(this);
293 }
294 }
295
296
297
298
299 static class Constants {
300 final static String ROOT_ELEMENT_NAME = "groupMember";
301 final static String TYPE_NAME = "GroupMemberType";
302 }
303
304
305
306
307
308 static class Elements {
309 final static String ID = "id";
310 final static String GROUP_ID = "groupId";
311 final static String MEMBER_ID = "memberId";
312 final static String TYPE_CODE = "typeCode";
313 }
314
315 public static class Cache {
316 public static final String NAME = KimConstants.Namespaces.KIM_NAMESPACE_2_0 + "/" + GroupMember.Constants.TYPE_NAME;
317 }
318 }