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