From 45f46bc045350ccef8324234cea3ea5020cc75fa Mon Sep 17 00:00:00 2001 From: Dragomir Todorov Date: Mon, 21 Jan 2019 14:23:54 +0200 Subject: [PATCH] NY-6173: Removed check and clear roles directly --- .../services/decomposition/AccountCreator.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) 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 9123af3..58f9e96 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); -- GitLab