diff --git a/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditional.java b/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditional.java index 3503b4236be83bffa281342e3d73a454e54f8d73..80a8f851bbe3f57114a0b012315145ba11051cec 100644 --- a/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditional.java +++ b/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditional.java @@ -15,6 +15,7 @@ import biz.nynja.account.models.AuthenticationProvider; import biz.nynja.account.models.ContactInfo; import biz.nynja.account.models.PendingAccountByAuthenticationProvider; import biz.nynja.account.models.Profile; +import biz.nynja.account.models.PendingAccount; @Repository public interface AccountRepositoryAdditional { @@ -44,4 +45,6 @@ public interface AccountRepositoryAdditional { boolean deleteContactInfo(UUID accountId, ContactInfo contactInfo); boolean editContactInfo(UUID accountId, ContactInfo oldContactInfo, ContactInfo editedContactInfo); + + PendingAccount savePendingAccount(PendingAccount updatedPendingAccount); } diff --git a/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java b/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java index 3254ff1b73434172817e16fac86e184db66537df..2d5738fb99e2e322f0f3098453bfebe4d6e42a88 100644 --- a/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java +++ b/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java @@ -97,17 +97,11 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio PendingAccount pendingAccount = pendingAccountRepository .findByAccountId(UUID.fromString(request.getAccountId())); if (pendingAccount == null) { - logger.info("Existing pending account with the provided id was not found."); - logger.debug("Existing pending account with the provided id {} was not found.", request.getAccountId()); + logger.info("Existing pending account with the provided id was not found or creation timeout expired.."); + logger.debug("Existing pending account with the provided id {} was not found or creation timeout expired..", request.getAccountId()); return null; } 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."); - pendingAccountRepository.deleteById(UUID.fromString(request.getAccountId())); - return null; - } WriteResult wr = null; try { newAccountInsert(batchOperations, request, pendingAccount, timeCreated); @@ -654,4 +648,12 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio } return false; } + + public PendingAccount savePendingAccount(PendingAccount pendingAccount) { + String cql = "INSERT INTO pendingAccount (accountId, profileId, authenticationProvider, authenticationProviderType, creationTimestamp)" + + " VALUES (" + pendingAccount.getAccountId() + ", " + pendingAccount.getProfileId() + ", '" + pendingAccount.getAuthenticationProvider() + "', '" + pendingAccount.getAuthenticationProviderType() + "'," + pendingAccount.getCreationTimestamp() + ") " + + "USING TTL "+COMPLETE_PENDING_ACCOUNT_TIMEOUT_IN_MINUTES *60 +";"; + cassandraTemplate.getCqlOperations().execute(cql); + return pendingAccount; + } } diff --git a/src/main/java/biz/nynja/account/repositories/PendingAccountRepository.java b/src/main/java/biz/nynja/account/repositories/PendingAccountRepository.java index 4d3c6f1eec8766ea9cef3ffbe029d9eb2970eb3e..052aaf58012a12ec0d85dac3a07544ef0141f174 100644 --- a/src/main/java/biz/nynja/account/repositories/PendingAccountRepository.java +++ b/src/main/java/biz/nynja/account/repositories/PendingAccountRepository.java @@ -8,7 +8,6 @@ import java.util.UUID; import org.springframework.data.cassandra.repository.CassandraRepository; import org.springframework.stereotype.Repository; -import biz.nynja.account.models.Account; import biz.nynja.account.models.PendingAccount; @Repository @@ -16,4 +15,7 @@ public interface PendingAccountRepository extends CassandraRepository S save(S s); } diff --git a/src/main/java/biz/nynja/account/services/AccountServiceImpl.java b/src/main/java/biz/nynja/account/services/AccountServiceImpl.java index 77058b72fd2547ba345f16fc1442ecc60233d249..0618e73f4700e58c817a3eaf8cec50c72413c746 100644 --- a/src/main/java/biz/nynja/account/services/AccountServiceImpl.java +++ b/src/main/java/biz/nynja/account/services/AccountServiceImpl.java @@ -382,7 +382,7 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas .setAuthenticationProviderType(foundExistingPendingAccount.getAuthenticationProviderType()); updatedPendingAccount.setCreationTimestamp(Instant.now().toEpochMilli()); - PendingAccount updatePendingAccount = pendingAccountRepository.save(updatedPendingAccount); + PendingAccount updatePendingAccount = accountRepositoryAdditional.savePendingAccount(updatedPendingAccount); CreatePendingAccountResponse response = CreatePendingAccountResponse.newBuilder() .setPendingAccountDetails(updatePendingAccount.toProto()).build(); logger.info("Pending account created."); @@ -405,7 +405,7 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas pendingAccount.setProfileId(UUID.randomUUID()); pendingAccount.setCreationTimestamp(Instant.now().toEpochMilli()); - PendingAccount savedPendingAccount = pendingAccountRepository.save(pendingAccount); + PendingAccount savedPendingAccount = accountRepositoryAdditional.savePendingAccount(pendingAccount); logger.debug("Pending account \"{}\" saved into the DB", savedPendingAccount.toString()); CreatePendingAccountResponse response = CreatePendingAccountResponse.newBuilder() .setPendingAccountDetails(savedPendingAccount.toProto()).build(); diff --git a/src/test/java/biz/nynja/account/services/AccountServiceTests.java b/src/test/java/biz/nynja/account/services/AccountServiceTests.java index 7da87396bdf5a5034cf558dc56dc8e3b4eaf58f5..2528aeca8200259716d0a0e8eb372509f00bf5b3 100644 --- a/src/test/java/biz/nynja/account/services/AccountServiceTests.java +++ b/src/test/java/biz/nynja/account/services/AccountServiceTests.java @@ -461,7 +461,7 @@ public class AccountServiceTests extends GrpcServerTestBase { AuthenticationProvider.createAuthenticationProviderFromStrings(request.getAuthenticationType().name(), request.getAuthenticationProvider()))) .willReturn(existingPendingAccountByAuthenticationProvider); - given(pendingAccountRepository.save(Mockito.any(PendingAccount.class))).willReturn(existingPendingAccount); + given(accountRepositoryAdditional.savePendingAccount(Mockito.any(PendingAccount.class))).willReturn(existingPendingAccount); final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); final CreatePendingAccountResponse reply = accountServiceBlockingStub.createPendingAccount(request); @@ -500,7 +500,7 @@ public class AccountServiceTests extends GrpcServerTestBase { public void testCreatePendingAccountOK() { final CreatePendingAccountRequest request = CreatePendingAccountRequest.newBuilder() .setAuthenticationType(AuthenticationType.EMAIL).setAuthenticationProvider(Util.EMAIL).build(); - given(pendingAccountRepository.save(Mockito.any(PendingAccount.class))).willReturn(pendingAccount); + given(accountRepositoryAdditional.savePendingAccount(Mockito.any(PendingAccount.class))).willReturn(pendingAccount); final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); final CreatePendingAccountResponse reply = accountServiceBlockingStub.createPendingAccount(request); @@ -514,7 +514,7 @@ public class AccountServiceTests extends GrpcServerTestBase { final CreatePendingAccountRequest request = CreatePendingAccountRequest.newBuilder() .setAuthenticationType(AuthenticationType.EMAIL) .setAuthenticationProvider("invalid.E-mail1.@domain_test.com1").build(); - given(pendingAccountRepository.save(Mockito.any(PendingAccount.class))).willReturn(pendingAccount); + given(accountRepositoryAdditional.savePendingAccount(Mockito.any(PendingAccount.class))).willReturn(pendingAccount); final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); final CreatePendingAccountResponse reply = accountServiceBlockingStub.createPendingAccount(request); @@ -527,7 +527,7 @@ public class AccountServiceTests extends GrpcServerTestBase { public void testCreatePendingAccountInvalidPhone() { final CreatePendingAccountRequest request = CreatePendingAccountRequest.newBuilder() .setAuthenticationType(AuthenticationType.PHONE).setAuthenticationProvider("BG:084365:5555").build(); - given(pendingAccountRepository.save(Mockito.any(PendingAccount.class))).willReturn(pendingAccount); + given(accountRepositoryAdditional.savePendingAccount(Mockito.any(PendingAccount.class))).willReturn(pendingAccount); final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); final CreatePendingAccountResponse reply = accountServiceBlockingStub.createPendingAccount(request);