Done ticket GEPAFINBE-154
This commit is contained in:
@@ -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 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 REQUIRED_REQUESTED_AMOUNT_MSG = "validation.required.requested.amount";
|
||||||
|
public static final String CRITERIA_TABLE_COLUMNS="criteria_table_columns";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -152,6 +152,31 @@ public class PdfDao {
|
|||||||
// Create value cell with rounded corners
|
// Create value cell with rounded corners
|
||||||
PdfPTable valueTable = new PdfPTable(1);
|
PdfPTable valueTable = new PdfPTable(1);
|
||||||
valueTable.setWidthPercentage(100);
|
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<?>) {
|
if (value instanceof List<?>) {
|
||||||
// Further check if the list contains Strings
|
// Further check if the list contains Strings
|
||||||
List<?> list = (List<?>) value;
|
List<?> list = (List<?>) value;
|
||||||
@@ -184,7 +209,6 @@ public class PdfDao {
|
|||||||
Object object = value;
|
Object object = value;
|
||||||
String stringvalue = Utils.convertToString(object);
|
String stringvalue = Utils.convertToString(object);
|
||||||
List<Map<String, Object>> fieldValueList = Utils.convertJsonStringIntoJsonList(stringvalue);
|
List<Map<String, Object>> fieldValueList = Utils.convertJsonStringIntoJsonList(stringvalue);
|
||||||
|
|
||||||
document = createPdfTable(fieldValueList, document, contentResponseBean);
|
document = createPdfTable(fieldValueList, document, contentResponseBean);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -231,12 +255,13 @@ public class PdfDao {
|
|||||||
document.add(valueTable);
|
document.add(valueTable);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
String fieldValue1= (String) value;
|
if (value instanceof String) {
|
||||||
if(Utils.isValidDateString(fieldValue1)){
|
String fieldValue1 = (String) value;
|
||||||
fieldValue1=Utils.formatDateString(String.valueOf(value));
|
if (Utils.isValidDateString(fieldValue1)) {
|
||||||
|
fieldValue1 = Utils.formatDateString(String.valueOf(value));
|
||||||
}
|
}
|
||||||
if(Boolean.TRUE.equals(Utils.isItalianFormattedAmount(fieldValue)) ){
|
if(contentResponseBean.getName().equals("numberinput") && Boolean.TRUE.equals(Utils.isNumeric(fieldValue))){
|
||||||
fieldValue= String.valueOf(Utils.convertToItalianFormat(fieldValue));
|
fieldValue1=Utils.convertToItalianFormat(fieldValue);
|
||||||
}
|
}
|
||||||
// PdfPCell valueCell = new PdfPCell(new Phrase(fieldValue1, valueFont));
|
// PdfPCell valueCell = new PdfPCell(new Phrase(fieldValue1, valueFont));
|
||||||
PdfPCell valueCell = PdfUtils.htmlToPdfPCell(fieldValue1, valueFont);
|
PdfPCell valueCell = PdfUtils.htmlToPdfPCell(fieldValue1, valueFont);
|
||||||
@@ -252,6 +277,7 @@ public class PdfDao {
|
|||||||
valueTable.addCell(valueCell);
|
valueTable.addCell(valueCell);
|
||||||
document.add(valueTable);
|
document.add(valueTable);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
document.add(new Paragraph("\n")); // Add line break after each value
|
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, Boolean> formulaEnabledMap = new HashMap<>();
|
||||||
Map<String, String> formulaTypeMap = new HashMap<>();
|
Map<String, String> formulaTypeMap = new HashMap<>();
|
||||||
Map<String, String> fieldTypeMap = 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
|
Font lightGrayFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new BaseColor(110, 110, 110)); // Light gray
|
||||||
|
|
||||||
|
|
||||||
contentResponseBean.getSettings().stream()
|
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)
|
.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
|
||||||
@@ -283,7 +310,7 @@ public class PdfDao {
|
|||||||
Boolean isFormulaEnabled = (Boolean) fieldData.get("enableFormula");
|
Boolean isFormulaEnabled = (Boolean) fieldData.get("enableFormula");
|
||||||
String formulaType = (String) fieldData.get("lastRowFormula");
|
String formulaType = (String) fieldData.get("lastRowFormula");
|
||||||
String fieldType = (String) fieldData.get("fieldtype"); // Get the field type (e.g., numeric)
|
String fieldType = (String) fieldData.get("fieldtype"); // Get the field type (e.g., numeric)
|
||||||
|
String total= (String) fieldData.get("lastRowText");
|
||||||
if (fieldName != null && fieldDataValue != null) {
|
if (fieldName != null && fieldDataValue != null) {
|
||||||
stateFieldMap.put(fieldName, fieldDataValue);
|
stateFieldMap.put(fieldName, fieldDataValue);
|
||||||
}
|
}
|
||||||
@@ -297,6 +324,9 @@ public class PdfDao {
|
|||||||
if (fieldType != null) {
|
if (fieldType != null) {
|
||||||
fieldTypeMap.put(fieldName, fieldType); // Store the fieldType in the map
|
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
|
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
|
Object value = row.getOrDefault(key, ""); // Fetch value or use empty string if key not present
|
||||||
// String fieldValue= (String) value;
|
// String fieldValue= (String) value;
|
||||||
String fieldValue = value != null ? value.toString() : "";
|
String fieldValue = value != null ? value.toString() : "";
|
||||||
if(Boolean.TRUE.equals(Utils.isItalianFormattedAmount(fieldValue)) ){
|
// if(Boolean.TRUE.equals(Utils.isItalianFormattedAmount(fieldValue)) ){
|
||||||
fieldValue= String.valueOf(Utils.convertToItalianFormat(fieldValue));
|
//// fieldValue= String.valueOf(Utils.convertToItalianFormat(fieldValue));
|
||||||
}
|
// }
|
||||||
if (Boolean.TRUE.equals(formulaEnabledMap.get(key)) && Boolean.TRUE.equals(GepafinConstant.NUMERIC.equalsIgnoreCase(fieldTypeMap.get(key)))) {
|
if (Boolean.TRUE.equals(formulaEnabledMap.get(key)) && Boolean.TRUE.equals(GepafinConstant.NUMERIC.equalsIgnoreCase(fieldTypeMap.get(key)))) {
|
||||||
calculateValue(key, fieldValue, formulaTypeMap, columnSums);
|
calculateValue(key, fieldValue, formulaTypeMap, columnSums);
|
||||||
}
|
}
|
||||||
|
if(Boolean.TRUE.equals(Utils.isNumeric(fieldValue))){
|
||||||
|
fieldValue=Utils.convertToItalianFormat(fieldValue);
|
||||||
|
}
|
||||||
|
|
||||||
PdfPCell dataCell = PdfUtils.htmlToPdfPCell(fieldValue != null ? fieldValue : "", textFont);
|
PdfPCell dataCell = PdfUtils.htmlToPdfPCell(fieldValue != null ? fieldValue : "", textFont);
|
||||||
dataCell.setBackgroundColor(new BaseColor(239, 243, 248)); // Light blue for the cell
|
dataCell.setBackgroundColor(new BaseColor(239, 243, 248)); // Light blue for the cell
|
||||||
@@ -397,14 +430,19 @@ public class PdfDao {
|
|||||||
table.addCell(emptyCell);
|
table.addCell(emptyCell);
|
||||||
}
|
}
|
||||||
} else {
|
} 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));
|
emptyCell.setBackgroundColor(new BaseColor(239, 243, 248));
|
||||||
table.addCell(emptyCell);
|
table.addCell(emptyCell);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Add the last table to the document
|
// Add the last table to the document
|
||||||
document.add(table);
|
document.add(table);
|
||||||
|
|
||||||
@@ -415,7 +453,7 @@ public class PdfDao {
|
|||||||
try {
|
try {
|
||||||
if (Boolean.FALSE.equals(StringUtils.isEmpty(fieldValue))) {
|
if (Boolean.FALSE.equals(StringUtils.isEmpty(fieldValue))) {
|
||||||
// Use Locale.ITALY to parse the number with the Italian format (comma as decimal separator)
|
// 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
|
Number number = format.parse(fieldValue); // Parse the fieldValue as a number
|
||||||
double numericValue = number.doubleValue(); // Convert the parsed number to double
|
double numericValue = number.doubleValue(); // Convert the parsed number to double
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
package net.gepafin.tendermanagement.util;
|
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.DocumentException;
|
||||||
import com.itextpdf.text.Element;
|
import com.itextpdf.text.Element;
|
||||||
import com.itextpdf.text.Font;
|
import com.itextpdf.text.Font;
|
||||||
@@ -60,6 +62,24 @@ public class PdfUtils {
|
|||||||
return cell;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -753,6 +753,12 @@ public class Utils {
|
|||||||
private static Map<String, Object> defaultErrorResponse() {
|
private static Map<String, Object> defaultErrorResponse() {
|
||||||
return Collections.singletonMap("message", Translator.toLocale(GepafinConstant.INVALID_VATNUMBER));
|
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+)?");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user