| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.kim.bo.role.impl; |
| 17 | |
|
| 18 | |
import org.apache.log4j.Logger; |
| 19 | |
import org.hibernate.annotations.Fetch; |
| 20 | |
import org.hibernate.annotations.FetchMode; |
| 21 | |
import org.hibernate.annotations.Type; |
| 22 | |
import org.kuali.rice.core.xml.dto.AttributeSet; |
| 23 | |
import org.kuali.rice.kim.bo.role.KimPermission; |
| 24 | |
import org.kuali.rice.kim.bo.role.dto.KimPermissionInfo; |
| 25 | |
import org.kuali.rice.kim.bo.types.dto.KimTypeAttributeInfo; |
| 26 | |
import org.kuali.rice.kim.bo.types.dto.KimTypeInfo; |
| 27 | |
import org.kuali.rice.kim.service.KIMServiceLocatorWeb; |
| 28 | |
import org.kuali.rice.kim.service.KimTypeInfoService; |
| 29 | |
import org.kuali.rice.kim.util.KimConstants; |
| 30 | |
import org.kuali.rice.kns.bo.PersistableBusinessObjectBase; |
| 31 | |
import org.kuali.rice.kns.service.DataDictionaryService; |
| 32 | |
import org.kuali.rice.kns.service.KNSServiceLocatorWeb; |
| 33 | |
import org.springframework.util.AutoPopulatingList; |
| 34 | |
|
| 35 | |
import javax.persistence.*; |
| 36 | |
import java.util.Iterator; |
| 37 | |
import java.util.List; |
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
@SuppressWarnings("unchecked") |
| 43 | |
@Entity |
| 44 | |
@Table(name="KRIM_PERM_T") |
| 45 | 0 | public class KimPermissionImpl extends PersistableBusinessObjectBase implements KimPermission { |
| 46 | 0 | private static final Logger LOG = Logger.getLogger(KimPermissionImpl.class); |
| 47 | |
|
| 48 | |
private static final long serialVersionUID = 1L; |
| 49 | |
|
| 50 | |
@Id |
| 51 | |
@Column(name="PERM_ID") |
| 52 | |
protected String permissionId; |
| 53 | |
@Column(name="NMSPC_CD") |
| 54 | |
protected String namespaceCode; |
| 55 | |
@Column(name="NM") |
| 56 | |
protected String name; |
| 57 | |
@Column(name="DESC_TXT", length=400) |
| 58 | |
protected String description; |
| 59 | |
@Type(type="yes_no") |
| 60 | |
@Column(name="ACTV_IND") |
| 61 | |
protected boolean active; |
| 62 | |
|
| 63 | 0 | @OneToMany(targetEntity=PermissionAttributeDataImpl.class,cascade={CascadeType.ALL},fetch=FetchType.EAGER) |
| 64 | |
@Fetch(value = FetchMode.SELECT) |
| 65 | |
@JoinColumn(name="PERM_ID", insertable=false, updatable=false) |
| 66 | |
protected List<PermissionAttributeDataImpl> detailObjects = new AutoPopulatingList(PermissionAttributeDataImpl.class); |
| 67 | |
|
| 68 | |
@Column(name="PERM_TMPL_ID") |
| 69 | |
protected String templateId; |
| 70 | |
|
| 71 | |
@OneToOne(targetEntity=KimPermissionTemplateImpl.class,cascade={},fetch=FetchType.EAGER) |
| 72 | |
@JoinColumn(name="PERM_TMPL_ID", insertable=false, updatable=false) |
| 73 | |
protected KimPermissionTemplateImpl template; |
| 74 | |
|
| 75 | 0 | @OneToMany(targetEntity=RolePermissionImpl.class,cascade={CascadeType.ALL},fetch=FetchType.EAGER) |
| 76 | |
@Fetch(value = FetchMode.SELECT) |
| 77 | |
@JoinColumn(name="PERM_ID", insertable=false, updatable=false) |
| 78 | |
protected List<RolePermissionImpl> rolePermissions = new AutoPopulatingList(RolePermissionImpl.class); |
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
public boolean isActive() { |
| 84 | 0 | return active; |
| 85 | |
} |
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
public void setActive(boolean active) { |
| 91 | 0 | this.active = active; |
| 92 | 0 | } |
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
public String getDescription() { |
| 98 | 0 | return description; |
| 99 | |
} |
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
public String getPermissionId() { |
| 105 | 0 | return permissionId; |
| 106 | |
} |
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
public String getName() { |
| 112 | 0 | return name; |
| 113 | |
} |
| 114 | |
|
| 115 | |
public void setDescription(String permissionDescription) { |
| 116 | 0 | this.description = permissionDescription; |
| 117 | 0 | } |
| 118 | |
|
| 119 | |
public void setName(String permissionName) { |
| 120 | 0 | this.name = permissionName; |
| 121 | 0 | } |
| 122 | |
|
| 123 | |
public KimPermissionInfo toSimpleInfo() { |
| 124 | 0 | KimPermissionInfo dto = new KimPermissionInfo(); |
| 125 | 0 | dto.setPermissionId( getPermissionId() ); |
| 126 | 0 | dto.setNamespaceCode( getNamespaceCode() ); |
| 127 | 0 | dto.setName( getName() ); |
| 128 | 0 | dto.setDescription( getDescription() ); |
| 129 | 0 | dto.setActive( isActive() ); |
| 130 | 0 | dto.setTemplate( getTemplate().toSimpleInfo() ); |
| 131 | 0 | dto.setTemplateId( getTemplateId() ); |
| 132 | 0 | dto.setDetails( getDetails() ); |
| 133 | |
|
| 134 | 0 | return dto; |
| 135 | |
} |
| 136 | |
|
| 137 | |
public List<PermissionAttributeDataImpl> getDetailObjects() { |
| 138 | 0 | return this.detailObjects; |
| 139 | |
} |
| 140 | |
|
| 141 | |
public void setDetails(List<PermissionAttributeDataImpl> detailObjects) { |
| 142 | 0 | this.detailObjects = detailObjects; |
| 143 | 0 | } |
| 144 | |
|
| 145 | |
public KimPermissionTemplateImpl getTemplate() { |
| 146 | 0 | return this.template; |
| 147 | |
} |
| 148 | |
|
| 149 | |
public void setTemplate(KimPermissionTemplateImpl template) { |
| 150 | 0 | this.template = template; |
| 151 | 0 | } |
| 152 | |
|
| 153 | |
public String getTemplateId() { |
| 154 | 0 | return this.templateId; |
| 155 | |
} |
| 156 | |
|
| 157 | |
public void setTemplateId(String templateId) { |
| 158 | 0 | this.templateId = templateId; |
| 159 | 0 | } |
| 160 | |
|
| 161 | 0 | protected transient AttributeSet detailsAsAttributeSet = null; |
| 162 | |
|
| 163 | |
public AttributeSet getDetails() { |
| 164 | 0 | if ( detailsAsAttributeSet == null ) { |
| 165 | 0 | KimTypeInfo kimType = getTypeInfoService().getKimType( getTemplate().getKimTypeId() ); |
| 166 | 0 | AttributeSet m = new AttributeSet(); |
| 167 | 0 | for ( PermissionAttributeDataImpl data : getDetailObjects() ) { |
| 168 | 0 | KimTypeAttributeInfo attribute = null; |
| 169 | 0 | if ( kimType != null ) { |
| 170 | 0 | attribute = kimType.getAttributeDefinition( data.getKimAttributeId() ); |
| 171 | |
} else { |
| 172 | 0 | LOG.warn( "Unable to get KimTypeInfo for permission: " + this + "\nKim Type ID: " + getTemplate().kimTypeId ); |
| 173 | |
} |
| 174 | 0 | if ( attribute != null ) { |
| 175 | 0 | m.put( attribute.getAttributeName(), data.getAttributeValue() ); |
| 176 | |
} else { |
| 177 | 0 | LOG.warn( "Unable to get attribute for ID: " + data.getKimAttributeId() + " from KimTypeInfo: " + kimType ); |
| 178 | 0 | m.put( data.getKimAttribute().getAttributeName(), data.getAttributeValue() ); |
| 179 | |
} |
| 180 | 0 | } |
| 181 | 0 | detailsAsAttributeSet = m; |
| 182 | |
} |
| 183 | 0 | return detailsAsAttributeSet; |
| 184 | |
} |
| 185 | |
|
| 186 | |
public boolean hasDetails() { |
| 187 | 0 | return !getDetailObjects().isEmpty(); |
| 188 | |
} |
| 189 | |
|
| 190 | |
public String getNamespaceCode() { |
| 191 | 0 | return this.namespaceCode; |
| 192 | |
} |
| 193 | |
|
| 194 | |
public void setNamespaceCode(String namespaceCode) { |
| 195 | 0 | this.namespaceCode = namespaceCode; |
| 196 | 0 | } |
| 197 | |
|
| 198 | |
public void setPermissionId(String permissionId) { |
| 199 | 0 | this.permissionId = permissionId; |
| 200 | 0 | } |
| 201 | |
|
| 202 | |
public void setDetailObjects(List<PermissionAttributeDataImpl> detailObjects) { |
| 203 | 0 | this.detailObjects = detailObjects; |
| 204 | 0 | } |
| 205 | |
|
| 206 | |
|
| 207 | |
|
| 208 | |
|
| 209 | |
public List<RolePermissionImpl> getRolePermissions() { |
| 210 | 0 | return this.rolePermissions; |
| 211 | |
} |
| 212 | |
|
| 213 | |
|
| 214 | |
|
| 215 | |
|
| 216 | |
public void setRolePermissions(List<RolePermissionImpl> rolePermissions) { |
| 217 | 0 | this.rolePermissions = rolePermissions; |
| 218 | 0 | } |
| 219 | |
|
| 220 | |
public String getDetailObjectsValues(){ |
| 221 | 0 | StringBuffer detailObjectsToDisplay = new StringBuffer(); |
| 222 | 0 | Iterator<PermissionAttributeDataImpl> permIter = getDetailObjects().iterator(); |
| 223 | 0 | while ( permIter.hasNext() ) { |
| 224 | 0 | PermissionAttributeDataImpl permissionAttributeData = permIter.next(); |
| 225 | 0 | detailObjectsToDisplay.append( permissionAttributeData.getAttributeValue() ); |
| 226 | 0 | if ( permIter.hasNext() ) { |
| 227 | 0 | detailObjectsToDisplay.append( KimConstants.KimUIConstants.COMMA_SEPARATOR ); |
| 228 | |
} |
| 229 | 0 | } |
| 230 | 0 | return detailObjectsToDisplay.toString(); |
| 231 | |
} |
| 232 | |
|
| 233 | |
public String getDetailObjectsToDisplay() { |
| 234 | 0 | KimTypeInfo kimType = getTypeInfoService().getKimType( getTemplate().getKimTypeId() ); |
| 235 | 0 | StringBuffer detailObjectsToDisplay = new StringBuffer(); |
| 236 | 0 | Iterator<PermissionAttributeDataImpl> permIter = getDetailObjects().iterator(); |
| 237 | 0 | while ( permIter.hasNext() ) { |
| 238 | 0 | PermissionAttributeDataImpl permissionAttributeData = permIter.next(); |
| 239 | 0 | detailObjectsToDisplay.append( getKimAttributeLabelFromDD(kimType.getAttributeDefinition(permissionAttributeData.getKimAttributeId()))); |
| 240 | 0 | detailObjectsToDisplay.append( KimConstants.KimUIConstants.NAME_VALUE_SEPARATOR ); |
| 241 | 0 | detailObjectsToDisplay.append( permissionAttributeData.getAttributeValue() ); |
| 242 | 0 | if ( permIter.hasNext() ) { |
| 243 | 0 | detailObjectsToDisplay.append( KimConstants.KimUIConstants.COMMA_SEPARATOR ); |
| 244 | |
} |
| 245 | 0 | } |
| 246 | 0 | return detailObjectsToDisplay.toString(); |
| 247 | |
} |
| 248 | |
|
| 249 | |
protected String getKimAttributeLabelFromDD( KimTypeAttributeInfo attribute ){ |
| 250 | 0 | return getDataDictionaryService().getAttributeLabel(attribute.getComponentName(), attribute.getAttributeName() ); |
| 251 | |
} |
| 252 | |
|
| 253 | |
private transient static DataDictionaryService dataDictionaryService; |
| 254 | |
|
| 255 | |
protected DataDictionaryService getDataDictionaryService() { |
| 256 | 0 | if(dataDictionaryService == null){ |
| 257 | 0 | dataDictionaryService = KNSServiceLocatorWeb.getDataDictionaryService(); |
| 258 | |
} |
| 259 | 0 | return dataDictionaryService; |
| 260 | |
} |
| 261 | |
|
| 262 | |
private transient static KimTypeInfoService kimTypeInfoService; |
| 263 | |
protected KimTypeInfoService getTypeInfoService() { |
| 264 | 0 | if(kimTypeInfoService == null){ |
| 265 | 0 | kimTypeInfoService = KIMServiceLocatorWeb.getTypeInfoService(); |
| 266 | |
} |
| 267 | 0 | return kimTypeInfoService; |
| 268 | |
} |
| 269 | |
} |