Coverage Report - org.kuali.rice.kim.impl.role.RoleBo
 
Classes in this File Line Coverage Branch Coverage Complexity
RoleBo
8%
2/24
4%
1/22
0
 
 1  
 /**
 2  
  * Copyright 2005-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  
 
 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  
 import org.joda.time.DateTime
 41  
 import org.kuali.rice.krad.bo.ExternalizableBusinessObject
 42  
 
 43  
 @Entity
 44  
 @Table(name = "KRIM_ROLE_T")
 45  
 public class RoleBo extends PersistableBusinessObjectBase implements RoleContract {
 46  
 
 47  
     private static final long serialVersionUID = 1L;
 48  
 
 49  
     @Id
 50  
     @Column(name = "ROLE_ID")
 51  
     String id;
 52  
 
 53  
     @Column(name = "ROLE_NM")
 54  
     String name;
 55  
 
 56  
     @Column(name = "DESC_TXT", length = 4000)
 57  
     String description;
 58  
 
 59  
     @Type(type = "yes_no")
 60  
     @Column(name = "ACTV_IND")
 61  
     boolean active;
 62  
 
 63  
     @Column(name = "KIM_TYP_ID")
 64  
     String kimTypeId;
 65  
 
 66  
     @Column(name = "NMSPC_CD")
 67  
     String namespaceCode;
 68  
 
 69  
     @OneToMany(targetEntity = RoleMemberBo.class, cascade = [CascadeType.MERGE, CascadeType.REFRESH], fetch = FetchType.EAGER)
 70  
     @Fetch(value = FetchMode.SELECT)
 71  
     @JoinColumn(name = "ROLE_ID", insertable = false, updatable = false)
 72  1
     List<RoleMemberBo> members = new AutoPopulatingList(RoleMemberBo.class);
 73  
 
 74  
     @Transient
 75  
     String principalName;
 76  
 
 77  
     @Transient
 78  
     String groupNamespaceCode;
 79  
 
 80  
     @Transient
 81  
     String groupName;
 82  
 
 83  
     @Transient
 84  
     String permNamespaceCode;
 85  
 
 86  
     @Transient
 87  
     String permName;
 88  
 
 89  
     @Transient
 90  
     String permTmplNamespaceCode;
 91  
 
 92  
     @Transient
 93  
     String permTmplName;
 94  
 
 95  
     @Transient
 96  
     String respNamespaceCode;
 97  
 
 98  
     @Transient
 99  
     String respName;
 100  
 
 101  
     @Transient
 102  
     String respTmplNamespaceCode;
 103  
 
 104  
     @Transient
 105  
     String respTmplName;
 106  
 
 107  
     protected List<String> getMembersOfType(String memberTypeCode) {
 108  0
         List<String> roleMembers = new ArrayList<String>();
 109  0
         for (RoleMemberBo member: getMembers()) {
 110  0
             if (member.getMemberTypeCode().equals(memberTypeCode)
 111  0
                     && member.isActive(new DateTime())) {
 112  0
                 roleMembers.add(member.getMemberId());
 113  
             }
 114  
         }
 115  0
         return roleMembers;
 116  
     }
 117  
 
 118  
     public KimTypeBo getKimRoleType() {
 119  0
         return KimTypeBo.from(getTypeInfoService().getKimType(kimTypeId));
 120  
     }
 121  
 
 122  
     private transient static KimTypeInfoService kimTypeInfoService;
 123  
 
 124  
     protected KimTypeInfoService getTypeInfoService() {
 125  0
         if (kimTypeInfoService == null) {
 126  0
             kimTypeInfoService = KimApiServiceLocator.getKimTypeInfoService();
 127  
         }
 128  0
         return kimTypeInfoService;
 129  
     }
 130  
 
 131  
 
 132  
     public static Role to(RoleBo bo) {
 133  0
         if (bo == null) {return null;}
 134  1
         return Role.Builder.create(bo).build()
 135  
     }
 136  
 
 137  
     public static RoleBo from(Role immutable) {
 138  0
         if (immutable == null) {return null}
 139  0
         RoleBo bo = new RoleBo()
 140  0
         bo.id = immutable.id;
 141  0
         bo.name = immutable.name
 142  0
         bo.namespaceCode = immutable.namespaceCode
 143  0
         bo.description = immutable.description
 144  0
         bo.kimTypeId = immutable.kimTypeId
 145  0
         bo.active = immutable.active
 146  0
         bo.versionNumber = immutable.versionNumber
 147  0
         bo.objectId = immutable.objectId
 148  
 
 149  0
         return bo
 150  
     }
 151  
 }