Set<GroupMember> newMembers = CollectUtils.newHashSet();
Set<GroupMember> removedMembers = CollectUtils.newHashSet();
User manager = entityDao.get(User.class, getUserId());
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.getMembers().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.execute(Operation.saveOrUpdate(newMembers).remove(removedMembers));
}