Applied table validation

This commit is contained in:
nisha
2025-01-20 18:09:29 +05:30
parent 4cb4d78403
commit f4f084719f
5 changed files with 109 additions and 19 deletions

View File

@@ -55,13 +55,13 @@ public class FormDao {
@Autowired
private CallRepository callRepository;
@Autowired
private Validator validator;
@Autowired
private CriteriaFormFieldRepository criteriaFormFieldRepository;
@Autowired
private EvaluationCriteriaService evaluationCriteriaService;
@@ -144,7 +144,7 @@ public class FormDao {
validateAndSaveCriteriaFormField(callEntity, formEntity, formRequest.getContent());
return convertFormEntityToFormResponseBean(formEntity);
}
private void validateAndSaveCriteriaFormField(CallEntity callEntity, FormEntity formEntity,
List<ContentRequestBean> contentResponseBeans) {
@@ -211,7 +211,7 @@ public class FormDao {
/** This code is responsible for adding a version history log for the "creating criteria form field" operation. **/
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.INSERT).oldData(null).newData(criteriaFormField).build());
}
public void validateForm(FormRequest formRequest){
@@ -397,9 +397,9 @@ public class FormDao {
FieldValidator validator = FieldValidator.create();
formResponseBean.getContent().forEach(contentResponseBean -> {
String fieldId = contentResponseBean.getId();
String value = (String) formFieldMap.get(fieldId);
String fieldLabel=contentResponseBean.getLabel();
Object object=formFieldMap.get(fieldId);
String value =Utils.convertToString(object);
if(value == null && isApplicationFormExist) {
return;
}
@@ -408,7 +408,7 @@ public class FormDao {
.minLength(value, fieldValidatorBean.getMinLength(), fieldLabel) // Only applies if minLength is not null
.maxLength(value, fieldValidatorBean.getMaxLength(), fieldLabel) // Only applies if maxLength is not null
.matchesPattern(value, fieldValidatorBean.getPattern(), fieldLabel) // Only applies if pattern is present
.validateCustom(value, fieldValidatorBean.getCustom(), fieldLabel); // Add the custom validation here
.validateCustom(value, fieldValidatorBean.getCustom(), fieldLabel,contentResponseBean); // Add the custom validation here
if (fieldValidatorBean.getCustom() != null && fieldValidatorBean.getCustom().equals(GepafinConstant.IS_PIVA)) {
String error = validateVatNumber(value, fieldValidatorBean.getCustom(), fieldLabel);
if(error != null) {
@@ -428,11 +428,14 @@ public class FormDao {
for (Object value : list) {
setFormFieldMap(fieldId, formFieldMap, value);
}
}
}else if (list.stream().allMatch(item -> item instanceof Map<?, ?> map &&
map.keySet().stream().allMatch(String.class::isInstance))) {
if (fieldValue != null) {
formFieldMap.put(fieldId, fieldValue);
}
} else setFormFieldMap(fieldId, formFieldMap, fieldValue);
}
else setFormFieldMap(fieldId, formFieldMap, fieldValue);
}
private void setFormFieldMap(String fieldId, Map<String, Object> formFieldMap, Object value) {
if (value instanceof String) {
if(value !=null && Boolean.FALSE.equals(StringUtils.isEmpty((String)value))) {
@@ -453,7 +456,7 @@ public class FormDao {
for(ApplicationFormFieldEntity applicationFormFieldEntity:applicationFormFieldEntityList) {
formFieldMap.put(applicationFormFieldEntity.getFieldId(),applicationFormFieldEntity.getFieldValue());
}
FormResponseBean formResponseBean = convertFormEntityToFormResponseBean(formEntity);
FieldValidator validator = FieldValidator.create();
formResponseBean.getContent().forEach(contentResponseBean -> {
@@ -462,10 +465,11 @@ public class FormDao {
FieldValidatorBean fieldValidatorBean = Utils.convertSourceObjectToDestinationObject(contentResponseBean.getValidators(), FieldValidatorBean.class);
validator
.isRequired(value,fieldValidatorBean.getIsRequired(),fieldId);
.isRequired(value,fieldValidatorBean.getIsRequired(),contentResponseBean.getLabel());
});
validator.validate();
if (validator.hasErrors()) {
return false; // Validation failed, return false
return false;
}
return true;
}