From fa8d04d598678329123764965302b7dd59ecd80c Mon Sep 17 00:00:00 2001 From: ase-101 Date: Fri, 2 Feb 2024 22:53:02 +0530 Subject: [PATCH] ES-756 Signed-off-by: ase-101 --- .../signup/services/CacheUtilService.java | 15 ++++++++------- .../signup/services/RegistrationService.java | 18 +++++++++--------- .../io/mosip/signup/util/SignUpConstants.java | 2 +- .../signup/services/CacheUtilServiceTest.java | 6 +++--- .../services/RegistrationServiceTest.java | 12 ++++++------ 5 files changed, 27 insertions(+), 26 deletions(-) diff --git a/signup-service/src/main/java/io/mosip/signup/services/CacheUtilService.java b/signup-service/src/main/java/io/mosip/signup/services/CacheUtilService.java index e26bb831..75a0b9da 100644 --- a/signup-service/src/main/java/io/mosip/signup/services/CacheUtilService.java +++ b/signup-service/src/main/java/io/mosip/signup/services/CacheUtilService.java @@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.CacheManager; import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.CachePut; import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; @@ -28,16 +29,16 @@ public RegistrationTransaction setChallengeGeneratedTransaction(String transacti } @CacheEvict(value = SignUpConstants.CHALLENGE_GENERATED, key = "#transactionId") - @Cacheable(value = SignUpConstants.CHALLENGE_VERIFIED, key = "#transactionId") - public RegistrationTransaction setChallengeVerifiedTransaction(String transactionId, + @Cacheable(value = SignUpConstants.CHALLENGE_VERIFIED, key = "#verifiedTransactionId") + public RegistrationTransaction setChallengeVerifiedTransaction(String transactionId, String verifiedTransactionId, RegistrationTransaction registrationTransaction) { return registrationTransaction; } @CacheEvict(value = SignUpConstants.CHALLENGE_VERIFIED, key = "#transactionId") - @Cacheable(value = SignUpConstants.REGISTERED_CACHE, key = "#transactionId") - public RegistrationTransaction setRegisteredTransaction(String transactionId, - RegistrationTransaction registrationTransaction) { + @CachePut(value = SignUpConstants.STATUS_CHECK, key = "#transactionId") + public RegistrationTransaction setStatusCheckTransaction(String transactionId, + RegistrationTransaction registrationTransaction) { return registrationTransaction; } @@ -65,8 +66,8 @@ public RegistrationTransaction getChallengeVerifiedTransaction(String transactio return cacheManager.getCache(SignUpConstants.CHALLENGE_VERIFIED).get(transactionId, RegistrationTransaction.class); } - public RegistrationTransaction getRegisteredTransaction(String transactionId) { - return cacheManager.getCache(SignUpConstants.REGISTERED_CACHE).get(transactionId, RegistrationTransaction.class); + public RegistrationTransaction getStatusCheckTransaction(String transactionId) { + return cacheManager.getCache(SignUpConstants.STATUS_CHECK).get(transactionId, RegistrationTransaction.class); } public boolean isIdentifierBlocked(String identifier) { diff --git a/signup-service/src/main/java/io/mosip/signup/services/RegistrationService.java b/signup-service/src/main/java/io/mosip/signup/services/RegistrationService.java index 40099678..d888751e 100644 --- a/signup-service/src/main/java/io/mosip/signup/services/RegistrationService.java +++ b/signup-service/src/main/java/io/mosip/signup/services/RegistrationService.java @@ -25,7 +25,6 @@ import org.springframework.util.StringUtils; import org.springframework.web.client.RestTemplate; -import javax.crypto.SecretKey; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletResponse; @@ -208,11 +207,11 @@ public VerifyChallengeResponse verifyChallenge(VerifyChallengeRequest verifyChal fetchAndCheckIdentity(transactionId, transaction, verifyChallengeRequest); //After successful verification of the user, change the transactionId - transactionId = IdentityProviderUtil.createTransactionId(null); - addVerifiedCookieInResponse(transactionId, registerTransactionTimeout+statusCheckTransactionTimeout); + String verifiedTransactionId = IdentityProviderUtil.createTransactionId(null); + addVerifiedCookieInResponse(verifiedTransactionId, registerTransactionTimeout+statusCheckTransactionTimeout); - cacheUtilService.setChallengeVerifiedTransaction(transactionId, transaction); - log.debug("Transaction {} : verify challenge status {}", transactionId, ActionStatus.SUCCESS); + cacheUtilService.setChallengeVerifiedTransaction(transactionId, verifiedTransactionId, transaction); + log.debug("Transaction {} : verify challenge status {}", verifiedTransactionId, ActionStatus.SUCCESS); return new VerifyChallengeResponse(ActionStatus.SUCCESS); } @@ -241,7 +240,7 @@ public RegisterResponse register(RegisterRequest registerRequest, String transac saveIdentityData(registerRequest, transactionId, transaction); transaction.setRegistrationStatus(RegistrationStatus.PENDING); - cacheUtilService.setRegisteredTransaction(transactionId, transaction); + cacheUtilService.setStatusCheckTransaction(transactionId, transaction); notificationHelper.sendSMSNotificationAsync(registerRequest.getUserInfo().getPhone(), transaction.getLocale(), REGISTRATION_SMS_NOTIFICATION_TEMPLATE_KEY, null) @@ -309,7 +308,7 @@ public RegistrationStatusResponse updatePassword(ResetPasswordRequest resetPassw transaction.getHandlesStatus().put(getHandleRequestId(transaction.getApplicationId(), "phone", resetPasswordRequest.getIdentifier()), RegistrationStatus.PENDING); transaction.setRegistrationStatus(RegistrationStatus.PENDING); - cacheUtilService.setRegisteredTransaction(transactionId, transaction); + cacheUtilService.setStatusCheckTransaction(transactionId, transaction); notificationHelper.sendSMSNotificationAsync(resetPasswordRequest.getIdentifier(), transaction.getLocale(), FORGOT_PASSWORD_SMS_NOTIFICATION_TEMPLATE_KEY, null) @@ -327,7 +326,7 @@ public RegistrationStatusResponse getRegistrationStatus(String transactionId) if (transactionId == null || transactionId.isEmpty()) throw new InvalidTransactionException(); - RegistrationTransaction registrationTransaction = cacheUtilService.getRegisteredTransaction( + RegistrationTransaction registrationTransaction = cacheUtilService.getStatusCheckTransaction( transactionId); if (registrationTransaction == null) throw new InvalidTransactionException(); @@ -340,9 +339,10 @@ public RegistrationStatusResponse getRegistrationStatus(String transactionId) registrationTransaction.getHandlesStatus().put(handleRequestId, registrationStatus); //TODO This is temporary fix, we need to remove this field later from registrationTransaction DTO. registrationTransaction.setRegistrationStatus(registrationStatus); + cacheUtilService.setStatusCheckTransaction(transactionId, registrationTransaction); } } - registrationTransaction = cacheUtilService.setRegisteredTransaction(transactionId, registrationTransaction); + registrationTransaction = cacheUtilService.getStatusCheckTransaction(transactionId); RegistrationStatusResponse registrationStatusResponse = new RegistrationStatusResponse(); registrationStatusResponse.setStatus(registrationTransaction.getRegistrationStatus()); return registrationStatusResponse; diff --git a/signup-service/src/main/java/io/mosip/signup/util/SignUpConstants.java b/signup-service/src/main/java/io/mosip/signup/util/SignUpConstants.java index 0e98a2f8..e9061067 100644 --- a/signup-service/src/main/java/io/mosip/signup/util/SignUpConstants.java +++ b/signup-service/src/main/java/io/mosip/signup/util/SignUpConstants.java @@ -4,7 +4,7 @@ public class SignUpConstants { public static final String CHALLENGE_GENERATED = "challenge_generated"; public static final String CHALLENGE_VERIFIED = "challenge_verified"; - public static final String REGISTERED_CACHE = "status_check"; + public static final String STATUS_CHECK = "status_check"; public static final String BLOCKED_IDENTIFIER = "blocked_identifier"; public static final String KEYSTORE = "keystore"; public static final String KEY_ALIAS = "key_alias"; diff --git a/signup-service/src/test/java/io/mosip/signup/services/CacheUtilServiceTest.java b/signup-service/src/test/java/io/mosip/signup/services/CacheUtilServiceTest.java index 3e137197..ca32be57 100644 --- a/signup-service/src/test/java/io/mosip/signup/services/CacheUtilServiceTest.java +++ b/signup-service/src/test/java/io/mosip/signup/services/CacheUtilServiceTest.java @@ -33,14 +33,14 @@ public void test_RegistrationTransaction_cache() { Assert.assertEquals(cacheUtilService.setChallengeGeneratedTransaction("mock", registrationTransaction), registrationTransaction); - Assert.assertEquals(cacheUtilService.setChallengeVerifiedTransaction("mock", + Assert.assertEquals(cacheUtilService.setChallengeVerifiedTransaction("mock", "vmock", registrationTransaction), registrationTransaction); - Assert.assertEquals(cacheUtilService.setRegisteredTransaction("mock", + Assert.assertEquals(cacheUtilService.setStatusCheckTransaction("mock", registrationTransaction), registrationTransaction); Assert.assertNotNull(cacheUtilService.getChallengeGeneratedTransaction("mock")); Assert.assertNotNull(cacheUtilService.getChallengeVerifiedTransaction("mock")); - Assert.assertNotNull(cacheUtilService.getRegisteredTransaction("mock")); + Assert.assertNotNull(cacheUtilService.getStatusCheckTransaction("mock")); } @Test diff --git a/signup-service/src/test/java/io/mosip/signup/services/RegistrationServiceTest.java b/signup-service/src/test/java/io/mosip/signup/services/RegistrationServiceTest.java index 2375edcb..0fca5cfb 100644 --- a/signup-service/src/test/java/io/mosip/signup/services/RegistrationServiceTest.java +++ b/signup-service/src/test/java/io/mosip/signup/services/RegistrationServiceTest.java @@ -1862,8 +1862,8 @@ public void doGetRegistrationStatus_withCompletedTransaction_thenPass() { String transactionId = "TRAN-1234"; RegistrationTransaction registrationTransaction = new RegistrationTransaction("+85577410541", Purpose.REGISTRATION); registrationTransaction.setRegistrationStatus(RegistrationStatus.COMPLETED); - when(cacheUtilService.getRegisteredTransaction(transactionId)).thenReturn(registrationTransaction); - when(cacheUtilService.setRegisteredTransaction(transactionId, registrationTransaction)).thenReturn(registrationTransaction); + when(cacheUtilService.getStatusCheckTransaction(transactionId)).thenReturn(registrationTransaction); + when(cacheUtilService.setStatusCheckTransaction(transactionId, registrationTransaction)).thenReturn(registrationTransaction); RegistrationStatusResponse registrationStatusResponse = registrationService.getRegistrationStatus(transactionId); Assert.assertNotNull(registrationStatusResponse); @@ -1875,8 +1875,8 @@ public void doGetRegistrationStatus_withPendingTransaction_thenPass() { String transactionId = "TRAN-1234"; RegistrationTransaction registrationTransaction = new RegistrationTransaction("+85577410541", Purpose.REGISTRATION); registrationTransaction.setRegistrationStatus(RegistrationStatus.PENDING); - when(cacheUtilService.getRegisteredTransaction(transactionId)).thenReturn(registrationTransaction); - when(cacheUtilService.setRegisteredTransaction(transactionId, registrationTransaction)).thenReturn(registrationTransaction); + when(cacheUtilService.getStatusCheckTransaction(transactionId)).thenReturn(registrationTransaction); + when(cacheUtilService.setStatusCheckTransaction(transactionId, registrationTransaction)).thenReturn(registrationTransaction); RegistrationStatusResponse registrationStatusResponse = registrationService.getRegistrationStatus(transactionId); Assert.assertNotNull(registrationStatusResponse); @@ -1888,8 +1888,8 @@ public void doGetRegistrationStatus_withFailedTransaction_thenPass() { String transactionId = "TRAN-1234"; RegistrationTransaction registrationTransaction = new RegistrationTransaction("+85577410541", Purpose.REGISTRATION); registrationTransaction.setRegistrationStatus(RegistrationStatus.FAILED); - when(cacheUtilService.getRegisteredTransaction(transactionId)).thenReturn(registrationTransaction); - when(cacheUtilService.setRegisteredTransaction(transactionId, registrationTransaction)).thenReturn(registrationTransaction); + when(cacheUtilService.getStatusCheckTransaction(transactionId)).thenReturn(registrationTransaction); + when(cacheUtilService.setStatusCheckTransaction(transactionId, registrationTransaction)).thenReturn(registrationTransaction); RegistrationStatusResponse registrationStatusResponse = registrationService.getRegistrationStatus(transactionId); Assert.assertNotNull(registrationStatusResponse);