001/* 002 * The Kuali Financial System, a comprehensive financial management system for higher education. 003 * 004 * Copyright 2005-2014 The Kuali Foundation 005 * 006 * This program is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU Affero General Public License as 008 * published by the Free Software Foundation, either version 3 of the 009 * License, or (at your option) any later version. 010 * 011 * This program is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU Affero General Public License for more details. 015 * 016 * You should have received a copy of the GNU Affero General Public License 017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 018 */ 019package org.kuali.rice.kim.impl.jaxb; 020 021import java.io.Serializable; 022import java.util.Set; 023 024import javax.xml.bind.annotation.XmlAccessType; 025import javax.xml.bind.annotation.XmlAccessorType; 026import javax.xml.bind.annotation.XmlElement; 027import javax.xml.bind.annotation.XmlTransient; 028import javax.xml.bind.annotation.XmlType; 029import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; 030 031import org.kuali.rice.core.util.jaxb.NameAndNamespacePair; 032import org.kuali.rice.core.util.jaxb.NameAndNamespacePairValidatingAdapter; 033import org.kuali.rice.core.util.jaxb.StringTrimmingAdapter; 034import org.kuali.rice.kim.api.jaxb.NameAndNamespacePairToKimTypeIdAdapter; 035import org.kuali.rice.kim.api.role.RoleContract; 036 037/** 038 * This class represents a <role> XML element. 039 * 040 * @author Kuali Rice Team (rice.collab@kuali.org) 041 */ 042@XmlAccessorType(XmlAccessType.FIELD) 043@XmlType(name="RoleType", propOrder={ 044 "roleNameAndNamespace", "kimTypeId", "roleDescription", "active", "roleMembers", "rolePermissions" 045}) 046public class RoleXmlDTO implements Serializable { 047 048 private static final long serialVersionUID = 1L; 049 050 @XmlTransient 051 private String roleId; 052 053 @XmlElement(name="roleName") 054 @XmlJavaTypeAdapter(NameAndNamespacePairValidatingAdapter.class) 055 private NameAndNamespacePair roleNameAndNamespace; 056 057 @XmlElement(name="kimTypeName") 058 @XmlJavaTypeAdapter(NameAndNamespacePairToKimTypeIdAdapter.class) 059 private String kimTypeId; 060 061 @XmlElement(name="description") 062 @XmlJavaTypeAdapter(StringTrimmingAdapter.class) 063 private String roleDescription; 064 065 @XmlElement(name="active") 066 private Boolean active; 067 068 @XmlElement(name="roleMembers") 069 private RoleMembersXmlDTO.WithinRole roleMembers; 070 071 @XmlElement(name="rolePermissions") 072 private RolePermissionsXmlDTO.WithinRole rolePermissions; 073 074 @XmlTransient 075 private boolean alreadyPersisted = false; 076 077 @XmlTransient 078 private Set<String> existingRoleMemberIds; 079 080 public RoleXmlDTO() { 081 this.active = Boolean.TRUE; 082 } 083 084 public RoleXmlDTO(RoleContract role, RoleMembersXmlDTO.WithinRole roleMembers, RolePermissionsXmlDTO.WithinRole rolePermissions) { 085 if (role == null) { 086 throw new IllegalArgumentException("role cannot be null"); 087 } 088 089 this.roleNameAndNamespace = new NameAndNamespacePair(role.getNamespaceCode(), role.getName()); 090 this.kimTypeId = role.getKimTypeId(); 091 this.roleDescription = role.getDescription(); 092 this.active = Boolean.valueOf(role.isActive()); 093 this.roleMembers = roleMembers; 094 this.rolePermissions = rolePermissions; 095 } 096 097 /** 098 * @return the roleId 099 */ 100 public String getRoleId() { 101 return this.roleId; 102 } 103 104 /** 105 * @param roleId the roleId to set 106 */ 107 public void setRoleId(String roleId) { 108 this.roleId = roleId; 109 } 110 111 /** 112 * @return the roleNameAndNamespace 113 */ 114 public NameAndNamespacePair getRoleNameAndNamespace() { 115 return this.roleNameAndNamespace; 116 } 117 118 /** 119 * @param roleNameAndNamespace the roleNameAndNamespace to set 120 */ 121 public void setRoleNameAndNamespace(NameAndNamespacePair roleNameAndNamespace) { 122 this.roleNameAndNamespace = roleNameAndNamespace; 123 } 124 125 /** 126 * @return the kimTypeId 127 */ 128 public String getKimTypeId() { 129 return this.kimTypeId; 130 } 131 132 /** 133 * @param kimTypeId the kimTypeId to set 134 */ 135 public void setKimTypeId(String kimTypeId) { 136 this.kimTypeId = kimTypeId; 137 } 138 139 /** 140 * @return the roleDescription 141 */ 142 public String getRoleDescription() { 143 return this.roleDescription; 144 } 145 146 /** 147 * @param roleDescription the roleDescription to set 148 */ 149 public void setRoleDescription(String roleDescription) { 150 this.roleDescription = roleDescription; 151 } 152 153 /** 154 * @return the active 155 */ 156 public Boolean getActive() { 157 return this.active; 158 } 159 160 /** 161 * @param active the active to set 162 */ 163 public void setActive(Boolean active) { 164 this.active = active; 165 } 166 167 /** 168 * @return the roleMembers 169 */ 170 public RoleMembersXmlDTO.WithinRole getRoleMembers() { 171 return this.roleMembers; 172 } 173 174 /** 175 * @param roleMembers the roleMembers to set 176 */ 177 public void setRoleMembers(RoleMembersXmlDTO.WithinRole roleMembers) { 178 this.roleMembers = roleMembers; 179 } 180 181 /** 182 * @return the rolePermissions 183 */ 184 public RolePermissionsXmlDTO.WithinRole getRolePermissions() { 185 return this.rolePermissions; 186 } 187 188 /** 189 * @param rolePermissions the rolePermissions to set 190 */ 191 public void setRolePermissions(RolePermissionsXmlDTO.WithinRole rolePermissions) { 192 this.rolePermissions = rolePermissions; 193 } 194 195 /** 196 * @return the alreadyPersisted 197 */ 198 public boolean isAlreadyPersisted() { 199 return this.alreadyPersisted; 200 } 201 202 /** 203 * @param alreadyPersisted the alreadyPersisted to set 204 */ 205 public void setAlreadyPersisted(boolean alreadyPersisted) { 206 this.alreadyPersisted = alreadyPersisted; 207 } 208 209 /** 210 * @return the existingRoleMemberIds 211 */ 212 public Set<String> getExistingRoleMemberIds() { 213 return this.existingRoleMemberIds; 214 } 215 216 /** 217 * @param existingRoleMemberIds the existingRoleMemberIds to set 218 */ 219 public void setExistingRoleMemberIds(Set<String> existingRoleMemberIds) { 220 this.existingRoleMemberIds = existingRoleMemberIds; 221 } 222 223 /** 224 * Retrieves the role's name from the role-name-and-namespace combo. 225 * 226 * @return The name of the role, or null if the role-name-and-namespace combo is null. 227 */ 228 public String getRoleName() { 229 return (roleNameAndNamespace != null) ? roleNameAndNamespace.getName() : null; 230 } 231 232 /** 233 * Retrieves the role's namespace code from the role-name-and-namespace combo. 234 * 235 * @return The namespace code of the role, or null if the role-name-and-namespace combo is null. 236 */ 237 public String getNamespaceCode() { 238 return (roleNameAndNamespace != null) ? roleNameAndNamespace.getNamespaceCode() : null; 239 } 240}