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 6494dfd8538..2b659684f5f 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 @@ -118,17 +118,28 @@ public boolean sendOtp(OtpRequestDTO otpRequestDTO, String idvid, String idvidTy + EnvUtil.getKeySplitter() + otpRequestDTO.getTransactionID() + EnvUtil.getKeySplitter() + otp).getBytes()); - OtpTransaction txn = new OtpTransaction(); - txn.setId(UUID.randomUUID().toString()); - txn.setRefId(securityManager.hash(otpRequestDTO.getIndividualId())); - txn.setOtpHash(otpHash); - txn.setCrBy(securityManager.getUser()); - txn.setGeneratedDtimes(otpGenerationTime); - txn.setCrDtimes(otpGenerationTime); - txn.setExpiryDtimes(otpGenerationTime.plusSeconds( - EnvUtil.getOtpExpiryTime())); - txn.setStatusCode(IdAuthCommonConstants.ACTIVE_STATUS); - otpRepo.save(txn); + OtpTransaction otpTxn; + if (otpEntityOpt.isPresent() + && (otpTxn = otpEntityOpt.get()).getStatusCode().equals(IdAuthCommonConstants.ACTIVE_STATUS)) { + otpTxn.setOtpHash(otpHash); + otpTxn.setUpdBy(securityManager.getUser()); + otpTxn.setUpdDTimes(otpGenerationTime); + otpTxn.setGeneratedDtimes(otpGenerationTime); + otpTxn.setExpiryDtimes(otpGenerationTime.plusSeconds(EnvUtil.getOtpExpiryTime())); + otpRepo.save(otpTxn); + } else { + OtpTransaction txn = new OtpTransaction(); + txn.setId(UUID.randomUUID().toString()); + txn.setRefId(securityManager.hash(otpRequestDTO.getIndividualId())); + txn.setOtpHash(otpHash); + txn.setCrBy(securityManager.getUser()); + txn.setCrDtimes(otpGenerationTime); + txn.setGeneratedDtimes(otpGenerationTime); + txn.setExpiryDtimes(otpGenerationTime.plusSeconds( + EnvUtil.getOtpExpiryTime())); + txn.setStatusCode(IdAuthCommonConstants.ACTIVE_STATUS); + otpRepo.save(txn); + } String notificationProperty = null; notificationProperty = otpRequestDTO