diff --git a/src/main/java/biz/nynja/account/services/decomposition/AccountCreator.java b/src/main/java/biz/nynja/account/services/decomposition/AccountCreator.java index 9123af320b46845f216fd640adba58e85373a228..58f9e96532529e58fc9ed41239502d3a008c04bd 100644 --- a/src/main/java/biz/nynja/account/services/decomposition/AccountCreator.java +++ b/src/main/java/biz/nynja/account/services/decomposition/AccountCreator.java @@ -3,13 +3,12 @@ */ package biz.nynja.account.services.decomposition; +import static biz.nynja.account.validation.Validators.pendingAccount; + import java.time.Instant; import java.util.Optional; import java.util.UUID; -import biz.nynja.account.phone.PhoneNumberNormalizer; -import biz.nynja.account.validation.Validation; -import biz.nynja.account.validation.Validators; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; @@ -27,11 +26,10 @@ import biz.nynja.account.models.Account; import biz.nynja.account.models.AuthenticationProvider; import biz.nynja.account.models.PendingAccount; import biz.nynja.account.models.PendingAccountByAuthenticationProvider; +import biz.nynja.account.phone.PhoneNumberNormalizer; import biz.nynja.account.repositories.AccountRepositoryAdditional; import biz.nynja.account.repositories.PendingAccountRepository; -import static biz.nynja.account.validation.Validators.pendingAccount; - @Service public class AccountCreator { @@ -82,12 +80,14 @@ public class AccountCreator { pendingAccount.setProfileId(UUID.randomUUID()); if (pendingAccountRepository.findByAccountId(pendingAccount.getAccountId()) != null || accountRepositoryAdditional.accountIdAlreadyUsed(pendingAccount.getAccountId())) { - logger.error("Can not create pending account. The account id {} is already used.", pendingAccount.getAccountId()); + logger.error("Can not create pending account. The account id {} is already used.", + pendingAccount.getAccountId()); return CreatePendingAccountResponse.newBuilder() .setError(ErrorResponse.newBuilder().setCause(Cause.INTERNAL_SERVER_ERROR)).build(); } if (accountRepositoryAdditional.profileIdAlreadyUsed(pendingAccount.getProfileId())) { - logger.error("Can not create pending account. The profile id {} is already used.", pendingAccount.getProfileId()); + logger.error("Can not create pending account. The profile id {} is already used.", + pendingAccount.getProfileId()); return CreatePendingAccountResponse.newBuilder() .setError(ErrorResponse.newBuilder().setCause(Cause.INTERNAL_SERVER_ERROR)).build(); } @@ -151,9 +151,7 @@ public class AccountCreator { return response; } - if (request.getRolesList() == null || request.getRolesList().isEmpty()) { - request = CompletePendingAccountCreationRequest.newBuilder(request).addRoles(Role.USER).build(); - } + request = CompletePendingAccountCreationRequest.newBuilder(request).clearRoles().addRoles(Role.USER).build(); Account createdAccount = accountRepositoryAdditional.completePendingAccountCreation(request);