Coverage Report - org.kuali.rice.kim.impl.identity.type.EntityTypeContactInfoBo
 
Classes in this File Line Coverage Branch Coverage Complexity
EntityTypeContactInfoBo
48%
15/31
20%
5/24
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.identity.type
 17  
 
 18  
 import javax.persistence.CascadeType
 19  
 import javax.persistence.Column
 20  
 import javax.persistence.Entity
 21  
 import javax.persistence.FetchType
 22  
 import javax.persistence.Id
 23  
 import javax.persistence.IdClass
 24  
 import javax.persistence.JoinColumn
 25  
 import javax.persistence.JoinColumns
 26  
 import javax.persistence.ManyToOne
 27  
 import javax.persistence.OneToMany
 28  
 import javax.persistence.Table
 29  
 import org.apache.commons.collections.CollectionUtils
 30  
 import org.hibernate.annotations.Type
 31  
 import org.kuali.rice.kim.api.identity.EntityUtils
 32  
 import org.kuali.rice.kim.api.identity.address.EntityAddress
 33  
 
 34  
 import org.kuali.rice.kim.api.identity.phone.EntityPhone
 35  
 import org.kuali.rice.kim.api.identity.type.EntityTypeContactInfo
 36  
 import org.kuali.rice.kim.api.identity.type.EntityTypeContactInfoContract
 37  
 import org.kuali.rice.kim.impl.identity.EntityTypeBo
 38  
 import org.kuali.rice.kim.impl.identity.address.EntityAddressBo
 39  
 import org.kuali.rice.kim.impl.identity.email.EntityEmailBo
 40  
 import org.kuali.rice.kim.impl.identity.phone.EntityPhoneBo
 41  
 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase
 42  
 import org.kuali.rice.kim.api.identity.type.EntityTypeContactInfoDefault
 43  
 import org.kuali.rice.kim.api.identity.email.EntityEmail
 44  
 
 45  
 @Entity
 46  
 @IdClass(EntityTypeContactInfoId.class)
 47  
 @Table(name = "KRIM_ENTITY_ENT_TYP_T")
 48  
 public class EntityTypeContactInfoBo extends PersistableBusinessObjectBase implements EntityTypeContactInfoContract {
 49  
 
 50  
     private static final long serialVersionUID = 1L;
 51  
 
 52  
     @Id
 53  
     @Column(name = "ENTITY_ID")
 54  
     String entityId;
 55  
 
 56  
     @Id
 57  
     @Column(name = "ENT_TYP_CD")
 58  
     String entityTypeCode;
 59  
 
 60  
     @ManyToOne(targetEntity = EntityTypeBo.class, fetch = FetchType.EAGER, cascade = [])
 61  
     @JoinColumn(name = "ENT_TYP_CD", insertable = false, updatable = false)
 62  
     EntityTypeBo entityType;
 63  
 
 64  
     @OneToMany(targetEntity = EntityTypeContactInfoBo.class, fetch = FetchType.EAGER, cascade = [ CascadeType.ALL ])
 65  
     @JoinColumns([
 66  
         @JoinColumn(name="ENTITY_ID", insertable = false, updatable = false),
 67  
         @JoinColumn(name="ENT_TYP_CD", insertable = false, updatable = false)
 68  
     ])
 69  
     List<EntityEmailBo> emailAddresses;
 70  
 
 71  
     @OneToMany(targetEntity = EntityPhoneBo.class, fetch = FetchType.EAGER, cascade = [ CascadeType.ALL ])
 72  
     @JoinColumns([
 73  
         @JoinColumn(name="ENTITY_ID", insertable = false, updatable = false),
 74  
         @JoinColumn(name="ENT_TYP_CD", insertable = false, updatable = false)
 75  
     ])
 76  
     List<EntityPhoneBo> phoneNumbers
 77  
 
 78  
     @OneToMany(targetEntity = EntityAddressBo.class, fetch = FetchType.EAGER, cascade = [ CascadeType.ALL ])
 79  
     @JoinColumns([
 80  
         @JoinColumn(name="ENTITY_ID", insertable = false, updatable = false),
 81  
         @JoinColumn(name="ENT_TYP_CD", insertable = false, updatable = false)
 82  
     ])
 83  
     List<EntityAddressBo> addresses;
 84  
 
 85  
     @Type(type="yes_no")
 86  
     @Column(name="ACTV_IND")
 87  
     boolean active;
 88  
 
 89  
          /*
 90  
        * Converts a mutable EntityTypeDataBo to an immutable EntityTypeData representation.
 91  
        * @param bo
 92  
        * @return an immutable EntityTypeData
 93  
        */
 94  
       static EntityTypeContactInfo to(EntityTypeContactInfoBo bo) {
 95  0
         if (bo == null) { return null }
 96  1
         return EntityTypeContactInfo.Builder.create(bo).build()
 97  
       }
 98  
 
 99  
       static EntityTypeContactInfoDefault toDefault(EntityTypeContactInfoBo bo) {
 100  0
           if (bo == null) { return null }
 101  0
           return new EntityTypeContactInfoDefault(bo.getEntityTypeCode(),
 102  0
                                         EntityAddressBo.to(bo.getDefaultAddress()),
 103  0
                                         EntityEmailBo.to(bo.getDefaultEmailAddress()),
 104  0
                                         EntityPhoneBo.to(bo.getDefaultPhoneNumber()))
 105  
       }
 106  
 
 107  
       /**
 108  
        * Creates a EntityTypeDataBo business object from an immutable representation of a EntityTypeData.
 109  
        * @param an immutable EntityTypeData
 110  
        * @return a EntityTypeDataBo
 111  
        */
 112  
       static EntityTypeContactInfoBo from(EntityTypeContactInfo immutable) {
 113  0
         if (immutable == null) {return null}
 114  
 
 115  1
         EntityTypeContactInfoBo bo = new EntityTypeContactInfoBo()
 116  1
         bo.active = immutable.active
 117  
 
 118  1
         bo.entityId = immutable.entityId
 119  1
         bo.entityTypeCode = immutable.entityTypeCode
 120  1
         bo.addresses = new ArrayList<EntityAddressBo>()
 121  1
         if (CollectionUtils.isNotEmpty(immutable.addresses)) {
 122  0
             for (EntityAddress address : immutable.addresses) {
 123  0
                 bo.addresses.add(EntityAddressBo.from(address))
 124  
             }
 125  
         }
 126  1
         bo.phoneNumbers = new ArrayList<EntityPhoneBo>()
 127  1
         if (CollectionUtils.isNotEmpty(immutable.phoneNumbers)) {
 128  0
             for (EntityPhone phone : immutable.phoneNumbers) {
 129  0
                 bo.phoneNumbers.add(EntityPhoneBo.from(phone))
 130  
             }
 131  
         }
 132  1
         bo.emailAddresses = new ArrayList<EntityEmailBo>()
 133  1
         if (CollectionUtils.isNotEmpty(immutable.emailAddresses)) {
 134  0
             for (EntityEmail email : immutable.emailAddresses) {
 135  0
                 bo.emailAddresses.add(EntityEmailBo.from(email))
 136  
             }
 137  
         }
 138  1
         bo.versionNumber = immutable.versionNumber
 139  1
         bo.objectId = immutable.objectId
 140  
 
 141  1
         return bo;
 142  
       }
 143  
 
 144  
     EntityAddressBo getDefaultAddress() {
 145  0
         return EntityUtils.getDefaultItem(this.addresses);
 146  
     }
 147  
     EntityEmailBo getDefaultEmailAddress() {
 148  0
         return EntityUtils.getDefaultItem(this.emailAddresses);
 149  
     }
 150  
     EntityPhoneBo getDefaultPhoneNumber() {
 151  0
         return EntityUtils.getDefaultItem(this.phoneNumbers);
 152  
     }
 153  
 
 154  
     EntityTypeBo getEntityType() {
 155  1
         return this.entityType
 156  
     }
 157  
 
 158  
 }