View Javadoc

1   /**
2    * Copyright 2005-2012 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   * An lightweight association of a Responsibility and a Role represented by references to the identifiers of a
39   * Role and a Responsibility that are related to each other.
40   *
41   * @author Kuali Rice Team (rice.collab@kuali.org)
42   */
43  @XmlRootElement(name = RoleResponsibility.Constants.ROOT_ELEMENT_NAME)
44  @XmlAccessorType(XmlAccessType.NONE)
45  @XmlType(name = RoleResponsibility.Constants.TYPE_NAME, propOrder = {
46          RoleResponsibility.Elements.ROLE_RESPONSIBILITY_ID,
47          RoleResponsibility.Elements.ROLE_ID,
48          RoleResponsibility.Elements.RESPONSIBILITY_ID,
49          CoreConstants.CommonElements.ACTIVE,
50          CoreConstants.CommonElements.VERSION_NUMBER,
51          CoreConstants.CommonElements.FUTURE_ELEMENTS
52  })
53  final public class RoleResponsibility extends AbstractDataTransferObject implements RoleResponsibilityContract {
54      private static final long serialVersionUID = 1L;
55  
56      @XmlElement(name = RoleResponsibility.Elements.ROLE_RESPONSIBILITY_ID, required = true)
57      private final String roleResponsibilityId;
58  
59      @XmlElement(name = RoleResponsibility.Elements.ROLE_ID)
60      private final String roleId;
61  
62      @XmlElement(name = RoleResponsibility.Elements.RESPONSIBILITY_ID)
63      private final String responsibilityId;
64  
65      @XmlElement(name = CoreConstants.CommonElements.ACTIVE)
66      private final boolean active;
67  
68      @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER)
69      private final Long versionNumber;
70  
71      @SuppressWarnings("unused")
72      @XmlAnyElement
73      private final Collection<Element> _futureElements = null;
74  
75  
76      /**
77       * This constructor should never be called except during JAXB unmarshalling.
78       */
79      @SuppressWarnings("unused")
80      private RoleResponsibility() {
81          this.roleResponsibilityId = null;
82          this.roleId = null;
83          this.responsibilityId = null;
84          this.versionNumber = null;
85          this.active = false;
86      }
87  
88      private RoleResponsibility(Builder b) {
89          this.roleResponsibilityId = b.getRoleResponsibilityId();
90          this.responsibilityId = b.getResponsibilityId();
91          this.roleId = b.getRoleId();
92          this.active = b.isActive();
93          this.versionNumber = b.getVersionNumber();
94      }
95  
96      @Override
97      public String getResponsibilityId() {
98          return this.responsibilityId;
99      }
100 
101     @Override
102     public String getRoleId() {
103         return this.roleId;
104     }
105 
106     @Override
107     public String getRoleResponsibilityId() {
108         return this.roleResponsibilityId;
109     }
110 
111     @Override
112     public boolean isActive() {
113         return this.active;
114     }
115 
116     @Override
117     public Long getVersionNumber() {
118         return this.versionNumber;
119     }
120 
121     public static class Builder implements RoleResponsibilityContract, ModelBuilder, ModelObjectComplete {
122         private String roleResponsibilityId;
123         private String roleId;
124         private String responsibilityId;
125         private boolean active = true;
126         private Long versionNumber;
127 
128 
129         private Builder() {
130         }
131 
132         public static Builder create() {
133             return new Builder();
134         }
135 
136         public static Builder create(String roleResponsibilityId, String roleId, String responsibilityId) {
137             Builder b = create();
138             b.setRoleResponsibilityId(roleResponsibilityId);
139             b.setRoleId(roleId);
140             b.setResponsibilityId(responsibilityId);
141             return b;
142         }
143 
144         public static Builder create(RoleResponsibilityContract rrContract) {
145             Builder b = create();
146             b.setRoleResponsibilityId(rrContract.getRoleResponsibilityId());
147             b.setResponsibilityId(rrContract.getResponsibilityId());
148             b.setRoleId(rrContract.getRoleId());
149             b.setActive(rrContract.isActive());
150             b.setVersionNumber(rrContract.getVersionNumber());
151             return b;
152         }
153 
154         @Override
155         public RoleResponsibility build() {
156             if (versionNumber == null || roleResponsibilityId == null) {
157                 throw new IllegalStateException(
158                         "versionNumber and roleResponsibilityId must be non-null for a RoleResponsibility object");
159             }
160             return new RoleResponsibility(this);
161         }
162 
163         @Override
164         public String getRoleResponsibilityId() {
165             return roleResponsibilityId;
166         }
167 
168         public void setRoleResponsibilityId(String roleResponsibilityId) {
169             if (StringUtils.isBlank(roleResponsibilityId)) {
170                 throw new IllegalArgumentException("roleResponsibilityId cannot be blank or null");
171             }
172             this.roleResponsibilityId = roleResponsibilityId;
173         }
174 
175         @Override
176         public String getRoleId() {
177             return roleId;
178         }
179 
180         public void setRoleId(String roleId) {
181             this.roleId = roleId;
182         }
183 
184         @Override
185         public String getResponsibilityId() {
186             return responsibilityId;
187         }
188 
189         public void setResponsibilityId(String responsibilityId) {
190             this.responsibilityId = responsibilityId;
191         }
192 
193 
194         @Override
195         public boolean isActive() {
196             return active;
197         }
198 
199         public void setActive(boolean active) {
200             this.active = active;
201         }
202 
203         @Override
204         public Long getVersionNumber() {
205             return versionNumber;
206         }
207 
208         public void setVersionNumber(Long versionNumber) {
209             if (versionNumber == null) {
210                 throw new IllegalArgumentException("versionNumber must be non-null");
211             }
212             this.versionNumber = versionNumber;
213         }
214 
215         @Override
216         public int hashCode() {
217             return HashCodeBuilder.reflectionHashCode(this);
218         }
219 
220         @Override
221         public boolean equals(Object obj) {
222             return EqualsBuilder.reflectionEquals(obj, this);
223         }
224 
225         @Override
226         public String toString() {
227             return ToStringBuilder.reflectionToString(this);
228         }
229     }
230 
231     /**
232      * A private class which exposes constants which define the XML element names to use
233      * when this object is marshalled to XML.
234      */
235     static class Elements {
236         final static String ROLE_RESPONSIBILITY_ID = "roleResponsibilityId";
237         final static String ROLE_ID = "roleId";
238         final static String RESPONSIBILITY_ID = "responsibilityId";
239     }
240 
241     /**
242      * Defines some internal constants used on this class.
243      */
244     static class Constants {
245         final static String ROOT_ELEMENT_NAME = "roleResponsibility";
246         final static String TYPE_NAME = "RoleResponsibilityType";
247     }
248 
249     public static class Cache {
250         public static final String NAME = KimConstants.Namespaces.KIM_NAMESPACE_2_0 + "/" + RoleResponsibility.Constants.TYPE_NAME;
251     }
252 }