Applied validation application form field
This commit is contained in:
@@ -158,4 +158,5 @@ public class GepafinConstant {
|
|||||||
public static final String FAILED_RETAIN_FIELD="failed.retain.field";
|
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 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 COMPLETED_STEPS_NOT_VALID="completed.steps.not.valid";
|
||||||
|
public static final String FIELD_ID_NOT_FOUND="field.id.not.found";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.text.MessageFormat;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -68,6 +69,7 @@ public class ApplicationDao {
|
|||||||
public ApplicationResponseBean createApplication(ApplicationRequestBean applicationRequestBean, UserEntity userEntity, Long formId,Long applicationId) {
|
public ApplicationResponseBean createApplication(ApplicationRequestBean applicationRequestBean, UserEntity userEntity, Long formId,Long applicationId) {
|
||||||
FormEntity formEntity = formService.validateForm(formId);
|
FormEntity formEntity = formService.validateForm(formId);
|
||||||
CallEntity call = callService.validatePublishedCall(formEntity.getCall().getId());
|
CallEntity call = callService.validatePublishedCall(formEntity.getCall().getId());
|
||||||
|
validateFormFields(applicationRequestBean,formEntity);
|
||||||
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
||||||
if(Boolean.TRUE.equals(applicationEntity.getStatus().equals(ApplicationStatusTypeEnum.SUBMIT.getValue()))){
|
if(Boolean.TRUE.equals(applicationEntity.getStatus().equals(ApplicationStatusTypeEnum.SUBMIT.getValue()))){
|
||||||
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.APPLICATION_ALREADY_SUBMITTED));
|
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;
|
double progress = ((double) completedSteps / totalSteps) * 100;
|
||||||
return (int) Math.round(progress);
|
return (int) Math.round(progress);
|
||||||
}
|
}
|
||||||
|
public void validateFormFields(ApplicationRequestBean request, FormEntity formEntity) {
|
||||||
|
List<String> errors=new ArrayList<>();
|
||||||
|
List<ContentResponseBean> contentResponseBeans=Utils.convertJsonStringToList(formEntity.getContent(),ContentResponseBean.class);
|
||||||
|
|
||||||
|
List<ApplicationFormFieldRequestBean> requestFields = request.getFormFields();
|
||||||
|
|
||||||
|
Map<String, String> 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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -186,3 +186,4 @@ failed.retain.field=Failed to retain specific fields.
|
|||||||
application.is.incomplete = The application is incomplete.
|
application.is.incomplete = The application is incomplete.
|
||||||
total.steps.not.zero=Total steps cannot be zero.
|
total.steps.not.zero=Total steps cannot be zero.
|
||||||
completed.steps.not.valid=Completed steps should be between 0 and total steps.
|
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.
|
||||||
@@ -179,3 +179,4 @@ failed.retain.field=Impossibile conservare campi specifici.
|
|||||||
|
|
||||||
total.steps.not.zero=Il totale dei passaggi non può essere zero.
|
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.
|
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.
|
||||||
|
|||||||
Reference in New Issue
Block a user