use of org.summerb.microservices.users.api.dto.User 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);
}
}
use of org.summerb.microservices.users.api.dto.User 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.microservices.users.api.dto.User in project summerb by skarpushin.
the class UserServiceImpl method createUser.
@Override
@Transactional(rollbackFor = Throwable.class)
public User createUser(User userTemplate) throws FieldValidationException {
Assert.notNull(userTemplate);
validateUser(userTemplate);
User userToCreate = new User();
userToCreate.setDisplayName(userTemplate.getDisplayName());
userToCreate.setEmail(userTemplate.getEmail());
userToCreate.setIntegrationData(userTemplate.getIntegrationData());
userToCreate.setIsBlocked(userTemplate.getIsBlocked());
userToCreate.setLocale(userTemplate.getLocale());
userToCreate.setRegisteredAt(userTemplate.getRegisteredAt());
userToCreate.setTimeZone(userTemplate.getTimeZone());
// Patch data
if (userTemplate.getUuid() != null) {
ValidationUtils.isValidNotNullableUuid(userTemplate.getUuid());
userToCreate.setUuid(userTemplate.getUuid());
} else {
userToCreate.setUuid(UUID.randomUUID().toString());
}
if (userToCreate.getRegisteredAt() == 0) {
userToCreate.setRegisteredAt(new Date().getTime());
}
if (userToCreate.getLocale() == null) {
userToCreate.setLocale(LocaleContextHolder.getLocale().toString());
}
if (userToCreate.getTimeZone() == null) {
userToCreate.setTimeZone(Calendar.getInstance().getTimeZone().getID());
}
// Create
try {
userDao.createUser(userToCreate);
eventBus.post(EntityChangedEvent.added(userToCreate));
} catch (DuplicateKeyException dke) {
throw new FieldValidationException(new DuplicateUserValidationError(User.FN_EMAIL));
} catch (Throwable t) {
String msg = String.format("Failed to create user with email '%s'", userToCreate.getEmail());
throw new UserServiceUnexpectedException(msg, t);
}
return userToCreate;
}
use of org.summerb.microservices.users.api.dto.User in project summerb by skarpushin.
the class AuthTokenDaoImplTest method testIsAuthTokenValid_expectWillNotUpdateLastVerifiedForOldValue.
@Test
public void testIsAuthTokenValid_expectWillNotUpdateLastVerifiedForOldValue() throws Exception {
User user = userService.createUser(UserFactory.createNewUserTemplate());
passwordService.setUserPassword(user.getUuid(), "aaa");
AuthToken authToken = authTokenService.authenticate(user.getEmail(), "aaa", "LOCAL");
assertNotNull(authToken);
authTokenDao.updateToken(authToken.getUuid(), 5, null);
authToken = authTokenService.getAuthTokenByUuid(authToken.getUuid());
assertTrue(authToken.getLastVerifiedAt() > 5);
}
use of org.summerb.microservices.users.api.dto.User in project summerb by skarpushin.
the class AuthTokenDaoImplTest method testIsAuthTokenValid_expectTokenMustBeValidRightAfterCreation.
@Test
public void testIsAuthTokenValid_expectTokenMustBeValidRightAfterCreation() throws Exception {
User user = userService.createUser(UserFactory.createNewUserTemplate());
passwordService.setUserPassword(user.getUuid(), "aaa");
AuthToken authToken = authTokenService.authenticate(user.getEmail(), "aaa", "LOCAL");
assertNotNull(authToken);
AuthToken result = authTokenService.isAuthTokenValid(user.getUuid(), authToken.getUuid(), authToken.getTokenValue());
assertNotNull(result);
}
Aggregations