From 7bde0e91e77a73595ee8c6743ff2286e8c8244bf Mon Sep 17 00:00:00 2001 From: nisha Date: Tue, 1 Oct 2024 18:05:35 +0530 Subject: [PATCH] Applied validation for few fields in call --- .../net/gepafin/tendermanagement/dao/CallDao.java | 14 +++++++++++++- .../model/request/UpdateCallRequestStep1.java | 11 +++++++++++ .../service/impl/CallValidatorServiceImpl.java | 6 +++--- .../tendermanagement/util/DateTimeUtil.java | 4 +++- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/gepafin/tendermanagement/dao/CallDao.java b/src/main/java/net/gepafin/tendermanagement/dao/CallDao.java index a0a5a110..fca314ed 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/CallDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/CallDao.java @@ -126,7 +126,7 @@ public class CallDao { callEntity.setConfidi(createCallRequest.getConfidi()); } callEntity.setDocumentationRequested(createCallRequest.getDocumentationRequested()); - if (createCallRequest.getAmountMin().compareTo(BigDecimal.ZERO) < 0) { + if (createCallRequest.getAmountMin() != null && createCallRequest.getAmountMin().compareTo(BigDecimal.ZERO) < 0) { throw new CustomValidationException(Status.VALIDATION_ERROR,Translator.toLocale(GepafinConstant.AMOUNT_GREATER_THAN_ZERO_MSG)); } callEntity.setAmountMin(createCallRequest.getAmountMin()); @@ -474,6 +474,18 @@ public class CallDao { setIfUpdated(callEntity::getAmountMax, callEntity::setAmountMax, updateCallRequest.getAmountMax()); setIfUpdated(callEntity::getDocumentationRequested, callEntity::setDocumentationRequested, updateCallRequest.getDocumentationRequested()); + + if (updateCallRequest.getAmountMin() != null && updateCallRequest.getAmountMin().compareTo(BigDecimal.ZERO) < 0) { + throw new CustomValidationException(Status.VALIDATION_ERROR,Translator.toLocale(GepafinConstant.AMOUNT_GREATER_THAN_ZERO_MSG)); + } + if(updateCallRequest.getEmail()==null || Boolean.FALSE.equals(Utils.isValidEmail(updateCallRequest.getEmail()))){ + throw new CustomValidationException(Status.VALIDATION_ERROR,Translator.toLocale(GepafinConstant.VALIDATION_EMAIL,updateCallRequest.getEmail())); + } + setIfUpdated(callEntity::getAmountMin, callEntity::setAmountMin, updateCallRequest.getAmountMin()); + setIfUpdated(callEntity::getEmail, callEntity::setEmail, updateCallRequest.getEmail()); + setIfUpdated(callEntity::getPhoneNumber, callEntity::setPhoneNumber, updateCallRequest.getPhoneNumber()); + setIfUpdated(callEntity::getStartTime, callEntity::setStartTime, DateTimeUtil.parseTime(updateCallRequest.getStartTime())); + setIfUpdated(callEntity::getEndTime, callEntity::setEndTime, DateTimeUtil.parseTime(updateCallRequest.getEndTime())); setIfUpdated(callEntity::getConfidi, callEntity::setConfidi, updateCallRequest.getConfidi()); updateLookUpData(callEntity, updateCallRequest.getAimedTo(), LookUpDataTypeEnum.AIMED_TO); updateFaq(updateCallRequest.getFaq(), callEntity, userEntity, LookUpDataTypeEnum.FAQ); diff --git a/src/main/java/net/gepafin/tendermanagement/model/request/UpdateCallRequestStep1.java b/src/main/java/net/gepafin/tendermanagement/model/request/UpdateCallRequestStep1.java index 4d4de6e9..e57f8715 100644 --- a/src/main/java/net/gepafin/tendermanagement/model/request/UpdateCallRequestStep1.java +++ b/src/main/java/net/gepafin/tendermanagement/model/request/UpdateCallRequestStep1.java @@ -2,6 +2,7 @@ package net.gepafin.tendermanagement.model.request; import java.math.BigDecimal; import java.time.LocalDateTime; +import java.time.LocalTime; import java.util.List; import lombok.Data; @@ -25,6 +26,16 @@ public class UpdateCallRequestStep1 { private String documentationRequested; + private BigDecimal amountMin; + + private String email; + + private String phoneNumber; + + private String startTime; + + private String endTime; + private Boolean confidi; private List faq; diff --git a/src/main/java/net/gepafin/tendermanagement/service/impl/CallValidatorServiceImpl.java b/src/main/java/net/gepafin/tendermanagement/service/impl/CallValidatorServiceImpl.java index aa2df691..3c7091cf 100644 --- a/src/main/java/net/gepafin/tendermanagement/service/impl/CallValidatorServiceImpl.java +++ b/src/main/java/net/gepafin/tendermanagement/service/impl/CallValidatorServiceImpl.java @@ -30,9 +30,9 @@ public class CallValidatorServiceImpl { .notNull(response.getAmountMax(), "amountMax") .notNull(response.getThreshold(), "threshold") .notNull(response.getEmail(),"email") -// .notNull(response.getAmountMin(),"amountMin") -// .notNull(response.getStartTime(),"startTime") -// .notNull(response.getEndTime(),"endTime") + .notNull(response.getAmountMin(),"amountMin") + .notNull(response.getStartTime(),"startTime") + .notNull(response.getEndTime(),"endTime") .notNull(response.getDocumentationRequested(), "documentationRequested") .notEmpty(response.getAimedTo(), "aimedTo") .notEmpty(response.getCriteria(), "criteria") diff --git a/src/main/java/net/gepafin/tendermanagement/util/DateTimeUtil.java b/src/main/java/net/gepafin/tendermanagement/util/DateTimeUtil.java index 4bfe0998..63ed91a5 100644 --- a/src/main/java/net/gepafin/tendermanagement/util/DateTimeUtil.java +++ b/src/main/java/net/gepafin/tendermanagement/util/DateTimeUtil.java @@ -66,7 +66,9 @@ public class DateTimeUtil { public static LocalTime parseTime(String timeString) throws DateTimeParseException { DateTimeFormatter formatter; - + if(timeString==null) { + return null; + } if (!TIME_PATTERN.matcher(timeString).matches()) { throw new CustomValidationException(Status.BAD_REQUEST,"Invalid time format: " + timeString); }