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