Coverage Report - org.kuali.rice.kim.impl.identity.entity.EntityBo
 
Classes in this File Line Coverage Branch Coverage Complexity
EntityBo
0%
0/90
0%
0/96
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.entity
 17  
 
 18  
 import javax.persistence.CascadeType
 19  
 import javax.persistence.Column
 20  
 import javax.persistence.FetchType
 21  
 import javax.persistence.Id
 22  
 import javax.persistence.JoinColumn
 23  
 import javax.persistence.OneToMany
 24  
 import javax.persistence.OneToOne
 25  
 import javax.persistence.Table
 26  
 import org.apache.commons.collections.CollectionUtils
 27  
 import org.hibernate.annotations.Fetch
 28  
 import org.hibernate.annotations.FetchMode
 29  
 import org.hibernate.annotations.Type
 30  
 import org.kuali.rice.kim.api.identity.EntityUtils
 31  
 import org.kuali.rice.kim.api.identity.affiliation.EntityAffiliation
 32  
 import org.kuali.rice.kim.api.identity.citizenship.EntityCitizenship
 33  
 import org.kuali.rice.kim.api.identity.employment.EntityEmployment
 34  
 import org.kuali.rice.kim.api.identity.entity.Entity
 35  
 import org.kuali.rice.kim.api.identity.entity.EntityContract
 36  
 import org.kuali.rice.kim.api.identity.entity.EntityDefault
 37  
 import org.kuali.rice.kim.api.identity.external.EntityExternalIdentifier
 38  
 import org.kuali.rice.kim.api.identity.name.EntityName
 39  
 import org.kuali.rice.kim.api.identity.name.EntityNameContract
 40  
 import org.kuali.rice.kim.api.identity.personal.EntityEthnicity
 41  
 import org.kuali.rice.kim.api.identity.principal.Principal
 42  
 import org.kuali.rice.kim.api.identity.residency.EntityResidency
 43  
 import org.kuali.rice.kim.api.identity.type.EntityTypeContactInfo
 44  
 import org.kuali.rice.kim.api.identity.visa.EntityVisa
 45  
 import org.kuali.rice.kim.impl.identity.affiliation.EntityAffiliationBo
 46  
 import org.kuali.rice.kim.impl.identity.citizenship.EntityCitizenshipBo
 47  
 import org.kuali.rice.kim.impl.identity.employment.EntityEmploymentBo
 48  
 import org.kuali.rice.kim.impl.identity.external.EntityExternalIdentifierBo
 49  
 import org.kuali.rice.kim.impl.identity.name.EntityNameBo
 50  
 import org.kuali.rice.kim.impl.identity.personal.EntityBioDemographicsBo
 51  
 import org.kuali.rice.kim.impl.identity.personal.EntityEthnicityBo
 52  
 import org.kuali.rice.kim.impl.identity.principal.PrincipalBo
 53  
 import org.kuali.rice.kim.impl.identity.privacy.EntityPrivacyPreferencesBo
 54  
 import org.kuali.rice.kim.impl.identity.residency.EntityResidencyBo
 55  
 import org.kuali.rice.kim.impl.identity.type.EntityTypeContactInfoBo
 56  
 import org.kuali.rice.kim.impl.identity.visa.EntityVisaBo
 57  
 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase
 58  
 
 59  
 @javax.persistence.Entity
 60  
 @Table(name = "KRIM_ENTITY_T")
 61  
 class EntityBo extends PersistableBusinessObjectBase implements EntityContract {
 62  
     @Id
 63  
         @Column(name = "ENTITY_ID")
 64  
         String id;
 65  
 
 66  
         @OneToMany(fetch = FetchType.EAGER, cascade = [ CascadeType.ALL ])
 67  
         @Fetch(value = FetchMode.SELECT)
 68  
         @JoinColumn(name = "ENTITY_ID", insertable = false, updatable = false)
 69  0
         List<EntityNameBo> names = new ArrayList<EntityNameBo>()
 70  
 
 71  
         @OneToMany(fetch = FetchType.EAGER, cascade = [ CascadeType.ALL ])
 72  
         @Fetch(value = FetchMode.SELECT)
 73  
         @JoinColumn(name = "ENTITY_ID", insertable = false, updatable = false)
 74  0
         List<PrincipalBo> principals = new ArrayList<PrincipalBo>()
 75  
 
 76  
         @OneToMany(fetch=FetchType.EAGER,cascade=[CascadeType.ALL])
 77  
         @Fetch(value = FetchMode.SELECT)
 78  
         @JoinColumn(name="ENTITY_ID", insertable = false, updatable = false)
 79  0
     List<EntityExternalIdentifierBo> externalIdentifiers = new ArrayList<EntityExternalIdentifierBo>()
 80  
 
 81  
         @Fetch(value = FetchMode.SELECT)
 82  
         @OneToMany(fetch=FetchType.EAGER,cascade=[CascadeType.ALL])
 83  
         @JoinColumn(name="ENTITY_ID", insertable = false, updatable = false)
 84  0
         List<EntityAffiliationBo> affiliations  = new ArrayList<EntityAffiliationBo>()
 85  
 
 86  
         @OneToMany(fetch=FetchType.EAGER, cascade=[CascadeType.ALL])
 87  
         @Fetch(value = FetchMode.SELECT)
 88  
         @JoinColumn(name="ENTITY_ID", insertable = false, updatable = false)
 89  0
         List<EntityEmploymentBo> employmentInformation = new ArrayList<EntityEmploymentBo>()
 90  
 
 91  
         @OneToMany(fetch = FetchType.EAGER, cascade = [ CascadeType.ALL ])
 92  
         @Fetch(value = FetchMode.SELECT)
 93  
         @JoinColumn(name = "ENTITY_ID", insertable = false, updatable = false)
 94  0
         List<EntityTypeContactInfoBo> entityTypeContactInfos  = new ArrayList<EntityTypeContactInfoBo>()
 95  
         
 96  
         @OneToOne(targetEntity=EntityPrivacyPreferencesBo.class, fetch = FetchType.EAGER, cascade = [CascadeType.MERGE, CascadeType.REFRESH])
 97  
         @JoinColumn(name = "ENTITY_ID", insertable = false, updatable = false)
 98  
         EntityPrivacyPreferencesBo privacyPreferences
 99  
 
 100  
         @OneToOne(targetEntity=EntityBioDemographicsBo.class, fetch = FetchType.EAGER, cascade = [])
 101  
         @JoinColumn(name = "ENTITY_ID", insertable = false, updatable = false)
 102  
         EntityBioDemographicsBo bioDemographics
 103  
         
 104  
         @OneToMany(targetEntity = EntityCitizenshipBo.class, fetch = FetchType.EAGER, cascade = [ CascadeType.ALL ])
 105  
         @Fetch(value = FetchMode.SELECT)
 106  
         @JoinColumn(name = "ENTITY_ID", insertable = false, updatable = false)
 107  0
         List<EntityCitizenshipBo> citizenships = new ArrayList<EntityCitizenshipBo>()
 108  
 
 109  
         @OneToMany(targetEntity = EntityEthnicityBo.class, fetch = FetchType.EAGER, cascade = [ CascadeType.ALL ])
 110  
         @Fetch(value = FetchMode.SELECT)
 111  
         @JoinColumn(name = "ENTITY_ID", insertable = false, updatable = false)
 112  0
         List<EntityEthnicityBo> ethnicities  = new ArrayList<EntityEthnicityBo>()
 113  
 
 114  
         @OneToMany(targetEntity = EntityResidencyBo.class, fetch = FetchType.EAGER, cascade = [ CascadeType.ALL ])
 115  
         @Fetch(value = FetchMode.SELECT)
 116  
         @JoinColumn(name = "ENTITY_ID", insertable = false, updatable = false)
 117  0
         List<EntityResidencyBo> residencies = new ArrayList<EntityResidencyBo>()
 118  
 
 119  
         @OneToMany(targetEntity = EntityVisaBo.class, fetch = FetchType.EAGER, cascade = [ CascadeType.ALL ])
 120  
         @Fetch(value = FetchMode.SELECT)
 121  
         @JoinColumn(name = "ENTITY_ID", insertable = false, updatable = false)
 122  0
         List<EntityVisaBo> visas  = new ArrayList<EntityVisaBo>()
 123  
 
 124  
     @Type(type="yes_no")
 125  
     @Column(name="ACTV_IND")
 126  
     boolean active;
 127  
 
 128  
     /*
 129  
      * Converts a mutable EntityBo to an immutable Entity representation.
 130  
      * @param bo
 131  
      * @return an immutable Entity
 132  
      */
 133  
     static Entity to(EntityBo bo) {
 134  0
         if (bo == null) { return null }
 135  0
         return Entity.Builder.create(bo).build()
 136  
     }
 137  
 
 138  
     static EntityDefault toDefault(EntityBo bo) {
 139  0
         if (bo == null) { return null }
 140  0
         return EntityDefault.Builder.create(bo).build()
 141  
     }
 142  
 
 143  
     static EntityBo from(Entity immutable) {
 144  0
         return fromAndUpdate(immutable, null)
 145  
     }
 146  
 
 147  
     /**
 148  
      * Creates a EntityBo business object from an immutable representation of a Entity.
 149  
      * @param an immutable Entity
 150  
      * @return a EntityBo
 151  
      */
 152  
     static EntityBo fromAndUpdate(Entity immutable, EntityBo toUpdate) {
 153  0
         if (immutable == null) {return null}
 154  
 
 155  0
         EntityBo bo = toUpdate
 156  0
         if (toUpdate == null) {
 157  0
             bo = new EntityBo()
 158  
         }
 159  
 
 160  0
         bo.active = immutable.active
 161  0
         bo.id = immutable.id
 162  
 
 163  
 
 164  0
         bo.names = new ArrayList<EntityNameBo>()
 165  0
         if (CollectionUtils.isNotEmpty(immutable.names)) {
 166  0
             for (EntityName name : immutable.names) {
 167  0
                 bo.names.add(EntityNameBo.from(name))
 168  
             }
 169  
         }
 170  
 
 171  0
             bo.principals = new ArrayList<PrincipalBo>()
 172  0
         if (CollectionUtils.isNotEmpty(immutable.principals)) {
 173  0
             for (Principal principal : immutable.principals) {
 174  0
                 bo.principals.add(PrincipalBo.from(principal))
 175  
             }
 176  
         }
 177  
 
 178  0
         bo.externalIdentifiers = new ArrayList<EntityExternalIdentifierBo>();
 179  0
         if (CollectionUtils.isNotEmpty(immutable.externalIdentifiers)) {
 180  0
             for (EntityExternalIdentifier externalId : immutable.externalIdentifiers) {
 181  0
                 bo.externalIdentifiers.add(EntityExternalIdentifierBo.from(externalId))
 182  
             }
 183  
         }
 184  
 
 185  0
         bo.affiliations = new ArrayList<EntityAffiliationBo>()
 186  0
         if (CollectionUtils.isNotEmpty(immutable.affiliations)) {
 187  0
             for (EntityAffiliation affiliation : immutable.affiliations) {
 188  0
                 bo.affiliations.add(EntityAffiliationBo.from(affiliation))
 189  
             }
 190  
         }
 191  
 
 192  0
         bo.employmentInformation = new ArrayList<EntityEmploymentBo>()
 193  0
         if (CollectionUtils.isNotEmpty(immutable.employmentInformation)) {
 194  0
             for (EntityEmployment employment : immutable.employmentInformation) {
 195  0
                 bo.employmentInformation.add(EntityEmploymentBo.from(employment))
 196  
             }
 197  
         }
 198  
 
 199  0
         bo.entityTypeContactInfos = new ArrayList<EntityTypeContactInfoBo>()
 200  0
         if (CollectionUtils.isNotEmpty(immutable.entityTypeContactInfos)) {
 201  0
             for (EntityTypeContactInfo entityType : immutable.entityTypeContactInfos) {
 202  0
                 bo.entityTypeContactInfos.add(EntityTypeContactInfoBo.from(entityType))
 203  
             }
 204  
         }
 205  
 
 206  0
         if (immutable.privacyPreferences != null) {
 207  0
             bo.privacyPreferences = EntityPrivacyPreferencesBo.from(immutable.privacyPreferences)
 208  
         }
 209  
 
 210  0
         if (immutable.bioDemographics != null) {
 211  0
             bo.bioDemographics = EntityBioDemographicsBo.from(immutable.bioDemographics)
 212  
         }
 213  
 
 214  0
         bo.citizenships = new ArrayList<EntityCitizenshipBo>()
 215  0
         if (CollectionUtils.isNotEmpty(immutable.citizenships)) {
 216  0
             for (EntityCitizenship citizenship : immutable.citizenships) {
 217  0
                 bo.citizenships.add(EntityCitizenshipBo.from(citizenship))
 218  
             }
 219  
         }
 220  
 
 221  0
         bo.ethnicities = new ArrayList<EntityEthnicityBo>()
 222  0
         if (CollectionUtils.isNotEmpty(immutable.ethnicities)) {
 223  0
             for (EntityEthnicity ethnicity : immutable.ethnicities) {
 224  0
                 bo.ethnicities.add(EntityEthnicityBo.from(ethnicity))
 225  
             }
 226  
         }
 227  
 
 228  0
         bo.residencies = new ArrayList<EntityResidencyBo>()
 229  0
         if (CollectionUtils.isNotEmpty(immutable.residencies)) {
 230  0
             for (EntityResidency residency : immutable.residencies) {
 231  0
                 bo.residencies.add(EntityResidencyBo.from(residency))
 232  
             }
 233  
         }
 234  
 
 235  0
         bo.visas = new ArrayList<EntityVisaBo>()
 236  0
         if (CollectionUtils.isNotEmpty(immutable.visas)) {
 237  0
             for (EntityVisa visa : immutable.visas) {
 238  0
                 bo.visas.add(EntityVisaBo.from(visa))
 239  
             }
 240  
         }
 241  
 
 242  0
         bo.versionNumber = immutable.versionNumber
 243  0
         bo.objectId = immutable.objectId
 244  
 
 245  0
         return bo;
 246  
     }
 247  
 
 248  
 
 249  
     EntityTypeContactInfoBo getEntityTypeContactInfoByTypeCode(String entityTypeCode) {
 250  0
         if (CollectionUtils.isEmpty(this.entityTypeContactInfos)) {
 251  0
             return null
 252  
         }
 253  0
         for (EntityTypeContactInfoBo entType : this.entityTypeContactInfos) {
 254  0
             if (entType.getEntityTypeCode().equals(entityTypeCode)) {
 255  0
                 return entType
 256  
             }
 257  
         }
 258  0
         return null
 259  
     }
 260  
 
 261  
     EntityEmploymentBo getPrimaryEmployment() {
 262  0
         if (CollectionUtils.isEmpty(this.employmentInformation)) {
 263  0
             return null
 264  
         }
 265  0
         for (EntityEmploymentBo employment : this.employmentInformation) {
 266  0
             if (employment.isPrimary() && employment.isActive()) {
 267  0
                 return employment
 268  
             }
 269  
         }
 270  0
         return null
 271  
     }
 272  
 
 273  
     EntityAffiliationBo getDefaultAffiliation() {
 274  0
         return EntityUtils.getDefaultItem(this.affiliations)
 275  
     }
 276  
 
 277  
     EntityExternalIdentifierBo getEntityExternalIdentifier(String externalIdentifierTypeCode) {
 278  0
         if (CollectionUtils.isEmpty(this.externalIdentifiers)) {
 279  0
             return null
 280  
         }
 281  0
         for (EntityExternalIdentifierBo externalId : this.externalIdentifiers) {
 282  0
             if (externalId.getExternalIdentifierTypeCode().equals(externalIdentifierTypeCode)) {
 283  0
                 return externalId
 284  
             }
 285  
         }
 286  0
         return null
 287  
     }
 288  
 
 289  
     EntityNameContract getDefaultName() {
 290  0
         return EntityUtils.getDefaultItem(this.names)
 291  
     }
 292  
 
 293  
     @Override
 294  
     public EntityPrivacyPreferencesBo getPrivacyPreferences() {
 295  0
         return this.privacyPreferences
 296  
     }
 297  
 
 298  
     @Override
 299  
     public EntityBioDemographicsBo getBioDemographics() {
 300  0
         return this.bioDemographics
 301  
     }
 302  
 }