diff --git a/src/main/java/biz/nynja/account/services/AccountServiceImpl.java b/src/main/java/biz/nynja/account/services/AccountServiceImpl.java index 058737bb55d42b88f2ee988e885c406e67d9aee0..d33e6249e3dd11755c6190599b4571d11c2b2f3b 100644 --- a/src/main/java/biz/nynja/account/services/AccountServiceImpl.java +++ b/src/main/java/biz/nynja/account/services/AccountServiceImpl.java @@ -5,6 +5,7 @@ package biz.nynja.account.services; import static biz.nynja.account.validation.Validators.account; import static biz.nynja.account.validation.Validators.authenticationProvider; +import static biz.nynja.account.validation.Validators.pendingAccount; import static biz.nynja.account.validation.Validators.phoneValidator; import static biz.nynja.account.validation.Validators.util; @@ -456,14 +457,19 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas @Permitted(role = RoleConstants.USER) public void createPendingAccount(CreatePendingAccountRequest request, StreamObserver responseObserver) { + CreatePendingAccountResponse response; logger.info("Creating pending account..."); logger.debug("Creating pending account: {} ...", request); - CreatePendingAccountResponse response = accountCreator.retrieveCreatePendingAccountResponse(request); + Optional cause = pendingAccount.validateCreatePendingAccountRequest(request); + if (cause.isPresent()) { + response = CreatePendingAccountResponse.newBuilder().setError(ErrorResponse.newBuilder().setCause(cause.get())) + .build(); + } else { + response = accountCreator.retrieveCreatePendingAccountResponse(request); + } - logger.info("SUCCESS: Created pending account for provider {}: \"{}\"", request.getAuthenticationProvider(), - response); responseObserver.onNext(response); responseObserver.onCompleted(); } 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..d8893c461fa640d3cd5d986a50959956aaa38003 100644 --- a/src/main/java/biz/nynja/account/services/decomposition/AccountCreator.java +++ b/src/main/java/biz/nynja/account/services/decomposition/AccountCreator.java @@ -55,11 +55,6 @@ public class AccountCreator { * @return */ public CreatePendingAccountResponse retrieveCreatePendingAccountResponse(CreatePendingAccountRequest request) { - Optional cause = pendingAccount.validateCreatePendingAccountRequest(request); - if (cause.isPresent()) { - return CreatePendingAccountResponse.newBuilder().setError(ErrorResponse.newBuilder().setCause(cause.get())) - .build(); - } if (request.getAuthenticationType() == AuthenticationType.PHONE) { // Get the normalized phone number from libphone @@ -98,8 +93,8 @@ public class AccountCreator { logger.debug("Pending account \"{}\" saved into the DB", savedPendingAccount); response = CreatePendingAccountResponse.newBuilder().setPendingAccountDetails(savedPendingAccount.toProto()) .build(); - logger.info("Pending account created successfully."); - logger.debug("Pending account: \"{}\" created successfully.", response); + logger.info("SUCCESS: Pending account created successfully."); + logger.debug("SUCCESS: Pending account: \"{}\" created successfully.", response); return response; } catch (Exception e) { logger.error(e.getMessage()); diff --git a/src/main/java/biz/nynja/account/validation/Validators.java b/src/main/java/biz/nynja/account/validation/Validators.java index 21dc73cca84cc91da3fc83b7dfd5d5d0375b88a2..ee8971197aceb42bb756115759fb95502c7902b8 100644 --- a/src/main/java/biz/nynja/account/validation/Validators.java +++ b/src/main/java/biz/nynja/account/validation/Validators.java @@ -453,9 +453,13 @@ public class Validators { logger.info("Checking email: {}", email); EmailValidator eValidator = EmailValidator.getInstance(); - boolean result = eValidator.isValid(email); - logger.info("Email: {} is " + (result ? "" : "not ") + "valid.", email); - return result; + boolean validated = eValidator.isValid(email); + if (!validated) { + logger.error("Email: {} is not valid.", email); + } else { + logger.info("Email: {} is valid.", email); + } + return validated; } public boolean validateBirthdayIsSet(Date birthday) {