Collection<String> friendLogins = friendRepository.findFriendsForUser(login);
Collection<UserGroupDTO> userGroupDTOs = new TreeSet<UserGroupDTO>();
for (Map.Entry<String, String> member : membersMap.entrySet()) {
User user = userRepository.findUserByLogin(member.getKey());
if(user != null) { //User might be deleted
UserGroupDTO dto = new UserGroupDTO();
dto.setLogin(user.getLogin());
dto.setUsername(user.getUsername());
dto.setAvatar(user.getAvatar());
dto.setFirstName(user.getFirstName());
dto.setLastName(user.getLastName());
dto.setRole(member.getValue());
dto.setActivated(user.getActivated());
if (friendLogins.contains(user.getLogin())) {
dto.setFriend(true);
}
if (login.equals(user.getLogin())) {
dto.setYou(true);
}
userGroupDTOs.add(dto);
}
}
return userGroupDTOs;