From 0bd0c3eb976565cbe19bded94e3ba523a557792a Mon Sep 17 00:00:00 2001 From: Stanimir Penkov Date: Mon, 15 Oct 2018 16:27:09 +0300 Subject: [PATCH 1/6] NY-3808: Endpoint for adding contact info to account - implemented endpoint for adding contact info to account; - changed access modifiers in AccountRepositoryAdditionalImpl.java Signed-off-by: Stanimir Penkov --- .../nynja/account/components/Validator.java | 47 +++++++++++++++++++ .../AccountRepositoryAdditional.java | 3 ++ .../AccountRepositoryAdditionalImpl.java | 40 +++++++++++++--- .../account/services/AccountServiceImpl.java | 43 +++++++++++++++++ 4 files changed, 127 insertions(+), 6 deletions(-) diff --git a/src/main/java/biz/nynja/account/components/Validator.java b/src/main/java/biz/nynja/account/components/Validator.java index 8544c46..93d801d 100644 --- a/src/main/java/biz/nynja/account/components/Validator.java +++ b/src/main/java/biz/nynja/account/components/Validator.java @@ -19,12 +19,14 @@ import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.stereotype.Component; import biz.nynja.account.grpc.AddAuthenticationProviderRequest; +import biz.nynja.account.grpc.AddContactInfoRequest; import com.google.i18n.phonenumbers.NumberParseException; import com.google.i18n.phonenumbers.PhoneNumberUtil; import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber; import biz.nynja.account.grpc.AuthProviderDetails; import biz.nynja.account.grpc.AuthenticationType; import biz.nynja.account.grpc.CompletePendingAccountCreationRequest; +import biz.nynja.account.grpc.ContactType; import biz.nynja.account.grpc.CreatePendingAccountRequest; import biz.nynja.account.grpc.DeleteAuthenticationProviderRequest; import biz.nynja.account.grpc.ErrorResponse.Cause; @@ -236,6 +238,34 @@ public class Validator { return null; } + public Cause validateContactInfo(ContactType type, String contactInfoValue) { + if (contactInfoValue == null || contactInfoValue.trim().isEmpty()) { + return Cause.MISSING_CONTACT_INFO_IDENTIFIER; + } + switch (type) { + case MISSING_CONTACT_TYPE: + return Cause.MISSING_CONTACT_INFO_TYPE; + case PHONE_CONTACT: + // We expect to receive phone number in the following format : ":" + String[] provider = contactInfoValue.split(":"); + if (provider == null || provider.length != 2) { + return Cause.PHONE_NUMBER_INVALID; + } + if (!isPhoneNumberValid(provider[1], provider[0])) { + return Cause.PHONE_NUMBER_INVALID; + } + break; + case EMAIL_CONTACT: + if (!isEmailValid(contactInfoValue)) { + return Cause.EMAIL_INVALID; + } + break; + default: + break; + } + return null; + } + public Cause validateCreatePendingAccountRequest(CreatePendingAccountRequest request) { return validateAuthProvider(request.getAuthenticationType(), request.getAuthenticationProvider()); } @@ -310,6 +340,23 @@ public class Validator { request.getAuthenticationProvider().getAuthenticationProvider()); } + public Cause checkAddContactInfoRequest(AddContactInfoRequest request) { + if ((request.getAccountId() == null) || (request.getAccountId().isEmpty())) { + return Cause.MISSING_ACCOUNT_ID; + } + if (request.getContactInfo().getTypeValue() == 0) { + return Cause.MISSING_CONTACT_INFO_TYPE; + + } + if (request.getContactInfo().getValue() == null || request.getContactInfo().getValue().isEmpty()) { + return Cause.MISSING_CONTACT_INFO_IDENTIFIER; + } + if (!isValidUuid(request.getAccountId())) { + return Cause.INVALID_ACCOUNT_ID; + } + return validateContactInfo(request.getContactInfo().getType(), request.getContactInfo().getValue()); + } + public Cause validateDeleteAuthenticationProviderRequest(DeleteAuthenticationProviderRequest request) { if (!isValidUuid(request.getProfileId())) { return Cause.INVALID_PROFILE_ID; diff --git a/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditional.java b/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditional.java index e7628f9..382adca 100644 --- a/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditional.java +++ b/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditional.java @@ -12,6 +12,7 @@ import biz.nynja.account.grpc.UpdateAccountRequest; import biz.nynja.account.grpc.UpdateProfileRequest; import biz.nynja.account.models.Account; import biz.nynja.account.models.AuthenticationProvider; +import biz.nynja.account.models.ContactInfo; import biz.nynja.account.models.PendingAccountByAuthenticationProvider; import biz.nynja.account.models.Profile; @@ -37,4 +38,6 @@ public interface AccountRepositoryAdditional { boolean addAuthenticationProvider(UUID profileId, AuthenticationProvider authProvider); boolean deleteAuthenticationProvider(Profile profile, AuthenticationProvider authProvider); + + boolean addContactInfo(UUID accountId, ContactInfo contactInfo); } diff --git a/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java b/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java index e760dab..3cc02ff 100644 --- a/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java +++ b/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java @@ -15,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.cassandra.core.CassandraBatchOperations; import org.springframework.data.cassandra.core.CassandraTemplate; +import org.springframework.data.cassandra.core.UpdateOptions; import org.springframework.data.cassandra.core.WriteResult; import org.springframework.stereotype.Service; @@ -62,19 +63,19 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio private ProfileRepository profileRepository; @Autowired - AccountByUsernameRepository accountByUsernameRepository; + private AccountByUsernameRepository accountByUsernameRepository; @Autowired - AccountByAuthenticationProviderRepository accountByAuthenticationProviderRepository; + private AccountByAuthenticationProviderRepository accountByAuthenticationProviderRepository; @Autowired - AccountByProfileIdRepository accountByProfileIdRepository; + private AccountByProfileIdRepository accountByProfileIdRepository; @Autowired - ProfileByAuthenticationProviderRepository profileByAuthenticationProviderRepository; + private ProfileByAuthenticationProviderRepository profileByAuthenticationProviderRepository; @Autowired - PendingAccountByAuthenticationProviderRepository pendingAccountByAuthenticationProviderRepository; + private PendingAccountByAuthenticationProviderRepository pendingAccountByAuthenticationProviderRepository; @Autowired private PendingAccountRepository pendingAccountRepository; @@ -515,7 +516,34 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio } @Override - public boolean deleteAuthenticationProvider(Profile profile, AuthenticationProvider authProvider) { + public boolean addContactInfo(UUID accountId, ContactInfo contactInfo) { + Account accountToUpdate = accountRepository.findByAccountId(accountId); + if (accountToUpdate == null) { + logger.error("Existing account with the provided id {} was not found.", accountId); + return false; + } + Set contactsInfoSet = accountToUpdate.getContactsInfo(); + if (contactsInfoSet == null) { + contactsInfoSet = new HashSet(); + } + if (contactInfo != null) { + if (!contactsInfoSet.add(contactInfo)) { + return false; + } + accountToUpdate.setContactsInfo(contactsInfoSet); + } + Long timeUpdated = new Date().getTime(); + accountToUpdate.setLastUpdateTimestamp(timeUpdated); + WriteResult wr = cassandraTemplate.update(accountToUpdate, UpdateOptions.builder().ifExists(true).build()); + if (wr != null && wr.wasApplied()) { + return true; + } + return false; + } + + @Override + public boolean deleteAuthenticationProvider(Profile profile, + AuthenticationProvider authProvider) { BatchStatement batch = new BatchStatement(); ResultSet rs = null; diff --git a/src/main/java/biz/nynja/account/services/AccountServiceImpl.java b/src/main/java/biz/nynja/account/services/AccountServiceImpl.java index fff5366..cfc91d1 100644 --- a/src/main/java/biz/nynja/account/services/AccountServiceImpl.java +++ b/src/main/java/biz/nynja/account/services/AccountServiceImpl.java @@ -23,9 +23,12 @@ import biz.nynja.account.grpc.AccountsByProfileIdRequest; import biz.nynja.account.grpc.AccountsList; import biz.nynja.account.grpc.AccountsResponse; import biz.nynja.account.grpc.AddAuthenticationProviderRequest; +import biz.nynja.account.grpc.AddContactInfoRequest; import biz.nynja.account.grpc.AuthProviderDetails; import biz.nynja.account.grpc.AuthenticationType; import biz.nynja.account.grpc.CompletePendingAccountCreationRequest; +import biz.nynja.account.grpc.ContactDetails; +import biz.nynja.account.grpc.ContactType; import biz.nynja.account.grpc.CreateAccountRequest; import biz.nynja.account.grpc.CreatePendingAccountRequest; import biz.nynja.account.grpc.CreatePendingAccountResponse; @@ -38,6 +41,7 @@ import biz.nynja.account.grpc.ErrorResponse.Cause; import biz.nynja.account.models.Account; import biz.nynja.account.models.AccountByProfileId; import biz.nynja.account.models.AuthenticationProvider; +import biz.nynja.account.models.ContactInfo; import biz.nynja.account.models.PendingAccount; import biz.nynja.account.models.PendingAccountByAuthenticationProvider; import biz.nynja.account.repositories.AccountByAuthenticationProviderRepository; @@ -550,6 +554,45 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas return; } + @Override + public void addContactInfoToAccount(AddContactInfoRequest request, + StreamObserver responseObserver) { + logger.info("Adding contact info to account requested."); + logger.debug("Adding contact info to account requested: {}", request); + Cause cause = validator.checkAddContactInfoRequest(request); + if (cause != null) { + responseObserver + .onNext(StatusResponse.newBuilder().setError(ErrorResponse.newBuilder().setCause(cause)).build()); + responseObserver.onCompleted(); + return; + } + if (request.getContactInfo().getType() == ContactType.PHONE_CONTACT) { + // Get the normalized phone number from libphone + ContactDetails newContactDetails = ContactDetails.newBuilder().setType(request.getContactInfo().getType()) + .setValue(validator.getNormalizedPhoneNumber(request.getContactInfo().getValue())) + .setLabel(request.getContactInfo().getLabel()).build(); + + AddContactInfoRequest newRequest = AddContactInfoRequest.newBuilder().setAccountId(request.getAccountId()) + .setContactInfo(newContactDetails).build(); + request = newRequest; + } + boolean result = accountRepositoryAdditional.addContactInfo(UUID.fromString(request.getAccountId()), + ContactInfo.createContactInfoFromProto(request.getContactInfo())); + if (result) { + logger.info("Contact info {}:{} was added to account {}.", request.getContactInfo().getType().name(), + request.getContactInfo().getValue(), request.getAccountId()); + responseObserver.onNext(StatusResponse.newBuilder().setStatus("SUCCESS").build()); + responseObserver.onCompleted(); + return; + } + logger.error("Contact info {}:{} was not added to account {}.", request.getContactInfo().getType().name(), + request.getContactInfo().getValue(), request.getAccountId()); + responseObserver.onNext(StatusResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.INTERNAL_SERVER_ERROR)).build()); + responseObserver.onCompleted(); + return; + } + @Override public void deleteAuthenticationProviderFromProfile(DeleteAuthenticationProviderRequest request, StreamObserver responseObserver) { -- GitLab From 6f81841b631576f233b066c399655bbc9a7c0cbf Mon Sep 17 00:00:00 2001 From: Stanimir Penkov Date: Mon, 15 Oct 2018 16:32:39 +0300 Subject: [PATCH 2/6] NY-3808: Remove blank rows Signed-off-by: Stanimir Penkov --- src/main/java/biz/nynja/account/components/Validator.java | 1 - src/main/java/biz/nynja/account/services/AccountServiceImpl.java | 1 - 2 files changed, 2 deletions(-) diff --git a/src/main/java/biz/nynja/account/components/Validator.java b/src/main/java/biz/nynja/account/components/Validator.java index 93d801d..2da72ad 100644 --- a/src/main/java/biz/nynja/account/components/Validator.java +++ b/src/main/java/biz/nynja/account/components/Validator.java @@ -346,7 +346,6 @@ public class Validator { } if (request.getContactInfo().getTypeValue() == 0) { return Cause.MISSING_CONTACT_INFO_TYPE; - } if (request.getContactInfo().getValue() == null || request.getContactInfo().getValue().isEmpty()) { return Cause.MISSING_CONTACT_INFO_IDENTIFIER; diff --git a/src/main/java/biz/nynja/account/services/AccountServiceImpl.java b/src/main/java/biz/nynja/account/services/AccountServiceImpl.java index cfc91d1..84f5ac7 100644 --- a/src/main/java/biz/nynja/account/services/AccountServiceImpl.java +++ b/src/main/java/biz/nynja/account/services/AccountServiceImpl.java @@ -571,7 +571,6 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas ContactDetails newContactDetails = ContactDetails.newBuilder().setType(request.getContactInfo().getType()) .setValue(validator.getNormalizedPhoneNumber(request.getContactInfo().getValue())) .setLabel(request.getContactInfo().getLabel()).build(); - AddContactInfoRequest newRequest = AddContactInfoRequest.newBuilder().setAccountId(request.getAccountId()) .setContactInfo(newContactDetails).build(); request = newRequest; -- GitLab From e6fe1f364a7dba6d359963aa2e3a4a25a605b8b7 Mon Sep 17 00:00:00 2001 From: Stanimir Penkov Date: Mon, 15 Oct 2018 17:13:35 +0300 Subject: [PATCH 3/6] NY-3808: Log error message for existing contact info - added error message for existing contact info; - changed message in ContactInfo.java. Signed-off-by: Stanimir Penkov --- src/main/java/biz/nynja/account/models/ContactInfo.java | 2 +- .../account/repositories/AccountRepositoryAdditionalImpl.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/biz/nynja/account/models/ContactInfo.java b/src/main/java/biz/nynja/account/models/ContactInfo.java index c4f13cc..982681d 100644 --- a/src/main/java/biz/nynja/account/models/ContactInfo.java +++ b/src/main/java/biz/nynja/account/models/ContactInfo.java @@ -79,7 +79,7 @@ public class ContactInfo { @Override public String toString() { - return new StringBuilder("Contact [type=").append(type).append(", value=").append(value).append(", label=") + return new StringBuilder("Contact info [type=").append(type).append(", value=").append(value).append(", label=") .append(label).append("]").toString(); } diff --git a/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java b/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java index 3cc02ff..a345ed7 100644 --- a/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java +++ b/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java @@ -528,6 +528,7 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio } if (contactInfo != null) { if (!contactsInfoSet.add(contactInfo)) { + logger.error("Error adding contact info to account {}. {} already exists.", accountId, contactInfo.toString()); return false; } accountToUpdate.setContactsInfo(contactsInfoSet); -- GitLab From c1358c4e5d84771634f2cb735b64db8f46748e3c Mon Sep 17 00:00:00 2001 From: Stanimir Penkov Date: Tue, 16 Oct 2018 14:14:39 +0300 Subject: [PATCH 4/6] NY-3808: Apply code alignment Signed-off-by: Stanimir Penkov --- .../account/repositories/AccountRepositoryAdditionalImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java b/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java index a345ed7..7984fee 100644 --- a/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java +++ b/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java @@ -528,7 +528,8 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio } if (contactInfo != null) { if (!contactsInfoSet.add(contactInfo)) { - logger.error("Error adding contact info to account {}. {} already exists.", accountId, contactInfo.toString()); + logger.error("Error adding contact info to account {}. {} already exists.", accountId, + contactInfo.toString()); return false; } accountToUpdate.setContactsInfo(contactsInfoSet); -- GitLab From 8d22d78a5c3bd788b0daf7c954c6054d04a8201e Mon Sep 17 00:00:00 2001 From: Stanimir Penkov Date: Tue, 16 Oct 2018 15:34:15 +0300 Subject: [PATCH 5/6] NY-3808: Use the cause for error adding contact info Signed-off-by: Stanimir Penkov --- .../java/biz/nynja/account/services/AccountServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/biz/nynja/account/services/AccountServiceImpl.java b/src/main/java/biz/nynja/account/services/AccountServiceImpl.java index 84f5ac7..f719b31 100644 --- a/src/main/java/biz/nynja/account/services/AccountServiceImpl.java +++ b/src/main/java/biz/nynja/account/services/AccountServiceImpl.java @@ -587,7 +587,7 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas logger.error("Contact info {}:{} was not added to account {}.", request.getContactInfo().getType().name(), request.getContactInfo().getValue(), request.getAccountId()); responseObserver.onNext(StatusResponse.newBuilder() - .setError(ErrorResponse.newBuilder().setCause(Cause.INTERNAL_SERVER_ERROR)).build()); + .setError(ErrorResponse.newBuilder().setCause(Cause.ERROR_ADDING_CONTACT_INFO)).build()); responseObserver.onCompleted(); return; } -- GitLab From e4bedcb4ca825e6561af3dd188a85d0e8ea1afff Mon Sep 17 00:00:00 2001 From: Stanimir Penkov Date: Thu, 18 Oct 2018 17:13:09 +0300 Subject: [PATCH 6/6] NY-3808: Code Review Feedback - extracted additional method; - changed setting of time; - added empty rows to improve readability. Signed-off-by: Stanimir Penkov --- .../AccountRepositoryAdditionalImpl.java | 11 ++++---- .../account/services/AccountServiceImpl.java | 27 ++++++++++++------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java b/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java index 7984fee..8aa3bfc 100644 --- a/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java +++ b/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java @@ -3,6 +3,7 @@ */ package biz.nynja.account.repositories; +import java.time.Instant; import java.util.Date; import java.util.HashSet; import java.util.List; @@ -95,7 +96,7 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio logger.debug("Existing pending account with the provided id {} was not found.", request.getAccountId()); return null; } - Long timeCreated = new Date().getTime(); + Long timeCreated = Instant.now().toEpochMilli(); Long checkMinutes = timeCreated - pendingAccount.getCreationTimestamp(); if (checkMinutes > COMPLETE_PENDING_ACCOUNT_TIMEOUT_IN_MINUTES * 60 * 1000) { logger.info("Account creation timeout expired."); @@ -172,7 +173,7 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio logger.debug("Existing profile with the provided id {} was not found.", request.getProfileId()); return null; } - Long timeUpdated = new Date().getTime(); + Long timeUpdated = Instant.now().toEpochMilli(); WriteResult wr = null; try { updateProfileData(batchOperations, request, existingProfile, timeUpdated); @@ -201,7 +202,7 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio logger.debug("Existing account with the provided id {} was not found.", request.getAccountId()); return null; } - Long timeUpdated = new Date().getTime(); + Long timeUpdated = Instant.now().toEpochMilli(); WriteResult wr = null; try { updateAccountData(batchOperations, request, existingAccount, timeUpdated); @@ -283,7 +284,7 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio Profile existingProfile) { // update authentication providers of the profile by removing the one of the deleted account (if not // already manually removed by the user) - Long timeUpdated = new Date().getTime(); + Long timeUpdated = Instant.now().toEpochMilli(); if (existingProfile.getAuthenticationProviders() != null) { Set existingAuthenticationProvidersSet = new HashSet( existingProfile.getAuthenticationProviders()); @@ -534,7 +535,7 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio } accountToUpdate.setContactsInfo(contactsInfoSet); } - Long timeUpdated = new Date().getTime(); + Long timeUpdated = Instant.now().toEpochMilli(); accountToUpdate.setLastUpdateTimestamp(timeUpdated); WriteResult wr = cassandraTemplate.update(accountToUpdate, UpdateOptions.builder().ifExists(true).build()); if (wr != null && wr.wasApplied()) { diff --git a/src/main/java/biz/nynja/account/services/AccountServiceImpl.java b/src/main/java/biz/nynja/account/services/AccountServiceImpl.java index f719b31..fe0bea3 100644 --- a/src/main/java/biz/nynja/account/services/AccountServiceImpl.java +++ b/src/main/java/biz/nynja/account/services/AccountServiceImpl.java @@ -3,6 +3,7 @@ */ package biz.nynja.account.services; +import java.time.Instant; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -251,7 +252,7 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas updatedPendingAccount.setAuthenticationProvider(foundExistingPendingAccount.getAuthenticationProvider()); updatedPendingAccount .setAuthenticationProviderType(foundExistingPendingAccount.getAuthenticationProviderType()); - updatedPendingAccount.setCreationTimestamp(new Date().getTime()); + updatedPendingAccount.setCreationTimestamp(Instant.now().toEpochMilli()); PendingAccount updatePendingAccount = pendingAccountRepository.save(updatedPendingAccount); CreatePendingAccountResponse response = CreatePendingAccountResponse.newBuilder() @@ -279,7 +280,7 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas pendingAccount.setAccountId(UUID.randomUUID()); pendingAccount.setProfileId(UUID.randomUUID()); - pendingAccount.setCreationTimestamp(new Date().getTime()); + pendingAccount.setCreationTimestamp(Instant.now().toEpochMilli()); PendingAccount savedPendingAccount = pendingAccountRepository.save(pendingAccount); logger.debug("Pending account \"{}\" saved into the DB", savedPendingAccount.toString()); @@ -559,6 +560,7 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas StreamObserver responseObserver) { logger.info("Adding contact info to account requested."); logger.debug("Adding contact info to account requested: {}", request); + Cause cause = validator.checkAddContactInfoRequest(request); if (cause != null) { responseObserver @@ -566,15 +568,11 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas responseObserver.onCompleted(); return; } + if (request.getContactInfo().getType() == ContactType.PHONE_CONTACT) { - // Get the normalized phone number from libphone - ContactDetails newContactDetails = ContactDetails.newBuilder().setType(request.getContactInfo().getType()) - .setValue(validator.getNormalizedPhoneNumber(request.getContactInfo().getValue())) - .setLabel(request.getContactInfo().getLabel()).build(); - AddContactInfoRequest newRequest = AddContactInfoRequest.newBuilder().setAccountId(request.getAccountId()) - .setContactInfo(newContactDetails).build(); - request = newRequest; + request = normalizePhoneNumber(request); } + boolean result = accountRepositoryAdditional.addContactInfo(UUID.fromString(request.getAccountId()), ContactInfo.createContactInfoFromProto(request.getContactInfo())); if (result) { @@ -592,6 +590,17 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas return; } + private AddContactInfoRequest normalizePhoneNumber(AddContactInfoRequest request) { + // Get the normalized phone number from libphone + ContactDetails newContactDetails = ContactDetails.newBuilder().setType(request.getContactInfo().getType()) + .setValue(validator.getNormalizedPhoneNumber(request.getContactInfo().getValue())) + .setLabel(request.getContactInfo().getLabel()).build(); + AddContactInfoRequest newRequest = AddContactInfoRequest.newBuilder().setAccountId(request.getAccountId()) + .setContactInfo(newContactDetails).build(); + request = newRequest; + return request; + } + @Override public void deleteAuthenticationProviderFromProfile(DeleteAuthenticationProviderRequest request, StreamObserver responseObserver) { -- GitLab