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