Coverage Report - org.kuali.rice.kim.impl.permission.PermissionBo
 
Classes in this File Line Coverage Branch Coverage Complexity
PermissionBo
60%
17/28
25%
3/12
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 javax.persistence.Transient
 29  
 import org.hibernate.annotations.Fetch
 30  
 import org.hibernate.annotations.FetchMode
 31  
 import org.hibernate.annotations.Type
 32  
 import org.kuali.rice.kim.api.permission.Permission
 33  
 import org.kuali.rice.kim.api.permission.PermissionContract
 34  
 import org.kuali.rice.kim.impl.common.attribute.KimAttributeDataBo
 35  
 import org.kuali.rice.kim.impl.role.RolePermissionBo
 36  
 import org.kuali.rice.kim.util.KimConstants
 37  
 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase
 38  
 
 39  
 @Entity
 40  
 @Table(name = "KRIM_PERM_T")
 41  
 public class PermissionBo extends PersistableBusinessObjectBase implements PermissionContract {
 42  
     private static final long serialVersionUID = 1L;
 43  
 
 44  
     @Id
 45  
     @Column(name = "PERM_ID")
 46  
     String id
 47  
 
 48  
     @Column(name = "NMSPC_CD")
 49  
     String namespaceCode
 50  
 
 51  
     @Column(name = "NM")
 52  
     String name
 53  
 
 54  
     @Column(name = "DESC_TXT", length = 400)
 55  
     String description;
 56  
 
 57  
     @Column(name = "PERM_TMPL_ID")
 58  
     String templateId
 59  
 
 60  
     @Column(name = "ACTV_IND")
 61  
     @Type(type = "yes_no")
 62  
     boolean active
 63  
 
 64  
     @OneToOne(targetEntity = PermissionTemplateBo.class, cascade = [], fetch = FetchType.EAGER)
 65  
     @JoinColumn(name = "PERM_TMPL_ID", insertable = false, updatable = false)
 66  
     PermissionTemplateBo template;
 67  
 
 68  
     @OneToMany(targetEntity = PermissionAttributeBo.class, cascade = [CascadeType.ALL], fetch = FetchType.EAGER, mappedBy = "id")
 69  
     @Fetch(value = FetchMode.SELECT)
 70  
     List<PermissionAttributeBo> attributeDetails
 71  
 
 72  
     @Transient
 73  
     Map<String,String> attributes;
 74  
 
 75  
     @OneToMany(targetEntity = RolePermissionBo.class, cascade = [CascadeType.ALL], fetch = FetchType.EAGER, mappedBy = "id")
 76  
     @Fetch(value = FetchMode.SELECT)
 77  
     List<RolePermissionBo> rolePermissions
 78  
 
 79  
     Map<String,String> getAttributes() {
 80  2
         return attributeDetails != null ? KimAttributeDataBo.toAttributes(attributeDetails) : attributes
 81  
     }
 82  
 
 83  
     //TODO: rename/fix later - only including this method and attributeDetails field for Role conversion
 84  
 
 85  
     Map<String,String> getDetails() {
 86  0
         return attributeDetails != null ? KimAttributeDataBo.toAttributes(attributeDetails) : attributes
 87  
     }
 88  
 
 89  
     public String getDetailObjectsValues() {
 90  0
         StringBuffer detailObjectsToDisplay = new StringBuffer();
 91  0
         Iterator<PermissionAttributeBo> permIter = attributeDetails.iterator();
 92  0
         while (permIter.hasNext()) {
 93  0
             PermissionAttributeBo permissionAttributeData = permIter.next();
 94  0
             detailObjectsToDisplay.append(permissionAttributeData.getAttributeValue());
 95  0
             if (permIter.hasNext()) {
 96  0
                 detailObjectsToDisplay.append(KimConstants.KimUIConstants.COMMA_SEPARATOR);
 97  
             }
 98  
         }
 99  0
         return detailObjectsToDisplay.toString();
 100  
     }
 101  
 
 102  
     /**
 103  
      * Converts a mutable bo to its immutable counterpart
 104  
      * @param bo the mutable business object
 105  
      * @return the immutable object
 106  
      */
 107  
     static Permission to(PermissionBo bo) {
 108  1
         if (bo == null) {
 109  0
             return null
 110  
         }
 111  
 
 112  1
         return Permission.Builder.create(bo).build();
 113  
     }
 114  
 
 115  
     /**
 116  
      * Converts a immutable object to its mutable counterpart
 117  
      * @param im immutable object
 118  
      * @return the mutable bo
 119  
      */
 120  
     static PermissionBo from(Permission im) {
 121  1
         if (im == null) {
 122  0
             return null
 123  
         }
 124  
 
 125  1
         PermissionBo bo = new PermissionBo()
 126  1
         bo.id = im.id
 127  1
         bo.namespaceCode = im.namespaceCode
 128  1
         bo.name = im.name
 129  1
         bo.description = im.description
 130  1
         bo.active = im.active
 131  1
         bo.templateId = im.template.getId()
 132  1
         bo.template = PermissionTemplateBo.from(im.template)
 133  1
         bo.attributes = im.attributes
 134  1
         bo.versionNumber = im.versionNumber
 135  1
         bo.objectId = im.objectId;
 136  
 
 137  1
         return bo
 138  
     }
 139  
 
 140  
     PermissionTemplateBo getTemplate() {
 141  1
         return template;
 142  
     }
 143  
 }