Set<GroupMember> removedMembers = CollectUtils.newHashSet();
User manager = getUser();
Collection<GroupMember> members = userService.getGroupMembers(manager,
GroupMember.Ship.GRANTER);
for (GroupMember member : members) {
GroupMember myMember = memberMap.get(member.getGroup());
boolean isMember = getBool("member" + member.getGroup().getId());
boolean isGranter = getBool("granter" + member.getGroup().getId());
boolean isManager = getBool("manager" + member.getGroup().getId());
if (!isMember && !isGranter && !isManager) {
if (null != myMember) {
user.getGroups().remove(myMember);
removedMembers.add(myMember);
}
} else {
if (null == myMember) {
myMember = new GroupMemberBean(member.getGroup(), user, null);
}
myMember.setUpdatedAt(new Date());
myMember.setMember(isMember);
myMember.setGranter(isGranter);
myMember.setManager(isManager);
newMembers.add(myMember);
}
}
entityDao.saveOrUpdate(newMembers);
entityDao.remove(removedMembers);