001/*
002 * Copyright 2011 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/ecl1.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 */
016package org.kuali.rice.kim.impl.jaxb;
017
018import java.io.Serializable;
019import java.util.HashMap;
020import java.util.Map;
021
022import javax.xml.bind.annotation.XmlAccessType;
023import javax.xml.bind.annotation.XmlAccessorType;
024import javax.xml.bind.annotation.XmlElement;
025import javax.xml.bind.annotation.XmlTransient;
026import javax.xml.bind.annotation.XmlType;
027import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
028
029import org.kuali.rice.core.util.jaxb.NameAndNamespacePair;
030import org.kuali.rice.core.util.jaxb.NameAndNamespacePairValidatingAdapter;
031import org.kuali.rice.core.util.jaxb.StringTrimmingAdapter;
032import org.kuali.rice.kim.api.jaxb.NameAndNamespacePairToPermTemplateIdAdapter;
033import org.kuali.rice.kim.api.jaxb.PermissionDetailListAdapter;
034import org.kuali.rice.kim.api.permission.PermissionContract;
035
036/**
037 * This class represents a <permission> XML element.
038 * 
039 * @author Kuali Rice Team (rice.collab@kuali.org)
040 */
041@XmlAccessorType(XmlAccessType.FIELD)
042@XmlType(name="PermissionType", propOrder={
043        "permissionNameAndNamespace", "permissionTemplateId", "permissionDescription", "active", "permissionDetails"
044})
045public class PermissionXmlDTO implements Serializable {
046    
047    private static final long serialVersionUID = 1L;
048
049    @XmlTransient
050    private String permissionId;
051    
052    @XmlElement(name="permissionName")
053    @XmlJavaTypeAdapter(NameAndNamespacePairValidatingAdapter.class)
054    private NameAndNamespacePair permissionNameAndNamespace;
055    
056    @XmlElement(name="templateName")
057    @XmlJavaTypeAdapter(NameAndNamespacePairToPermTemplateIdAdapter.class)
058    private String permissionTemplateId;
059    
060    @XmlElement(name="description")
061    @XmlJavaTypeAdapter(StringTrimmingAdapter.class)
062    private String permissionDescription;
063    
064    @XmlElement(name="active")
065    private Boolean active;
066    
067    @XmlElement(name="permissionDetails")
068    @XmlJavaTypeAdapter(PermissionDetailListAdapter.class)
069    private Map<String, String> permissionDetails;
070    
071    public PermissionXmlDTO() {
072        this.active = Boolean.TRUE;
073    }
074    
075    public PermissionXmlDTO(PermissionContract permission) {
076        this.permissionNameAndNamespace = new NameAndNamespacePair(permission.getNamespaceCode(), permission.getName());
077        this.permissionTemplateId = permission.getTemplate().getId();
078        this.permissionDescription = permission.getDescription();
079        this.active = Boolean.valueOf(permission.isActive());
080        this.permissionDetails = (permission.getAttributes() != null) ?
081                new HashMap<String, String>(permission.getAttributes()) : new HashMap<String, String>();
082    }
083    
084    /**
085     * @return the permissionId
086     */
087    public String getPermissionId() {
088        return this.permissionId;
089    }
090
091    /**
092     * @param permissionId the permissionId to set
093     */
094    public void setPermissionId(String permissionId) {
095        this.permissionId = permissionId;
096    }
097
098    /**
099     * @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}