From 60ababe561b9f317d48a1e44dbb3e7e4aa1377a9 Mon Sep 17 00:00:00 2001 From: Loganathan Sekar Date: Fri, 9 Feb 2024 11:51:14 +0530 Subject: [PATCH] Fix to saving entity Signed-off-by: Loganathan Sekar --- .../common/service/integration/OTPManager.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/integration/OTPManager.java b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/integration/OTPManager.java index 77a4ab1b09d..3508889e87a 100644 --- a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/integration/OTPManager.java +++ b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/integration/OTPManager.java @@ -109,7 +109,7 @@ public boolean sendOtp(OtpRequestDTO otpRequestDTO, String idvid, String idvidTy if(otpEntityOpt.isPresent()) { OtpTransaction otpEntity = otpEntityOpt.get(); - requireOtpNotFrozen(otpEntity); + requireOtpNotFrozen(otpEntity, false); } String otp = generateOTP(otpRequestDTO.getIndividualId()); @@ -217,10 +217,9 @@ public boolean validateOtp(String pinValue, String otpKey, String individualId) } OtpTransaction otpEntity = otpEntityOpt.get(); - requireOtpNotFrozen(otpEntity); + requireOtpNotFrozen(otpEntity, true); if(otpEntity.getStatusCode().equals(IdAuthCommonConstants.UNFROZEN)) { - otpRepo.save(otpEntity); throw new IdAuthenticationBusinessException(IdAuthenticationErrorConstants.OTP_REQUEST_REQUIRED); } @@ -257,13 +256,16 @@ public boolean validateOtp(String pinValue, String otpKey, String individualId) * @param otpEntity the otp entity * @throws IdAuthenticationBusinessException the id authentication business exception */ - private void requireOtpNotFrozen(OtpTransaction otpEntity) throws IdAuthenticationBusinessException { + private void requireOtpNotFrozen(OtpTransaction otpEntity, boolean saveEntity) throws IdAuthenticationBusinessException { if(otpEntity.getStatusCode().equals(IdAuthCommonConstants.FROZEN)) { if(!isAfterFrozenDuration(otpEntity)) { throw createOTPFrozenException(); } logger.info("OTP Frozen wait time is over. Allowing further."); otpEntity.setStatusCode(IdAuthCommonConstants.UNFROZEN); + if(saveEntity) { + otpRepo.save(otpEntity); + } } }