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