View Javadoc
1   /**
2    * Copyright 2005-2014 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  public final class RoleResponsibility extends AbstractDataTransferObject implements RoleResponsibilityContract {
54      private static final long serialVersionUID = 1L;
55  
56      @XmlElement(name = RoleResponsibility.Elements.ROLE_RESPONSIBILITY_ID, required = false)
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 roleId, String responsibilityId) {
137             Builder b = create();
138 
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             return new RoleResponsibility(this);
157         }
158 
159         @Override
160         public String getRoleResponsibilityId() {
161             return roleResponsibilityId;
162         }
163 
164         public void setRoleResponsibilityId(String roleResponsibilityId) {
165             if (StringUtils.isWhitespace(roleResponsibilityId)) {
166                 throw new IllegalArgumentException("roleResponsibilityId cannot be whitespace");
167             }
168             this.roleResponsibilityId = roleResponsibilityId;
169         }
170 
171         @Override
172         public String getRoleId() {
173             return roleId;
174         }
175 
176         public void setRoleId(String roleId) {
177             this.roleId = roleId;
178         }
179 
180         @Override
181         public String getResponsibilityId() {
182             return responsibilityId;
183         }
184 
185         public void setResponsibilityId(String responsibilityId) {
186             this.responsibilityId = responsibilityId;
187         }
188 
189 
190         @Override
191         public boolean isActive() {
192             return active;
193         }
194 
195         public void setActive(boolean active) {
196             this.active = active;
197         }
198 
199         @Override
200         public Long getVersionNumber() {
201             return versionNumber;
202         }
203 
204         public void setVersionNumber(Long versionNumber) {
205             this.versionNumber = versionNumber;
206         }
207 
208         @Override
209         public int hashCode() {
210             return HashCodeBuilder.reflectionHashCode(this);
211         }
212 
213         @Override
214         public boolean equals(Object obj) {
215             return EqualsBuilder.reflectionEquals(obj, this);
216         }
217 
218         @Override
219         public String toString() {
220             return ToStringBuilder.reflectionToString(this);
221         }
222     }
223 
224     /**
225      * A private class which exposes constants which define the XML element names to use
226      * when this object is marshalled to XML.
227      */
228     static class Elements {
229         final static String ROLE_RESPONSIBILITY_ID = "roleResponsibilityId";
230         final static String ROLE_ID = "roleId";
231         final static String RESPONSIBILITY_ID = "responsibilityId";
232     }
233 
234     /**
235      * Defines some internal constants used on this class.
236      */
237     static class Constants {
238         final static String ROOT_ELEMENT_NAME = "roleResponsibility";
239         final static String TYPE_NAME = "RoleResponsibilityType";
240     }
241 
242     public static class Cache {
243         public static final String NAME = KimConstants.Namespaces.KIM_NAMESPACE_2_0 + "/" + RoleResponsibility.Constants.TYPE_NAME;
244     }
245 }