Coverage Report - org.kuali.rice.kim.impl.role.RoleBo
 
Classes in this File Line Coverage Branch Coverage Complexity
RoleBo
13%
3/22
7%
1/14
0
 
 1  
 /*
 2  
  * Copyright 2006-2011 The Kuali Foundation
 3  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 4  
  * you may not use this file except in compliance with the License.
 5  
  * You may obtain a copy of the License at
 6  
  *
 7  
  * http://www.opensource.org/licenses/ecl2.php
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing, software
 10  
  * distributed under the License is distributed on an "AS IS" BASIS,
 11  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
  * See the License for the specific language governing permissions and
 13  
  * limitations under the License.
 14  
  */
 15  
 
 16  
 
 17  
 
 18  
 package org.kuali.rice.kim.impl.role;
 19  
 
 20  
 
 21  
 import javax.persistence.CascadeType
 22  
 import javax.persistence.Column
 23  
 import javax.persistence.Entity
 24  
 import javax.persistence.FetchType
 25  
 import javax.persistence.Id
 26  
 import javax.persistence.JoinColumn
 27  
 import javax.persistence.OneToMany
 28  
 import javax.persistence.Table
 29  
 import javax.persistence.Transient
 30  
 import org.hibernate.annotations.Fetch
 31  
 import org.hibernate.annotations.FetchMode
 32  
 import org.hibernate.annotations.Type
 33  
 import org.kuali.rice.kim.api.role.Role
 34  
 import org.kuali.rice.kim.api.role.RoleContract
 35  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator
 36  
 import org.kuali.rice.kim.api.type.KimTypeInfoService
 37  
 import org.kuali.rice.kim.impl.type.KimTypeBo
 38  
 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase
 39  
 import org.springframework.util.AutoPopulatingList
 40  
 
 41  
 @Entity
 42  
 @Table(name = "KRIM_ROLE_T")
 43  
 public class RoleBo extends PersistableBusinessObjectBase implements RoleContract {
 44  
 
 45  
     private static final long serialVersionUID = 1L;
 46  
 
 47  
     @Id
 48  
     @Column(name = "ROLE_ID")
 49  
     String id;
 50  
 
 51  
     @Column(name = "ROLE_NM")
 52  
     String name;
 53  
 
 54  
     @Column(name = "DESC_TXT", length = 4000)
 55  
     String description;
 56  
 
 57  
     @Type(type = "yes_no")
 58  
     @Column(name = "ACTV_IND")
 59  
     boolean active;
 60  
 
 61  
     @Column(name = "KIM_TYP_ID")
 62  
     String kimTypeId;
 63  
 
 64  
     @Column(name = "NMSPC_CD")
 65  
     String namespaceCode;
 66  
 
 67  
     @OneToMany(targetEntity = RoleMemberBo.class, cascade = [CascadeType.MERGE, CascadeType.REFRESH], fetch = FetchType.EAGER)
 68  
     @Fetch(value = FetchMode.SELECT)
 69  
     @JoinColumn(name = "ROLE_ID", insertable = false, updatable = false)
 70  1
     List<RoleMemberBo> members = new AutoPopulatingList(RoleMemberBo.class);
 71  
 
 72  
     @Transient
 73  
     protected String principalName;
 74  
 
 75  
     @Transient
 76  
     String groupNamespaceCode;
 77  
 
 78  
     @Transient
 79  
     String groupName;
 80  
 
 81  
     @Transient
 82  
     String permNamespaceCode;
 83  
 
 84  
     @Transient
 85  
     String permName;
 86  
 
 87  
     @Transient
 88  
     String permTmplNamespaceCode;
 89  
 
 90  
     @Transient
 91  
     String permTmplName;
 92  
 
 93  
     @Transient
 94  
     String respNamespaceCode;
 95  
 
 96  
     @Transient
 97  
     String respName;
 98  
 
 99  
     @Transient
 100  
     String respTmplNamespaceCode;
 101  
 
 102  
     @Transient
 103  
     String respTmplName;
 104  
 
 105  
     protected List<String> getMembersOfType(String memberTypeCode) {
 106  0
         List<String> roleMembers = new ArrayList<String>();
 107  0
         for (RoleMemberBo member: getMembers()) {
 108  0
             if (member.getMemberTypeCode().equals(memberTypeCode)
 109  0
                     && member.isActive()) {
 110  0
                 roleMembers.add(member.getMemberId());
 111  
             }
 112  
         }
 113  0
         return roleMembers;
 114  
     }
 115  
 
 116  
     public KimTypeBo getKimRoleType() {
 117  0
         return KimTypeBo.from(getTypeInfoService().getKimType(kimTypeId));
 118  
     }
 119  
 
 120  
     private transient static KimTypeInfoService kimTypeInfoService;
 121  
 
 122  
     protected KimTypeInfoService getTypeInfoService() {
 123  0
         if (kimTypeInfoService == null) {
 124  0
             kimTypeInfoService = KimApiServiceLocator.getKimTypeInfoService();
 125  
         }
 126  0
         return kimTypeInfoService;
 127  
     }
 128  
 
 129  
 
 130  
     public static Role to(RoleBo bo) {
 131  1
         if (bo == null) {return null;}
 132  1
         return Role.Builder.create(bo).build()
 133  
     }
 134  
 
 135  
     public static RoleBo from(Role immutable) {
 136  0
         if (immutable == null) {return null}
 137  0
         RoleBo bo = new RoleBo()
 138  0
         bo.id = immutable.id;
 139  0
         bo.name = immutable.name
 140  0
         bo.namespaceCode = immutable.namespaceCode
 141  0
         bo.description = immutable.description
 142  0
         bo.kimTypeId = immutable.kimTypeId
 143  0
         bo.active = immutable.active
 144  0
         bo.versionNumber = immutable.versionNumber
 145  
     }
 146  
 }