Coverage Report - org.kuali.rice.kim.service.impl.IdentityServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
IdentityServiceImpl
0%
0/208
0%
0/104
3.026
 
 1  
 /*
 2  
  * Copyright 2008-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.service.impl;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.kim.api.entity.Type;
 20  
 import org.kuali.rice.kim.api.entity.principal.Principal;
 21  
 import org.kuali.rice.kim.api.entity.privacy.EntityPrivacyPreferences;
 22  
 import org.kuali.rice.kim.api.entity.services.IdentityService;
 23  
 import org.kuali.rice.kim.api.entity.type.EntityTypeDataDefault;
 24  
 import org.kuali.rice.kim.bo.entity.KimEntityAffiliation;
 25  
 import org.kuali.rice.kim.bo.entity.KimEntityExternalIdentifier;
 26  
 import org.kuali.rice.kim.bo.entity.dto.KimEntityAffiliationInfo;
 27  
 import org.kuali.rice.kim.bo.entity.dto.KimEntityDefaultInfo;
 28  
 import org.kuali.rice.kim.bo.entity.dto.KimEntityEmploymentInformationInfo;
 29  
 import org.kuali.rice.kim.bo.entity.dto.KimEntityExternalIdentifierInfo;
 30  
 import org.kuali.rice.kim.bo.entity.dto.KimEntityInfo;
 31  
 import org.kuali.rice.kim.bo.entity.dto.KimEntityNameInfo;
 32  
 import org.kuali.rice.kim.bo.entity.dto.KimEntityNamePrincipalNameInfo;
 33  
 import org.kuali.rice.kim.bo.entity.impl.KimEntityImpl;
 34  
 import org.kuali.rice.kim.bo.entity.impl.KimEntityNameImpl;
 35  
 import org.kuali.rice.kim.bo.reference.dto.AffiliationTypeInfo;
 36  
 import org.kuali.rice.kim.bo.reference.dto.EmploymentStatusInfo;
 37  
 import org.kuali.rice.kim.bo.reference.dto.EmploymentTypeInfo;
 38  
 import org.kuali.rice.kim.bo.reference.dto.EntityNameTypeInfo;
 39  
 import org.kuali.rice.kim.bo.reference.dto.ExternalIdentifierTypeInfo;
 40  
 import org.kuali.rice.kim.bo.reference.impl.AffiliationTypeImpl;
 41  
 import org.kuali.rice.kim.bo.reference.impl.EmploymentStatusImpl;
 42  
 import org.kuali.rice.kim.bo.reference.impl.EmploymentTypeImpl;
 43  
 import org.kuali.rice.kim.bo.reference.impl.EntityNameTypeImpl;
 44  
 import org.kuali.rice.kim.bo.reference.impl.ExternalIdentifierTypeImpl;
 45  
 import org.kuali.rice.kim.impl.entity.EntityTypeBo;
 46  
 import org.kuali.rice.kim.impl.entity.address.EntityAddressBo;
 47  
 import org.kuali.rice.kim.impl.entity.address.EntityAddressTypeBo;
 48  
 import org.kuali.rice.kim.impl.entity.citizenship.EntityCitizenshipStatusBo;
 49  
 import org.kuali.rice.kim.impl.entity.email.EntityEmailBo;
 50  
 import org.kuali.rice.kim.impl.entity.email.EntityEmailTypeBo;
 51  
 import org.kuali.rice.kim.impl.entity.phone.EntityPhoneBo;
 52  
 import org.kuali.rice.kim.impl.entity.phone.EntityPhoneTypeBo;
 53  
 import org.kuali.rice.kim.impl.entity.principal.PrincipalBo;
 54  
 import org.kuali.rice.kim.impl.entity.privacy.EntityPrivacyPreferencesBo;
 55  
 import org.kuali.rice.kim.impl.entity.type.EntityTypeDataBo;
 56  
 import org.kuali.rice.kim.service.IdentityUpdateService;
 57  
 import org.kuali.rice.kim.util.KIMPropertyConstants;
 58  
 import org.kuali.rice.kim.util.KIMWebServiceConstants;
 59  
 import org.kuali.rice.kns.lookup.CollectionIncomplete;
 60  
 import org.kuali.rice.kns.service.BusinessObjectService;
 61  
 import org.kuali.rice.kns.service.KNSServiceLocator;
 62  
 import org.kuali.rice.kns.service.KNSServiceLocatorWeb;
 63  
 import org.kuali.rice.kns.util.ObjectUtils;
 64  
 
 65  
 import javax.jws.WebService;
 66  
 import java.util.ArrayList;
 67  
 import java.util.Collection;
 68  
 import java.util.Collections;
 69  
 import java.util.HashMap;
 70  
 import java.util.List;
 71  
 import java.util.Map;
 72  
 
 73  
 /**
 74  
  * Base implementation of the identity (entity) service.  This version assumes the KimEntity
 75  
  * and related data is located within the KIM database. 
 76  
  * 
 77  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 78  
  */
 79  
 
 80  
 @WebService(endpointInterface = KIMWebServiceConstants.IdentityService.INTERFACE_CLASS, serviceName = KIMWebServiceConstants.IdentityService.WEB_SERVICE_NAME, portName = KIMWebServiceConstants.IdentityService.WEB_SERVICE_PORT, targetNamespace = KIMWebServiceConstants.MODULE_TARGET_NAMESPACE)
 81  0
 public class IdentityServiceImpl implements IdentityService, IdentityUpdateService {
 82  
 
 83  
         private BusinessObjectService businessObjectService;
 84  
 
 85  
         /**
 86  
          * @see org.kuali.rice.kim.api.entity.services.IdentityService#getEntityInfo(java.lang.String)
 87  
          */
 88  
         public KimEntityInfo getEntityInfo(String entityId) {
 89  0
                 KimEntityImpl entity = getEntityImpl( entityId );
 90  0
                 if ( entity == null ) {
 91  0
                         return null;
 92  
                 }
 93  0
                 return convertEntityImplToInfo( entity );
 94  
         }
 95  
         
 96  
         /**
 97  
          * @see org.kuali.rice.kim.api.entity.services.IdentityService#getEntityInfoByPrincipalId(java.lang.String)
 98  
          */
 99  
         public KimEntityInfo getEntityInfoByPrincipalId(String principalId) {
 100  0
                 KimEntityImpl entity = getEntityByPrincipalId(principalId);
 101  0
                 if ( entity == null ) {
 102  0
                         return null;
 103  
                 }
 104  0
                 return convertEntityImplToInfo(entity);
 105  
         }
 106  
         
 107  
         /**
 108  
          * @see org.kuali.rice.kim.api.entity.services.IdentityService#getEntityInfoByPrincipalName(java.lang.String)
 109  
          */
 110  
         public KimEntityInfo getEntityInfoByPrincipalName(String principalName) {
 111  0
                 KimEntityImpl entity = getEntityByPrincipalName(principalName);
 112  0
                 if ( entity == null ) {
 113  0
                         return null;
 114  
                 }
 115  0
                 return convertEntityImplToInfo(entity);
 116  
         }
 117  
         
 118  
         /**
 119  
          * @see org.kuali.rice.kim.api.entity.services.IdentityService#getEntityDefaultInfo(java.lang.String)
 120  
          */
 121  
         public KimEntityDefaultInfo getEntityDefaultInfo(String entityId) {
 122  0
                 KimEntityImpl entity = getEntityImpl( entityId );
 123  0
                 if ( entity == null ) {
 124  0
                         return null;
 125  
                 }
 126  0
                 return convertEntityImplToDefaultInfo( entity );
 127  
         }
 128  
         
 129  
         /**
 130  
          * @see org.kuali.rice.kim.api.entity.services.IdentityService#getEntityDefaultInfoByPrincipalId(java.lang.String)
 131  
          */
 132  
         public KimEntityDefaultInfo getEntityDefaultInfoByPrincipalId(String principalId) {
 133  0
                 KimEntityImpl entity = getEntityByPrincipalId(principalId);
 134  0
                 if ( entity == null ) {
 135  0
                         return null;
 136  
                 }
 137  0
                 return convertEntityImplToDefaultInfo(entity);
 138  
         }
 139  
         
 140  
         /**
 141  
          * @see org.kuali.rice.kim.api.entity.services.IdentityService#getEntityDefaultInfoByPrincipalName(java.lang.String)
 142  
          */
 143  
         public KimEntityDefaultInfo getEntityDefaultInfoByPrincipalName(String principalName) {
 144  0
                 KimEntityImpl entity = getEntityByPrincipalName(principalName);
 145  0
                 if ( entity == null ) {
 146  0
                         return null;
 147  
                 }
 148  0
                 return convertEntityImplToDefaultInfo(entity);
 149  
         }
 150  
         
 151  
         /**
 152  
          * @see org.kuali.rice.kim.api.entity.services.IdentityService#getPrincipalByPrincipalNameAndPassword(java.lang.String, java.lang.String)
 153  
          */
 154  
         @SuppressWarnings("unchecked")
 155  
         public Principal getPrincipalByPrincipalNameAndPassword(String principalName, String password) {
 156  0
                  Map<String,Object> criteria = new HashMap<String,Object>(3);
 157  0
          criteria.put(KIMPropertyConstants.Principal.PRINCIPAL_NAME, principalName);
 158  0
          criteria.put(KIMPropertyConstants.Principal.PASSWORD, password);
 159  0
          criteria.put(KIMPropertyConstants.Principal.ACTIVE, true);
 160  0
          Collection<PrincipalBo> principals = getBusinessObjectService().findMatching(PrincipalBo.class, criteria);
 161  
 
 162  0
          if (!principals.isEmpty()) {
 163  0
              return PrincipalBo.to(principals.iterator().next());
 164  
          }
 165  0
          return null;
 166  
         }
 167  
         
 168  
         /**
 169  
          * @see org.kuali.rice.kim.api.entity.services.IdentityService#lookupEntityInfo(Map, boolean)
 170  
          */
 171  
         @SuppressWarnings("unchecked")
 172  
         public List<KimEntityInfo> lookupEntityInfo(
 173  
                         Map<String,String> searchCriteria, boolean unbounded) {
 174  0
                 Collection baseResults = lookupEntityImpls(searchCriteria, unbounded);
 175  0
                 List<KimEntityInfo> results = new ArrayList<KimEntityInfo>( baseResults.size() );
 176  0
                 for ( KimEntityImpl entity : (Collection<KimEntityImpl>)baseResults ) {
 177  0
                         results.add( convertEntityImplToInfo( entity ) );
 178  
                 }
 179  0
                 if ( baseResults instanceof CollectionIncomplete ) {
 180  0
                         results = new CollectionIncomplete<KimEntityInfo>( results, ((CollectionIncomplete<KimEntityInfo>)baseResults).getActualSizeIfTruncated() ); 
 181  
                 }                
 182  0
                 return results;
 183  
         }
 184  
         /**
 185  
          * @see org.kuali.rice.kim.api.entity.services.IdentityService#lookupEntityDefaultInfo(Map, boolean)
 186  
          */
 187  
         @SuppressWarnings("unchecked")
 188  
         public List<KimEntityDefaultInfo> lookupEntityDefaultInfo(
 189  
                         Map<String,String> searchCriteria, boolean unbounded) {
 190  0
                 Collection baseResults = lookupEntityImpls(searchCriteria, unbounded);
 191  0
                 List<KimEntityDefaultInfo> results = new ArrayList<KimEntityDefaultInfo>( baseResults.size() );
 192  0
                 for ( KimEntityImpl entity : (Collection<KimEntityImpl>)baseResults ) {
 193  0
                         results.add( convertEntityImplToDefaultInfo( entity ) );
 194  
                 }
 195  0
                 if ( baseResults instanceof CollectionIncomplete ) {
 196  0
                         results = new CollectionIncomplete<KimEntityDefaultInfo>( results, ((CollectionIncomplete<KimEntityDefaultInfo>)baseResults).getActualSizeIfTruncated() ); 
 197  
                 }                
 198  0
                 return results;
 199  
         }
 200  
 
 201  
         protected Collection lookupEntityImpls(Map<String,String> searchCriteria, boolean unbounded) {
 202  0
                 if ( unbounded ) {
 203  0
                         return KNSServiceLocatorWeb.getLookupService().findCollectionBySearchUnbounded( KimEntityImpl.class, searchCriteria );
 204  
                 } else {
 205  0
                         return KNSServiceLocatorWeb.getLookupService().findCollectionBySearch( KimEntityImpl.class, searchCriteria );
 206  
                 }
 207  
         }
 208  
 
 209  
         /**
 210  
          * @see org.kuali.rice.kim.api.entity.services.IdentityService#getMatchingEntityCount(java.util.Map)
 211  
          */
 212  
         public int getMatchingEntityCount(Map<String,String> searchCriteria) {
 213  0
                 return getBusinessObjectService().countMatching( KimEntityImpl.class, searchCriteria );
 214  
         }
 215  
         
 216  
         protected KimEntityInfo convertEntityImplToInfo( KimEntityImpl entity ) {
 217  0
                 return new KimEntityInfo(entity);
 218  
         }
 219  
 
 220  
         protected KimEntityDefaultInfo convertEntityImplToDefaultInfo( KimEntityImpl entity ) {
 221  0
                 KimEntityDefaultInfo info = new KimEntityDefaultInfo();
 222  0
                 info.setEntityId( entity.getEntityId() );
 223  0
                 info.setActive( entity.isActive() );
 224  0
                 ArrayList<Principal> principalInfo = new ArrayList<Principal>( entity.getPrincipals().size() );
 225  0
                 info.setPrincipals( principalInfo );
 226  0
                 for ( PrincipalBo p : entity.getPrincipals() ) {
 227  0
                         principalInfo.add( PrincipalBo.to(p) );
 228  
                 }
 229  0
                 EntityPrivacyPreferences privacy = null;
 230  0
                 if ( ObjectUtils.isNotNull( entity.getPrivacyPreferences() ) ) {
 231  0
             privacy = EntityPrivacyPreferences.Builder.create(entity.getPrivacyPreferences()).build();
 232  
         }
 233  
 
 234  0
                 info.setPrivacyPreferences(privacy);
 235  0
                 info.setDefaultName( new KimEntityNameInfo( entity.getDefaultName() ) );
 236  0
                 ArrayList<EntityTypeDataDefault> entityTypesInfo = new ArrayList<EntityTypeDataDefault>( entity.getEntityTypes().size() );
 237  0
                 info.setEntityTypes( entityTypesInfo );
 238  0
                 for ( EntityTypeDataBo entityTypeDataBo : entity.getEntityTypes() ) {
 239  0
                         entityTypesInfo.add( EntityTypeDataBo.toDefault(entityTypeDataBo) );
 240  
                 }
 241  
                 
 242  0
                 ArrayList<KimEntityAffiliationInfo> affInfo = new ArrayList<KimEntityAffiliationInfo>( entity.getAffiliations().size() );
 243  0
                 info.setAffiliations( affInfo );
 244  0
                 for ( KimEntityAffiliation aff : entity.getAffiliations() ) {
 245  0
                         affInfo.add( new KimEntityAffiliationInfo( aff ) );
 246  0
                         if ( aff.isActive() && aff.isDefaultValue() ) {
 247  0
                                 info.setDefaultAffiliation( affInfo.get( affInfo.size() - 1 ) );
 248  
                         }
 249  
                 }
 250  0
                 info.setPrimaryEmployment( new KimEntityEmploymentInformationInfo( entity.getPrimaryEmployment() ) );
 251  0
                 ArrayList<KimEntityExternalIdentifierInfo> idInfo = new ArrayList<KimEntityExternalIdentifierInfo>( entity.getExternalIdentifiers().size() );
 252  0
                 info.setExternalIdentifiers( idInfo );
 253  0
                 for ( KimEntityExternalIdentifier id : entity.getExternalIdentifiers() ) {
 254  0
                         idInfo.add( new KimEntityExternalIdentifierInfo( id ) );
 255  
                 }
 256  0
                 return info;
 257  
         }
 258  
         
 259  
         /**
 260  
          * @see org.kuali.rice.kim.api.entity.services.IdentityService#getEntityPrivacyPreferences(java.lang.String)
 261  
          */
 262  
         public EntityPrivacyPreferences getEntityPrivacyPreferences(String entityId) {
 263  0
                 Map<String,String> criteria = new HashMap<String,String>(1);
 264  0
         criteria.put(KIMPropertyConstants.Entity.ENTITY_ID, entityId);
 265  0
                 return EntityPrivacyPreferencesBo.to(getBusinessObjectService().findByPrimaryKey(EntityPrivacyPreferencesBo.class, criteria));
 266  
         }
 267  
 
 268  
         /**
 269  
          * @see org.kuali.rice.kim.api.entity.services.IdentityService#getPrincipal(java.lang.String)
 270  
          */
 271  
         public Principal getPrincipal(String principalId) {
 272  0
                 PrincipalBo principal = getPrincipalImpl( principalId );
 273  0
                 if ( principal == null ) {
 274  0
                         return null;
 275  
                 }
 276  0
                 return PrincipalBo.to(principal);
 277  
         }
 278  
         
 279  
         private PrincipalBo getPrincipalImpl(String principalId) {
 280  0
                 Map<String,String> criteria = new HashMap<String,String>(1);
 281  0
         criteria.put(KIMPropertyConstants.Principal.PRINCIPAL_ID, principalId);
 282  0
                 return getBusinessObjectService().findByPrimaryKey(PrincipalBo.class, criteria);
 283  
         }
 284  
 
 285  
         public KimEntityImpl getEntityImpl(String entityId) {
 286  0
                 KimEntityImpl entityImpl = getBusinessObjectService().findByPrimaryKey(KimEntityImpl.class, Collections.singletonMap("entityId", entityId));
 287  0
         if(entityImpl!=null) {
 288  0
                 entityImpl.refresh();
 289  
             /*TODO: We need to try and remove this.  Currently, without it, some integration tests fail because of some
 290  
              * sort of OJB caching and not filling in the type values.  We need to figure out why this is happening and fix it.
 291  
              * Yes, this is a hack :P
 292  
              */
 293  0
             for (EntityTypeDataBo type : entityImpl.getEntityTypes()) {
 294  0
                 type.refresh();
 295  0
                 for (EntityAddressBo addressBo : type.getAddresses()) {
 296  0
                     addressBo.refreshReferenceObject("addressType");
 297  
                 }
 298  0
                 for (EntityEmailBo emailBo : type.getEmailAddresses()) {
 299  0
                     emailBo.refreshReferenceObject("emailType");
 300  
                 }
 301  0
                 for (EntityPhoneBo phoneBo : type.getPhoneNumbers()) {
 302  0
                     phoneBo.refreshReferenceObject("phoneType");
 303  
                 }
 304  
             }
 305  
         }
 306  0
         return entityImpl;
 307  
         }
 308  
         
 309  
         /**
 310  
          * @see org.kuali.rice.kim.api.entity.services.IdentityService#lookupEntitys(java.util.Map)
 311  
          */
 312  
         @SuppressWarnings("unchecked")
 313  
         protected List<KimEntityImpl> lookupEntitys(Map<String, String> searchCriteria) {
 314  0
                 return new ArrayList(KNSServiceLocatorWeb.getLookupService().findCollectionBySearchUnbounded( KimEntityImpl.class, searchCriteria ));
 315  
         }
 316  
 
 317  
         /**
 318  
          * @see org.kuali.rice.kim.api.entity.services.IdentityService#lookupEntityIds(java.util.Map)
 319  
          */
 320  
         public List<String> lookupEntityIds(Map<String,String> searchCriteria) {
 321  0
                 List<KimEntityImpl> entities = lookupEntitys( searchCriteria );
 322  0
                 List<String> entityIds = new ArrayList<String>( entities.size() );
 323  0
                 for ( KimEntityImpl entity : entities ) {
 324  0
                         entityIds.add( entity.getEntityId() );
 325  
                 }
 326  0
                 return entityIds;
 327  
         }
 328  
 
 329  
         /**
 330  
          * @see org.kuali.rice.kim.api.entity.services.IdentityService#getPrincipalByPrincipalName(java.lang.String)
 331  
          */
 332  
         @SuppressWarnings("unchecked")
 333  
         public Principal getPrincipalByPrincipalName(String principalName) {
 334  0
                 if ( StringUtils.isBlank(principalName) ) {
 335  0
                         return null;
 336  
                 }
 337  0
                 Map<String,Object> criteria = new HashMap<String,Object>(1);
 338  0
         criteria.put(KIMPropertyConstants.Principal.PRINCIPAL_NAME, principalName.toLowerCase());
 339  0
         Collection<PrincipalBo> principals = getBusinessObjectService().findMatching(PrincipalBo.class, criteria);
 340  0
         if (!principals.isEmpty() && principals.size() == 1) {
 341  0
             return PrincipalBo.to(principals.iterator().next());
 342  
         }
 343  0
         return null;
 344  
     }
 345  
 
 346  
         /**
 347  
          * @see org.kuali.rice.kim.api.entity.services.IdentityService#getEntityByPrincipalName(java.lang.String)
 348  
          */
 349  
         protected KimEntityImpl getEntityByPrincipalName(String principalName) {
 350  0
                 if ( StringUtils.isBlank( principalName ) ) {
 351  0
                         return null;
 352  
                 }
 353  0
         return getEntityByKeyValue("principals." + KIMPropertyConstants.Principal.PRINCIPAL_NAME, principalName.toLowerCase());
 354  
         }
 355  
 
 356  
         /**
 357  
          * @see org.kuali.rice.kim.api.entity.services.IdentityService#getEntityByPrincipalId(java.lang.String)
 358  
          */
 359  
         protected KimEntityImpl getEntityByPrincipalId(String principalId) {
 360  0
                 if ( StringUtils.isBlank( principalId ) ) {
 361  0
                         return null;
 362  
                 }
 363  0
         return getEntityByKeyValue("principals." + KIMPropertyConstants.Principal.PRINCIPAL_ID, principalId);
 364  
         }
 365  
         
 366  
         /**
 367  
          * @see org.kuali.rice.kim.api.entity.services.IdentityService#getEntityIdByPrincipalId(java.lang.String)
 368  
          */
 369  
         public String getEntityIdByPrincipalId(String principalId) {
 370  0
                 if ( StringUtils.isBlank( principalId ) ) {
 371  0
                         return null;
 372  
                 }
 373  0
                 PrincipalBo principal = getPrincipalImpl(principalId);
 374  0
                 return principal != null ? principal.getEntityId() : null;
 375  
     }
 376  
 
 377  
         /**
 378  
          * @see org.kuali.rice.kim.api.entity.services.IdentityService#getEntityIdByPrincipalName(java.lang.String)
 379  
          */
 380  
         public String getEntityIdByPrincipalName(String principalName) {
 381  0
                 if ( StringUtils.isBlank( principalName ) ) {
 382  0
                         return null;
 383  
                 }
 384  0
                 Principal principal = getPrincipalByPrincipalName(principalName);
 385  0
                 return principal != null ? principal.getEntityId() : null;
 386  
     }
 387  
         
 388  
         /**
 389  
          * @see org.kuali.rice.kim.api.entity.services.IdentityService#getPrincipalIdByPrincipalName(java.lang.String)
 390  
          */
 391  
         public String getPrincipalIdByPrincipalName(String principalName) {
 392  0
                 if ( StringUtils.isBlank( principalName ) ) {
 393  0
                         return null;
 394  
                 }
 395  0
                 Principal principal = getPrincipalByPrincipalName( principalName );
 396  0
                 return principal != null ? principal.getPrincipalId() : null;
 397  
         }
 398  
         
 399  
         /**
 400  
          * @see org.kuali.rice.kim.api.entity.services.IdentityService#getDefaultNamesForEntityIds(java.util.List)
 401  
          */
 402  
         public Map<String, KimEntityNameInfo> getDefaultNamesForEntityIds(List<String> entityIds) {
 403  
                 // TODO - Use a DAO
 404  0
                 Map<String, KimEntityNameInfo> result = new HashMap<String, KimEntityNameInfo>(entityIds.size());
 405  
                 
 406  0
                 for(String s : entityIds) {
 407  0
                         Map<String,Object> criteria = new HashMap<String,Object>();
 408  0
                         criteria.put(KIMPropertyConstants.Entity.ENTITY_ID, s);
 409  0
                         criteria.put("defaultValue", true);
 410  
                         
 411  0
                         KimEntityNameImpl name = (KimEntityNameImpl) getBusinessObjectService().findByPrimaryKey(KimEntityNameImpl.class, criteria);
 412  
                         
 413  0
                         result.put(s, new KimEntityNameInfo( name ) );
 414  0
                 }
 415  
                 
 416  0
                 return result;
 417  
         }
 418  
         
 419  
         /**
 420  
          * @see org.kuali.rice.kim.api.entity.services.IdentityService#getDefaultNamesForPrincipalIds(java.util.List)
 421  
          */
 422  
         public Map<String, KimEntityNamePrincipalNameInfo> getDefaultNamesForPrincipalIds(List<String> principalIds) {
 423  
                 // TODO - use a dao?
 424  
                 // TODO - what if principal not found, NullPointerException
 425  0
                 Map<String, KimEntityNamePrincipalNameInfo> result = new HashMap<String, KimEntityNamePrincipalNameInfo>(principalIds.size());
 426  
                 
 427  0
                 for(String s : principalIds) {
 428  0
                         KimEntityNamePrincipalNameInfo namePrincipal = new KimEntityNamePrincipalNameInfo();
 429  
                         
 430  0
                         Map<String,String> criteria = new HashMap<String,String>();
 431  0
                         criteria.put(KIMPropertyConstants.Principal.PRINCIPAL_ID, s);
 432  0
                         PrincipalBo principal = (PrincipalBo) getBusinessObjectService().findByPrimaryKey(PrincipalBo.class, criteria);
 433  
                         
 434  0
                         if (null != principal) {
 435  0
                                 namePrincipal.setPrincipalName(principal.getPrincipalName());
 436  
                                 
 437  0
                                 criteria.clear();
 438  0
                                 criteria.put(KIMPropertyConstants.Entity.ENTITY_ID, principal.getEntityId());
 439  0
                                 criteria.put("defaultValue", "Y");
 440  0
                                 KimEntityNameImpl name = (KimEntityNameImpl) getBusinessObjectService().findByPrimaryKey(KimEntityNameImpl.class, criteria);
 441  
                                 
 442  0
                                 namePrincipal.setDefaultEntityName( new KimEntityNameInfo( name ) );
 443  
                                 
 444  0
                                 result.put(s, namePrincipal);
 445  
                         }
 446  0
                 }
 447  
                 
 448  0
                 return result;
 449  
         }
 450  
         
 451  
         /**
 452  
          * Generic helper method for performing a lookup through the business object service.
 453  
          */
 454  
         @SuppressWarnings("unchecked")
 455  
         protected KimEntityImpl getEntityByKeyValue(String key, String value) {
 456  0
                 Map<String,String> criteria = new HashMap<String,String>(1);
 457  0
         criteria.put(key, value);
 458  0
         Collection<KimEntityImpl> entities = (Collection<KimEntityImpl>)getBusinessObjectService().findMatching(KimEntityImpl.class, criteria);
 459  0
         if (entities.size() >= 1) {
 460  0
                 return entities.iterator().next();
 461  
         }
 462  0
                 return null;
 463  
         }
 464  
 
 465  
         protected BusinessObjectService getBusinessObjectService() {
 466  0
                 if ( businessObjectService == null ) {
 467  0
                         businessObjectService = KNSServiceLocator.getBusinessObjectService();
 468  
                 }
 469  0
                 return businessObjectService;
 470  
         }
 471  
 
 472  
         public Type getAddressType( String code ) {
 473  0
                 EntityAddressTypeBo impl = getBusinessObjectService().findBySinglePrimaryKey(EntityAddressTypeBo.class, code);
 474  0
                 if ( impl == null ) {
 475  0
                         return null;
 476  
                 }
 477  0
                 return EntityAddressTypeBo.to(impl);
 478  
         }
 479  
         
 480  
         public AffiliationTypeInfo getAffiliationType( String code ) {
 481  0
                 AffiliationTypeImpl impl = getBusinessObjectService().findBySinglePrimaryKey(AffiliationTypeImpl.class, code);
 482  0
                 if ( impl == null ) {
 483  0
                         return null;
 484  
                 }
 485  0
                 return impl.toInfo();
 486  
         }
 487  
 
 488  
         public Type getCitizenshipStatus( String code ) {
 489  0
                 EntityCitizenshipStatusBo impl = getBusinessObjectService().findBySinglePrimaryKey(EntityCitizenshipStatusBo.class, code);
 490  0
                 if ( impl == null ) {
 491  0
                         return null;
 492  
                 }
 493  0
                 return EntityCitizenshipStatusBo.to(impl);
 494  
         }
 495  
 
 496  
         public Type getEmailType( String code ) {
 497  0
                 EntityEmailTypeBo impl = getBusinessObjectService().findBySinglePrimaryKey(EntityEmailTypeBo.class, code);
 498  0
                 if ( impl == null ) {
 499  0
                         return null;
 500  
                 }
 501  0
                 return EntityEmailTypeBo.to(impl);
 502  
         }
 503  
 
 504  
         public EmploymentStatusInfo getEmploymentStatus( String code ) {
 505  0
                 EmploymentStatusImpl impl = getBusinessObjectService().findBySinglePrimaryKey(EmploymentStatusImpl.class, code);
 506  0
                 if ( impl == null ) {
 507  0
                         return null;
 508  
                 }
 509  0
                 return impl.toInfo();
 510  
         }
 511  
 
 512  
         public EmploymentTypeInfo getEmploymentType( String code ) {
 513  0
                 EmploymentTypeImpl impl = getBusinessObjectService().findBySinglePrimaryKey(EmploymentTypeImpl.class, code);
 514  0
                 if ( impl == null ) {
 515  0
                         return null;
 516  
                 }
 517  0
                 return impl.toInfo();
 518  
         }
 519  
 
 520  
         public EntityNameTypeInfo getEntityNameType( String code ) {
 521  0
                 EntityNameTypeImpl impl = getBusinessObjectService().findBySinglePrimaryKey(EntityNameTypeImpl.class, code);
 522  0
                 if ( impl == null ) {
 523  0
                         return null;
 524  
                 }
 525  0
                 return impl.toInfo();
 526  
         }
 527  
 
 528  
         public Type getEntityType( String code ) {
 529  0
                 EntityTypeBo impl = getBusinessObjectService().findBySinglePrimaryKey(EntityTypeBo.class, code);
 530  0
                 if ( impl == null ) {
 531  0
                         return null;
 532  
                 }
 533  0
                 return EntityTypeBo.to(impl);
 534  
         }
 535  
 
 536  
         public ExternalIdentifierTypeInfo getExternalIdentifierType( String code ) {
 537  0
                 ExternalIdentifierTypeImpl impl = getBusinessObjectService().findBySinglePrimaryKey(ExternalIdentifierTypeImpl.class, code);
 538  0
                 if ( impl == null ) {
 539  0
                         return null;
 540  
                 }
 541  0
                 return impl.toInfo();
 542  
         }
 543  
         
 544  
         public Type getPhoneType( String code ) {
 545  0
                 EntityPhoneTypeBo impl = getBusinessObjectService().findBySinglePrimaryKey(EntityPhoneTypeBo.class, code);
 546  0
                 if ( impl == null ) {
 547  0
                         return null;
 548  
                 }
 549  0
                 return EntityPhoneTypeBo.to(impl);
 550  
         }
 551  
         
 552  
 //        protected static Map<String,ExternalIdentifierTypeInfo> externalIdentifierTypeInfoCache = new HashMap<String, ExternalIdentifierTypeInfo>();
 553  
 //        public ExternalIdentifierTypeInfo getExternalIdentifierType( String code ) {
 554  
 //                if ( !externalIdentifierTypeInfoCache.containsKey(code) ) {
 555  
 //                        Map<String,String> pk = new HashMap<String, String>(1);
 556  
 //                        pk.put("code", code);
 557  
 //                        ExternalIdentifierTypeImpl impl = (ExternalIdentifierTypeImpl)getBusinessObjectService().findByPrimaryKey(ExternalIdentifierTypeImpl.class, pk);
 558  
 //                        if ( impl != null ) {
 559  
 //                                externalIdentifierTypeInfoCache.put(code, impl.toInfo());
 560  
 //                        }
 561  
 //                }
 562  
 //                return externalIdentifierTypeInfoCache.get(code);
 563  
 //        }
 564  
         
 565  
 }