Skip to content

Commit

Permalink
Fix user full name in Avatar
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed Jun 22, 2017
1 parent 9a90064 commit 1782d60
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion src/main/java/de/metas/ui/web/session/UserSessionRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private void loadFromAD_User(final UserSession userSession, final I_AD_User from
final JSONUserSessionChangesEventBuilder changesCollector = JSONUserSessionChangesEvent.builder();

// Fullname
final String userFullnameOld = userSession.setUserFullname(fromUser.getName());
final String userFullnameOld = userSession.setUserFullname(buildUserFullname(fromUser));
final String userFullnameNew = userSession.getUserFullname();
if (!Objects.equals(userFullnameNew, userFullnameOld))
{
Expand Down Expand Up @@ -119,6 +119,49 @@ private void loadFromAD_User(final UserSession userSession, final I_AD_User from
}
}

/**
* Builds user's full name.
*
* @param user
* @return user's full name (e.g. FirstName LastName)
* @task https://github.com/metasfresh/metasfresh-webui-api/issues/468
*/
private final String buildUserFullname(final I_AD_User user)
{
final StringBuilder fullname = new StringBuilder();
final String firstname = user.getFirstname();
if (!Check.isEmpty(firstname, true))
{
fullname.append(firstname.trim());
}

final String lastname = user.getLastname();
if (!Check.isEmpty(lastname, true))
{
if (fullname.length() > 0)
{
fullname.append(" ");
}
fullname.append(lastname.trim());
}

if (fullname.length() <= 0)
{
final String login = user.getLogin();
if (!Check.isEmpty(login, true)) // shall not happen to be empty
{
fullname.append(login.trim());
}
}

if (fullname.length() <= 0)
{
fullname.append(user.getAD_User_ID());
}

return fullname.toString();
}

public void setAD_Language(final int adUserId, final String adLanguage)
{
final I_AD_User user = Services.get(IUserDAO.class).retrieveUserInTrx(adUserId);
Expand Down

0 comments on commit 1782d60

Please sign in to comment.