View Javadoc
1   /*
2    * Copyright 2011 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/ecl1.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.impl.jaxb;
17  
18  import java.io.Serializable;
19  import java.util.Set;
20  
21  import javax.xml.bind.annotation.XmlAccessType;
22  import javax.xml.bind.annotation.XmlAccessorType;
23  import javax.xml.bind.annotation.XmlElement;
24  import javax.xml.bind.annotation.XmlTransient;
25  import javax.xml.bind.annotation.XmlType;
26  import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
27  
28  import org.kuali.rice.core.util.jaxb.NameAndNamespacePair;
29  import org.kuali.rice.core.util.jaxb.NameAndNamespacePairValidatingAdapter;
30  import org.kuali.rice.core.util.jaxb.StringTrimmingAdapter;
31  import org.kuali.rice.kim.api.jaxb.NameAndNamespacePairToKimTypeIdAdapter;
32  import org.kuali.rice.kim.api.role.RoleContract;
33  
34  /**
35   * This class represents a <role> XML element.
36   * 
37   * @author Kuali Rice Team (rice.collab@kuali.org)
38   */
39  @XmlAccessorType(XmlAccessType.FIELD)
40  @XmlType(name="RoleType", propOrder={
41          "roleNameAndNamespace", "kimTypeId", "roleDescription", "active", "roleMembers", "rolePermissions"
42  })
43  public class RoleXmlDTO implements Serializable {
44      
45      private static final long serialVersionUID = 1L;
46  
47      @XmlTransient
48      private String roleId;
49      
50      @XmlElement(name="roleName")
51      @XmlJavaTypeAdapter(NameAndNamespacePairValidatingAdapter.class)
52      private NameAndNamespacePair roleNameAndNamespace;
53      
54      @XmlElement(name="kimTypeName")
55      @XmlJavaTypeAdapter(NameAndNamespacePairToKimTypeIdAdapter.class)
56      private String kimTypeId;
57      
58      @XmlElement(name="description")
59      @XmlJavaTypeAdapter(StringTrimmingAdapter.class)
60      private String roleDescription;
61      
62      @XmlElement(name="active")
63      private Boolean active;
64      
65      @XmlElement(name="roleMembers")
66      private RoleMembersXmlDTO.WithinRole roleMembers;
67      
68      @XmlElement(name="rolePermissions")
69      private RolePermissionsXmlDTO.WithinRole rolePermissions;
70  
71      @XmlTransient
72      private boolean alreadyPersisted = false;
73      
74      @XmlTransient
75      private Set<String> existingRoleMemberIds;
76      
77      public RoleXmlDTO() {
78          this.active = Boolean.TRUE;
79      }
80      
81      public RoleXmlDTO(RoleContract role, RoleMembersXmlDTO.WithinRole roleMembers, RolePermissionsXmlDTO.WithinRole rolePermissions) {
82          if (role == null) {
83              throw new IllegalArgumentException("role cannot be null");
84          }
85          
86          this.roleNameAndNamespace = new NameAndNamespacePair(role.getNamespaceCode(), role.getName());
87          this.kimTypeId = role.getKimTypeId();
88          this.roleDescription = role.getDescription();
89          this.active = Boolean.valueOf(role.isActive());
90          this.roleMembers = roleMembers;
91          this.rolePermissions = rolePermissions;
92      }
93  
94      /**
95       * @return the roleId
96       */
97      public String getRoleId() {
98          return this.roleId;
99      }
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 }