From 06020a946b090d184e3d42ec14e8b768c01237f3 Mon Sep 17 00:00:00 2001 From: Aiham Date: Mon, 18 Dec 2023 14:37:00 +0530 Subject: [PATCH 1/3] [MOSIP-29805] Updated Anonymous profile Signed-off-by: Aiham --- .../src/main/resources/application.properties | 4 +++- .../anonymous/service/AnonymousProfileService.java | 7 +++++-- .../service/test/AnonymousProfileServiceTest.java | 11 +++++++---- .../src/test/resources/application.properties | 2 ++ 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/pre-registration/pre-registration-application-service/src/main/resources/application.properties b/pre-registration/pre-registration-application-service/src/main/resources/application.properties index bf3692fded3..98b834d7793 100644 --- a/pre-registration/pre-registration-application-service/src/main/resources/application.properties +++ b/pre-registration/pre-registration-application-service/src/main/resources/application.properties @@ -424,4 +424,6 @@ auth.server.admin.allowed.audience=mosip-regproc-client,mosip-prereg-client,mosi #the custom auth provider component names list #mosip.security.authentication.provider.beans.list=customJWTAuthProvider mosip.security.authentication.provider.beans.list.pre-registration-application-service=customJWTAuthProvider -mosip.security.authentication.provider.beans.list.pre-registration-booking-service=customJWTAuthProvider \ No newline at end of file +mosip.security.authentication.provider.beans.list.pre-registration-booking-service=customJWTAuthProvider + +mosip.preregistration.user.admin:admin \ No newline at end of file diff --git a/pre-registration/pre-registration-core/src/main/java/io/mosip/analytics/event/anonymous/service/AnonymousProfileService.java b/pre-registration/pre-registration-core/src/main/java/io/mosip/analytics/event/anonymous/service/AnonymousProfileService.java index 49e13944279..0fb4d0449e2 100644 --- a/pre-registration/pre-registration-core/src/main/java/io/mosip/analytics/event/anonymous/service/AnonymousProfileService.java +++ b/pre-registration/pre-registration-core/src/main/java/io/mosip/analytics/event/anonymous/service/AnonymousProfileService.java @@ -31,6 +31,9 @@ public class AnonymousProfileService implements AnonymousProfileServiceIntf { @Value("${mosip.utc-datetime-pattern}") private String utcDateTimePattern; + @Value("${mosip.preregistration.user.admin}") + private String userName; + /** * Autowired reference for {@link #AnonymousProfileRepostiory} */ @@ -67,9 +70,9 @@ public AnonymousProfileResponseDTO saveAnonymousProfile(AnonymousProfileRequestD AnonymousProfileEntity requestEntity = new AnonymousProfileEntity(); requestEntity.setId(UUIDGeneratorUtil.generateId()); requestEntity.setProfile(requestDto.getProfileDetails()); - requestEntity.setCreatedBy(authUserDetails().getUserId()); + requestEntity.setCreatedBy(userName); requestEntity.setCreateDateTime(currentDateTime); - requestEntity.setUpdatedBy(authUserDetails().getUserId()); + requestEntity.setUpdatedBy(userName); requestEntity.setUpdateDateTime(currentDateTime); requestEntity.setIsDeleted(false); diff --git a/pre-registration/pre-registration-core/src/test/java/io/mosip/analytics/event/anonymous/service/test/AnonymousProfileServiceTest.java b/pre-registration/pre-registration-core/src/test/java/io/mosip/analytics/event/anonymous/service/test/AnonymousProfileServiceTest.java index 5ac060de5fe..123402a874c 100644 --- a/pre-registration/pre-registration-core/src/test/java/io/mosip/analytics/event/anonymous/service/test/AnonymousProfileServiceTest.java +++ b/pre-registration/pre-registration-core/src/test/java/io/mosip/analytics/event/anonymous/service/test/AnonymousProfileServiceTest.java @@ -42,6 +42,9 @@ public class AnonymousProfileServiceTest { @Value("${mosip.utc-datetime-pattern}") private String utcDateTimePattern; + @Value("${mosip.preregistration.user.admin}") + private String userName; + AnonymousProfileResponseDTO responseDto = new AnonymousProfileResponseDTO(); LocalDateTime currentDateTime = LocalDateTime.now(ZoneId.of("UTC")); @@ -70,9 +73,9 @@ public void saveAnonymousProfileTest() { requestEntity.setId(id); requestEntity.setProfile(requestDto.getProfileDetails()); - requestEntity.setCreatedBy(anonymousProfileService.authUserDetails().getUserId()); + requestEntity.setCreatedBy(userName); requestEntity.setCreateDateTime(currentDateTime); - requestEntity.setUpdatedBy(anonymousProfileService.authUserDetails().getUserId()); + requestEntity.setUpdatedBy(userName); requestEntity.setUpdateDateTime(currentDateTime); requestEntity.setIsDeleted(false); requestDto.setProfileDetails(profile); @@ -95,9 +98,9 @@ public void saveAnonymousProfileExceptionTest() throws Exception { requestEntity.setId(id); requestEntity.setProfile(requestDto.getProfileDetails()); - requestEntity.setCreatedBy(anonymousProfileService.authUserDetails().getUserId()); + requestEntity.setCreatedBy(userName); requestEntity.setCreateDateTime(currentDateTime); - requestEntity.setUpdatedBy(anonymousProfileService.authUserDetails().getUserId()); + requestEntity.setUpdatedBy(userName); requestEntity.setUpdateDateTime(currentDateTime); requestEntity.setIsDeleted(false); requestDto.setProfileDetails(profile); diff --git a/pre-registration/pre-registration-core/src/test/resources/application.properties b/pre-registration/pre-registration-core/src/test/resources/application.properties index cc59d72a026..77e1ad9546e 100644 --- a/pre-registration/pre-registration-core/src/test/resources/application.properties +++ b/pre-registration/pre-registration-core/src/test/resources/application.properties @@ -82,3 +82,5 @@ spring.cloud.config.uri=${dev.dns.url}/config spring.cloud.config.label=develop spring.cloud.config.name=pre-registration spring.profiles.active=mz + +mosip.preregistration.user.admin:admin From 23eebd4c476bd1f79f9d0e37b687858913c44ccc Mon Sep 17 00:00:00 2001 From: Aiham Date: Tue, 19 Dec 2023 16:17:57 +0530 Subject: [PATCH 2/3] [MOSIP-29805] Updated naming convention Signed-off-by: Aiham --- .../src/main/resources/application.properties | 2 +- .../anonymous/service/AnonymousProfileService.java | 8 ++++---- .../service/test/AnonymousProfileServiceTest.java | 12 ++++++------ .../src/test/resources/application.properties | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pre-registration/pre-registration-application-service/src/main/resources/application.properties b/pre-registration/pre-registration-application-service/src/main/resources/application.properties index 98b834d7793..07319c22819 100644 --- a/pre-registration/pre-registration-application-service/src/main/resources/application.properties +++ b/pre-registration/pre-registration-application-service/src/main/resources/application.properties @@ -426,4 +426,4 @@ auth.server.admin.allowed.audience=mosip-regproc-client,mosip-prereg-client,mosi mosip.security.authentication.provider.beans.list.pre-registration-application-service=customJWTAuthProvider mosip.security.authentication.provider.beans.list.pre-registration-booking-service=customJWTAuthProvider -mosip.preregistration.user.admin:admin \ No newline at end of file +mosip.preregistration.anonymous-profile-username:admin \ No newline at end of file diff --git a/pre-registration/pre-registration-core/src/main/java/io/mosip/analytics/event/anonymous/service/AnonymousProfileService.java b/pre-registration/pre-registration-core/src/main/java/io/mosip/analytics/event/anonymous/service/AnonymousProfileService.java index 0fb4d0449e2..52118562038 100644 --- a/pre-registration/pre-registration-core/src/main/java/io/mosip/analytics/event/anonymous/service/AnonymousProfileService.java +++ b/pre-registration/pre-registration-core/src/main/java/io/mosip/analytics/event/anonymous/service/AnonymousProfileService.java @@ -31,8 +31,8 @@ public class AnonymousProfileService implements AnonymousProfileServiceIntf { @Value("${mosip.utc-datetime-pattern}") private String utcDateTimePattern; - @Value("${mosip.preregistration.user.admin}") - private String userName; + @Value("${mosip.preregistration.anonymous-profile-username}") + private String anonymousProfileUsername; /** * Autowired reference for {@link #AnonymousProfileRepostiory} @@ -70,9 +70,9 @@ public AnonymousProfileResponseDTO saveAnonymousProfile(AnonymousProfileRequestD AnonymousProfileEntity requestEntity = new AnonymousProfileEntity(); requestEntity.setId(UUIDGeneratorUtil.generateId()); requestEntity.setProfile(requestDto.getProfileDetails()); - requestEntity.setCreatedBy(userName); + requestEntity.setCreatedBy(anonymousProfileUsername); requestEntity.setCreateDateTime(currentDateTime); - requestEntity.setUpdatedBy(userName); + requestEntity.setUpdatedBy(anonymousProfileUsername); requestEntity.setUpdateDateTime(currentDateTime); requestEntity.setIsDeleted(false); diff --git a/pre-registration/pre-registration-core/src/test/java/io/mosip/analytics/event/anonymous/service/test/AnonymousProfileServiceTest.java b/pre-registration/pre-registration-core/src/test/java/io/mosip/analytics/event/anonymous/service/test/AnonymousProfileServiceTest.java index 123402a874c..efce6323c63 100644 --- a/pre-registration/pre-registration-core/src/test/java/io/mosip/analytics/event/anonymous/service/test/AnonymousProfileServiceTest.java +++ b/pre-registration/pre-registration-core/src/test/java/io/mosip/analytics/event/anonymous/service/test/AnonymousProfileServiceTest.java @@ -42,8 +42,8 @@ public class AnonymousProfileServiceTest { @Value("${mosip.utc-datetime-pattern}") private String utcDateTimePattern; - @Value("${mosip.preregistration.user.admin}") - private String userName; + @Value("${mosip.preregistration.anonymous-profile-username}") + private String anonymousProfileUsername; AnonymousProfileResponseDTO responseDto = new AnonymousProfileResponseDTO(); @@ -73,9 +73,9 @@ public void saveAnonymousProfileTest() { requestEntity.setId(id); requestEntity.setProfile(requestDto.getProfileDetails()); - requestEntity.setCreatedBy(userName); + requestEntity.setCreatedBy(anonymousProfileUsername); requestEntity.setCreateDateTime(currentDateTime); - requestEntity.setUpdatedBy(userName); + requestEntity.setUpdatedBy(anonymousProfileUsername); requestEntity.setUpdateDateTime(currentDateTime); requestEntity.setIsDeleted(false); requestDto.setProfileDetails(profile); @@ -98,9 +98,9 @@ public void saveAnonymousProfileExceptionTest() throws Exception { requestEntity.setId(id); requestEntity.setProfile(requestDto.getProfileDetails()); - requestEntity.setCreatedBy(userName); + requestEntity.setCreatedBy(anonymousProfileUsername); requestEntity.setCreateDateTime(currentDateTime); - requestEntity.setUpdatedBy(userName); + requestEntity.setUpdatedBy(anonymousProfileUsername); requestEntity.setUpdateDateTime(currentDateTime); requestEntity.setIsDeleted(false); requestDto.setProfileDetails(profile); diff --git a/pre-registration/pre-registration-core/src/test/resources/application.properties b/pre-registration/pre-registration-core/src/test/resources/application.properties index 77e1ad9546e..749d06e43f3 100644 --- a/pre-registration/pre-registration-core/src/test/resources/application.properties +++ b/pre-registration/pre-registration-core/src/test/resources/application.properties @@ -83,4 +83,4 @@ spring.cloud.config.label=develop spring.cloud.config.name=pre-registration spring.profiles.active=mz -mosip.preregistration.user.admin:admin +mosip.preregistration.anonymous-profile-username:admin From b446ff636ca6f77d0c5e9e39ec1046e504b4b6d8 Mon Sep 17 00:00:00 2001 From: Aiham Date: Thu, 4 Jan 2024 11:05:19 +0530 Subject: [PATCH 3/3] [MOSIP-25644] Fixed otp issue Signed-off-by: Aiham --- .../application/repository/OtpTxnRepository.java | 2 +- .../preregistration/application/service/OTPManager.java | 4 ++-- .../preregistration/application/service/OTPManagerTest.java | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pre-registration/pre-registration-application-service/src/main/java/io/mosip/preregistration/application/repository/OtpTxnRepository.java b/pre-registration/pre-registration-application-service/src/main/java/io/mosip/preregistration/application/repository/OtpTxnRepository.java index 7965b2a8c34..2dd703d2a93 100644 --- a/pre-registration/pre-registration-application-service/src/main/java/io/mosip/preregistration/application/repository/OtpTxnRepository.java +++ b/pre-registration/pre-registration-application-service/src/main/java/io/mosip/preregistration/application/repository/OtpTxnRepository.java @@ -13,7 +13,7 @@ public interface OtpTxnRepository extends BaseRepository Boolean existsByOtpHashAndStatusCode(String otpHash, String statusCode); - OtpTransaction findByOtpHashAndStatusCode(String otpHash, String statusCode); + OtpTransaction findTopByOtpHashAndStatusCode(String otpHash, String statusCode); /** * Obtain the number of count of request_dTtimes for particular userId with diff --git a/pre-registration/pre-registration-application-service/src/main/java/io/mosip/preregistration/application/service/OTPManager.java b/pre-registration/pre-registration-application-service/src/main/java/io/mosip/preregistration/application/service/OTPManager.java index 512214be493..d8438f01823 100644 --- a/pre-registration/pre-registration-application-service/src/main/java/io/mosip/preregistration/application/service/OTPManager.java +++ b/pre-registration/pre-registration-application-service/src/main/java/io/mosip/preregistration/application/service/OTPManager.java @@ -122,7 +122,7 @@ public boolean sendOtp(MainRequestDTO requestDTO, String channelT (userId + environment.getProperty(PreRegLoginConstant.KEY_SPLITTER) + otp).getBytes()); if (otpRepo.existsByOtpHashAndStatusCode(otpHash, PreRegLoginConstant.ACTIVE_STATUS)) { - OtpTransaction otpTxn = otpRepo.findByOtpHashAndStatusCode(otpHash, PreRegLoginConstant.ACTIVE_STATUS); + OtpTransaction otpTxn = otpRepo.findTopByOtpHashAndStatusCode(otpHash, PreRegLoginConstant.ACTIVE_STATUS); otpTxn.setOtpHash(otpHash); otpTxn.setUpdBy(environment.getProperty(PreRegLoginConstant.MOSIP_PRE_REG_CLIENTID)); otpTxn.setUpdDTimes(DateUtils.getUTCCurrentDateTime()); @@ -230,7 +230,7 @@ public boolean validateOtp(String otp, String userId) throws PreRegLoginExceptio if (!otpRepo.existsByOtpHashAndStatusCode(otpHash, PreRegLoginConstant.ACTIVE_STATUS)) return false; - OtpTransaction otpTxn = otpRepo.findByOtpHashAndStatusCode(otpHash, PreRegLoginConstant.ACTIVE_STATUS); + OtpTransaction otpTxn = otpRepo.findTopByOtpHashAndStatusCode(otpHash, PreRegLoginConstant.ACTIVE_STATUS); otpTxn.setStatusCode(PreRegLoginConstant.USED_STATUS); otpRepo.save(otpTxn); if (!(otpTxn.getExpiryDtimes().isAfter(DateUtils.getUTCCurrentDateTime()))) { diff --git a/pre-registration/pre-registration-application-service/src/test/java/io/mosip/preregistration/application/service/OTPManagerTest.java b/pre-registration/pre-registration-application-service/src/test/java/io/mosip/preregistration/application/service/OTPManagerTest.java index 2f800eff6eb..a44def08504 100644 --- a/pre-registration/pre-registration-application-service/src/test/java/io/mosip/preregistration/application/service/OTPManagerTest.java +++ b/pre-registration/pre-registration-application-service/src/test/java/io/mosip/preregistration/application/service/OTPManagerTest.java @@ -220,7 +220,7 @@ public void testsendOtpSuccessEmail2() throws IOException { Mockito.when(otpRepo.existsByOtpHashAndStatusCode(Mockito.any(), Mockito.any())) .thenReturn(true); OtpTransaction otpTxn = new OtpTransaction(); - Mockito.when(otpRepo.findByOtpHashAndStatusCode(Mockito.any(), Mockito.any())) + Mockito.when(otpRepo.findTopByOtpHashAndStatusCode(Mockito.any(), Mockito.any())) .thenReturn(otpTxn); Mockito.when(restTemplate.exchange( Mockito.eq("home/authenticate/clientidsecretkey"), @@ -330,7 +330,7 @@ public void testvalidateOtpPreRegLoginException(){ Mockito.when(otpRepo.existsByOtpHashAndStatusCode(Mockito.any(), Mockito.any())).thenReturn(true); OtpTransaction otpTxn = new OtpTransaction(); otpTxn.setExpiryDtimes(DateUtils.getUTCCurrentDateTime()); - Mockito.when(otpRepo.findByOtpHashAndStatusCode(Mockito.any(), Mockito.any())) + Mockito.when(otpRepo.findTopByOtpHashAndStatusCode(Mockito.any(), Mockito.any())) .thenReturn(otpTxn); otpManager.validateOtp(null,null); } @@ -342,7 +342,7 @@ public void testvalidateOtpSuccess2(){ LocalDateTime a = LocalDateTime.of(2028, 2, 13, 15, 56); otpTxn.setExpiryDtimes(a); - Mockito.when(otpRepo.findByOtpHashAndStatusCode(Mockito.any(), Mockito.any())) + Mockito.when(otpRepo.findTopByOtpHashAndStatusCode(Mockito.any(), Mockito.any())) .thenReturn(otpTxn); assertTrue(otpManager.validateOtp(null,null)); }