Coverage Report - org.kuali.rice.kim.impl.identity.address.EntityAddressBo
 
Classes in this File Line Coverage Branch Coverage Complexity
EntityAddressBo
54%
39/72
28%
14/50
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.address
 17  
 
 18  
 import javax.persistence.Column
 19  
 import javax.persistence.Entity
 20  
 import javax.persistence.FetchType
 21  
 import javax.persistence.Id
 22  
 import javax.persistence.JoinColumn
 23  
 import javax.persistence.ManyToOne
 24  
 import javax.persistence.Table
 25  
 import javax.persistence.Transient
 26  
 import org.hibernate.annotations.Type
 27  
 
 28  
 import org.kuali.rice.kim.api.identity.address.EntityAddress
 29  
 import org.kuali.rice.kim.api.identity.address.EntityAddressContract
 30  
 import org.kuali.rice.kim.api.identity.privacy.EntityPrivacyPreferences
 31  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator
 32  
 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase
 33  
 import org.kuali.rice.kim.api.KimApiConstants
 34  
 import java.sql.Timestamp
 35  
 import org.joda.time.DateTime
 36  
 
 37  
 /**
 38  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 39  
  */
 40  
 @Entity
 41  
 @Table(name = "KRIM_ENTITY_ADDR_T")
 42  
 public class EntityAddressBo extends PersistableBusinessObjectBase implements EntityAddressContract {
 43  
     private static final long serialVersionUID = 1L;
 44  
 
 45  
         @Id
 46  
         @Column(name = "ENTITY_ADDR_ID")
 47  
         String id
 48  
 
 49  
         @Column(name = "ENTITY_ID")
 50  
         String entityId
 51  
 
 52  
         @Column(name = "ADDR_TYP_CD")
 53  
         String addressTypeCode
 54  
 
 55  
         @Column(name = "ENT_TYP_CD")
 56  
         String entityTypeCode
 57  
 
 58  
         @Column(name = "CITY_NM")
 59  
         String city
 60  
 
 61  
         @Column(name = "STATE_PVC_CD")
 62  
         String stateProvinceCode
 63  
 
 64  
         @Column(name = "POSTAL_CD")
 65  
         String postalCode
 66  
 
 67  
         @Column(name = "POSTAL_CNTRY_CD")
 68  
         String countryCode
 69  
 
 70  
     @Column(name = "ATTN_LINE")
 71  
         String attentionLine;
 72  
 
 73  
         @Column(name = "ADDR_LINE_1")
 74  
         String line1
 75  
 
 76  
         @Column(name = "ADDR_LINE_2")
 77  
         String line2
 78  
 
 79  
         @Column(name = "ADDR_LINE_3")
 80  
         String line3
 81  
 
 82  
     @Type(type="yes_no")
 83  
         @Column(name="DFLT_IND")
 84  
         boolean defaultValue;
 85  
 
 86  
     @Type(type="yes_no")
 87  
         @Column(name="ACTV_IND")
 88  
     boolean active;
 89  
 
 90  
         @ManyToOne(targetEntity=EntityAddressTypeBo.class, fetch=FetchType.EAGER, cascade=[])
 91  
         @JoinColumn(name = "ADDR_TYP_CD", insertable = false, updatable = false)
 92  
         EntityAddressTypeBo addressType;
 93  
 
 94  
     @Column(name = "ADDR_FMT")
 95  
     String addressFormat;
 96  
 
 97  
     @Column(name = "MOD_DT")
 98  
     Timestamp modifiedDate;
 99  
 
 100  
     @Column(name = "VALID_DT")
 101  
     Timestamp validatedDate;
 102  
 
 103  
     @Type(type="yes_no")
 104  
         @Column(name="VALID_IND")
 105  
     boolean validated;
 106  
 
 107  
     @Column(name = "NOTE_MSG")
 108  
         String noteMessage;
 109  
 
 110  
         @Transient
 111  
     boolean suppressAddress;
 112  
 
 113  
     /*
 114  
      * Converts a mutable EntityAddressBo to an immutable EntityAddress representation.
 115  
      * @param bo
 116  
      * @return an immutable EntityAddress
 117  
      */
 118  
     static EntityAddress to(EntityAddressBo bo) {
 119  0
       if (bo == null) { return null }
 120  1
       return EntityAddress.Builder.create(bo).build()
 121  
     }
 122  
 
 123  
     /**
 124  
      * Creates a EntityAddressBo business object from an immutable representation of a EntityAddress.
 125  
      * @param an immutable EntityAddress
 126  
      * @return a EntityAddressBo
 127  
      */
 128  
     static EntityAddressBo from(EntityAddress immutable) {
 129  0
         if (immutable == null) {return null}
 130  
 
 131  1
         EntityAddressBo bo = new EntityAddressBo()
 132  1
         bo.active = immutable.active
 133  1
         bo.entityTypeCode = immutable.entityTypeCode
 134  1
         if (immutable.addressType != null) {
 135  0
             bo.addressTypeCode = immutable.addressType.code
 136  
         }
 137  1
         bo.addressType = EntityAddressTypeBo.from(immutable.addressType)
 138  1
         bo.defaultValue = immutable.defaultValue
 139  1
         bo.attentionLine = immutable.attentionLineUnmasked
 140  1
         bo.line1 = immutable.line1Unmasked
 141  1
         bo.line2 = immutable.line2Unmasked
 142  1
         bo.line3 = immutable.line3Unmasked
 143  1
         bo.city = immutable.cityUnmasked
 144  1
         bo.stateProvinceCode = immutable.stateProvinceCodeUnmasked
 145  1
         bo.countryCode = immutable.countryCodeUnmasked
 146  1
         bo.postalCode = immutable.postalCodeUnmasked
 147  1
         bo.addressFormat = immutable.addressFormat
 148  1
         if (immutable.modifiedDate != null) {
 149  0
             bo.modifiedDate = new Timestamp(immutable.modifiedDate.millis);
 150  
         }
 151  1
         if (immutable.validatedDate != null) {
 152  0
             bo.validatedDate = new Timestamp(immutable.validatedDate.millis);
 153  
         }
 154  1
         bo.validated = immutable.validated
 155  1
         bo.noteMessage = immutable.noteMessage
 156  1
         bo.id = immutable.id
 157  1
         bo.entityId = immutable.entityId
 158  1
         bo.active = immutable.active
 159  1
         bo.versionNumber = immutable.versionNumber
 160  
 
 161  1
         return bo;
 162  
     }
 163  
 
 164  
 
 165  
     @Override
 166  
     EntityAddressTypeBo getAddressType() {
 167  1
         return addressType
 168  
     }
 169  
 
 170  
     public void setAddressType(EntityAddressTypeBo addressType) {
 171  1
         this.addressType = addressType
 172  
     }
 173  
 
 174  
     @Override
 175  
     boolean isSuppressAddress() {
 176  1
         if (this.suppressAddress == null) {
 177  0
             EntityPrivacyPreferences privacy = KimApiServiceLocator.getIdentityService().getEntityPrivacyPreferences(getEntityId())
 178  0
             if (privacy != null) {
 179  0
                this.suppressAddress = privacy.isSuppressAddress()
 180  
             } else {
 181  0
                 this.suppressAddress = false
 182  
             }
 183  
         }
 184  
 
 185  1
         return suppressAddress;
 186  
     }
 187  
 
 188  
     @Override
 189  
     String getAttentionLine() {
 190  0
         if (isSuppressAddress()) {
 191  0
             return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK;
 192  
         }
 193  0
         return this.attentionLine;
 194  
     }
 195  
 
 196  
     @Override
 197  
     String getLine1() {
 198  0
         if (isSuppressAddress()) {
 199  0
             return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK;
 200  
         }
 201  0
         return this.line1;
 202  
     }
 203  
 
 204  
     @Override
 205  
     String getLine2() {
 206  0
         if (isSuppressAddress()) {
 207  0
             return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK;
 208  
         }
 209  0
         return this.line2;
 210  
     }
 211  
 
 212  
     @Override
 213  
     String getLine3() {
 214  0
         if (isSuppressAddress()) {
 215  0
             return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK;
 216  
         }
 217  0
         return this.line3;
 218  
     }
 219  
 
 220  
     @Override
 221  
     String getCity() {
 222  0
         if (isSuppressAddress()) {
 223  0
             return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK;
 224  
         }
 225  0
         return this.city;
 226  
     }
 227  
 
 228  
     @Override
 229  
     String getStateProvinceCode() {
 230  0
         if (isSuppressAddress()) {
 231  0
             return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK_CODE;
 232  
         }
 233  0
         return this.stateProvinceCode;
 234  
     }
 235  
 
 236  
     @Override
 237  
     String getPostalCode() {
 238  0
         if (isSuppressAddress()) {
 239  0
             return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK_ZIP;
 240  
         }
 241  0
         return this.postalCode;
 242  
     }
 243  
 
 244  
     @Override
 245  
     String getCountryCode() {
 246  0
         if (isSuppressAddress()) {
 247  0
             return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK_CODE;
 248  
         }
 249  0
         return this.countryCode;
 250  
     }
 251  
 
 252  
     @Override
 253  
     String getAttentionLineUnmasked() {
 254  1
         return attentionLine
 255  
     }
 256  
     @Override
 257  
     String getLine1Unmasked() {
 258  1
         return line1
 259  
     }
 260  
     @Override
 261  
     String getLine2Unmasked() {
 262  1
         return line2
 263  
     }
 264  
     @Override
 265  
     String getLine3Unmasked() {
 266  1
         return line3
 267  
     }
 268  
     @Override
 269  
     String getCityUnmasked() {
 270  1
         return city
 271  
     }
 272  
     @Override
 273  
     String getStateProvinceCodeUnmasked() {
 274  1
         return stateProvinceCode
 275  
     }
 276  
     @Override
 277  
     String getPostalCodeUnmasked() {
 278  1
         return postalCode
 279  
     }
 280  
     @Override
 281  
     String getCountryCodeUnmasked() {
 282  1
         return countryCode
 283  
     }
 284  
 
 285  
     @Override
 286  
     DateTime getModifiedDate() {
 287  1
         return modifiedDate ? new DateTime(modifiedDate.time) : null
 288  
     }
 289  
 
 290  
     @Override
 291  
     DateTime getValidatedDate() {
 292  1
         return validatedDate ? new DateTime(validatedDate.time) : null
 293  
     }
 294  
 }