Fixed table validation issue

This commit is contained in:
nisha
2025-02-03 12:28:12 +05:30
parent 7fc53897e2
commit bb6187a908
2 changed files with 45 additions and 3 deletions

View File

@@ -471,7 +471,9 @@ public class FormDao {
FieldValidatorBean fieldValidatorBean = Utils.convertSourceObjectToDestinationObject(contentResponseBean.getValidators(), FieldValidatorBean.class);
String fieldValue = getFieldValue(contentResponseBean);
validator.isRequired(value, fieldValidatorBean.getIsRequired(), fieldValue);
validator.isRequired(value, fieldValidatorBean.getIsRequired(), fieldValue)
.validateCustomTableValidation(value,fieldValidatorBean.getCustom(),fieldValue,contentResponseBean);
});
if (Boolean.TRUE.equals(isSendValidationError)) {
validator.validate();

View File

@@ -147,11 +147,51 @@ public class FieldValidator {
return this;
}
private static void checkTableValidation(String value, String fieldId, ContentResponseBean contentResponseBean, List<String> errors) {
public FieldValidator validateCustomTableValidation(String value, String customRule, String fieldId, ContentResponseBean contentResponseBean) {
if (customRule == null || value == null) {
return this; // No custom rule to validate
}
switch (customRule) {
case GepafinConstant.NON_EMPTY_TABLES:
try {
checkTableValidation(value, fieldId, contentResponseBean, errors);
} catch (Exception e) {
throw new RuntimeException(e);
}
break;
default:
// If the custom rule is unknown, just log or add an error (optional)
errors.add(MessageFormat.format(Translator.toLocale(GepafinConstant.VALIDATION_FIELD_CUSTOM), fieldId, customRule));
break;
}
return this;
}
private static void checkTableValidation(String value, String fieldId, ContentResponseBean contentResponseBean, List<String> errors) throws Exception {
Map<String, Boolean> stateFieldMap= new HashMap<>();
String tableType = contentResponseBean.getSettings().stream()
.filter(setting ->GepafinConstant.CRITERIA_TABLE_COLUMNS.equals(setting.getName())) // Check for "table_columns"
.map(SettingResponseBean::getName) // Extract the name
.findFirst() // Get the first matching result
.orElse(null); // Default to null if no match
if (tableType!=null){
try {
Object object = PdfUtils.extractRows(value);;
value= Utils.convertToString(object);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
contentResponseBean.getSettings().stream()
.filter(setting -> "table_columns".equals(setting.getName())) // Check for "table_columns"
.filter(setting -> "table_columns".equals(setting.getName()) || GepafinConstant.CRITERIA_TABLE_COLUMNS.equals(setting.getName())) // Check for "table_columns"
.map(SettingResponseBean::getValue)
.filter(Objects::nonNull) // Ensure value is not null
.filter(settingValue -> settingValue instanceof Map) // Ensure value is a Map