Merge pull request #215 from Kitzanos/fixed-table-validation-issue-prod
Cherry-pick (Fixed table validation issue)
This commit is contained in:
@@ -160,7 +160,7 @@ public class FieldValidator {
|
|||||||
|
|
||||||
|
|
||||||
public FieldValidator validateCustomTableValidation(String value, String customRule, String fieldId, ContentResponseBean contentResponseBean) {
|
public FieldValidator validateCustomTableValidation(String value, String customRule, String fieldId, ContentResponseBean contentResponseBean) {
|
||||||
if (customRule == null || value == null) {
|
if (customRule == null ) {
|
||||||
return this; // No custom rule to validate
|
return this; // No custom rule to validate
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,6 +168,7 @@ public class FieldValidator {
|
|||||||
|
|
||||||
case GepafinConstant.NON_EMPTY_TABLES:
|
case GepafinConstant.NON_EMPTY_TABLES:
|
||||||
try {
|
try {
|
||||||
|
|
||||||
checkTableValidation(value, fieldId, contentResponseBean, errors);
|
checkTableValidation(value, fieldId, contentResponseBean, errors);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
@@ -186,6 +187,7 @@ public class FieldValidator {
|
|||||||
.findFirst() // Get the first matching result
|
.findFirst() // Get the first matching result
|
||||||
.orElse(null); // Default to null if no match
|
.orElse(null); // Default to null if no match
|
||||||
|
|
||||||
|
|
||||||
if (tableType!=null){
|
if (tableType!=null){
|
||||||
try {
|
try {
|
||||||
Object object = PdfUtils.extractRows(value);;
|
Object object = PdfUtils.extractRows(value);;
|
||||||
@@ -224,31 +226,47 @@ public class FieldValidator {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int rowIndex = 0; rowIndex < fieldValueList.size(); rowIndex++) {
|
// for (int rowIndex = 0; rowIndex < fieldValueList.size(); rowIndex++) {
|
||||||
Map<String, Object> field = fieldValueList.get(rowIndex);
|
// Map<String, Object> field = fieldValueList.get(rowIndex);
|
||||||
|
//
|
||||||
|
// boolean hasSingleNonNullPredefinedFalse = false;
|
||||||
|
//
|
||||||
|
// for (Map.Entry<String, Boolean> entry : stateFieldMap.entrySet()) {
|
||||||
|
// String stateKey = entry.getKey();
|
||||||
|
// Boolean isPredefinedFalse = Boolean.FALSE.equals(entry.getValue());
|
||||||
|
//
|
||||||
|
// if (isPredefinedFalse) {
|
||||||
|
// Object fieldValue = field.get(stateKey);
|
||||||
|
// if (fieldValue != null && !StringUtils.isEmpty(fieldValue.toString())) {
|
||||||
|
// hasSingleNonNullPredefinedFalse = true;
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (!hasSingleNonNullPredefinedFalse) {
|
||||||
|
// errors.add(MessageFormat.format(
|
||||||
|
// Translator.toLocale(GepafinConstant.VALIDATION_IN_TABLE),
|
||||||
|
// fieldId));
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
boolean hasSingleNonNullPredefinedFalse = false;
|
|
||||||
|
|
||||||
for (Map.Entry<String, Boolean> entry : stateFieldMap.entrySet()) {
|
boolean hasAtLeastOneNonEmptyPredefinedFalse = fieldValueList.stream()
|
||||||
String stateKey = entry.getKey();
|
.anyMatch(field -> stateFieldMap.entrySet().stream()
|
||||||
Boolean isPredefinedFalse = Boolean.FALSE.equals(entry.getValue());
|
.filter(entry -> Boolean.FALSE.equals(entry.getValue())) // Check only predefined: false fields
|
||||||
|
.anyMatch(entry -> {
|
||||||
if (isPredefinedFalse) {
|
Object fieldValue = field.get(entry.getKey());
|
||||||
Object fieldValue = field.get(stateKey);
|
return fieldValue != null && !StringUtils.isEmpty(fieldValue.toString());
|
||||||
if (fieldValue != null && !StringUtils.isEmpty(fieldValue.toString())) {
|
})
|
||||||
hasSingleNonNullPredefinedFalse = true;
|
);
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!hasSingleNonNullPredefinedFalse) {
|
|
||||||
errors.add(MessageFormat.format(
|
|
||||||
Translator.toLocale(GepafinConstant.VALIDATION_IN_TABLE),
|
|
||||||
fieldId));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (!hasAtLeastOneNonEmptyPredefinedFalse) {
|
||||||
|
errors.add(MessageFormat.format(
|
||||||
|
Translator.toLocale(GepafinConstant.VALIDATION_IN_TABLE),
|
||||||
|
fieldId));
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user