use of org.summerb.users.api.exceptions.UserNotFoundException in project summerb by skarpushin.
the class UsersServiceFacadeImpl method registerUser.
@Transactional(rollbackFor = Throwable.class)
@Override
public User registerUser(Registration registration) throws FieldValidationException {
try {
Preconditions.checkArgument(registration != null, "Registration param must be not null");
// Validate display name
validateRegistration(registration);
// Validate user status
UserStatus userStatus = getUserStatusByEmail(registration.getEmail());
if (userStatus == UserStatus.AwaitingActivation) {
throw new FieldValidationException(new RegistrationAlreadyRequestedValidationError());
}
// Create user
User user = null;
if (userStatus == UserStatus.Provisioned) {
user = userService.getUserByEmail(registration.getEmail());
user.setDisplayName(registration.getDisplayName());
user.setLocale(CurrentRequestUtils.getLocale().toString());
user.setTimeZone(TimeZone.getDefault().getID());
userService.updateUser(user);
} else {
user = new User();
user.setEmail(registration.getEmail());
user.setDisplayName(registration.getDisplayName());
user.setLocale(CurrentRequestUtils.getLocale().toString());
user.setTimeZone(TimeZone.getDefault().getID());
user = userService.createUser(user);
}
// Create password
passwordService.setUserPassword(user.getUuid(), registration.getPassword());
// Create user account permissions
permissionService.grantPermission(SecurityConstants.DOMAIN, user.getUuid(), null, SecurityConstants.MARKER_AWAITING_ACTIVATION);
runUserRegisteredHandler(user);
//
return user;
} catch (UserNotFoundException e) {
throw new UserServiceUnexpectedException("User was just created, but not found", e);
} catch (Throwable t) {
Throwables.throwIfInstanceOf(t, FieldValidationException.class);
throw new RuntimeException("Unexpected error while registering user", t);
}
}
use of org.summerb.users.api.exceptions.UserNotFoundException in project summerb by skarpushin.
the class UserServiceImpl method getUserByEmail.
@Override
public User getUserByEmail(String userEmail) throws FieldValidationException, UserNotFoundException {
Assert.notNull(userEmail, "user email must be provided");
validateEmail(userEmail);
User foundUser;
try {
foundUser = userDao.findUserByEmail(userEmail);
} catch (Throwable t) {
String msg = String.format("Failed to find user by email '%s'", userEmail);
throw new UserServiceUnexpectedException(msg, t);
}
if (foundUser == null) {
throw new UserNotFoundException(userEmail);
}
return foundUser;
}
use of org.summerb.users.api.exceptions.UserNotFoundException in project summerb by skarpushin.
the class UserServiceImpl method updateUser.
@Override
@Transactional(rollbackFor = Throwable.class)
public void updateUser(User user) throws FieldValidationException, UserNotFoundException {
Preconditions.checkArgument(user != null, "User reference required");
Preconditions.checkArgument(StringUtils.hasText(user.getUuid()), "User uuid must be provided");
validateUser(user);
boolean isUpdatedSuccessfully;
try {
isUpdatedSuccessfully = userDao.updateUser(user);
eventBus.post(EntityChangedEvent.updated(user));
} catch (DuplicateKeyException dke) {
throw new FieldValidationException(new DuplicateUserValidationError(User.FN_EMAIL));
} catch (Throwable t) {
String msg = String.format("Failed to update user '%s'", user.getUuid());
throw new UserServiceUnexpectedException(msg, t);
}
if (!isUpdatedSuccessfully) {
throw new UserNotFoundException(user.getUuid());
}
}
use of org.summerb.users.api.exceptions.UserNotFoundException in project summerb by skarpushin.
the class UserServiceImpl method getUserByUuid.
@Override
public User getUserByUuid(String userUuid) throws UserNotFoundException {
Assert.hasText(userUuid, "userUuid must be provided");
User foundUser;
try {
foundUser = userDao.findUserByUuid(userUuid);
} catch (Throwable t) {
String msg = String.format("Failed to find user '%s'", userUuid);
throw new UserServiceUnexpectedException(msg, t);
}
if (foundUser == null) {
throw new UserNotFoundException(userUuid);
}
return foundUser;
}
use of org.summerb.users.api.exceptions.UserNotFoundException in project summerb by skarpushin.
the class UserServiceImpl method deleteUserByUuid.
@Override
@Transactional(rollbackFor = Throwable.class)
public void deleteUserByUuid(String userUuid) throws UserNotFoundException {
Preconditions.checkArgument(userUuid != null, "User uuid required");
Preconditions.checkArgument(StringUtils.hasText(userUuid), "User uuid must be provided");
boolean isDeletedSucceessfully = false;
try {
User userToDelete = userDao.findUserByUuid(userUuid);
if (userToDelete != null) {
isDeletedSucceessfully = userDao.deleteUser(userUuid);
// NOTE: Assumed, that all related stuff will be deleted
// automatically using CASCADE DELETE in the database
eventBus.post(EntityChangedEvent.removedObject(userToDelete));
}
} catch (Throwable t) {
String msg = String.format("Failed to delete user '%s'", userUuid);
throw new UserServiceUnexpectedException(msg, t);
}
if (!isDeletedSucceessfully) {
throw new UserNotFoundException(userUuid);
}
}
Aggregations