Commit a481fa6b authored by michael.simon's avatar michael.simon
Browse files

straighten out use of entitymanager

parent 87a7853e
......@@ -44,14 +44,28 @@ public class JpaGroupDao extends JpaBaseDao<GroupEntity, Long> implements GroupD
UserGroupEntity userGroup = createNewUserGroup();
userGroup.setUser(user);
userGroup.setGroup(group);
if (user.getGroups() != null)
user.getGroups().add(userGroup);
if (group.getUsers() != null)
group.getUsers().add(userGroup);
em.persist(userGroup);
}
@Override
public void removeUserGromGroup(UserEntity user, GroupEntity group) {
UserGroupEntity userGroup = findUserGroupEntity(user, group);
if (userGroup != null)
if (userGroup != null) {
if (user.getGroups() != null)
user.getGroups().remove(userGroup);
if (group.getUsers() != null)
group.getUsers().remove(userGroup);
em.remove(userGroup);
}
}
@Override
......
......@@ -307,7 +307,7 @@ public class HomeOrgGroupUpdater implements Serializable {
logger.debug("Adding user {} to group {}", user.getEppn(), groupEntity.getName());
groupDao.addUserToGroup(user, groupEntity);
changedGroups.remove(groupEntity);
groupEntity = dao.persist(groupEntity);
//groupEntity = dao.persist(groupEntity);
auditor.logAction(user.getEppn(), "ADD TO GROUP", groupEntity.getName(), null, AuditStatus.SUCCESS);
changedGroups.add(groupEntity);
......
......@@ -126,6 +126,8 @@ public class UserUpdater implements Serializable {
throws UserUpdateException {
logger.debug("Updating user {}", user.getEppn());
user = userDao.merge(user);
boolean changed = false;
UserUpdateAuditor auditor = new UserUpdateAuditor(auditDao, auditDetailDao, appConfig);
......@@ -205,9 +207,6 @@ public class UserUpdater implements Serializable {
user.setLastUpdate(new Date());
user.setLastFailedUpdate(null);
user.setGroups(null);
user = userDao.persist(user);
if (changed) {
fireUserChangeEvent(user, auditor.getActualExecutor());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment