public static Profile createProfile ( Connection < ? > connection ) { Profile profile = new Profile ( ) ; UserProfile providerProfile = connection . fetchUserProfile ( ) ; String email = providerProfile . getEmail ( ) ; if ( StringUtils . isEmpty ( email ) ) { throw new IllegalStateException ( "No email included in provider profile" ) ; } String username = providerProfile . getUsername ( ) ; if ( StringUtils . isEmpty ( username ) ) { username = email ; } String firstName = providerProfile . getFirstName ( ) ; String lastName = providerProfile . getLastName ( ) ; String displayName ; if ( StringUtils . isNotEmpty ( connection . getDisplayName ( ) ) ) { displayName = connection . getDisplayName ( ) ; } else { displayName = firstName + " " + lastName ; } profile . setUsername ( username ) ; profile . setEmail ( email ) ; profile . setAttribute ( FIRST_NAME_ATTRIBUTE_NAME , firstName ) ; profile . setAttribute ( LAST_NAME_ATTRIBUTE_NAME , lastName ) ; profile . setAttribute ( DISPLAY_NAME_ATTRIBUTE_NAME , displayName ) ; if ( StringUtils . isNotEmpty ( connection . getImageUrl ( ) ) ) { profile . setAttribute ( AVATAR_LINK_ATTRIBUTE_NAME , connection . getImageUrl ( ) ) ; } return profile ; }
Creates a profile from the specified connection .