View Javadoc

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