Coverage Report - org.kuali.rice.kim.bo.impl.GenericPermission
 
Classes in this File Line Coverage Branch Coverage Complexity
GenericPermission
0%
0/67
0%
0/14
1.385
 
 1  
 /*
 2  
  * Copyright 2007-2009 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.impl;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.hibernate.annotations.Type;
 20  
 import org.kuali.rice.core.util.AttributeSet;
 21  
 import org.kuali.rice.kim.bo.role.KimPermission;
 22  
 import org.kuali.rice.kns.bo.PersistableBusinessObjectBase;
 23  
 
 24  
 import javax.persistence.*;
 25  
 import java.util.Iterator;
 26  
 
 27  
 /**
 28  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 29  
  */
 30  
 
 31  
 @SuppressWarnings("unchecked")
 32  
 @Entity
 33  
 @Table(name="KRIM_PERM_T")
 34  
 public class GenericPermission extends PersistableBusinessObjectBase {
 35  
 //        private static final Logger LOG = Logger.getLogger(GenericPermission.class);        
 36  
         
 37  
         private static final long serialVersionUID = 1L;
 38  
         
 39  
         @Id
 40  
         @Column(name="PERM_ID")
 41  
         protected String permissionId;
 42  
         @Column(name="NMSPC_CD")
 43  
         protected String namespaceCode;
 44  
         @Column(name="NM")
 45  
         protected String name;
 46  
         @Column(name="DESC_TXT", length=400)
 47  
         protected String description;
 48  
         @Type(type="yes_no")
 49  
         @Column(name="ACTV_IND")
 50  
         protected boolean active;
 51  
         @Column(name="PERM_TMPL_ID")
 52  
         protected String templateId;
 53  
         @Transient
 54  
         protected String detailValues;
 55  
         @Transient
 56  
         protected AttributeSet details;
 57  
         
 58  
         /**
 59  
          * This constructs a ...
 60  
          * 
 61  
          */
 62  0
         public GenericPermission() {
 63  0
         }
 64  
         
 65  0
         public GenericPermission( KimPermission perm ) {
 66  0
                 loadFromKimPermission( perm );
 67  0
         }
 68  
         public void loadFromKimPermission( KimPermission perm ) {
 69  0
                 setPermissionId( perm.getPermissionId() );
 70  0
                 setNamespaceCode( perm.getNamespaceCode() );
 71  0
                 setName( perm.getName() );
 72  0
                 setTemplateId( perm.getTemplateId() );
 73  0
                 setDescription( perm.getDescription() );
 74  0
                 setActive( perm.isActive() );
 75  0
                 setDetails( perm.getDetails() );
 76  0
         }
 77  
         
 78  
         public String getDetailValues() {
 79  
                 /*StringBuffer sb = new StringBuffer();
 80  
                 if ( details != null ) {
 81  
                         Iterator<String> keyIter = details.keySet().iterator();
 82  
                         while ( keyIter.hasNext() ) {
 83  
                                 String key = keyIter.next();
 84  
                                 sb.append( key ).append( '=' ).append( details.get( key ) );
 85  
                                 if ( keyIter.hasNext() ) {
 86  
                                         sb.append( '\n' );
 87  
                                 }
 88  
                         }
 89  
                 }
 90  
                 return sb.toString();*/
 91  0
                 return detailValues;
 92  
         }
 93  
         
 94  
         public void setDetailValues( String detailValues ) {
 95  0
                 this.detailValues = detailValues;
 96  0
                 String detailValuesTemp = detailValues;
 97  0
                 AttributeSet details = new AttributeSet();
 98  0
                 if ( detailValuesTemp != null ) {
 99  
                         // ensure that all line delimiters are single linefeeds
 100  0
                         detailValuesTemp = detailValuesTemp.replace( "\r\n", "\n" );
 101  0
                         detailValuesTemp = detailValuesTemp.replace( '\r', '\n' );
 102  0
                         if ( StringUtils.isNotBlank( detailValuesTemp ) ) {
 103  0
                                 String[] values = detailValuesTemp.split( "\n" );
 104  0
                                 for ( String attrib : values ) {
 105  0
                                         if ( attrib.indexOf( '=' ) != -1 ) {
 106  0
                                                 String[] keyValueArray = attrib.split( "=", 2 );
 107  0
                                                 details.put( keyValueArray[0].trim(), keyValueArray[1].trim() );
 108  
                                         }
 109  
                                 }
 110  
                         }
 111  
                 }
 112  0
                 this.details = details;
 113  0
         }
 114  
         
 115  
         public void setDetailValues( AttributeSet detailsAttribs ) {
 116  0
                 StringBuffer sb = new StringBuffer();
 117  0
                 if ( detailsAttribs != null ) {
 118  0
                         Iterator<String> keyIter = detailsAttribs.keySet().iterator();
 119  0
                         while ( keyIter.hasNext() ) {
 120  0
                                 String key = keyIter.next();
 121  0
                                 sb.append( key ).append( '=' ).append( detailsAttribs.get( key ) );
 122  0
                                 if ( keyIter.hasNext() ) {
 123  0
                                         sb.append( '\n' );
 124  
                                 }
 125  0
                         }
 126  
                 }
 127  0
                 detailValues = sb.toString();
 128  0
         }
 129  
         
 130  
         /**
 131  
          * @see org.kuali.rice.kns.bo.Inactivateable#isActive()
 132  
          */
 133  
         public boolean isActive() {
 134  0
                 return active;
 135  
         }
 136  
 
 137  
         /**
 138  
          * @see org.kuali.rice.kns.bo.Inactivateable#setActive(boolean)
 139  
          */
 140  
         public void setActive(boolean active) {
 141  0
                 this.active = active;
 142  0
         }
 143  
 
 144  
         /**
 145  
          * @see org.kuali.rice.kim.bo.role.KimPermission#getDescription()
 146  
          */
 147  
         public String getDescription() {
 148  0
                 return description;
 149  
         }
 150  
 
 151  
         /**
 152  
          * @see org.kuali.rice.kim.bo.role.KimPermission#getPermissionId()
 153  
          */
 154  
         public String getPermissionId() {
 155  0
                 return permissionId;
 156  
         }
 157  
 
 158  
         /**
 159  
          * @see org.kuali.rice.kim.bo.role.KimPermission#getName()
 160  
          */
 161  
         public String getName() {
 162  0
                 return name;
 163  
         }
 164  
 
 165  
         public void setDescription(String permissionDescription) {
 166  0
                 this.description = permissionDescription;
 167  0
         }
 168  
 
 169  
         public void setName(String permissionName) {
 170  0
                 this.name = permissionName;
 171  0
         }
 172  
 
 173  
         public void setDetails( AttributeSet details ) {
 174  0
                 this.details = details;
 175  0
                 setDetailValues(details);
 176  0
         }
 177  
         
 178  
         public String getTemplateId() {
 179  0
                 return this.templateId;
 180  
         }
 181  
 
 182  
         public void setTemplateId(String templateId) {
 183  0
                 this.templateId = templateId;
 184  0
         }
 185  
 
 186  
         public AttributeSet getDetails() {
 187  0
                 return details;
 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  
 
 203  
         public void refresh() {
 204  
                 // do nothing - not a persistable object
 205  0
         }
 206  
         
 207  
         @Override
 208  
         public void refreshNonUpdateableReferences() {
 209  
                 // do nothing - not a persistable object
 210  0
         }
 211  
         @Override
 212  
         public void refreshReferenceObject(String referenceObjectName) {
 213  
                 // do nothing - not a persistable object
 214  0
         }
 215  
 
 216  
         @Override
 217  
         protected void prePersist() {
 218  0
                 throw new UnsupportedOperationException( "This object should never be persisted.");
 219  
         }
 220  
         
 221  
         @Override
 222  
         protected void preUpdate() {
 223  0
                 throw new UnsupportedOperationException( "This object should never be persisted.");
 224  
         }
 225  
 
 226  
         @Override
 227  
         protected void preRemove() {
 228  0
                 throw new UnsupportedOperationException( "This object should never be persisted.");
 229  
         }
 230  
 
 231  
 }