return userDao.findByLogin(login);
}
public void updateUserDetails(Long userId, UserDetails userDetails)
throws InstanceNotFoundException, DuplicateInstanceException {
User user = userDao.find(userId);
try {
if (user.getEmail().equals(userDetails.getEmail())) {
throw new InstanceNotFoundException(null, null);
}
userDao.findByEmail(userDetails.getEmail());
throw new DuplicateInstanceException(userDetails.getEmail(),
User.class.getName());
} catch (InstanceNotFoundException e) {
try {
if (user.getLogin().equals(userDetails.getLogin())) {
throw new InstanceNotFoundException(null, null);
}
userDao.findByLogin(userDetails.getLogin());
throw new DuplicateInstanceException(userDetails.getLogin(),
User.class.getName());
} catch (InstanceNotFoundException e1) {
user.setFirstName(userDetails.getFirstName());
user.setLastName(userDetails.getLastName());
user.setEmail(userDetails.getEmail());
user.setLogin(userDetails.getLogin());
}
}
}