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 org.apache.commons.lang.StringUtils;
019    import org.apache.commons.lang.builder.EqualsBuilder;
020    import org.apache.commons.lang.builder.HashCodeBuilder;
021    import org.apache.commons.lang.builder.ToStringBuilder;
022    import org.kuali.rice.core.api.CoreConstants;
023    import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
024    import org.kuali.rice.core.api.mo.ModelBuilder;
025    import org.kuali.rice.core.api.mo.ModelObjectComplete;
026    import org.kuali.rice.kim.api.KimConstants;
027    import org.w3c.dom.Element;
028    
029    import javax.xml.bind.annotation.XmlAccessType;
030    import javax.xml.bind.annotation.XmlAccessorType;
031    import javax.xml.bind.annotation.XmlAnyElement;
032    import javax.xml.bind.annotation.XmlElement;
033    import javax.xml.bind.annotation.XmlRootElement;
034    import javax.xml.bind.annotation.XmlType;
035    import java.util.Collection;
036    
037    /**
038     * @author Kuali Rice Team (rice.collab@kuali.org)
039     */
040    @XmlRootElement(name = RoleResponsibilityAction.Constants.ROOT_ELEMENT_NAME)
041    @XmlAccessorType(XmlAccessType.NONE)
042    @XmlType(name = RoleResponsibilityAction.Constants.TYPE_NAME, propOrder = {
043            RoleResponsibilityAction.Elements.ID,
044            RoleResponsibilityAction.Elements.ROLE_RESPONSIBILITY_ID,
045            RoleResponsibilityAction.Elements.ROLE_MEMBER_ID,
046            RoleResponsibilityAction.Elements.ACTION_TYPE_CODE,
047            RoleResponsibilityAction.Elements.ACTION_POLICY_CODE,
048            RoleResponsibilityAction.Elements.FORCE_ACTION,
049            RoleResponsibilityAction.Elements.PRIORITY_NUMBER,
050            RoleResponsibilityAction.Elements.ROLE_RESPONSIBILITY,
051            CoreConstants.CommonElements.VERSION_NUMBER,
052            CoreConstants.CommonElements.FUTURE_ELEMENTS
053    })
054    public class RoleResponsibilityAction extends AbstractDataTransferObject implements RoleResponsibilityActionContract {
055    
056        @XmlElement(name = RoleResponsibilityAction.Elements.ID, required = false)
057        private final String id;
058    
059        @XmlElement(name = RoleResponsibilityAction.Elements.ROLE_RESPONSIBILITY_ID)
060        private final String roleResponsibilityId;
061    
062        @XmlElement(name = RoleResponsibilityAction.Elements.ROLE_MEMBER_ID)
063        private final String roleMemberId;
064    
065        @XmlElement(name = RoleResponsibilityAction.Elements.ACTION_TYPE_CODE)
066        private final String actionTypeCode;
067    
068        @XmlElement(name = RoleResponsibilityAction.Elements.ACTION_POLICY_CODE)
069        private final String actionPolicyCode;
070    
071        @XmlElement(name = RoleResponsibilityAction.Elements.FORCE_ACTION)
072        private final boolean forceAction;
073    
074        @XmlElement(name = RoleResponsibilityAction.Elements.PRIORITY_NUMBER)
075        private final Integer priorityNumber;
076    
077        @XmlElement(name = RoleResponsibilityAction.Elements.ROLE_RESPONSIBILITY)
078        private final RoleResponsibility roleResponsibility;
079    
080        @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER)
081        private final Long versionNumber;
082    
083        @SuppressWarnings("unused")
084        @XmlAnyElement
085        private final Collection<Element> _futureElements = null;
086    
087        /**
088         * Private default constructor should only be called by JAXB
089         */
090        @SuppressWarnings("unused")
091        private RoleResponsibilityAction() {
092            id = null;
093            roleResponsibilityId = null;
094            roleMemberId = null;
095            actionTypeCode = null;
096            actionPolicyCode = null;
097            forceAction = false;
098            priorityNumber = null;
099            roleResponsibility = null;
100            versionNumber = null;
101        }
102    
103        private RoleResponsibilityAction(Builder b) {
104            id = b.getId();
105            roleResponsibilityId = b.getRoleResponsibilityId();
106            roleMemberId = b.getRoleMemberId();
107            actionTypeCode = b.getActionTypeCode();
108            actionPolicyCode = b.getActionPolicyCode();
109            forceAction = b.isForceAction();
110            priorityNumber = b.getPriorityNumber();
111            roleResponsibility = b.getRoleResponsibility();
112            versionNumber = b.getVersionNumber();
113        }
114    
115        @Override
116        public String getId() {
117            return this.id;
118        }
119    
120        @Override
121        public String getRoleResponsibilityId() {
122            return this.roleResponsibilityId;
123        }
124    
125        @Override
126        public String getActionTypeCode() {
127            return this.actionTypeCode;
128        }
129    
130        @Override
131        public Integer getPriorityNumber() {
132            return this.priorityNumber;
133        }
134    
135        @Override
136        public String getActionPolicyCode() {
137            return this.actionPolicyCode;
138        }
139    
140        @Override
141        public String getRoleMemberId() {
142            return this.roleMemberId;
143        }
144    
145        @Override
146        public RoleResponsibility getRoleResponsibility() {
147            return this.roleResponsibility;
148        }
149    
150        @Override
151        public boolean isForceAction() {
152            return this.forceAction;
153        }
154    
155        @Override
156        public Long getVersionNumber() {
157            return this.versionNumber;
158        }
159    
160        public static class Builder implements RoleResponsibilityActionContract, ModelBuilder, ModelObjectComplete {
161    
162            private String id;
163            private String roleResponsibilityId;
164            private String roleMemberId;
165            private String actionTypeCode;
166            private String actionPolicyCode;
167            private boolean forceAction;
168            private Integer priorityNumber;
169            private RoleResponsibility roleResponsibility;
170            private Long versionNumber;
171    
172            private Builder() {
173            }
174    
175            public static Builder create() {
176                return new Builder();
177            }
178    
179            public static Builder create(RoleResponsibilityActionContract rra) {
180                Builder b = new Builder();
181                b.setForceAction(rra.isForceAction());
182                b.setActionPolicyCode(rra.getActionPolicyCode());
183                b.setActionTypeCode(rra.getActionTypeCode());
184                b.setPriorityNumber(rra.getPriorityNumber());
185                b.setRoleMemberId(rra.getRoleMemberId());
186                if (rra.getRoleResponsibility() != null) {
187                    b.setRoleResponsibility(RoleResponsibility.Builder.create(rra.getRoleResponsibility()).build());
188                }
189                b.setId(rra.getId());
190                b.setRoleResponsibilityId(rra.getRoleResponsibilityId());
191                b.setVersionNumber(rra.getVersionNumber());
192                return b;
193            }
194    
195            @Override
196            public RoleResponsibilityAction build() {
197                return new RoleResponsibilityAction(this);
198            }
199    
200            @Override
201            public String getId() {
202                return id;
203            }
204    
205            public void setId(String id) {
206                if (StringUtils.isWhitespace(id)) {
207                    throw new IllegalArgumentException("id must be not be whitespace");
208                }
209                this.id = id;
210            }
211    
212            @Override
213            public String getRoleResponsibilityId() {
214                return roleResponsibilityId;
215            }
216    
217            public void setRoleResponsibilityId(String roleResponsibilityId) {
218                this.roleResponsibilityId = roleResponsibilityId;
219            }
220    
221            @Override
222            public String getActionTypeCode() {
223                return actionTypeCode;
224            }
225    
226            public void setActionTypeCode(String actionTypeCode) {
227                this.actionTypeCode = actionTypeCode;
228            }
229    
230            @Override
231            public Integer getPriorityNumber() {
232                return priorityNumber;
233            }
234    
235            public void setPriorityNumber(Integer priorityNumber) {
236                this.priorityNumber = priorityNumber;
237            }
238    
239            @Override
240            public String getActionPolicyCode() {
241                return actionPolicyCode;
242            }
243    
244            public void setActionPolicyCode(String actionPolicyCode) {
245                this.actionPolicyCode = actionPolicyCode;
246            }
247    
248            @Override
249            public String getRoleMemberId() {
250                return roleMemberId;
251            }
252    
253            public void setRoleMemberId(String roleMemberId) {
254                this.roleMemberId = roleMemberId;
255            }
256    
257            @Override
258            public RoleResponsibility getRoleResponsibility() {
259                return roleResponsibility;
260            }
261    
262            public void setRoleResponsibility(RoleResponsibility roleResponsibility) {
263                this.roleResponsibility = roleResponsibility;
264            }
265    
266            @Override
267            public boolean isForceAction() {
268                return forceAction;
269            }
270    
271            public void setForceAction(boolean forceAction) {
272                this.forceAction = forceAction;
273            }
274    
275            @Override
276            public Long getVersionNumber() {
277                return versionNumber;
278            }
279    
280            public void setVersionNumber(Long versionNumber) {
281                this.versionNumber = versionNumber;
282            }
283    
284            @Override
285            public int hashCode() {
286                return HashCodeBuilder.reflectionHashCode(this);
287            }
288    
289            @Override
290            public boolean equals(Object obj) {
291                return EqualsBuilder.reflectionEquals(obj, this);
292            }
293    
294            @Override
295            public String toString() {
296                return ToStringBuilder.reflectionToString(this);
297            }
298        }
299    
300    
301        /**
302         * A private class which exposes constants which define the XML element names to use
303         * when this object is marshalled to XML.
304         */
305        static class Elements {
306            final static String ID = "id";
307            final static String ROLE_RESPONSIBILITY_ID = "roleResponsibilityId";
308            final static String ROLE_MEMBER_ID = "roleMemberId";
309            final static String ACTION_TYPE_CODE = "actionTypeCode";
310            final static String ACTION_POLICY_CODE = "actionPolicyCode";
311            final static String FORCE_ACTION = "forceAction";
312            final static String PRIORITY_NUMBER = "priorityNumber";
313            final static String ROLE_RESPONSIBILITY = "roleResponsibility";
314        }
315    
316        /**
317         * Defines some internal constants used on this class.
318         */
319        static class Constants {
320            final static String ROOT_ELEMENT_NAME = "roleResponsibilityAction";
321            final static String TYPE_NAME = "RoleResponsibilityActionType";
322        }
323    
324        public static class Cache {
325            public static final String NAME = KimConstants.Namespaces.KIM_NAMESPACE_2_0 + "/" + RoleResponsibilityAction.Constants.TYPE_NAME;
326        }
327    }