Coverage Report - org.kuali.rice.kim.bo.entity.dto.KimEntityInfo
 
Classes in this File Line Coverage Branch Coverage Complexity
KimEntityInfo
0%
0/110
0%
0/68
1.85
KimEntityInfo$1
0%
0/2
N/A
1.85
KimEntityInfo$2
0%
0/2
N/A
1.85
KimEntityInfo$3
0%
0/2
N/A
1.85
KimEntityInfo$4
0%
0/2
N/A
1.85
KimEntityInfo$5
0%
0/2
N/A
1.85
KimEntityInfo$XForm
N/A
N/A
1.85
 
 1  
 /*
 2  
  * Copyright 2007-2009 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.bo.entity.dto;
 17  
 
 18  
 import org.kuali.rice.kim.api.identity.EntityUtils;
 19  
 import org.kuali.rice.kim.api.identity.affiliation.EntityAffiliation;
 20  
 import org.kuali.rice.kim.api.identity.affiliation.EntityAffiliationContract;
 21  
 import org.kuali.rice.kim.api.identity.citizenship.EntityCitizenship;
 22  
 import org.kuali.rice.kim.api.identity.citizenship.EntityCitizenshipContract;
 23  
 import org.kuali.rice.kim.api.identity.name.EntityName;
 24  
 import org.kuali.rice.kim.api.identity.name.EntityNameContract;
 25  
 import org.kuali.rice.kim.api.identity.personal.EntityBioDemographics;
 26  
 import org.kuali.rice.kim.api.identity.principal.Principal;
 27  
 import org.kuali.rice.kim.api.identity.principal.PrincipalContract;
 28  
 import org.kuali.rice.kim.api.identity.privacy.EntityPrivacyPreferences;
 29  
 import org.kuali.rice.kim.api.identity.type.EntityTypeData;
 30  
 import org.kuali.rice.kim.api.identity.type.EntityTypeDataContract;
 31  
 import org.kuali.rice.kim.bo.entity.KimEntity;
 32  
 import org.kuali.rice.kim.bo.entity.KimEntityEmploymentInformation;
 33  
 import org.kuali.rice.kim.bo.entity.KimEntityEthnicity;
 34  
 import org.kuali.rice.kim.bo.entity.KimEntityExternalIdentifier;
 35  
 import org.kuali.rice.kim.bo.entity.KimEntityResidency;
 36  
 import org.kuali.rice.kim.bo.entity.KimEntityVisa;
 37  
 
 38  
 import java.util.ArrayList;
 39  
 import java.util.List;
 40  
 
 41  
 /**
 42  
  * This is a data transfer object containing all information related to a KIM
 43  
  * identity.
 44  
  * 
 45  
  * @author Kuali Rice Team (kuali-rice@googlegroups.com)
 46  
  */
 47  0
 public class KimEntityInfo extends KimInactivatableInfo implements KimEntity {
 48  
 
 49  
     private static final long serialVersionUID = 1L;
 50  
 
 51  
     private List<EntityAffiliation> affiliations;
 52  
     private EntityBioDemographics bioDemographics;
 53  
     private List<EntityCitizenship> citizenships;
 54  
     private List<KimEntityEmploymentInformationInfo> employmentInformation;
 55  
     private String entityId;
 56  
     private List<EntityTypeData> entityTypes;
 57  
     private List<KimEntityExternalIdentifierInfo> externalIdentifiers;
 58  
     private List<EntityName> names;
 59  
     private List<Principal> principals;
 60  
     private EntityPrivacyPreferences privacyPreferences;
 61  
     private List<KimEntityEthnicityInfo> ethnicities;
 62  
     private List<KimEntityResidencyInfo> residencies;
 63  
     private List<KimEntityVisaInfo> visas;
 64  
 
 65  
     /**
 66  
      * This constructs an empty KimEntityInfo
 67  
      */
 68  
     public KimEntityInfo() {
 69  0
         super();
 70  0
         active = true;
 71  0
     }
 72  
 
 73  
     /**
 74  
      * This constructs a KimEntityInfo derived from the {@link KimEntity} passed in.
 75  
      * 
 76  
      * @param entity the {@link KimEntity} that this KimEntityInfo is derived from.  If null, then an empty 
 77  
      * KimEntityInfo will be constructed.
 78  
      */
 79  
     public KimEntityInfo(KimEntity entity) {
 80  0
         this();
 81  
 
 82  0
         if (entity != null) {
 83  
 
 84  0
             entityId = entity.getEntityId();
 85  0
             active = entity.isActive();
 86  
 
 87  
             // See comments by utility method deriveCollection for why this is used.  
 88  
             // Essentially, the constructor was too darned long.
 89  
 
 90  0
             principals = new ArrayList<Principal>();
 91  0
             for (PrincipalContract contract : entity.getPrincipals()) {
 92  0
                 principals.add(Principal.Builder.create(contract).build());
 93  
             }
 94  
 
 95  0
             if (entity.getBioDemographics() != null) {
 96  0
                 bioDemographics = EntityBioDemographics.Builder.create(entity.getBioDemographics()).build();
 97  
             }
 98  
 
 99  0
             if (entity.getPrivacyPreferences() != null) {
 100  0
                 privacyPreferences = EntityPrivacyPreferences.Builder.create(entity.getPrivacyPreferences()).build();
 101  
             }
 102  
 
 103  0
             names = new ArrayList<EntityName>();
 104  0
             for (EntityNameContract name : entity.getNames()) {
 105  0
                 names.add(EntityName.Builder.create(name).build());
 106  
             }
 107  
 
 108  0
             entityTypes = new ArrayList<EntityTypeData>();
 109  0
             for (EntityTypeDataContract contract : entity.getEntityTypes()) {
 110  0
                 entityTypes.add(EntityTypeData.Builder.create(contract).build());
 111  
             }
 112  
 
 113  0
             affiliations = new ArrayList<EntityAffiliation>();
 114  0
             for (EntityAffiliationContract contract : entity.getAffiliations()) {
 115  0
                 affiliations.add(EntityAffiliation.Builder.create(contract).build());
 116  
             }
 117  
 
 118  0
             employmentInformation = deriveCollection(entity.getEmploymentInformation(), 
 119  0
                     new XForm<KimEntityEmploymentInformation, KimEntityEmploymentInformationInfo>() {
 120  
                 public KimEntityEmploymentInformationInfo xform(KimEntityEmploymentInformation source) {
 121  0
                     return new KimEntityEmploymentInformationInfo(source);
 122  
                 }
 123  
             });
 124  
 
 125  0
             externalIdentifiers = deriveCollection(entity.getExternalIdentifiers(), 
 126  0
                     new XForm<KimEntityExternalIdentifier, KimEntityExternalIdentifierInfo>() {
 127  
                 public KimEntityExternalIdentifierInfo xform(KimEntityExternalIdentifier source) {
 128  0
                     return new KimEntityExternalIdentifierInfo(source); 
 129  
                 }
 130  
             });        
 131  
 
 132  0
             citizenships = new ArrayList<EntityCitizenship>();
 133  0
             for (EntityCitizenshipContract contract : entity.getCitizenships()) {
 134  0
                 citizenships.add(EntityCitizenship.Builder.create(contract).build());
 135  
             }
 136  
 
 137  0
             ethnicities = deriveCollection(entity.getEthnicities(), new XForm<KimEntityEthnicity, KimEntityEthnicityInfo>() {
 138  
                 public KimEntityEthnicityInfo xform(KimEntityEthnicity source) {
 139  0
                     return new KimEntityEthnicityInfo(source);
 140  
                 }
 141  
             });
 142  
 
 143  0
             residencies = deriveCollection(entity.getResidencies(), new XForm<KimEntityResidency, KimEntityResidencyInfo>() {
 144  
                 public KimEntityResidencyInfo xform(KimEntityResidency source) {
 145  0
                     return new KimEntityResidencyInfo(source);
 146  
                 }
 147  
             });
 148  
 
 149  0
             visas = deriveCollection(entity.getVisas(), new XForm<KimEntityVisa, KimEntityVisaInfo>() {
 150  
                 public KimEntityVisaInfo xform(KimEntityVisa source) {
 151  0
                     return new KimEntityVisaInfo(source);
 152  
                 }
 153  
             });
 154  
         }
 155  0
     }
 156  
 
 157  
     /** 
 158  
      * {@inheritDoc}
 159  
      * @see KimEntity#getAffiliations()
 160  
      */
 161  
     public List<EntityAffiliation> getAffiliations() {
 162  
         // If our reference is null, assign and return an empty List
 163  0
         return (affiliations != null) ? affiliations : (affiliations = new ArrayList<EntityAffiliation>());
 164  
 
 165  
     }
 166  
 
 167  
     /** 
 168  
      * Setter for this {@link KimEntityInfo}'s affiliations.  Note the behavior of {@link #getAffiliations()} if
 169  
      * this is set to null;
 170  
      */
 171  
     public void setAffiliations(List<EntityAffiliation> affiliations) {
 172  0
         this.affiliations = affiliations;
 173  0
     }
 174  
 
 175  
     /** 
 176  
      * {@inheritDoc}
 177  
      * @see KimEntity#getDefaultAffiliation()
 178  
      */
 179  
     public EntityAffiliation getDefaultAffiliation() {
 180  0
         return EntityUtils.getDefaultItem(affiliations);
 181  
     }
 182  
 
 183  
     /** 
 184  
      * {@inheritDoc}
 185  
      * @see KimEntity#getBioDemographics()
 186  
      */
 187  
     public EntityBioDemographics getBioDemographics() {
 188  0
         return bioDemographics;
 189  
     }
 190  
 
 191  
     /** 
 192  
      * Setter for this {@link KimEntityInfo}'s demographic information.  Note the behavior of 
 193  
      * {@link #getBioDemographics()} if this is set to null;
 194  
      */
 195  
     public void setBioDemographics(EntityBioDemographics bioDemographics) {
 196  0
         this.bioDemographics = bioDemographics;
 197  0
     }
 198  
 
 199  
     /** 
 200  
      * {@inheritDoc}
 201  
      * @see KimEntity#getCitizenships()
 202  
      */
 203  
     public List<EntityCitizenship> getCitizenships() {
 204  
         // If our reference is null, assign and return an empty List
 205  0
         return (citizenships != null) ? citizenships : (citizenships = new ArrayList<EntityCitizenship>());
 206  
 
 207  
     }
 208  
 
 209  
     /** 
 210  
      * Setter for this {@link KimEntityInfo}'s demographic information.  Note the behavior of 
 211  
      * {@link #getCitizenships()} if this is set to null;
 212  
      */
 213  
     public void setCitizenships(List<EntityCitizenship> citizenships) {
 214  0
         this.citizenships = citizenships;
 215  0
     }
 216  
 
 217  
     /** 
 218  
      * {@inheritDoc}
 219  
      * @see KimEntity#getEmploymentInformation()
 220  
      */
 221  
     public List<KimEntityEmploymentInformationInfo> getEmploymentInformation() {
 222  
         // If our reference is null, assign and return an empty List
 223  0
         return (employmentInformation != null) ? employmentInformation
 224  
                 : (employmentInformation = new ArrayList<KimEntityEmploymentInformationInfo>());
 225  
     }
 226  
 
 227  
     /** 
 228  
      * Setter for this {@link KimEntityInfo}'s employment information.  Note the behavior of 
 229  
      * {@link #getEmploymentInformation()} if this is set to null;
 230  
      */
 231  
     public void setEmploymentInformation(List<KimEntityEmploymentInformationInfo> employmentInformation) {
 232  0
         this.employmentInformation = employmentInformation;
 233  0
     }
 234  
 
 235  
     /** 
 236  
      * {@inheritDoc}
 237  
      * @see KimEntity#getPrimaryEmployment()
 238  
      */
 239  
     public KimEntityEmploymentInformationInfo getPrimaryEmployment() {
 240  0
         KimEntityEmploymentInformationInfo result = null;
 241  0
         if (employmentInformation != null)
 242  0
             for (KimEntityEmploymentInformationInfo employment : employmentInformation) {
 243  0
                 if (employment.isPrimary()) {
 244  0
                     result = employment;
 245  
                 }
 246  
             }
 247  0
         return result;
 248  
     }
 249  
 
 250  
     /**
 251  
      * {@inheritDoc}
 252  
      * @see KimEntity#getEntityId()
 253  
      */
 254  
     public String getEntityId() {
 255  0
         return entityId;
 256  
     }
 257  
 
 258  
     /** 
 259  
      * Setter for this {@link KimEntityInfo}'s identity id.  Note the behavior of
 260  
      * {@link #getEntityId()} if this is set to null;
 261  
      */
 262  
     public void setEntityId(String entityId) {
 263  0
         this.entityId = entityId;
 264  0
     }
 265  
 
 266  
     /**
 267  
      * {@inheritDoc}
 268  
      * @see KimEntity#getEntityTypes()
 269  
      */
 270  
     public List<EntityTypeData> getEntityTypes() {
 271  
         // If our reference is null, assign and return an empty List
 272  0
         return (entityTypes != null) ? entityTypes : (entityTypes = new ArrayList<EntityTypeData>());
 273  
     }
 274  
 
 275  
     /** 
 276  
      * Setter for this {@link KimEntityInfo}'s identity types.  Note the behavior of
 277  
      * {@link #getEntityTypes()} if this is set to null;
 278  
      */
 279  
     public void setEntityTypes(List<EntityTypeData> entityTypes) {
 280  0
         this.entityTypes = entityTypes;
 281  0
     }
 282  
 
 283  
     /**
 284  
      * {@inheritDoc}
 285  
      * @see KimEntity#getExternalIdentifiers()
 286  
      */
 287  
     public List<KimEntityExternalIdentifierInfo> getExternalIdentifiers() {
 288  
         // If our reference is null, assign and return an empty List
 289  0
         return (externalIdentifiers != null) ? externalIdentifiers
 290  
                 : (externalIdentifiers = new ArrayList<KimEntityExternalIdentifierInfo>());
 291  
     }
 292  
 
 293  
     /** 
 294  
      * Setter for this {@link KimEntityInfo}'s external identifiers.  Note the behavior of 
 295  
      * {@link #getExternalIdentifiers()} if this is set to null;
 296  
      */
 297  
     public void setExternalIdentifiers(List<KimEntityExternalIdentifierInfo> externalIdentifiers) {
 298  0
         this.externalIdentifiers = externalIdentifiers;
 299  0
     }
 300  
 
 301  
     /**
 302  
      * {@inheritDoc}
 303  
      * @see KimEntity#getNames()
 304  
      */
 305  
     public List<EntityName> getNames() {
 306  
         // If our reference is null, assign and return an empty List
 307  0
         return (names != null) ? names : (names = new ArrayList<EntityName>());
 308  
     }
 309  
 
 310  
     /** 
 311  
      * Setter for this {@link KimEntityInfo}'s names.  Note the behavior of 
 312  
      * {@link #getNames()} if this is set to null;
 313  
      */
 314  
     public void setNames(List<EntityName> names) {
 315  0
         this.names = names;
 316  0
     }
 317  
 
 318  
     /**
 319  
      * {@inheritDoc}
 320  
      * @see KimEntity#getDefaultName()
 321  
      */
 322  
     public EntityName getDefaultName() {
 323  0
         EntityName result = null;
 324  0
         for (EntityName name : this.getNames()) {
 325  0
             if (result == null) {
 326  0
                 result = name;
 327  
             }
 328  0
             if (name.isDefaultValue()) {
 329  0
                 result = name;
 330  0
                 break;
 331  
             }
 332  
         }
 333  0
         return result;
 334  
     }
 335  
 
 336  
     /**
 337  
      * {@inheritDoc}
 338  
      * @see KimEntity#getPrincipals()
 339  
      */
 340  
     public List<Principal> getPrincipals() {
 341  
         // If our reference is null, assign and return an empty List
 342  0
         return (principals != null) ? principals : (principals = new ArrayList<Principal>());
 343  
     }
 344  
 
 345  
     /** 
 346  
      * Setter for this {@link KimEntityInfo}'s principals.  Note the behavior of 
 347  
      * {@link #getPrincipals()} if this is set to null;
 348  
      */
 349  
     public void setPrincipals(List<Principal> principals) {
 350  0
         this.principals = principals;
 351  0
     }
 352  
 
 353  
     /**
 354  
      * {@inheritDoc}
 355  
      * @see KimEntity#getPrivacyPreferences()
 356  
      */
 357  
     public EntityPrivacyPreferences getPrivacyPreferences() {
 358  0
         return privacyPreferences;
 359  
     }
 360  
 
 361  
     /** 
 362  
      * Setter for this {@link KimEntityInfo}'s privacy preferences.  Note the behavior of 
 363  
      * {@link #getPrivacyPreferences()} if this is set to null;
 364  
      */
 365  
     public void setPrivacyPreferences(EntityPrivacyPreferences privacyPreferences) {
 366  0
         this.privacyPreferences = privacyPreferences;
 367  0
     }
 368  
 
 369  
     /**
 370  
      * {@inheritDoc}
 371  
      * @see KimEntity#getEthnicities()
 372  
      */
 373  
     public List<KimEntityEthnicityInfo> getEthnicities() {
 374  
         // If our reference is null, assign and return an empty List
 375  0
         return (ethnicities != null) ? ethnicities : (ethnicities = new ArrayList<KimEntityEthnicityInfo>());
 376  
     }
 377  
 
 378  
     /** 
 379  
      * Setter for this {@link KimEntityInfo}'s ethnicities.  Note the behavior of 
 380  
      * {@link #getEthnicities()} if this is set to null;
 381  
      */
 382  
     public void setEthnicities(List<KimEntityEthnicityInfo> ethnicities) {
 383  0
         this.ethnicities = ethnicities;
 384  0
     }
 385  
 
 386  
     /**
 387  
      * {@inheritDoc}
 388  
      * @see KimEntity#getResidencies()
 389  
      */
 390  
     public List<KimEntityResidencyInfo> getResidencies() {
 391  
         // If our reference is null, assign and return an empty List
 392  0
         return (residencies != null) ? residencies : (residencies = new ArrayList<KimEntityResidencyInfo>());
 393  
     }
 394  
 
 395  
     /** 
 396  
      * Setter for this {@link KimEntityInfo}'s residencies.  Note the behavior of 
 397  
      * {@link #getResidencies()} if this is set to null;
 398  
      */
 399  
     public void setResidencies(List<KimEntityResidencyInfo> residencies) {
 400  0
         this.residencies = residencies;
 401  0
     }
 402  
 
 403  
     /**
 404  
      * {@inheritDoc}
 405  
      * @see KimEntity#getVisas()
 406  
      */
 407  
     public List<KimEntityVisaInfo> getVisas() {
 408  
         // If our reference is null, assign and return an empty List
 409  0
         return (visas != null) ? visas : (visas = new ArrayList<KimEntityVisaInfo>());
 410  
     }
 411  
 
 412  
     /** 
 413  
      * Setter for this {@link KimEntityInfo}'s visas.  Note the behavior of 
 414  
      * {@link #getVisas()} if this is set to null;
 415  
      */
 416  
     public void setVisas(List<KimEntityVisaInfo> visas) {
 417  0
         this.visas = visas;
 418  0
     }
 419  
 
 420  
     /**
 421  
      * {@inheritDoc}
 422  
      * @see KimEntity#getEntityExternalIdentifier(String)
 423  
      */
 424  
     public KimEntityExternalIdentifier getEntityExternalIdentifier(String externalIdentifierTypeCode) {
 425  0
         KimEntityExternalIdentifier result = null;
 426  
 
 427  0
         List<KimEntityExternalIdentifierInfo> externalIdentifiers = getExternalIdentifiers();
 428  0
         if (externalIdentifiers != null)
 429  0
             for (KimEntityExternalIdentifier eid : externalIdentifiers) {
 430  0
                 if (eid.getExternalIdentifierTypeCode().equals(externalIdentifierTypeCode)) {
 431  0
                     result = eid;
 432  
                 }
 433  
             }
 434  0
         return result;
 435  
     }
 436  
 
 437  
     /**
 438  
      * {@inheritDoc}
 439  
      * @see KimEntity#getEntityType(String)
 440  
      */
 441  
     public EntityTypeData getEntityType(String entityTypeCode) {
 442  0
         EntityTypeData result = null;
 443  
 
 444  0
         if (entityTypes != null)
 445  0
             for (EntityTypeData eType : entityTypes) {
 446  0
                 if (eType.getEntityTypeCode().equals(entityTypeCode)) {
 447  0
                     result = eType;
 448  
                 }
 449  
             }
 450  0
         return result;
 451  
     }
 452  
     
 453  
     /*
 454  
         // utility method converts this monstrous block:
 455  
         
 456  
         if (identity.getEntityTypes() != null) {
 457  
             entityTypes = new ArrayList<KimEntityEntityTypeInfo>(identity.getEntityTypes().size());
 458  
 
 459  
             for (KimEntityEntityType entityEntityType : identity.getEntityTypes()) if (entityEntityType != null) {
 460  
                 entityTypes.add(new KimEntityEntityTypeInfo(entityEntityType));
 461  
             }
 462  
         } else {
 463  
             entityTypes = new ArrayList<KimEntityEntityTypeInfo>();
 464  
         }
 465  
         
 466  
         // to this:
 467  
         
 468  
         entityTypes = deriveCollection(identity.getEntityTypes(), new XForm<KimEntityEntityType, KimEntityEntityTypeInfo>() {
 469  
             public KimEntityEntityTypeInfo xform(KimEntityEntityType source) {
 470  
                 return new KimEntityEntityTypeInfo(source);
 471  
             }
 472  
         });
 473  
      
 474  
         // Note that generic type C is required because some of the source collections use wildcards
 475  
      */
 476  
     private static <A,B,C> List<B> deriveCollection(List<A> source, XForm<C,B> transformer) {
 477  0
         List<B> result = null;
 478  0
         if (source != null) {
 479  0
             result = new ArrayList<B>(source.size());
 480  
             
 481  0
             for (A element : source) if (element != null) {
 482  0
                 B mutant = transformer.xform((C)element);
 483  0
                 if (mutant != null) {
 484  0
                     result.add(mutant);
 485  
                 }
 486  0
             }
 487  
         } else {
 488  0
             result = new ArrayList();
 489  
         }
 490  0
         return result;
 491  
     }
 492  
     
 493  
     private static interface XForm<A,B> {
 494  
         public B xform(A source);
 495  
     }
 496  
 
 497  
 }