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