@Test public void selectDisplayNameIfAbsent() { final Map<String, List<Object>> attributes = new HashMap<>(); attributes.put(CUSTOMARY_FIRST_NAME_ATTRIBUTE, Collections.singletonList(FIRST_NAME)); attributes.put(CUSTOMARY_LAST_NAME_ATTRIBUTE, Collections.singletonList(LAST_NAME)); final IPersonAttributes person = new NamedPersonImpl(USERNAME, attributes); final IPersonAttributes rslt = portalRootPersonAttributeDao.selectDisplayNameIfAbsent(person); Assert.assertEquals( FIRST_NAME + " " + LAST_NAME, rslt.getAttributeValue(ILocalAccountPerson.ATTR_DISPLAY_NAME)); }
protected IPersonAttributes selectDisplayNameIfAbsent(IPersonAttributes person) { IPersonAttributes rslt = person; if (!rslt.getAttributes().containsKey(ILocalAccountPerson.ATTR_DISPLAY_NAME)) { final StringBuilder displayName = new StringBuilder(); final Map<String, List<Object>> attributes = person.getAttributes(); final String firstName = attributes.containsKey(CUSTOMARY_FIRST_NAME_ATTRIBUTE) ? attributes.get(CUSTOMARY_FIRST_NAME_ATTRIBUTE).get(0).toString() : null; final String lastName = attributes.containsKey(CUSTOMARY_LAST_NAME_ATTRIBUTE) ? attributes.get(CUSTOMARY_LAST_NAME_ATTRIBUTE).get(0).toString() : null; if (StringUtils.isNotBlank(firstName) && StringUtils.isNotBlank(lastName)) { displayName.append(firstName).append(" ").append(lastName); } else { final String usernameAttribute = usernameAttributeProvider.getUsernameAttribute(); if (attributes.containsKey(usernameAttribute)) { final List<Object> username = attributes.get(usernameAttribute); if (username.size() > 0 && StringUtils.isNotBlank(username.get(0).toString())) { displayName.append(username.get(0).toString()); } } } if (displayName.length() > 0) { logger.debug( "Selected new displayName of '{}' for user '{}'", displayName, person.getName()); final Map<String, List<Object>> mutableMap = new LinkedHashMap<>(attributes); mutableMap.put( ILocalAccountPerson.ATTR_DISPLAY_NAME, Collections.singletonList(displayName.toString())); rslt = new NamedPersonImpl(person.getName(), mutableMap); } } return rslt; }
PortalRootPersonAttributeDao extends AbstractFlatteningPersonAttributeDao { protected IPersonAttributes selectDisplayNameIfAbsent(IPersonAttributes person) { IPersonAttributes rslt = person; if (!rslt.getAttributes().containsKey(ILocalAccountPerson.ATTR_DISPLAY_NAME)) { final StringBuilder displayName = new StringBuilder(); final Map<String, List<Object>> attributes = person.getAttributes(); final String firstName = attributes.containsKey(CUSTOMARY_FIRST_NAME_ATTRIBUTE) ? attributes.get(CUSTOMARY_FIRST_NAME_ATTRIBUTE).get(0).toString() : null; final String lastName = attributes.containsKey(CUSTOMARY_LAST_NAME_ATTRIBUTE) ? attributes.get(CUSTOMARY_LAST_NAME_ATTRIBUTE).get(0).toString() : null; if (StringUtils.isNotBlank(firstName) && StringUtils.isNotBlank(lastName)) { displayName.append(firstName).append(" ").append(lastName); } else { final String usernameAttribute = usernameAttributeProvider.getUsernameAttribute(); if (attributes.containsKey(usernameAttribute)) { final List<Object> username = attributes.get(usernameAttribute); if (username.size() > 0 && StringUtils.isNotBlank(username.get(0).toString())) { displayName.append(username.get(0).toString()); } } } if (displayName.length() > 0) { logger.debug( "Selected new displayName of '{}' for user '{}'", displayName, person.getName()); final Map<String, List<Object>> mutableMap = new LinkedHashMap<>(attributes); mutableMap.put( ILocalAccountPerson.ATTR_DISPLAY_NAME, Collections.singletonList(displayName.toString())); rslt = new NamedPersonImpl(person.getName(), mutableMap); } } return rslt; } }
PortalRootPersonAttributeDao extends AbstractFlatteningPersonAttributeDao { protected IPersonAttributes selectDisplayNameIfAbsent(IPersonAttributes person) { IPersonAttributes rslt = person; if (!rslt.getAttributes().containsKey(ILocalAccountPerson.ATTR_DISPLAY_NAME)) { final StringBuilder displayName = new StringBuilder(); final Map<String, List<Object>> attributes = person.getAttributes(); final String firstName = attributes.containsKey(CUSTOMARY_FIRST_NAME_ATTRIBUTE) ? attributes.get(CUSTOMARY_FIRST_NAME_ATTRIBUTE).get(0).toString() : null; final String lastName = attributes.containsKey(CUSTOMARY_LAST_NAME_ATTRIBUTE) ? attributes.get(CUSTOMARY_LAST_NAME_ATTRIBUTE).get(0).toString() : null; if (StringUtils.isNotBlank(firstName) && StringUtils.isNotBlank(lastName)) { displayName.append(firstName).append(" ").append(lastName); } else { final String usernameAttribute = usernameAttributeProvider.getUsernameAttribute(); if (attributes.containsKey(usernameAttribute)) { final List<Object> username = attributes.get(usernameAttribute); if (username.size() > 0 && StringUtils.isNotBlank(username.get(0).toString())) { displayName.append(username.get(0).toString()); } } } if (displayName.length() > 0) { logger.debug( "Selected new displayName of '{}' for user '{}'", displayName, person.getName()); final Map<String, List<Object>> mutableMap = new LinkedHashMap<>(attributes); mutableMap.put( ILocalAccountPerson.ATTR_DISPLAY_NAME, Collections.singletonList(displayName.toString())); rslt = new NamedPersonImpl(person.getName(), mutableMap); } } return rslt; }  }
PortalRootPersonAttributeDao extends AbstractFlatteningPersonAttributeDao { protected IPersonAttributes selectDisplayNameIfAbsent(IPersonAttributes person) { IPersonAttributes rslt = person; if (!rslt.getAttributes().containsKey(ILocalAccountPerson.ATTR_DISPLAY_NAME)) { final StringBuilder displayName = new StringBuilder(); final Map<String, List<Object>> attributes = person.getAttributes(); final String firstName = attributes.containsKey(CUSTOMARY_FIRST_NAME_ATTRIBUTE) ? attributes.get(CUSTOMARY_FIRST_NAME_ATTRIBUTE).get(0).toString() : null; final String lastName = attributes.containsKey(CUSTOMARY_LAST_NAME_ATTRIBUTE) ? attributes.get(CUSTOMARY_LAST_NAME_ATTRIBUTE).get(0).toString() : null; if (StringUtils.isNotBlank(firstName) && StringUtils.isNotBlank(lastName)) { displayName.append(firstName).append(" ").append(lastName); } else { final String usernameAttribute = usernameAttributeProvider.getUsernameAttribute(); if (attributes.containsKey(usernameAttribute)) { final List<Object> username = attributes.get(usernameAttribute); if (username.size() > 0 && StringUtils.isNotBlank(username.get(0).toString())) { displayName.append(username.get(0).toString()); } } } if (displayName.length() > 0) { logger.debug( "Selected new displayName of '{}' for user '{}'", displayName, person.getName()); final Map<String, List<Object>> mutableMap = new LinkedHashMap<>(attributes); mutableMap.put( ILocalAccountPerson.ATTR_DISPLAY_NAME, Collections.singletonList(displayName.toString())); rslt = new NamedPersonImpl(person.getName(), mutableMap); } } return rslt; }  IPersonAttributeDao getDelegatePersonAttributeDao(); @Required void setDelegatePersonAttributeDao(IPersonAttributeDao delegatePersonAttributeDao); @Autowired void setUsernameAttributeProvider(IUsernameAttributeProvider usernameAttributeProvider); Map<String, Map<String, List<Object>>> getAttributeOverridesMap(); void setAttributeOverridesMap(Map<String, Map<String, List<Object>>> overridesMap); void setUserAttributeOverride(String uid, Map<String, Object> attributes); void removeUserAttributeOverride(String uid); @Override IPersonAttributes getPerson(String uid); @Override Set<IPersonAttributes> getPeopleWithMultivaluedAttributes(
            Map<String, List<Object>> query); @Override Set<String> getPossibleUserAttributeNames(); @Override Set<String> getAvailableQueryAttributes(); }
PortalRootPersonAttributeDao extends AbstractFlatteningPersonAttributeDao { protected IPersonAttributes selectDisplayNameIfAbsent(IPersonAttributes person) { IPersonAttributes rslt = person; if (!rslt.getAttributes().containsKey(ILocalAccountPerson.ATTR_DISPLAY_NAME)) { final StringBuilder displayName = new StringBuilder(); final Map<String, List<Object>> attributes = person.getAttributes(); final String firstName = attributes.containsKey(CUSTOMARY_FIRST_NAME_ATTRIBUTE) ? attributes.get(CUSTOMARY_FIRST_NAME_ATTRIBUTE).get(0).toString() : null; final String lastName = attributes.containsKey(CUSTOMARY_LAST_NAME_ATTRIBUTE) ? attributes.get(CUSTOMARY_LAST_NAME_ATTRIBUTE).get(0).toString() : null; if (StringUtils.isNotBlank(firstName) && StringUtils.isNotBlank(lastName)) { displayName.append(firstName).append(" ").append(lastName); } else { final String usernameAttribute = usernameAttributeProvider.getUsernameAttribute(); if (attributes.containsKey(usernameAttribute)) { final List<Object> username = attributes.get(usernameAttribute); if (username.size() > 0 && StringUtils.isNotBlank(username.get(0).toString())) { displayName.append(username.get(0).toString()); } } } if (displayName.length() > 0) { logger.debug( "Selected new displayName of '{}' for user '{}'", displayName, person.getName()); final Map<String, List<Object>> mutableMap = new LinkedHashMap<>(attributes); mutableMap.put( ILocalAccountPerson.ATTR_DISPLAY_NAME, Collections.singletonList(displayName.toString())); rslt = new NamedPersonImpl(person.getName(), mutableMap); } } return rslt; }  IPersonAttributeDao getDelegatePersonAttributeDao(); @Required void setDelegatePersonAttributeDao(IPersonAttributeDao delegatePersonAttributeDao); @Autowired void setUsernameAttributeProvider(IUsernameAttributeProvider usernameAttributeProvider); Map<String, Map<String, List<Object>>> getAttributeOverridesMap(); void setAttributeOverridesMap(Map<String, Map<String, List<Object>>> overridesMap); void setUserAttributeOverride(String uid, Map<String, Object> attributes); void removeUserAttributeOverride(String uid); @Override IPersonAttributes getPerson(String uid); @Override Set<IPersonAttributes> getPeopleWithMultivaluedAttributes(
            Map<String, List<Object>> query); @Override Set<String> getPossibleUserAttributeNames(); @Override Set<String> getAvailableQueryAttributes();  }