Merge pull request #190 from Kitzanos/feature/GEPAFINBE-156
GEPAFINBE-156 (Fixed table validation issue)
This commit is contained in:
@@ -471,7 +471,9 @@ public class FormDao {
|
|||||||
|
|
||||||
FieldValidatorBean fieldValidatorBean = Utils.convertSourceObjectToDestinationObject(contentResponseBean.getValidators(), FieldValidatorBean.class);
|
FieldValidatorBean fieldValidatorBean = Utils.convertSourceObjectToDestinationObject(contentResponseBean.getValidators(), FieldValidatorBean.class);
|
||||||
String fieldValue = getFieldValue(contentResponseBean);
|
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)) {
|
if (Boolean.TRUE.equals(isSendValidationError)) {
|
||||||
validator.validate();
|
validator.validate();
|
||||||
|
|||||||
@@ -147,11 +147,51 @@ public class FieldValidator {
|
|||||||
return this;
|
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<>();
|
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()
|
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)
|
.map(SettingResponseBean::getValue)
|
||||||
.filter(Objects::nonNull) // Ensure value is not null
|
.filter(Objects::nonNull) // Ensure value is not null
|
||||||
.filter(settingValue -> settingValue instanceof Map) // Ensure value is a Map
|
.filter(settingValue -> settingValue instanceof Map) // Ensure value is a Map
|
||||||
|
|||||||
Reference in New Issue
Block a user