From 837bd63314eb926c0d189009338893a7ea0a48ab Mon Sep 17 00:00:00 2001 From: harish Date: Thu, 3 Oct 2024 19:39:33 +0530 Subject: [PATCH] Updated validation logic for start and end dates --- .../constants/GepafinConstant.java | 3 +++ .../gepafin/tendermanagement/dao/CallDao.java | 20 +++++++++++++++++++ src/main/resources/message_en.properties | 3 +++ src/main/resources/message_it.properties | 2 ++ 4 files changed, 28 insertions(+) diff --git a/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java b/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java index 3ebf7e5f..70e764f2 100644 --- a/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java +++ b/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java @@ -179,4 +179,7 @@ public class GepafinConstant { public static final String UNAUTHORIZED = "UNAUTHORIZED"; public static final String COMPANY_ID_MANDATORY = "company.id.mandatory"; public static final String USER_ALREADY_CONNECTED_TO_COMPANY = "user.already.connected.to.company"; + + public static final String CALL_NOT_STARTED_YET = "call.not.started.yet"; + public static final String CALL_ALREADY_ENDED = "call.already.ended"; } diff --git a/src/main/java/net/gepafin/tendermanagement/dao/CallDao.java b/src/main/java/net/gepafin/tendermanagement/dao/CallDao.java index e214e562..c6345d59 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/CallDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/CallDao.java @@ -3,6 +3,7 @@ package net.gepafin.tendermanagement.dao; import java.math.BigDecimal; import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.LocalTime; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -673,6 +674,25 @@ public class CallDao { Status.NOT_FOUND, Translator.toLocale(GepafinConstant.CALL_NOT_PUBLISHED)); } + LocalDate currentDate = LocalDate.now(); + LocalTime currentTime = LocalTime.now(); + + if (currentDate.isBefore(callEntity.getStartDate().toLocalDate()) || + (currentDate.isEqual(callEntity.getStartDate().toLocalDate()) && currentTime.isBefore(callEntity.getStartTime()))) { + throw new CustomValidationException( + Status.BAD_REQUEST, + Translator.toLocale(GepafinConstant.CALL_NOT_STARTED_YET) + ); + } + + if (currentDate.isAfter(callEntity.getEndDate().toLocalDate()) || + (currentDate.isEqual(callEntity.getEndDate().toLocalDate()) && currentTime.isAfter(callEntity.getEndTime()))) { + throw new CustomValidationException( + Status.BAD_REQUEST, + Translator.toLocale(GepafinConstant.CALL_ALREADY_ENDED) + ); + } + return callEntity; } diff --git a/src/main/resources/message_en.properties b/src/main/resources/message_en.properties index d70c97f4..62de4214 100644 --- a/src/main/resources/message_en.properties +++ b/src/main/resources/message_en.properties @@ -206,3 +206,6 @@ vatnumber.already.exists=VatNumber already exists. invalid.email=Invalid email. company.id.mandatory=Company id is mandatory. user.already.connected.to.company=The user is already connected to this company. + +call.not.started.yet = The call has not started yet. Please wait until the specified start date and time. +call.already.ended = The call has already ended. You cannot submit the application after the deadline. diff --git a/src/main/resources/message_it.properties b/src/main/resources/message_it.properties index 00e8dcfc..aa29d36e 100644 --- a/src/main/resources/message_it.properties +++ b/src/main/resources/message_it.properties @@ -199,3 +199,5 @@ vatnumber.already.exists=Il numero di partita IVA esiste gi invalid.email=Email non valida. company.id.mandatory=L'ID dell'azienda è obbligatorio. user.already.connected.to.company=L'utente è già collegato a questa azienda. +call.not.started.yet = La chiamata non è ancora iniziata. Attendere fino alla data e all'ora di inizio specificate. +call.already.ended = La chiamata è già terminata. Non è possibile inviare l'applicazione dopo la scadenza.