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.HashMap;
20  import java.util.Map;
21  
22  import javax.xml.bind.annotation.XmlAccessType;
23  import javax.xml.bind.annotation.XmlAccessorType;
24  import javax.xml.bind.annotation.XmlElement;
25  import javax.xml.bind.annotation.XmlTransient;
26  import javax.xml.bind.annotation.XmlType;
27  import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
28  
29  import org.kuali.rice.core.util.jaxb.NameAndNamespacePair;
30  import org.kuali.rice.core.util.jaxb.NameAndNamespacePairValidatingAdapter;
31  import org.kuali.rice.core.util.jaxb.StringTrimmingAdapter;
32  import org.kuali.rice.kim.api.jaxb.NameAndNamespacePairToPermTemplateIdAdapter;
33  import org.kuali.rice.kim.api.jaxb.PermissionDetailListAdapter;
34  import org.kuali.rice.kim.api.permission.PermissionContract;
35  
36  /**
37   * This class represents a <permission> XML element.
38   * 
39   * @author Kuali Rice Team (rice.collab@kuali.org)
40   */
41  @XmlAccessorType(XmlAccessType.FIELD)
42  @XmlType(name="PermissionType", propOrder={
43          "permissionNameAndNamespace", "permissionTemplateId", "permissionDescription", "active", "permissionDetails"
44  })
45  public class PermissionXmlDTO implements Serializable {
46      
47      private static final long serialVersionUID = 1L;
48  
49      @XmlTransient
50      private String permissionId;
51      
52      @XmlElement(name="permissionName")
53      @XmlJavaTypeAdapter(NameAndNamespacePairValidatingAdapter.class)
54      private NameAndNamespacePair permissionNameAndNamespace;
55      
56      @XmlElement(name="templateName")
57      @XmlJavaTypeAdapter(NameAndNamespacePairToPermTemplateIdAdapter.class)
58      private String permissionTemplateId;
59      
60      @XmlElement(name="description")
61      @XmlJavaTypeAdapter(StringTrimmingAdapter.class)
62      private String permissionDescription;
63      
64      @XmlElement(name="active")
65      private Boolean active;
66      
67      @XmlElement(name="permissionDetails")
68      @XmlJavaTypeAdapter(PermissionDetailListAdapter.class)
69      private Map<String, String> permissionDetails;
70      
71      public PermissionXmlDTO() {
72          this.active = Boolean.TRUE;
73      }
74      
75      public PermissionXmlDTO(PermissionContract permission) {
76          this.permissionNameAndNamespace = new NameAndNamespacePair(permission.getNamespaceCode(), permission.getName());
77          this.permissionTemplateId = permission.getTemplate().getId();
78          this.permissionDescription = permission.getDescription();
79          this.active = Boolean.valueOf(permission.isActive());
80          this.permissionDetails = (permission.getAttributes() != null) ?
81                  new HashMap<String, String>(permission.getAttributes()) : new HashMap<String, String>();
82      }
83      
84      /**
85       * @return the permissionId
86       */
87      public String getPermissionId() {
88          return this.permissionId;
89      }
90  
91      /**
92       * @param permissionId the permissionId to set
93       */
94      public void setPermissionId(String permissionId) {
95          this.permissionId = permissionId;
96      }
97  
98      /**
99       * @return the permissionNameAndNamespace
100      */
101     public NameAndNamespacePair getPermissionNameAndNamespace() {
102         return this.permissionNameAndNamespace;
103     }
104 
105     /**
106      * @param permissionNameAndNamespace the permissionNameAndNamespace to set
107      */
108     public void setPermissionNameAndNamespace(NameAndNamespacePair permissionNameAndNamespace) {
109         this.permissionNameAndNamespace = permissionNameAndNamespace;
110     }
111 
112     /**
113      * @return the permissionTemplateId
114      */
115     public String getPermissionTemplateId() {
116         return this.permissionTemplateId;
117     }
118 
119     /**
120      * @param permissionTemplateId the permissionTemplateId to set
121      */
122     public void setPermissionTemplateId(String permissionTemplateId) {
123         this.permissionTemplateId = permissionTemplateId;
124     }
125 
126     /**
127      * @return the permissionDescription
128      */
129     public String getPermissionDescription() {
130         return this.permissionDescription;
131     }
132 
133     /**
134      * @param permissionDescription the permissionDescription to set
135      */
136     public void setPermissionDescription(String permissionDescription) {
137         this.permissionDescription = permissionDescription;
138     }
139 
140     /**
141      * @return the active
142      */
143     public Boolean getActive() {
144         return this.active;
145     }
146 
147     /**
148      * @param active the active to set
149      */
150     public void setActive(Boolean active) {
151         this.active = active;
152     }
153 
154     /**
155      * @return the permissionDetails
156      */
157     public Map<String, String> getPermissionDetails() {
158         return this.permissionDetails;
159     }
160 
161     /**
162      * @param permissionDetails the permissionDetails to set
163      */
164     public void setPermissionDetails(Map<String, String> permissionDetails) {
165         this.permissionDetails = permissionDetails;
166     }
167 
168     /**
169      * Retrieves the permission's name from the permission-name-and-namespace combo.
170      * 
171      * @return The name of the permission, or null if the permission-name-and-namespace combo is null.
172      */
173     public String getPermissionName() {
174         return (permissionNameAndNamespace != null) ? permissionNameAndNamespace.getName() : null;
175     }
176 
177     /**
178      * Retrieves the permission's namespace code from the permission-name-and-namespace combo.
179      * 
180      * @return The namespace code of the permission, or null if the permission-name-and-namespace combo is null.
181      */
182     public String getNamespaceCode() {
183         return (permissionNameAndNamespace != null) ? permissionNameAndNamespace.getNamespaceCode() : null;
184     }
185 }