Set<IPersonAttributesGroupDefinition> groups = personAttributesGroupDefinitionDao.getPersonAttributesGroupDefinitionByName(groupName);
Set<IPersonAttributesGroupDefinition> attemptingToAddMembers = personAttributesGroupDefinitionDao.getPersonAttributesGroupDefinitionByName(member);
if (groups.isEmpty() || attemptingToAddMembers.isEmpty()) {
throw new RuntimeException("Group: " + groupName + " or member: " + member + " does not exist");
} else {
IPersonAttributesGroupDefinition group = groups.iterator().next();
IPersonAttributesGroupDefinition attemptingToAddMember = attemptingToAddMembers.iterator().next();
Set<IPersonAttributesGroupDefinition> groupMembers = group.getMembers();
for (IPersonAttributesGroupDefinition groupMember : groupMembers) {
if (groupMember.getName().equalsIgnoreCase(attemptingToAddMember.getName())) {
return;
}
}
groupMembers.add(attemptingToAddMember);
group.setMembers(groupMembers);