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