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