protected final IPersonAttributes mapPersonAttributes ( final IPersonAttributes person ) { final Map < String , List < Object > > personAttributes = person . getAttributes ( ) ; final Map < String , List < Object > > mappedAttributes ; //If no mapping just use the attributes as-is if ( this . resultAttributeMapping == null ) { if ( caseInsensitiveResultAttributes != null && ! ( caseInsensitiveResultAttributes . isEmpty ( ) ) ) { mappedAttributes = new LinkedHashMap <> ( ) ; for ( final Map . Entry < String , List < Object > > attribute : personAttributes . entrySet ( ) ) { final String attributeName = attribute . getKey ( ) ; mappedAttributes . put ( attributeName , canonicalizeAttribute ( attributeName , attribute . getValue ( ) , caseInsensitiveResultAttributes ) ) ; } } else { mappedAttributes = personAttributes ; } } //Map the attribute names via the resultAttributeMapping else { mappedAttributes = new LinkedHashMap <> ( ) ; for ( final Map . Entry < String , Set < String > > resultAttrEntry : this . resultAttributeMapping . entrySet ( ) ) { final String dataKey = resultAttrEntry . getKey ( ) ; // Only map found data attributes. // . See https://issues.jasig.org/browse/PERSONDIR-89 // Currently respects CaseInsensitive*NamedPersonImpl because BasePersonImpl's constructor if ( personAttributes . containsKey ( dataKey ) ) { Set < String > resultKeys = resultAttrEntry . getValue ( ) ; //If dataKey has no mapped resultKeys just use the dataKey if ( resultKeys == null ) { resultKeys = ImmutableSet . of ( dataKey ) ; } //Add the value to the mapped attributes for each mapped key, //possibly canonicalizing casing for each value List < Object > value = personAttributes . get ( dataKey ) ; for ( final String resultKey : resultKeys ) { value = canonicalizeAttribute ( resultKey , value , caseInsensitiveResultAttributes ) ; if ( resultKey == null ) { //TODO is this possible? mappedAttributes . put ( dataKey , value ) ; } else { mappedAttributes . put ( resultKey , value ) ; } } } } } final IPersonAttributes newPerson ; final String name = person . getName ( ) ; if ( name != null ) { newPerson = new NamedPersonImpl ( usernameCaseCanonicalizationMode . canonicalize ( name ) , mappedAttributes ) ; } else { final String userNameAttribute = this . getConfiguredUserNameAttribute ( ) ; final IPersonAttributes tmpNewPerson = new AttributeNamedPersonImpl ( userNameAttribute , mappedAttributes ) ; newPerson = new NamedPersonImpl ( usernameCaseCanonicalizationMode . canonicalize ( tmpNewPerson . getName ( ) ) , mappedAttributes ) ; } return newPerson ; }
Uses resultAttributeMapping to return a copy of the IPersonAttributes with only the attributes specified in resultAttributeMapping mapped to their result attribute names .