Coverage Report - org.kuali.rice.kim.impl.role.RoleMemberBo
 
Classes in this File Line Coverage Branch Coverage Complexity
RoleMemberBo
7%
2/27
5%
1/18
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  
 package org.kuali.rice.kim.impl.role;
 17  
 
 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.GeneratedValue
 24  
 import javax.persistence.Id
 25  
 import javax.persistence.JoinColumn
 26  
 import javax.persistence.OneToMany
 27  
 import javax.persistence.Table
 28  
 import javax.persistence.Transient
 29  
 import org.hibernate.annotations.GenericGenerator
 30  
 import org.hibernate.annotations.Parameter
 31  
 import org.kuali.rice.core.util.AttributeSet
 32  
 import org.kuali.rice.kim.api.role.Role
 33  
 import org.kuali.rice.kim.api.role.RoleMember
 34  
 import org.kuali.rice.kim.api.role.RoleMemberContract
 35  
 import org.kuali.rice.kim.api.role.RoleService
 36  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator
 37  
 import org.kuali.rice.kim.api.type.KimType
 38  
 import org.kuali.rice.kim.api.type.KimTypeAttribute
 39  
 import org.kuali.rice.kim.api.type.KimTypeInfoService
 40  
 import org.kuali.rice.kim.impl.membership.AbstractMemberBo
 41  
 import org.springframework.util.AutoPopulatingList
 42  
 
 43  
 @Entity
 44  
 @Table(name = "KRIM_ROLE_MBR_T")
 45  
 public class RoleMemberBo extends AbstractMemberBo implements RoleMemberContract {
 46  
 
 47  
     private static final long serialVersionUID = 1L;
 48  
 
 49  
     @Id
 50  
     @GeneratedValue(generator = "KRIM_ROLE_MBR_ID_S")
 51  
     @GenericGenerator(name = "KRIM_ROLE_MBR_ID_S", strategy = "org.kuali.rice.core.jpa.spring.RiceNumericStringSequenceStyleGenerator", parameters = [
 52  
     @Parameter(name = "sequence_name", value = "KRIM_ROLE_MBR_ID_S"),
 53  
     @Parameter(name = "value_column", value = "id")
 54  
     ])
 55  
     @Column(name = "ROLE_MBR_ID")
 56  
     String roleMemberId;
 57  
 
 58  
     @Column(name = "ROLE_ID")
 59  
     String roleId;
 60  
 
 61  
     @Column(name = "MBR_TYP_CD")
 62  
     String memberTypeCode
 63  
 
 64  
     @OneToMany(targetEntity = RoleMemberAttributeDataBo.class, cascade = [CascadeType.ALL], fetch = FetchType.EAGER)
 65  
     @JoinColumn(name = "ROLE_MBR_ID", insertable = false, updatable = false)
 66  
     List<RoleMemberAttributeDataBo> attributes; // = new AutoPopulatingList(RoleMemberAttributeDataBo.class);
 67  
 
 68  
     @Transient
 69  
     List<RoleResponsibilityActionBo> roleRspActions;
 70  
 
 71  
     @Transient
 72  
     transient AttributeSet qualifier = null;
 73  
 
 74  
 
 75  
     List<RoleMemberAttributeDataBo> getAttributes() {
 76  0
         if (this.attributes == null) {
 77  0
             return new AutoPopulatingList(RoleMemberAttributeDataBo.class);
 78  
         }
 79  0
         return this.attributes;
 80  
     }
 81  
 
 82  
     void setAttributes(List<RoleMemberAttributeDataBo> attributes) {
 83  0
         this.attributes = attributes;
 84  
     }
 85  
 
 86  
     AttributeSet getQualifier() {
 87  0
         if (qualifier == null) {
 88  0
             Role role = getRoleService().getRole(roleId);
 89  0
             KimType kimType = getTypeInfoService().getKimType(role.getKimTypeId());
 90  0
             AttributeSet m = new AttributeSet();
 91  0
             for (RoleMemberAttributeDataBo data: getAttributes()) {
 92  0
                 KimTypeAttribute attribute = null;
 93  0
                 if (kimType != null) {
 94  0
                     attribute = kimType.getAttributeDefinitionById(data.getKimAttributeId());
 95  
                 }
 96  0
                 if (attribute != null) {
 97  0
                     m.put(attribute.getKimAttribute().getAttributeName(), data.getAttributeValue());
 98  
                 } else {
 99  0
                     m.put(data.getKimAttribute().getAttributeName(), data.getAttributeValue());
 100  
                 }
 101  
             }
 102  0
             qualifier = m;
 103  
         }
 104  0
         return qualifier;
 105  
     }
 106  
 
 107  
     private transient static KimTypeInfoService kimTypeInfoService;
 108  
     private transient static RoleService roleService;
 109  
 
 110  
     protected static KimTypeInfoService getTypeInfoService() {
 111  0
         if (kimTypeInfoService == null) {
 112  0
             kimTypeInfoService = KimApiServiceLocator.getKimTypeInfoService();
 113  
         }
 114  0
         return kimTypeInfoService;
 115  
     }
 116  
 
 117  
     protected static RoleService getRoleService() {
 118  0
         if (roleService == null) {
 119  0
             roleService = KimApiServiceLocator.getRoleManagementService();
 120  
         }
 121  0
         return roleService;
 122  
     }
 123  
 
 124  
 
 125  
 
 126  
     public static RoleMember to(RoleMemberBo bo) {
 127  0
         if (bo == null) {return null;}
 128  0
         return RoleMember.Builder.create(bo).build();
 129  
     }
 130  
 
 131  
     public static RoleMemberBo from(RoleMember immutable) {
 132  2
         if (immutable == null) { return null; }
 133  
 
 134  2
         return new RoleMemberBo(
 135  
                 roleMemberId: immutable.roleMemberId,
 136  
                 roleId: immutable.roleId,
 137  
                 qualifier: immutable.qualifier,
 138  
                 roleRspActions: immutable.roleRspActions,
 139  
                 memberId: immutable.memberId,
 140  
                 memberTypeCode: immutable.memberTypeCode,
 141  
                 activeFromDate: immutable.activeFromDate,
 142  
                 activeToDate: immutable.activeToDate,
 143  
         )
 144  
     }
 145  
 }