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