From db42874e75ff4c57151532ad02119b74247bdede Mon Sep 17 00:00:00 2001 From: nisha Date: Wed, 25 Sep 2024 18:12:31 +0530 Subject: [PATCH] Applied validation application form field --- .../constants/GepafinConstant.java | 1 + .../tendermanagement/dao/ApplicationDao.java | 21 +++++++++++++++++++ src/main/resources/message_en.properties | 3 ++- src/main/resources/message_it.properties | 1 + 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java b/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java index ad8ca5b4..00fdc267 100644 --- a/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java +++ b/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java @@ -158,4 +158,5 @@ public class GepafinConstant { public static final String FAILED_RETAIN_FIELD="failed.retain.field"; public static final String TOTAL_STEPS_NOT_BE_ZERO="total.steps.not.zero"; public static final String COMPLETED_STEPS_NOT_VALID="completed.steps.not.valid"; + public static final String FIELD_ID_NOT_FOUND="field.id.not.found"; } diff --git a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java index 6b310bc6..8c05ca89 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java @@ -29,6 +29,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.text.MessageFormat; import java.time.LocalDateTime; import java.util.*; import java.util.stream.Collectors; @@ -68,6 +69,7 @@ public class ApplicationDao { public ApplicationResponseBean createApplication(ApplicationRequestBean applicationRequestBean, UserEntity userEntity, Long formId,Long applicationId) { FormEntity formEntity = formService.validateForm(formId); CallEntity call = callService.validatePublishedCall(formEntity.getCall().getId()); + validateFormFields(applicationRequestBean,formEntity); ApplicationEntity applicationEntity = validateApplication(applicationId); if(Boolean.TRUE.equals(applicationEntity.getStatus().equals(ApplicationStatusTypeEnum.SUBMIT.getValue()))){ throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.APPLICATION_ALREADY_SUBMITTED)); @@ -492,5 +494,24 @@ public class ApplicationDao { double progress = ((double) completedSteps / totalSteps) * 100; return (int) Math.round(progress); } + public void validateFormFields(ApplicationRequestBean request, FormEntity formEntity) { + List errors=new ArrayList<>(); + List contentResponseBeans=Utils.convertJsonStringToList(formEntity.getContent(),ContentResponseBean.class); + + List requestFields = request.getFormFields(); + + Map contentMap = contentResponseBeans.stream() + .collect(Collectors.toMap(ContentResponseBean::getId, ContentResponseBean::getLabel)); // Change getLabel() if needed + FieldValidator validator = FieldValidator.create(); + for (ApplicationFormFieldRequestBean requestField : requestFields) { + String fieldId = requestField.getFieldId(); + + if (!contentMap.containsKey(fieldId)) { + validator.addError(MessageFormat.format(Translator.toLocale(GepafinConstant.FIELD_ID_NOT_FOUND), fieldId)); + } + + } + validator.validate(); + } } diff --git a/src/main/resources/message_en.properties b/src/main/resources/message_en.properties index 12b06608..9f10dba0 100644 --- a/src/main/resources/message_en.properties +++ b/src/main/resources/message_en.properties @@ -185,4 +185,5 @@ failed.retain.field=Failed to retain specific fields. application.is.incomplete = The application is incomplete. total.steps.not.zero=Total steps cannot be zero. -completed.steps.not.valid=Completed steps should be between 0 and total steps. \ No newline at end of file +completed.steps.not.valid=Completed steps should be between 0 and total steps. +field.id.not.found=Field ID {0} does not exist in the form structure. \ No newline at end of file diff --git a/src/main/resources/message_it.properties b/src/main/resources/message_it.properties index a7d9068e..7a90dd8e 100644 --- a/src/main/resources/message_it.properties +++ b/src/main/resources/message_it.properties @@ -179,3 +179,4 @@ failed.retain.field=Impossibile conservare campi specifici. total.steps.not.zero=Il totale dei passaggi non puņ essere zero. completed.steps.not.valid=I passaggi completati devono essere compresi tra 0 e il totale dei passaggi. +field.id.not.found=L'ID campo {0} non esiste nella struttura del modulo.