View Javadoc
1   /**
2    * Copyright 2005-2016 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 java.util.Collection;
19  import java.util.Collections;
20  
21  import javax.xml.bind.annotation.XmlAccessType;
22  import javax.xml.bind.annotation.XmlAccessorType;
23  import javax.xml.bind.annotation.XmlAnyElement;
24  import javax.xml.bind.annotation.XmlElement;
25  import javax.xml.bind.annotation.XmlRootElement;
26  import javax.xml.bind.annotation.XmlType;
27  
28  import org.apache.commons.collections.CollectionUtils;
29  import org.apache.commons.lang.StringUtils;
30  import org.apache.commons.lang.builder.EqualsBuilder;
31  import org.apache.commons.lang.builder.HashCodeBuilder;
32  import org.apache.commons.lang.builder.ToStringBuilder;
33  import org.kuali.rice.core.api.CoreConstants;
34  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
35  import org.kuali.rice.core.api.mo.ModelBuilder;
36  import org.kuali.rice.core.api.mo.ModelObjectComplete;
37  import org.kuali.rice.kim.api.KimConstants;
38  import org.w3c.dom.Element;
39  
40  /**
41   * @author Kuali Rice Team (rice.collab@kuali.org)
42   */
43  @XmlRootElement(name = RoleResponsibilityAction.Constants.ROOT_ELEMENT_NAME)
44  @XmlAccessorType(XmlAccessType.NONE)
45  @XmlType(name = RoleResponsibilityAction.Constants.TYPE_NAME, propOrder = {
46          RoleResponsibilityAction.Elements.ID,
47          RoleResponsibilityAction.Elements.ROLE_RESPONSIBILITY_ID,
48          RoleResponsibilityAction.Elements.ROLE_MEMBER_ID,
49          RoleResponsibilityAction.Elements.ACTION_TYPE_CODE,
50          RoleResponsibilityAction.Elements.ACTION_POLICY_CODE,
51          RoleResponsibilityAction.Elements.FORCE_ACTION,
52          RoleResponsibilityAction.Elements.PRIORITY_NUMBER,
53          RoleResponsibilityAction.Elements.ROLE_RESPONSIBILITY,
54          CoreConstants.CommonElements.VERSION_NUMBER,
55          CoreConstants.CommonElements.FUTURE_ELEMENTS
56  })
57  public class RoleResponsibilityAction extends AbstractDataTransferObject implements RoleResponsibilityActionContract {
58      private static final long serialVersionUID = 1L;
59  
60      @XmlElement(name = RoleResponsibilityAction.Elements.ID, required = false)
61      private final String id;
62  
63      @XmlElement(name = RoleResponsibilityAction.Elements.ROLE_RESPONSIBILITY_ID)
64      private final String roleResponsibilityId;
65  
66      @XmlElement(name = RoleResponsibilityAction.Elements.ROLE_MEMBER_ID)
67      private final String roleMemberId;
68  
69      @XmlElement(name = RoleResponsibilityAction.Elements.ACTION_TYPE_CODE)
70      private final String actionTypeCode;
71  
72      @XmlElement(name = RoleResponsibilityAction.Elements.ACTION_POLICY_CODE)
73      private final String actionPolicyCode;
74  
75      @XmlElement(name = RoleResponsibilityAction.Elements.FORCE_ACTION)
76      private final boolean forceAction;
77  
78      @XmlElement(name = RoleResponsibilityAction.Elements.PRIORITY_NUMBER)
79      private final Integer priorityNumber;
80  
81      @XmlElement(name = RoleResponsibilityAction.Elements.ROLE_RESPONSIBILITY)
82      private final RoleResponsibility roleResponsibility;
83  
84      @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER)
85      private final Long versionNumber;
86  
87      @SuppressWarnings("unused")
88      @XmlAnyElement
89      private final Collection<Element> _futureElements = null;
90  
91      /**
92       * Private default constructor should only be called by JAXB
93       */
94      @SuppressWarnings("unused")
95      private RoleResponsibilityAction() {
96          id = null;
97          roleResponsibilityId = null;
98          roleMemberId = null;
99          actionTypeCode = null;
100         actionPolicyCode = null;
101         forceAction = false;
102         priorityNumber = null;
103         roleResponsibility = null;
104         versionNumber = null;
105     }
106 
107     private RoleResponsibilityAction(Builder b) {
108         id = b.getId();
109         roleResponsibilityId = b.getRoleResponsibilityId();
110         roleMemberId = b.getRoleMemberId();
111         actionTypeCode = b.getActionTypeCode();
112         actionPolicyCode = b.getActionPolicyCode();
113         forceAction = b.isForceAction();
114         priorityNumber = b.getPriorityNumber();
115         roleResponsibility = b.getRoleResponsibility();
116         versionNumber = b.getVersionNumber();
117     }
118 
119     @Override
120     public String getId() {
121         return this.id;
122     }
123 
124     @Override
125     public String getRoleResponsibilityId() {
126         return this.roleResponsibilityId;
127     }
128 
129     @Override
130     public String getActionTypeCode() {
131         return this.actionTypeCode;
132     }
133 
134     @Override
135     public Integer getPriorityNumber() {
136         return this.priorityNumber;
137     }
138 
139     @Override
140     public String getActionPolicyCode() {
141         return this.actionPolicyCode;
142     }
143 
144     @Override
145     public String getRoleMemberId() {
146         return this.roleMemberId;
147     }
148 
149     @Override
150     public RoleResponsibility getRoleResponsibility() {
151         return this.roleResponsibility;
152     }
153 
154     @Override
155     public boolean isForceAction() {
156         return this.forceAction;
157     }
158 
159     @Override
160     public Long getVersionNumber() {
161         return this.versionNumber;
162     }
163 
164     public static class Builder implements RoleResponsibilityActionContract, ModelBuilder, ModelObjectComplete {
165 
166         private String id;
167         private String roleResponsibilityId;
168         private String roleMemberId;
169         private String actionTypeCode;
170         private String actionPolicyCode;
171         private boolean forceAction;
172         private Integer priorityNumber;
173         private RoleResponsibility roleResponsibility;
174         private Long versionNumber;
175 
176         private Builder() {
177         }
178 
179         public static Builder create() {
180             return new Builder();
181         }
182 
183         public static Builder create(RoleResponsibilityActionContract rra) {
184             Builder b = new Builder();
185             b.setForceAction(rra.isForceAction());
186             b.setActionPolicyCode(rra.getActionPolicyCode());
187             b.setActionTypeCode(rra.getActionTypeCode());
188             b.setPriorityNumber(rra.getPriorityNumber());
189             b.setRoleMemberId(rra.getRoleMemberId());
190             if (rra.getRoleResponsibility() != null) {
191                 b.setRoleResponsibility(RoleResponsibility.Builder.create(rra.getRoleResponsibility()).build());
192             }
193             b.setId(rra.getId());
194             b.setRoleResponsibilityId(rra.getRoleResponsibilityId());
195             b.setVersionNumber(rra.getVersionNumber());
196             return b;
197         }
198 
199         @Override
200         public RoleResponsibilityAction build() {
201             return new RoleResponsibilityAction(this);
202         }
203 
204         @Override
205         public String getId() {
206             return id;
207         }
208 
209         public void setId(String id) {
210             if (StringUtils.isWhitespace(id)) {
211                 throw new IllegalArgumentException("id must be not be whitespace");
212             }
213             this.id = id;
214         }
215 
216         @Override
217         public String getRoleResponsibilityId() {
218             return roleResponsibilityId;
219         }
220 
221         public void setRoleResponsibilityId(String roleResponsibilityId) {
222             this.roleResponsibilityId = roleResponsibilityId;
223         }
224 
225         @Override
226         public String getActionTypeCode() {
227             return actionTypeCode;
228         }
229 
230         public void setActionTypeCode(String actionTypeCode) {
231             this.actionTypeCode = actionTypeCode;
232         }
233 
234         @Override
235         public Integer getPriorityNumber() {
236             return priorityNumber;
237         }
238 
239         public void setPriorityNumber(Integer priorityNumber) {
240             this.priorityNumber = priorityNumber;
241         }
242 
243         @Override
244         public String getActionPolicyCode() {
245             return actionPolicyCode;
246         }
247 
248         public void setActionPolicyCode(String actionPolicyCode) {
249             this.actionPolicyCode = actionPolicyCode;
250         }
251 
252         @Override
253         public String getRoleMemberId() {
254             return roleMemberId;
255         }
256 
257         public void setRoleMemberId(String roleMemberId) {
258             this.roleMemberId = roleMemberId;
259         }
260 
261         @Override
262         public RoleResponsibility getRoleResponsibility() {
263             return roleResponsibility;
264         }
265 
266         public void setRoleResponsibility(RoleResponsibility roleResponsibility) {
267             this.roleResponsibility = roleResponsibility;
268         }
269 
270         @Override
271         public boolean isForceAction() {
272             return forceAction;
273         }
274 
275         public void setForceAction(boolean forceAction) {
276             this.forceAction = forceAction;
277         }
278 
279         @Override
280         public Long getVersionNumber() {
281             return versionNumber;
282         }
283 
284         public void setVersionNumber(Long versionNumber) {
285             this.versionNumber = versionNumber;
286         }
287 
288         @Override
289         public int hashCode() {
290             return HashCodeBuilder.reflectionHashCode(this);
291         }
292 
293         @Override
294         public boolean equals(Object obj) {
295             return EqualsBuilder.reflectionEquals(obj, this);
296         }
297 
298         @Override
299         public String toString() {
300             return ToStringBuilder.reflectionToString(this);
301         }
302     }
303 
304     @Override
305     public boolean equals(Object obj) {
306         return equalsExcludeFields(obj, Constants.excludeFields);
307     }
308 
309     @Override
310     public int hashCode() {
311         return hashCodeExcludeFields(Constants.excludeFields);
312     }
313 
314     /**
315      * A private class which exposes constants which define the XML element names to use
316      * when this object is marshalled to XML.
317      */
318     static class Elements {
319         final static String ID = "id";
320         final static String ROLE_RESPONSIBILITY_ID = "roleResponsibilityId";
321         final static String ROLE_MEMBER_ID = "roleMemberId";
322         final static String ACTION_TYPE_CODE = "actionTypeCode";
323         final static String ACTION_POLICY_CODE = "actionPolicyCode";
324         final static String FORCE_ACTION = "forceAction";
325         final static String PRIORITY_NUMBER = "priorityNumber";
326         final static String ROLE_RESPONSIBILITY = "roleResponsibility";
327     }
328 
329 
330     /**
331      * Defines some internal constants used on this class.
332      */
333     @SuppressWarnings("unchecked")
334     static class Constants {
335         final static String ROOT_ELEMENT_NAME = "roleResponsibilityAction";
336         final static String TYPE_NAME = "RoleResponsibilityActionType";
337 
338         final static Collection<String> excludeFields;
339 
340         static {
341             excludeFields = Collections.unmodifiableCollection( (Collection<String>)
342                     CollectionUtils.union(
343                             Collections.singletonList("versionNumber"),
344                             getDefaultHashCodeEqualsExcludeFields()
345                     )
346             );
347         }
348     }
349 
350     public static class Cache {
351         public static final String NAME = KimConstants.Namespaces.KIM_NAMESPACE_2_0 + "/" + RoleResponsibilityAction.Constants.TYPE_NAME;
352     }
353 }