001    /**
002     * Copyright 2005-2014 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.rice.kim.api.role;
017    
018    import java.util.Collection;
019    import java.util.Collections;
020    
021    import javax.xml.bind.annotation.XmlAccessType;
022    import javax.xml.bind.annotation.XmlAccessorType;
023    import javax.xml.bind.annotation.XmlAnyElement;
024    import javax.xml.bind.annotation.XmlElement;
025    import javax.xml.bind.annotation.XmlRootElement;
026    import javax.xml.bind.annotation.XmlType;
027    
028    import org.apache.commons.collections.CollectionUtils;
029    import org.apache.commons.lang.StringUtils;
030    import org.apache.commons.lang.builder.EqualsBuilder;
031    import org.apache.commons.lang.builder.HashCodeBuilder;
032    import org.apache.commons.lang.builder.ToStringBuilder;
033    import org.kuali.rice.core.api.CoreConstants;
034    import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
035    import org.kuali.rice.core.api.mo.ModelBuilder;
036    import org.kuali.rice.core.api.mo.ModelObjectComplete;
037    import org.kuali.rice.kim.api.KimConstants;
038    import org.w3c.dom.Element;
039    
040    /**
041     * @author Kuali Rice Team (rice.collab@kuali.org)
042     */
043    @XmlRootElement(name = RoleResponsibilityAction.Constants.ROOT_ELEMENT_NAME)
044    @XmlAccessorType(XmlAccessType.NONE)
045    @XmlType(name = RoleResponsibilityAction.Constants.TYPE_NAME, propOrder = {
046            RoleResponsibilityAction.Elements.ID,
047            RoleResponsibilityAction.Elements.ROLE_RESPONSIBILITY_ID,
048            RoleResponsibilityAction.Elements.ROLE_MEMBER_ID,
049            RoleResponsibilityAction.Elements.ACTION_TYPE_CODE,
050            RoleResponsibilityAction.Elements.ACTION_POLICY_CODE,
051            RoleResponsibilityAction.Elements.FORCE_ACTION,
052            RoleResponsibilityAction.Elements.PRIORITY_NUMBER,
053            RoleResponsibilityAction.Elements.ROLE_RESPONSIBILITY,
054            CoreConstants.CommonElements.VERSION_NUMBER,
055            CoreConstants.CommonElements.FUTURE_ELEMENTS
056    })
057    public class RoleResponsibilityAction extends AbstractDataTransferObject implements RoleResponsibilityActionContract {
058        private static final long serialVersionUID = 1L;
059    
060        @XmlElement(name = RoleResponsibilityAction.Elements.ID, required = false)
061        private final String id;
062    
063        @XmlElement(name = RoleResponsibilityAction.Elements.ROLE_RESPONSIBILITY_ID)
064        private final String roleResponsibilityId;
065    
066        @XmlElement(name = RoleResponsibilityAction.Elements.ROLE_MEMBER_ID)
067        private final String roleMemberId;
068    
069        @XmlElement(name = RoleResponsibilityAction.Elements.ACTION_TYPE_CODE)
070        private final String actionTypeCode;
071    
072        @XmlElement(name = RoleResponsibilityAction.Elements.ACTION_POLICY_CODE)
073        private final String actionPolicyCode;
074    
075        @XmlElement(name = RoleResponsibilityAction.Elements.FORCE_ACTION)
076        private final boolean forceAction;
077    
078        @XmlElement(name = RoleResponsibilityAction.Elements.PRIORITY_NUMBER)
079        private final Integer priorityNumber;
080    
081        @XmlElement(name = RoleResponsibilityAction.Elements.ROLE_RESPONSIBILITY)
082        private final RoleResponsibility roleResponsibility;
083    
084        @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER)
085        private final Long versionNumber;
086    
087        @SuppressWarnings("unused")
088        @XmlAnyElement
089        private final Collection<Element> _futureElements = null;
090    
091        /**
092         * Private default constructor should only be called by JAXB
093         */
094        @SuppressWarnings("unused")
095        private RoleResponsibilityAction() {
096            id = null;
097            roleResponsibilityId = null;
098            roleMemberId = null;
099            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    }