@Override
public AppUserData retrieveUser(final Long userId) {
this.context.authenticatedUser();
final AppUser user = this.appUserRepository.findOne(userId);
if (user == null || user.isDeleted()) { throw new UserNotFoundException(userId); }
final Collection<RoleData> availableRoles = this.roleReadPlatformService.retrieveAll();
final Collection<RoleData> selectedUserRoles = new ArrayList<>();
final Set<Role> userRoles = user.getRoles();
for (final Role role : userRoles) {
selectedUserRoles.add(role.toData());
}
availableRoles.removeAll(selectedUserRoles);
final StaffData linkedStaff;
if (user.getStaff() != null) {
linkedStaff = this.staffReadPlatformService.retrieveStaff(user.getStaffId());
} else {
linkedStaff = null;
}
return AppUserData.instance(user.getId(), user.getUsername(), user.getEmail(), user.getOffice().getId(),
user.getOffice().getName(), user.getFirstname(), user.getLastname(), availableRoles, selectedUserRoles, linkedStaff);
}