Coverage Report - org.kuali.rice.kim.impl.permission.PermissionBo
 
Classes in this File Line Coverage Branch Coverage Complexity
PermissionBo
88%
16/18
50%
2/4
0
PermissionBo$_from_closure1
0%
0/1
N/A
0
 
 1  
 /*
 2  
  * Copyright 2006-2011 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  
 
 17  
 package org.kuali.rice.kim.impl.permission
 18  
 
 19  
 import javax.persistence.CascadeType
 20  
 import javax.persistence.Column
 21  
 import javax.persistence.Entity
 22  
 import javax.persistence.FetchType
 23  
 import javax.persistence.Id
 24  
 import javax.persistence.JoinColumn
 25  
 import javax.persistence.OneToMany
 26  
 import javax.persistence.OneToOne
 27  
 import javax.persistence.Table
 28  
 import org.hibernate.annotations.Fetch
 29  
 import org.hibernate.annotations.FetchMode
 30  
 import org.hibernate.annotations.Type
 31  
 import org.kuali.rice.kim.api.permission.Permission
 32  
 import org.kuali.rice.kim.api.permission.PermissionContract
 33  
 import org.kuali.rice.kim.impl.role.RolePermissionBo
 34  
 import org.kuali.rice.kns.bo.PersistableBusinessObjectBase
 35  
 
 36  
 @Entity
 37  
 @Table(name="KRIM_PERM_T")
 38  
 public class PermissionBo extends PersistableBusinessObjectBase implements PermissionContract {
 39  
     private static final long serialVersionUID = 1L;
 40  
 
 41  
     @Id
 42  
         @Column(name="PERM_ID")
 43  
         String id
 44  
 
 45  
         @Column(name="NMSPC_CD")
 46  
         String namespaceCode
 47  
         
 48  
     @Column(name="NM")
 49  
         String name
 50  
 
 51  
         @Column(name="DESC_TXT", length=400)
 52  
         String description;
 53  
 
 54  
         @Column(name="PERM_TMPL_ID")
 55  
         String templateId
 56  
         
 57  
         @Column(name="ACTV_IND")
 58  
         @Type(type="yes_no")
 59  
         boolean active
 60  
 
 61  
         @OneToOne(targetEntity=PermissionTemplateBo.class,cascade=[],fetch=FetchType.EAGER)
 62  
         @JoinColumn(name="PERM_TMPL_ID", insertable=false, updatable=false)
 63  
         PermissionTemplateBo template;
 64  
         
 65  
         @OneToMany(targetEntity=PermissionAttributeBo.class,cascade=[CascadeType.ALL],fetch=FetchType.EAGER,mappedBy="id")
 66  
         @Fetch(value = FetchMode.SELECT)
 67  
         List<PermissionAttributeBo> attributes
 68  
         
 69  
         @OneToMany(targetEntity=RolePermissionBo.class,cascade=[CascadeType.ALL],fetch=FetchType.EAGER,mappedBy="id")
 70  
     @Fetch(value = FetchMode.SELECT)
 71  
         List<RolePermissionBo> rolePermissions
 72  
 
 73  
     PermissionTemplateBo getTemplate() {
 74  1
         return template;
 75  
     }
 76  
 
 77  
     /**
 78  
      * Converts a mutable bo to its immutable counterpart
 79  
      * @param bo the mutable business object
 80  
      * @return the immutable object
 81  
      */
 82  
     static Permission to(PermissionBo bo) {
 83  1
         if (bo == null) {
 84  0
             return null
 85  
         }
 86  
 
 87  1
         return Permission.Builder.create(bo).build();
 88  
     }
 89  
 
 90  
     /**
 91  
      * Converts a immutable object to its mutable counterpart
 92  
      * @param im immutable object
 93  
      * @return the mutable bo
 94  
      */
 95  
     static PermissionBo from(Permission im) {
 96  1
         if (im == null) {
 97  0
             return null
 98  
         }
 99  
 
 100  1
         PermissionBo bo = new PermissionBo()
 101  1
         bo.id = im.id
 102  1
         bo.namespaceCode = im.namespaceCode
 103  1
         bo.name = im.name
 104  1
         bo.description = im.description
 105  1
         bo.active = im.active
 106  1
         bo.templateId = im.template.getId()
 107  1
         bo.template = PermissionTemplateBo.from(im.template)
 108  1
         bo.attributes = im.attributes.collect {
 109  0
             PermissionAttributeBo.from(it)
 110  
         }
 111  1
         bo.versionNumber = im.versionNumber
 112  1
                 bo.objectId = im.objectId;
 113  
 
 114  1
         return bo
 115  
     }
 116  
 
 117  
 }