View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.rice.kim.impl.jaxb;
20  
21  import java.io.Serializable;
22  import java.util.Set;
23  
24  import javax.xml.bind.annotation.XmlAccessType;
25  import javax.xml.bind.annotation.XmlAccessorType;
26  import javax.xml.bind.annotation.XmlElement;
27  import javax.xml.bind.annotation.XmlTransient;
28  import javax.xml.bind.annotation.XmlType;
29  import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
30  
31  import org.kuali.rice.core.util.jaxb.NameAndNamespacePair;
32  import org.kuali.rice.core.util.jaxb.NameAndNamespacePairValidatingAdapter;
33  import org.kuali.rice.core.util.jaxb.StringTrimmingAdapter;
34  import org.kuali.rice.kim.api.jaxb.NameAndNamespacePairToKimTypeIdAdapter;
35  import org.kuali.rice.kim.api.role.RoleContract;
36  
37  /**
38   * This class represents a &lt;role&gt; XML element.
39   * 
40   * @author Kuali Rice Team (rice.collab@kuali.org)
41   */
42  @XmlAccessorType(XmlAccessType.FIELD)
43  @XmlType(name="RoleType", propOrder={
44          "roleNameAndNamespace", "kimTypeId", "roleDescription", "active", "roleMembers", "rolePermissions"
45  })
46  public class RoleXmlDTO implements Serializable {
47      
48      private static final long serialVersionUID = 1L;
49  
50      @XmlTransient
51      private String roleId;
52      
53      @XmlElement(name="roleName")
54      @XmlJavaTypeAdapter(NameAndNamespacePairValidatingAdapter.class)
55      private NameAndNamespacePair roleNameAndNamespace;
56      
57      @XmlElement(name="kimTypeName")
58      @XmlJavaTypeAdapter(NameAndNamespacePairToKimTypeIdAdapter.class)
59      private String kimTypeId;
60      
61      @XmlElement(name="description")
62      @XmlJavaTypeAdapter(StringTrimmingAdapter.class)
63      private String roleDescription;
64      
65      @XmlElement(name="active")
66      private Boolean active;
67      
68      @XmlElement(name="roleMembers")
69      private RoleMembersXmlDTO.WithinRole roleMembers;
70      
71      @XmlElement(name="rolePermissions")
72      private RolePermissionsXmlDTO.WithinRole rolePermissions;
73  
74      @XmlTransient
75      private boolean alreadyPersisted = false;
76      
77      @XmlTransient
78      private Set<String> existingRoleMemberIds;
79      
80      public RoleXmlDTO() {
81          this.active = Boolean.TRUE;
82      }
83      
84      public RoleXmlDTO(RoleContract role, RoleMembersXmlDTO.WithinRole roleMembers, RolePermissionsXmlDTO.WithinRole rolePermissions) {
85          if (role == null) {
86              throw new IllegalArgumentException("role cannot be null");
87          }
88          
89          this.roleNameAndNamespace = new NameAndNamespacePair(role.getNamespaceCode(), role.getName());
90          this.kimTypeId = role.getKimTypeId();
91          this.roleDescription = role.getDescription();
92          this.active = Boolean.valueOf(role.isActive());
93          this.roleMembers = roleMembers;
94          this.rolePermissions = rolePermissions;
95      }
96  
97      /**
98       * @return the roleId
99       */
100     public String getRoleId() {
101         return this.roleId;
102     }
103 
104     /**
105      * @param roleId the roleId to set
106      */
107     public void setRoleId(String roleId) {
108         this.roleId = roleId;
109     }
110 
111     /**
112      * @return the roleNameAndNamespace
113      */
114     public NameAndNamespacePair getRoleNameAndNamespace() {
115         return this.roleNameAndNamespace;
116     }
117 
118     /**
119      * @param roleNameAndNamespace the roleNameAndNamespace to set
120      */
121     public void setRoleNameAndNamespace(NameAndNamespacePair roleNameAndNamespace) {
122         this.roleNameAndNamespace = roleNameAndNamespace;
123     }
124 
125     /**
126      * @return the kimTypeId
127      */
128     public String getKimTypeId() {
129         return this.kimTypeId;
130     }
131 
132     /**
133      * @param kimTypeId the kimTypeId to set
134      */
135     public void setKimTypeId(String kimTypeId) {
136         this.kimTypeId = kimTypeId;
137     }
138 
139     /**
140      * @return the roleDescription
141      */
142     public String getRoleDescription() {
143         return this.roleDescription;
144     }
145 
146     /**
147      * @param roleDescription the roleDescription to set
148      */
149     public void setRoleDescription(String roleDescription) {
150         this.roleDescription = roleDescription;
151     }
152 
153     /**
154      * @return the active
155      */
156     public Boolean getActive() {
157         return this.active;
158     }
159 
160     /**
161      * @param active the active to set
162      */
163     public void setActive(Boolean active) {
164         this.active = active;
165     }
166 
167     /**
168      * @return the roleMembers
169      */
170     public RoleMembersXmlDTO.WithinRole getRoleMembers() {
171         return this.roleMembers;
172     }
173 
174     /**
175      * @param roleMembers the roleMembers to set
176      */
177     public void setRoleMembers(RoleMembersXmlDTO.WithinRole roleMembers) {
178         this.roleMembers = roleMembers;
179     }
180 
181     /**
182      * @return the rolePermissions
183      */
184     public RolePermissionsXmlDTO.WithinRole getRolePermissions() {
185         return this.rolePermissions;
186     }
187 
188     /**
189      * @param rolePermissions the rolePermissions to set
190      */
191     public void setRolePermissions(RolePermissionsXmlDTO.WithinRole rolePermissions) {
192         this.rolePermissions = rolePermissions;
193     }
194 
195     /**
196      * @return the alreadyPersisted
197      */
198     public boolean isAlreadyPersisted() {
199         return this.alreadyPersisted;
200     }
201 
202     /**
203      * @param alreadyPersisted the alreadyPersisted to set
204      */
205     public void setAlreadyPersisted(boolean alreadyPersisted) {
206         this.alreadyPersisted = alreadyPersisted;
207     }
208     
209     /**
210      * @return the existingRoleMemberIds
211      */
212     public Set<String> getExistingRoleMemberIds() {
213         return this.existingRoleMemberIds;
214     }
215 
216     /**
217      * @param existingRoleMemberIds the existingRoleMemberIds to set
218      */
219     public void setExistingRoleMemberIds(Set<String> existingRoleMemberIds) {
220         this.existingRoleMemberIds = existingRoleMemberIds;
221     }
222 
223     /**
224      * Retrieves the role's name from the role-name-and-namespace combo.
225      * 
226      * @return The name of the role, or null if the role-name-and-namespace combo is null.
227      */
228     public String getRoleName() {
229         return (roleNameAndNamespace != null) ? roleNameAndNamespace.getName() : null;
230     }
231 
232     /**
233      * Retrieves the role's namespace code from the role-name-and-namespace combo.
234      * 
235      * @return The namespace code of the role, or null if the role-name-and-namespace combo is null.
236      */
237     public String getNamespaceCode() {
238         return (roleNameAndNamespace != null) ? roleNameAndNamespace.getNamespaceCode() : null;
239     }
240 }