UserSession usrSess = context.getUserSession();
Profile myProfile = usrSess.getProfile();
String myUserId = usrSess.getUserId();
final UserRepository userRepository = context.getBean(UserRepository.class);
final GroupRepository groupRepository = context.getBean(GroupRepository.class);
final UserGroupRepository userGroupRepository = context.getBean(UserGroupRepository.class);
if (myProfile == Profile.Administrator || myProfile == Profile.UserAdmin || myUserId.equals(id)) {
// -- get the profile of the user id supplied
User user = userRepository.findOne(Integer.valueOf(id));
if (user == null) {
throw new IllegalArgumentException("user "+id+" doesn't exist");
}
String theProfile = user.getProfile().name();
//--- retrieve user groups of the user id supplied
Element elGroups = new Element(Geonet.Elem.GROUPS);
List<Group> theGroups;
List<UserGroup> userGroups;
if (myProfile == Profile.Administrator && theProfile.equals(Profile.Administrator.name())) {
theGroups = groupRepository.findAll();
for (Group group : theGroups) {
final Element element = group.asXml();
element.addContent(new Element("profile").setText(Profile.Administrator.name()));
elGroups.addContent(element);