View Javadoc

1   /*
2    * Copyright 2006-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.kuali.rice.kim.api.group;
18  
19  import org.apache.commons.lang.StringUtils;
20  import org.joda.time.DateTime;
21  import org.kuali.rice.core.api.CoreConstants;
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.w3c.dom.Element;
27  
28  import javax.xml.bind.annotation.XmlAccessType;
29  import javax.xml.bind.annotation.XmlAccessorType;
30  import javax.xml.bind.annotation.XmlAnyElement;
31  import javax.xml.bind.annotation.XmlElement;
32  import javax.xml.bind.annotation.XmlRootElement;
33  import javax.xml.bind.annotation.XmlType;
34  import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
35  import java.io.Serializable;
36  import java.util.Collection;
37  
38  @XmlRootElement(name = GroupMember.Constants.ROOT_ELEMENT_NAME)
39  @XmlAccessorType(XmlAccessType.NONE)
40  @XmlType(name = GroupMember.Constants.TYPE_NAME, propOrder = {
41          GroupMember.Elements.ID,
42          GroupMember.Elements.GROUP_ID,
43          GroupMember.Elements.MEMBER_ID,
44          GroupMember.Elements.TYPE_CODE,
45          CoreConstants.CommonElements.ACTIVE_FROM_DATE,
46          CoreConstants.CommonElements.ACTIVE_TO_DATE,
47          CoreConstants.CommonElements.VERSION_NUMBER,
48          CoreConstants.CommonElements.OBJECT_ID,
49          CoreConstants.CommonElements.FUTURE_ELEMENTS
50  })
51  public class GroupMember extends AbstractDataTransferObject implements GroupMemberContract  {
52  
53      @XmlElement(name = Elements.ID, required = false)
54      private final String id;
55  
56      @XmlElement(name = Elements.GROUP_ID, required = true)
57      private final String groupId;
58  
59      @XmlElement(name = Elements.MEMBER_ID, required = true)
60      private final String memberId;
61  
62      @XmlElement(name = Elements.TYPE_CODE, required = true)
63      private final String typeCode;
64  
65      @XmlElement(name = CoreConstants.CommonElements.ACTIVE_FROM_DATE, required = false)
66      @XmlJavaTypeAdapter(DateTimeAdapter.class)
67      private final DateTime activeFromDate;
68  
69      @XmlElement(name = CoreConstants.CommonElements.ACTIVE_TO_DATE, required = false)
70      @XmlJavaTypeAdapter(DateTimeAdapter.class)
71  	private final DateTime activeToDate;
72  
73      @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
74      private final Long versionNumber;
75  
76      @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
77      private final String objectId;
78  
79      @SuppressWarnings("unused")
80      @XmlAnyElement
81      private final Collection<Element> _futureElements = null;
82  
83      private GroupMember() {
84          this.id = null;
85          this.groupId = null;
86          this.memberId = null;
87          this.typeCode = null;
88          this.versionNumber = null;
89          this.objectId = null;
90          this.activeFromDate = null;
91          this.activeToDate = null;
92      }
93  
94  
95      public GroupMember(Builder builder) {
96          this.id = builder.getId();
97          this.groupId = builder.getGroupId();
98          this.memberId = builder.getMemberId();
99          this.typeCode = builder.getTypeCode();
100         this.versionNumber = builder.getVersionNumber();
101         this.objectId = builder.getObjectId();
102         this.activeFromDate = builder.getActiveFromDate();
103         this.activeToDate = builder.getActiveToDate();
104     }
105 
106     public String getId() {
107         return id;
108     }
109 
110     public String getGroupId() {
111         return groupId;
112     }
113 
114     public String getMemberId() {
115         return memberId;
116     }
117 
118     public String getTypeCode() {
119         return typeCode;
120     }
121 
122     public DateTime getActiveFromDate() {
123         return activeFromDate;
124     }
125 
126     public DateTime getActiveToDate() {
127         return activeToDate;
128     }
129 
130     public Long getVersionNumber() {
131         return versionNumber;
132     }
133 
134     public String getObjectId() {
135         return objectId;
136     }
137 
138     @Override
139     public boolean isActive(DateTime activeAsOf) {
140         return InactivatableFromToUtils.isActive(activeFromDate, activeToDate, activeAsOf);
141     }
142 
143     public static class Builder implements GroupMemberContract, ModelBuilder, Serializable {
144         private String id;
145         private String groupId;
146         private String memberId;
147         private String typeCode;
148         private DateTime activeFromDate;
149         private DateTime activeToDate;
150         private Long versionNumber;
151         private String objectId;
152 
153         private Builder(String groupId, String memberId, String typeCode) {
154             setGroupId(groupId);
155             setMemberId(memberId);
156             setTypeCode(typeCode);
157         }
158 
159         /**
160          * creates a Parameter with the required fields.
161          */
162         public static Builder create(String groupId, String memberId, String typeCode) {
163             return new Builder(groupId, memberId, typeCode);
164         }
165 
166         /**
167          * creates a GroupMember from an existing {@link org.kuali.rice.kim.api.group.GroupMemberContract}.
168          */
169         public static Builder create(GroupMemberContract contract) {
170             if (contract == null) {
171                 throw new IllegalArgumentException("contract was null");
172             }
173             Builder builder = new Builder(contract.getGroupId(), contract.getMemberId(), contract.getTypeCode());
174             builder.setId(contract.getId());
175             builder.setActiveFromDate(contract.getActiveFromDate());
176             builder.setActiveToDate(contract.getActiveToDate());
177             builder.setVersionNumber(contract.getVersionNumber());
178             builder.setObjectId(contract.getObjectId());
179             return builder;
180         }
181 
182         @Override
183         public String getId() {
184             return id;
185         }
186 
187         public void setId(final String id) {
188             if (StringUtils.isWhitespace(id)) {
189                 throw new IllegalArgumentException("id is blank");
190             }
191             this.id = id;
192         }
193 
194         @Override
195         public String getGroupId() {
196             return groupId;
197         }
198 
199         public void setGroupId(final String groupId) {
200             if (StringUtils.isEmpty(groupId)) {
201                 throw new IllegalArgumentException("groupId is empty");
202             }
203             this.groupId = groupId;
204         }
205 
206         @Override
207         public String getMemberId() {
208             return memberId;
209         }
210 
211         public void setMemberId(final String memberId) {
212             if (StringUtils.isEmpty(memberId)) {
213                 throw new IllegalArgumentException("memberId is empty");
214             }
215             this.memberId = memberId;
216         }
217 
218         @Override
219         public String getTypeCode() {
220             return typeCode;
221         }
222 
223         public void setTypeCode(final String typeCode) {
224             if (StringUtils.isEmpty(typeCode)) {
225                 throw new IllegalArgumentException("typeCode is empty");
226             }
227             this.typeCode = typeCode;
228         }
229 
230         @Override
231         public DateTime getActiveFromDate() {
232             return activeFromDate;
233         }
234 
235         public void setActiveFromDate(final DateTime activeFromDate) {
236             this.activeFromDate = activeFromDate;
237         }
238 
239         @Override
240         public DateTime getActiveToDate() {
241             return activeToDate;
242         }
243 
244         public void setActiveToDate(final DateTime activeToDate) {
245             this.activeToDate = activeToDate;
246         }
247 
248         @Override
249         public Long getVersionNumber() {
250             return versionNumber;
251         }
252 
253         public void setVersionNumber(final Long versionNumber) {
254             this.versionNumber = versionNumber;
255         }
256 
257         @Override
258         public String getObjectId() {
259             return objectId;
260         }
261 
262         public void setObjectId(final String objectId) {
263             this.objectId = objectId;
264         }
265 
266         @Override
267         public boolean isActive(DateTime activeAsOf) {
268             return InactivatableFromToUtils.isActive(activeFromDate, activeToDate, activeAsOf);
269         }
270 
271         @Override
272         public GroupMember build() {
273             return new GroupMember(this);
274         }
275     }
276 
277     /**
278      * Defines some internal constants used on this class.
279      */
280     static class Constants {
281         final static String ROOT_ELEMENT_NAME = "groupMember";
282         final static String TYPE_NAME = "GroupMemberType";
283     }
284 
285     /**
286      * A private class which exposes constants which define the XML element names to use
287      * when this object is marshalled to XML.
288      */
289     static class Elements {
290         final static String ID = "id";
291         final static String GROUP_ID = "groupId";
292         final static String MEMBER_ID = "memberId";
293         final static String TYPE_CODE = "typeCode";
294     }
295 }