}
}
@Override
public User updateUser(User user) {
User currentUser = getSessionUser();
if (user.getLogin().isEmpty() || user.getPassword().isEmpty()) {
throw new IllegalArgumentException();
}
if (currentUser.getAdmin() || (currentUser.getId() == user.getId() && !user.getAdmin())) {
EntityManager entityManager = getSessionEntityManager();
synchronized (entityManager) {
entityManager.getTransaction().begin();
try {
// TODO: better solution?
if (currentUser.getId() == user.getId()) {
currentUser.setLogin(user.getLogin());
currentUser.setPassword(user.getPassword());
currentUser.setUserSettings(user.getUserSettings());
currentUser.setAdmin(user.getAdmin());
entityManager.merge(currentUser);
user = currentUser;
} else {
// TODO: handle other users
}