Coverage Report - org.kuali.rice.kim.impl.identity.personal.EntityBioDemographicsBo
 
Classes in this File Line Coverage Branch Coverage Complexity
EntityBioDemographicsBo
51%
42/82
33%
20/60
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.personal
 17  
 
 18  
 import java.text.SimpleDateFormat
 19  
 import javax.persistence.Column
 20  
 import javax.persistence.Entity
 21  
 import javax.persistence.Id
 22  
 import javax.persistence.Table
 23  
 import javax.persistence.Transient
 24  
 
 25  
 import org.kuali.rice.kim.api.identity.personal.EntityBioDemographics
 26  
 import org.kuali.rice.kim.api.identity.personal.EntityBioDemographicsContract
 27  
 import org.kuali.rice.kim.api.identity.privacy.EntityPrivacyPreferences
 28  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator
 29  
 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase
 30  
 import org.kuali.rice.kim.api.KimApiConstants
 31  
 import org.joda.time.Years
 32  
 import org.joda.time.DateTime
 33  
 
 34  
 @Entity
 35  
 @Table(name = "KRIM_ENTITY_BIO_T")
 36  
 class EntityBioDemographicsBo extends PersistableBusinessObjectBase implements EntityBioDemographicsContract {
 37  
     private static final long serialVersionUID = 6317317790920881093L;
 38  
 
 39  
     @Id
 40  
     @Column(name = "ENTITY_ID")
 41  
     String entityId;
 42  
 
 43  
     @Column(name = "BIRTH_DT")
 44  
     Date birthDateValue;
 45  
 
 46  
     @Column(name = "GNDR_CD")
 47  
     String genderCode;
 48  
 
 49  
     @Column(name = "GNDR_CHNG_CD")
 50  
     String genderChangeCode;
 51  
 
 52  
     @Column(name = "DECEASED_DT")
 53  
     Date deceasedDateValue;
 54  
 
 55  
     @Column(name = "MARITAL_STATUS")
 56  
     String maritalStatusCode;
 57  
 
 58  
     @Column(name = "PRIM_LANG_CD")
 59  
     String primaryLanguageCode;
 60  
 
 61  
     @Column(name = "SEC_LANG_CD")
 62  
     String secondaryLanguageCode;
 63  
 
 64  
     @Column(name = "BIRTH_CNTRY_CD")
 65  
     String birthCountry;
 66  
 
 67  
     @Column(name = "BIRTH_STATE_PVC_CD")
 68  
     String birthStateProvinceCode;
 69  
 
 70  
     @Column(name = "BIRTH_CITY")
 71  
     String birthCity;
 72  
 
 73  
     @Column(name = "GEO_ORIGIN")
 74  
     String geographicOrigin;
 75  
 
 76  
     @Column(name = "NOTE_MSG")
 77  
     String noteMessage;
 78  
 
 79  
     @Transient
 80  
     boolean suppressPersonal;
 81  
 
 82  
   /*
 83  
    * Converts a mutable EntityBioDemographicsBo to an immutable EntityBioDemographics representation.
 84  
    * @param bo
 85  
    * @return an immutable EntityBioDemographics
 86  
    */
 87  
   static EntityBioDemographics to(EntityBioDemographicsBo bo) {
 88  0
     if (bo == null) { return null }
 89  1
     return EntityBioDemographics.Builder.create(bo).build()
 90  
   }
 91  
 
 92  
   /**
 93  
    * Creates a EntityBioDemographicsBo business object from an immutable representation of a EntityBioDemographics.
 94  
    * @param an immutable EntityBioDemographics
 95  
    * @return a EntityBioDemographicsBo
 96  
    */
 97  
   static EntityBioDemographicsBo from(EntityBioDemographics immutable) {
 98  0
     if (immutable == null) {return null}
 99  
 
 100  1
     EntityBioDemographicsBo bo = new EntityBioDemographicsBo()
 101  1
     bo.entityId = immutable.entityId
 102  1
     if (immutable.birthDateUnmasked != null) {
 103  0
         bo.birthDateValue = new java.sql.Date(new SimpleDateFormat(EntityBioDemographicsContract.BIRTH_DATE_FORMAT).parse(immutable.birthDateUnmasked).time)
 104  
     }
 105  1
     bo.birthStateProvinceCode = immutable.birthStateProvinceCodeUnmasked
 106  1
     bo.birthCity = immutable.birthCityUnmasked
 107  1
     bo.birthCountry = immutable.birthCountryUnmasked
 108  1
     if (immutable.deceasedDate != null) {
 109  0
         bo.deceasedDateValue = new java.sql.Date(new SimpleDateFormat(EntityBioDemographicsContract.DECEASED_DATE_FORMAT).parse(immutable.deceasedDate).time)
 110  
     }
 111  1
     bo.genderCode = immutable.genderCodeUnmasked
 112  1
     bo.geographicOrigin = immutable.geographicOriginUnmasked
 113  1
     bo.maritalStatusCode = immutable.maritalStatusCodeUnmasked
 114  1
     bo.primaryLanguageCode = immutable.primaryLanguageCodeUnmasked
 115  1
     bo.secondaryLanguageCode = immutable.secondaryLanguageCodeUnmasked
 116  1
     bo.noteMessage = immutable.noteMessage
 117  1
     bo.suppressPersonal = immutable.suppressPersonal
 118  1
     bo.versionNumber = immutable.versionNumber
 119  1
     bo.objectId = immutable.objectId
 120  
 
 121  1
     return bo;
 122  
   }
 123  
 
 124  
     @Override
 125  
     String getBirthDate() {
 126  1
         if (this.birthDateValue != null) {
 127  0
             if (isSuppressPersonal()) {
 128  0
                 return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK
 129  
             }
 130  0
             return new SimpleDateFormat(BIRTH_DATE_FORMAT).format(this.birthDateValue)
 131  
         }
 132  1
         return null;
 133  
     }
 134  
 
 135  
     @Override
 136  
     Integer getAge() {
 137  0
         if (this.birthDateValue != null && ! isSuppressPersonal()) {
 138  0
             DateTime endDate;
 139  0
             if (this.deceasedDateValue != null) {
 140  0
                 endDate = new DateTime(this.deceasedDateValue);
 141  
             } else {
 142  0
                 endDate = new DateTime();
 143  
             }
 144  0
             return Years.yearsBetween(new DateTime(this.birthDateValue), endDate).getYears();
 145  
         }
 146  0
         return null;
 147  
     }
 148  
 
 149  
     @Override
 150  
     String getDeceasedDate() {
 151  1
         if (this.deceasedDateValue != null) {
 152  0
             return new SimpleDateFormat(DECEASED_DATE_FORMAT).format(this.deceasedDateValue)
 153  
         }
 154  1
         return null
 155  
     }
 156  
 
 157  
     @Override
 158  
     String getBirthDateUnmasked() {
 159  0
         if (this.birthDateValue != null) {
 160  0
             return new SimpleDateFormat(BIRTH_DATE_FORMAT).format(this.birthDateValue)
 161  
         }
 162  0
         return null;
 163  
     }
 164  
 
 165  
     @Override
 166  
     boolean isSuppressPersonal() {
 167  10
         if (this.suppressPersonal == null) {
 168  0
             EntityPrivacyPreferences privacy = KimApiServiceLocator.getIdentityService().getEntityPrivacyPreferences(getEntityId())
 169  0
             if (privacy != null) {
 170  0
                this.suppressPersonal = privacy.isSuppressPersonal()
 171  
             } else {
 172  0
                 this.suppressPersonal = false
 173  
             }
 174  
         }
 175  
 
 176  10
         return suppressPersonal;
 177  
     }
 178  
 
 179  
     String getGenderCode() {
 180  1
         if (isSuppressPersonal()) {
 181  0
             return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK_CODE
 182  
         }
 183  1
         return this.genderCode
 184  
     }
 185  
 
 186  
     String getGenderChangeCode() {
 187  1
         if (isSuppressPersonal()) {
 188  0
             return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK_CODE
 189  
         }
 190  1
         return this.genderChangeCode
 191  
     }
 192  
 
 193  
     String getMaritalStatusCode() {
 194  1
         if (isSuppressPersonal()) {
 195  0
             return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK_CODE
 196  
         }
 197  1
         return this.maritalStatusCode
 198  
     }
 199  
     String getPrimaryLanguageCode() {
 200  1
         if (isSuppressPersonal()) {
 201  0
             return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK_CODE
 202  
         }
 203  1
         return this.primaryLanguageCode
 204  
     }
 205  
     String getSecondaryLanguageCode() {
 206  1
         if (isSuppressPersonal()) {
 207  0
             return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK_CODE
 208  
         }
 209  1
         return this.secondaryLanguageCode
 210  
     }
 211  
     String getBirthCountry() {
 212  1
         if (isSuppressPersonal()) {
 213  0
             return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK_CODE
 214  
         }
 215  1
         return this.birthCountry
 216  
     }
 217  
     String getBirthStateProvinceCode() {
 218  1
         if (isSuppressPersonal()) {
 219  0
             return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK_CODE
 220  
         }
 221  1
         return this.birthStateProvinceCode
 222  
     }
 223  
     String getBirthCity() {
 224  1
         if (isSuppressPersonal()) {
 225  0
             return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK_CODE
 226  
         }
 227  1
         return this.birthCity
 228  
     }
 229  
     String getGeographicOrigin() {
 230  1
         if (isSuppressPersonal()) {
 231  0
             return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK_CODE
 232  
         }
 233  1
         return this.geographicOrigin
 234  
     }
 235  
 
 236  
 
 237  
     String getGenderCodeUnmasked() {
 238  0
         return this.genderCode
 239  
     }
 240  
     String getGenderChangeCodeUnmasked() {
 241  0
         return this.genderChangeCode
 242  
     }
 243  
     String getMaritalStatusCodeUnmasked() {
 244  0
         return this.maritalStatusCode
 245  
     }
 246  
     String getPrimaryLanguageCodeUnmasked() {
 247  0
         return this.primaryLanguageCode
 248  
     }
 249  
     String getSecondaryLanguageCodeUnmasked() {
 250  0
         return this.secondaryLanguageCode
 251  
     }
 252  
     String getBirthCountryUnmasked() {
 253  0
         return this.birthCountry
 254  
     }
 255  
     String getBirthStateProvinceCodeUnmasked() {
 256  0
         return this.birthStateProvinceCode
 257  
     }
 258  
     String getBirthCityUnmasked() {
 259  0
         return this.birthCity
 260  
     }
 261  
     String getGeographicOriginUnmasked() {
 262  0
         return this.geographicOrigin
 263  
     }
 264  
 }