001    /**
002     * Copyright 2005-2012 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.impl.jaxb;
017    
018    import java.io.Serializable;
019    import java.util.Set;
020    
021    import javax.xml.bind.annotation.XmlAccessType;
022    import javax.xml.bind.annotation.XmlAccessorType;
023    import javax.xml.bind.annotation.XmlElement;
024    import javax.xml.bind.annotation.XmlTransient;
025    import javax.xml.bind.annotation.XmlType;
026    import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
027    
028    import org.kuali.rice.core.util.jaxb.NameAndNamespacePair;
029    import org.kuali.rice.core.util.jaxb.NameAndNamespacePairValidatingAdapter;
030    import org.kuali.rice.core.util.jaxb.StringTrimmingAdapter;
031    import org.kuali.rice.kim.api.jaxb.NameAndNamespacePairToKimTypeIdAdapter;
032    import org.kuali.rice.kim.api.role.RoleContract;
033    
034    /**
035     * This class represents a <role> XML element.
036     * 
037     * @author Kuali Rice Team (rice.collab@kuali.org)
038     */
039    @XmlAccessorType(XmlAccessType.FIELD)
040    @XmlType(name="RoleType", propOrder={
041            "roleNameAndNamespace", "kimTypeId", "roleDescription", "active", "roleMembers", "rolePermissions"
042    })
043    public class RoleXmlDTO implements Serializable {
044        
045        private static final long serialVersionUID = 1L;
046    
047        @XmlTransient
048        private String roleId;
049        
050        @XmlElement(name="roleName")
051        @XmlJavaTypeAdapter(NameAndNamespacePairValidatingAdapter.class)
052        private NameAndNamespacePair roleNameAndNamespace;
053        
054        @XmlElement(name="kimTypeName")
055        @XmlJavaTypeAdapter(NameAndNamespacePairToKimTypeIdAdapter.class)
056        private String kimTypeId;
057        
058        @XmlElement(name="description")
059        @XmlJavaTypeAdapter(StringTrimmingAdapter.class)
060        private String roleDescription;
061        
062        @XmlElement(name="active")
063        private Boolean active;
064        
065        @XmlElement(name="roleMembers")
066        private RoleMembersXmlDTO.WithinRole roleMembers;
067        
068        @XmlElement(name="rolePermissions")
069        private RolePermissionsXmlDTO.WithinRole rolePermissions;
070    
071        @XmlTransient
072        private boolean alreadyPersisted = false;
073        
074        @XmlTransient
075        private Set<String> existingRoleMemberIds;
076        
077        public RoleXmlDTO() {
078            this.active = Boolean.TRUE;
079        }
080        
081        public RoleXmlDTO(RoleContract role, RoleMembersXmlDTO.WithinRole roleMembers, RolePermissionsXmlDTO.WithinRole rolePermissions) {
082            if (role == null) {
083                throw new IllegalArgumentException("role cannot be null");
084            }
085            
086            this.roleNameAndNamespace = new NameAndNamespacePair(role.getNamespaceCode(), role.getName());
087            this.kimTypeId = role.getKimTypeId();
088            this.roleDescription = role.getDescription();
089            this.active = Boolean.valueOf(role.isActive());
090            this.roleMembers = roleMembers;
091            this.rolePermissions = rolePermissions;
092        }
093    
094        /**
095         * @return the roleId
096         */
097        public String getRoleId() {
098            return this.roleId;
099        }
100    
101        /**
102         * @param roleId the roleId to set
103         */
104        public void setRoleId(String roleId) {
105            this.roleId = roleId;
106        }
107    
108        /**
109         * @return the roleNameAndNamespace
110         */
111        public NameAndNamespacePair getRoleNameAndNamespace() {
112            return this.roleNameAndNamespace;
113        }
114    
115        /**
116         * @param roleNameAndNamespace the roleNameAndNamespace to set
117         */
118        public void setRoleNameAndNamespace(NameAndNamespacePair roleNameAndNamespace) {
119            this.roleNameAndNamespace = roleNameAndNamespace;
120        }
121    
122        /**
123         * @return the kimTypeId
124         */
125        public String getKimTypeId() {
126            return this.kimTypeId;
127        }
128    
129        /**
130         * @param kimTypeId the kimTypeId to set
131         */
132        public void setKimTypeId(String kimTypeId) {
133            this.kimTypeId = kimTypeId;
134        }
135    
136        /**
137         * @return the roleDescription
138         */
139        public String getRoleDescription() {
140            return this.roleDescription;
141        }
142    
143        /**
144         * @param roleDescription the roleDescription to set
145         */
146        public void setRoleDescription(String roleDescription) {
147            this.roleDescription = roleDescription;
148        }
149    
150        /**
151         * @return the active
152         */
153        public Boolean getActive() {
154            return this.active;
155        }
156    
157        /**
158         * @param active the active to set
159         */
160        public void setActive(Boolean active) {
161            this.active = active;
162        }
163    
164        /**
165         * @return the roleMembers
166         */
167        public RoleMembersXmlDTO.WithinRole getRoleMembers() {
168            return this.roleMembers;
169        }
170    
171        /**
172         * @param roleMembers the roleMembers to set
173         */
174        public void setRoleMembers(RoleMembersXmlDTO.WithinRole roleMembers) {
175            this.roleMembers = roleMembers;
176        }
177    
178        /**
179         * @return the rolePermissions
180         */
181        public RolePermissionsXmlDTO.WithinRole getRolePermissions() {
182            return this.rolePermissions;
183        }
184    
185        /**
186         * @param rolePermissions the rolePermissions to set
187         */
188        public void setRolePermissions(RolePermissionsXmlDTO.WithinRole rolePermissions) {
189            this.rolePermissions = rolePermissions;
190        }
191    
192        /**
193         * @return the alreadyPersisted
194         */
195        public boolean isAlreadyPersisted() {
196            return this.alreadyPersisted;
197        }
198    
199        /**
200         * @param alreadyPersisted the alreadyPersisted to set
201         */
202        public void setAlreadyPersisted(boolean alreadyPersisted) {
203            this.alreadyPersisted = alreadyPersisted;
204        }
205        
206        /**
207         * @return the existingRoleMemberIds
208         */
209        public Set<String> getExistingRoleMemberIds() {
210            return this.existingRoleMemberIds;
211        }
212    
213        /**
214         * @param existingRoleMemberIds the existingRoleMemberIds to set
215         */
216        public void setExistingRoleMemberIds(Set<String> existingRoleMemberIds) {
217            this.existingRoleMemberIds = existingRoleMemberIds;
218        }
219    
220        /**
221         * Retrieves the role's name from the role-name-and-namespace combo.
222         * 
223         * @return The name of the role, or null if the role-name-and-namespace combo is null.
224         */
225        public String getRoleName() {
226            return (roleNameAndNamespace != null) ? roleNameAndNamespace.getName() : null;
227        }
228    
229        /**
230         * Retrieves the role's namespace code from the role-name-and-namespace combo.
231         * 
232         * @return The namespace code of the role, or null if the role-name-and-namespace combo is null.
233         */
234        public String getNamespaceCode() {
235            return (roleNameAndNamespace != null) ? roleNameAndNamespace.getNamespaceCode() : null;
236        }
237    }