View Javadoc

1   /**
2    * Copyright 2005-2013 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  package org.kuali.rice.kim.api.role;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.apache.commons.lang.builder.EqualsBuilder;
20  import org.apache.commons.lang.builder.HashCodeBuilder;
21  import org.apache.commons.lang.builder.ToStringBuilder;
22  import org.kuali.rice.core.api.CoreConstants;
23  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
24  import org.kuali.rice.core.api.mo.ModelBuilder;
25  import org.kuali.rice.core.api.mo.ModelObjectComplete;
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 java.util.Collection;
36  
37  
38  /**
39   * This is a description of what this class does - shyu don't forget to fill this in.
40   *
41   * @author Kuali Rice Team (rice.collab@kuali.org)
42   */
43  @XmlRootElement(name = Role.Constants.ROOT_ELEMENT_NAME)
44  @XmlAccessorType(XmlAccessType.NONE)
45  @XmlType(name = Role.Constants.TYPE_NAME, propOrder = {
46          Role.Elements.ID,
47          Role.Elements.NAME,
48          Role.Elements.NAMESPACE_CODE,
49          Role.Elements.DESCRIPTION,
50          Role.Elements.KIM_TYPE_ID,
51          Role.Elements.ACTIVE,
52          CoreConstants.CommonElements.VERSION_NUMBER,
53          CoreConstants.CommonElements.OBJECT_ID,
54          CoreConstants.CommonElements.FUTURE_ELEMENTS
55  })
56  public final class Role extends AbstractDataTransferObject implements RoleContract {
57      private static final long serialVersionUID = 1L;
58  
59      @XmlElement(name = Role.Elements.ID, required = true)
60      private final String id;
61  
62      @XmlElement(name = Role.Elements.NAME, required = true)
63      private final String name;
64  
65      @XmlElement(name = Role.Elements.NAMESPACE_CODE, required = true)
66      private final String namespaceCode;
67  
68      @XmlElement(name = Role.Elements.DESCRIPTION)
69      private final String description;
70  
71      @XmlElement(name = Role.Elements.KIM_TYPE_ID, required = true)
72      private final String kimTypeId;
73  
74      @XmlElement(name = CoreConstants.CommonElements.ACTIVE, required = true)
75      private final boolean active;
76  
77      @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER)
78      private final Long versionNumber;
79  
80      @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
81      private final String objectId;
82  
83      @SuppressWarnings("unused")
84      @XmlAnyElement
85      private final Collection<Element> _futureElements = null;
86  
87  
88      /**
89       * This constructor should never be called except during JAXB unmarshalling.
90       */
91      @SuppressWarnings("unused")
92      private Role() {
93          id = null;
94          name = null;
95          namespaceCode = null;
96          description = null;
97          kimTypeId = null;
98          active = false;
99          objectId = null;
100         versionNumber = null;
101     }
102 
103     private Role(Builder builder) {
104         id = builder.getId();
105         name = builder.getName();
106         namespaceCode = builder.getNamespaceCode();
107         description = builder.getDescription();
108         kimTypeId = builder.getKimTypeId();
109         active = builder.isActive();
110         versionNumber = builder.getVersionNumber();
111         objectId = builder.getObjectId();
112     }
113 
114 
115     /**
116      * Unique identifier for this role.
117      */
118     @Override
119     public String getId() {
120         return id;
121     }
122 
123     /**
124      * Namespace for this role - identifies the system/module to which this role applies
125      */
126     @Override
127     public String getNamespaceCode() {
128         return namespaceCode;
129     }
130 
131     /**
132      * Name for this role.  This value will be seen by the users.
133      */
134     @Override
135     public String getName() {
136         return name;
137     }
138 
139     /**
140      * Verbose description of the role and functionally what permissions it implies.
141      */
142     @Override
143     public String getDescription() {
144         return description;
145     }
146 
147     /**
148      * Type identifier for this role.  This will control what additional attributes are available
149      */
150     @Override
151     public String getKimTypeId() {
152         return kimTypeId;
153     }
154 
155     @Override
156     public Long getVersionNumber() {
157         return versionNumber;
158     }
159 
160     @Override
161     public String getObjectId() {
162         return objectId;
163     }
164 
165     @Override
166     public boolean isActive() {
167         return active;
168     }
169 
170     public static final class Builder implements RoleContract, ModelBuilder, ModelObjectComplete {
171 
172         private String id;
173         private String name;
174         private String namespaceCode;
175         private String description;
176         private String kimTypeId;
177         private boolean active;
178         private Long versionNumber;
179         private String objectId;
180 
181         private Builder() {
182         }
183 
184         public static Builder create() {
185             return new Builder();
186         }
187 
188         public static Builder create(String id, String name, String namespaceCode, String description, String kimTypeId) {
189             Builder b = new Builder();
190             b.setId(id);
191             b.setName(name);
192             b.setNamespaceCode(namespaceCode);
193             b.setDescription(description);
194             b.setKimTypeId(kimTypeId);
195             b.setActive(true);
196 
197             return b;
198         }
199 
200         public static Builder create(RoleContract roleContract) {
201             Builder b = new Builder();
202             b.setId(roleContract.getId());
203             b.setName(roleContract.getName());
204             b.setNamespaceCode(roleContract.getNamespaceCode());
205             b.setDescription(roleContract.getDescription());
206             b.setKimTypeId(roleContract.getKimTypeId());
207             b.setActive(roleContract.isActive());
208             b.setVersionNumber(roleContract.getVersionNumber());
209             b.setObjectId(roleContract.getObjectId());
210             return b;
211         }
212 
213         @Override
214         public Role build() {
215             return new Role(this);
216         }
217 
218         public void setId(String id) {
219             if (StringUtils.isWhitespace(id)) {
220                 throw new IllegalArgumentException("id cannot be blank");
221             }
222             this.id = id;
223         }
224 
225         @Override
226         public String getId() {
227             return id;
228         }
229 
230         public void setNamespaceCode(String namespaceCode) {
231             if (StringUtils.isBlank(namespaceCode)) {
232                 throw new IllegalArgumentException("namespaceCode cannot be blank or null");
233             }
234             this.namespaceCode = namespaceCode;
235         }
236 
237         @Override
238         public String getNamespaceCode() {
239             return namespaceCode;
240         }
241 
242         public void setName(String name) {
243             if (StringUtils.isBlank(name)) {
244                 throw new IllegalArgumentException("name cannot be blank or null");
245             }
246             this.name = name;
247         }
248 
249         @Override
250         public String getName() {
251             return name;
252         }
253 
254         public void setDescription(String description) {
255             this.description = description;
256         }
257 
258         @Override
259         public String getDescription() {
260             return description;
261         }
262 
263         public void setKimTypeId(String kimTypeId) {
264             if (StringUtils.isBlank(kimTypeId)) {
265                 throw new IllegalArgumentException("kimTypeId cannot be blank or null");
266             }
267             this.kimTypeId = kimTypeId;
268         }
269 
270         @Override
271         public String getKimTypeId() {
272             return kimTypeId;
273         }
274 
275         public void setActive(boolean active) {
276             this.active = active;
277         }
278 
279         @Override
280         public boolean isActive() {
281             return active;
282         }
283 
284         public void setVersionNumber(Long versionNumber) {
285             this.versionNumber = versionNumber;
286         }
287 
288         @Override
289         public Long getVersionNumber() {
290             return versionNumber;
291         }
292 
293         public void setObjectId(String objectId) {
294             this.objectId = objectId;
295         }
296 
297         @Override
298         public String getObjectId() {
299             return objectId;
300         }
301 
302         @Override
303         public int hashCode() {
304             return HashCodeBuilder.reflectionHashCode(this);
305         }
306 
307         @Override
308         public boolean equals(Object obj) {
309             return EqualsBuilder.reflectionEquals(obj, this);
310         }
311 
312         @Override
313         public String toString() {
314             return ToStringBuilder.reflectionToString(this);
315         }
316     }
317 
318     /**
319      * A private class which exposes constants which define the XML element names to use
320      * when this object is marshalled to XML.
321      */
322     static class Elements {
323         final static String ID = "id";
324         final static String NAME = "name";
325         final static String DESCRIPTION = "description";
326         final static String KIM_TYPE_ID = "kimTypeId";
327         final static String NAMESPACE_CODE = "namespaceCode";
328         final static String ACTIVE = "active";
329     }
330 
331     /**
332      * Defines some internal constants used on this class.
333      */
334     static class Constants {
335         final static String ROOT_ELEMENT_NAME = "role";
336         final static String TYPE_NAME = "RoleType";
337     }
338 
339     public static class Cache {
340         public static final String NAME = KimConstants.Namespaces.KIM_NAMESPACE_2_0 + "/" + Role.Constants.TYPE_NAME;
341     }
342 }