Resolved conflicts
This commit is contained in:
@@ -145,7 +145,7 @@ public class FieldValidator {
|
||||
break;
|
||||
|
||||
case GepafinConstant.NON_EMPTY_TABLES:
|
||||
checkTableValidation(value, fieldId, contentResponseBean, errors);
|
||||
// checkTableValidation(value, fieldId, contentResponseBean, errors);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -157,11 +157,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
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
package net.gepafin.tendermanagement.util;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.itextpdf.text.DocumentException;
|
||||
import com.itextpdf.text.Element;
|
||||
import com.itextpdf.text.Font;
|
||||
@@ -60,6 +62,24 @@ public class PdfUtils {
|
||||
return cell;
|
||||
}
|
||||
|
||||
public static Object extractRows(Object content) throws Exception {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
JsonNode rootNode;
|
||||
|
||||
// Check if input is already a JSON tree (Object) or a String
|
||||
if (content instanceof String) {
|
||||
rootNode = objectMapper.readTree((String) content);
|
||||
} else {
|
||||
rootNode = objectMapper.valueToTree(content);
|
||||
}
|
||||
|
||||
// Extract "rows" dynamically
|
||||
JsonNode rowsArray = rootNode.get("rows");
|
||||
|
||||
// Convert to a generic List
|
||||
return objectMapper.convertValue(rowsArray, List.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -778,4 +778,12 @@ public class Utils {
|
||||
return Double.NaN; // Return NaN if the expression is invalid
|
||||
}
|
||||
}
|
||||
public static boolean isNumeric(String input) {
|
||||
if (input == null || input.trim().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return input.matches("-?\\d+(\\.\\d+)?");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user