Done ticket GEPAFINBE-154

This commit is contained in:
rajesh
2025-01-31 11:12:59 +05:30
parent fd6865e754
commit 4a534aa98e
4 changed files with 98 additions and 33 deletions

View File

@@ -407,5 +407,6 @@ public class GepafinConstant {
public static final String ASSIGNED_APPLICATION_STATUS_UPDATED_SUCCESSFULLY = "assigned.application.status.updated.successfully";
public static final String REQUIRED_REQUESTED_AMOUNT_MSG = "validation.required.requested.amount";
public static final String CRITERIA_TABLE_COLUMNS="criteria_table_columns";
}

View File

@@ -152,6 +152,31 @@ public class PdfDao {
// Create value cell with rounded corners
PdfPTable valueTable = new PdfPTable(1);
valueTable.setWidthPercentage(100);
Object finalValue = value;
List<Object> criteriaObject = (List<Object>) contentResponseBean.getSettings().stream()
.filter(setting -> GepafinConstant.CRITERIA_TABLE_COLUMNS.equals(setting.getName()))
.findFirst()
.map(setting -> {
try {
// Assuming setting.getValue() contains the JSON string or object
return PdfUtils.extractRows(finalValue);
} catch (Exception e) {
throw new RuntimeException("Error extracting rows from setting value", e);
}
})
.orElse(null);
// Update value if criteriaObject is not null
if (criteriaObject != null) {
value = criteriaObject;
}
// Update value if criteriaObject is not null
if (value instanceof List<?>) {
// Further check if the list contains Strings
List<?> list = (List<?>) value;
@@ -184,7 +209,6 @@ public class PdfDao {
Object object = value;
String stringvalue = Utils.convertToString(object);
List<Map<String, Object>> fieldValueList = Utils.convertJsonStringIntoJsonList(stringvalue);
document = createPdfTable(fieldValueList, document, contentResponseBean);
}
}
@@ -231,12 +255,13 @@ public class PdfDao {
document.add(valueTable);
}
else {
if (value instanceof String) {
String fieldValue1 = (String) value;
if (Utils.isValidDateString(fieldValue1)) {
fieldValue1 = Utils.formatDateString(String.valueOf(value));
}
if(Boolean.TRUE.equals(Utils.isItalianFormattedAmount(fieldValue)) ){
fieldValue= String.valueOf(Utils.convertToItalianFormat(fieldValue));
if(contentResponseBean.getName().equals("numberinput") && Boolean.TRUE.equals(Utils.isNumeric(fieldValue))){
fieldValue1=Utils.convertToItalianFormat(fieldValue);
}
// PdfPCell valueCell = new PdfPCell(new Phrase(fieldValue1, valueFont));
PdfPCell valueCell = PdfUtils.htmlToPdfPCell(fieldValue1, valueFont);
@@ -252,6 +277,7 @@ public class PdfDao {
valueTable.addCell(valueCell);
document.add(valueTable);
}
}
}
document.add(new Paragraph("\n")); // Add line break after each value
@@ -264,11 +290,12 @@ public class PdfDao {
Map<String, Boolean> formulaEnabledMap = new HashMap<>();
Map<String, String> formulaTypeMap = new HashMap<>();
Map<String, String> fieldTypeMap = new HashMap<>();
Map<String, String> totalMap = new HashMap<>();
Font lightGrayFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new BaseColor(110, 110, 110)); // Light gray
contentResponseBean.getSettings().stream()
.filter(setting -> "table_columns".equals(setting.getName())) // Check for "table_columns"
.filter(setting -> "table_columns".equals(setting.getName()) || "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
@@ -283,7 +310,7 @@ public class PdfDao {
Boolean isFormulaEnabled = (Boolean) fieldData.get("enableFormula");
String formulaType = (String) fieldData.get("lastRowFormula");
String fieldType = (String) fieldData.get("fieldtype"); // Get the field type (e.g., numeric)
String total= (String) fieldData.get("lastRowText");
if (fieldName != null && fieldDataValue != null) {
stateFieldMap.put(fieldName, fieldDataValue);
}
@@ -297,6 +324,9 @@ public class PdfDao {
if (fieldType != null) {
fieldTypeMap.put(fieldName, fieldType); // Store the fieldType in the map
}
if(total!=null){
totalMap.put(fieldName,total);
}
});
PdfPTable table = new PdfPTable(stateFieldMap.size()); // Number of columns equals the number of map entries
@@ -342,12 +372,15 @@ public class PdfDao {
Object value = row.getOrDefault(key, ""); // Fetch value or use empty string if key not present
// String fieldValue= (String) value;
String fieldValue = value != null ? value.toString() : "";
if(Boolean.TRUE.equals(Utils.isItalianFormattedAmount(fieldValue)) ){
fieldValue= String.valueOf(Utils.convertToItalianFormat(fieldValue));
}
// if(Boolean.TRUE.equals(Utils.isItalianFormattedAmount(fieldValue)) ){
//// fieldValue= String.valueOf(Utils.convertToItalianFormat(fieldValue));
// }
if (Boolean.TRUE.equals(formulaEnabledMap.get(key)) && Boolean.TRUE.equals(GepafinConstant.NUMERIC.equalsIgnoreCase(fieldTypeMap.get(key)))) {
calculateValue(key, fieldValue, formulaTypeMap, columnSums);
}
if(Boolean.TRUE.equals(Utils.isNumeric(fieldValue))){
fieldValue=Utils.convertToItalianFormat(fieldValue);
}
PdfPCell dataCell = PdfUtils.htmlToPdfPCell(fieldValue != null ? fieldValue : "", textFont);
dataCell.setBackgroundColor(new BaseColor(239, 243, 248)); // Light blue for the cell
@@ -397,14 +430,19 @@ public class PdfDao {
table.addCell(emptyCell);
}
} else {
PdfPCell emptyCell = new PdfPCell(new Phrase(""));
String total=null;
if (totalMap.containsKey(key)) {
total=totalMap.getOrDefault(key, "");
}
PdfPCell emptyCell = new PdfPCell(new Phrase(total,lightGrayFont));
emptyCell.setPaddingTop(8f);
emptyCell.setPaddingLeft(8f);
emptyCell.setBackgroundColor(new BaseColor(239, 243, 248));
table.addCell(emptyCell);
}
}
// Add the last table to the document
document.add(table);
@@ -415,7 +453,7 @@ public class PdfDao {
try {
if (Boolean.FALSE.equals(StringUtils.isEmpty(fieldValue))) {
// Use Locale.ITALY to parse the number with the Italian format (comma as decimal separator)
NumberFormat format = NumberFormat.getInstance(Locale.ITALY);
NumberFormat format = NumberFormat.getInstance(Locale.ENGLISH);
Number number = format.parse(fieldValue); // Parse the fieldValue as a number
double numericValue = number.doubleValue(); // Convert the parsed number to double

View File

@@ -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);
}
}

View File

@@ -753,6 +753,12 @@ public class Utils {
private static Map<String, Object> defaultErrorResponse() {
return Collections.singletonMap("message", Translator.toLocale(GepafinConstant.INVALID_VATNUMBER));
}
public static boolean isNumeric(String input) {
if (input == null || input.trim().isEmpty()) {
return false;
}
return input.matches("-?\\d+(\\.\\d+)?");
}
}