Skip to content

Commit

Permalink
Fix to saving entity
Browse files Browse the repository at this point in the history
Signed-off-by: Loganathan Sekar <[email protected]>
  • Loading branch information
Loganathan Sekar authored and Loganathan Sekar committed Feb 9, 2024
1 parent 60211ae commit 60ababe
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
}
}

Expand Down

0 comments on commit 60ababe

Please sign in to comment.