Updated code for pdf tabel updation
This commit is contained in:
@@ -16,6 +16,7 @@ import net.gepafin.tendermanagement.model.response.*;
|
|||||||
import net.gepafin.tendermanagement.service.CallService;
|
import net.gepafin.tendermanagement.service.CallService;
|
||||||
import net.gepafin.tendermanagement.util.Utils;
|
import net.gepafin.tendermanagement.util.Utils;
|
||||||
import net.gepafin.tendermanagement.util.Validator;
|
import net.gepafin.tendermanagement.util.Validator;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -91,73 +92,73 @@ public class PdfDao {
|
|||||||
Font boldSmallFont = new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD,new BaseColor(105, 105, 105));
|
Font boldSmallFont = new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD,new BaseColor(105, 105, 105));
|
||||||
|
|
||||||
// Adding the "Documenti Allegati" section title
|
// Adding the "Documenti Allegati" section title
|
||||||
document.add(new Paragraph(" "));
|
// document.add(new Paragraph(" "));
|
||||||
|
//
|
||||||
// pageEvent.setTotalPages(writer.getPageNumber());
|
//// pageEvent.setTotalPages(writer.getPageNumber());
|
||||||
document.newPage();
|
// document.newPage();
|
||||||
// pageEvent.setTotalPages(writer.getPageNumber());
|
//// pageEvent.setTotalPages(writer.getPageNumber());
|
||||||
document.add(new Paragraph("Documenti Allegati", sectionFont));
|
// document.add(new Paragraph("Documenti Allegati", sectionFont));
|
||||||
document.add(new Paragraph(" "));
|
// document.add(new Paragraph(" "));
|
||||||
|
//
|
||||||
|
//
|
||||||
// 1. Autocertificazione possesso Requisiti
|
//// 1. Autocertificazione possesso Requisiti
|
||||||
Paragraph p1 = new Paragraph();
|
// Paragraph p1 = new Paragraph();
|
||||||
p1.add(new Chunk("1. ", boldSmallFont));
|
// p1.add(new Chunk("1. ", boldSmallFont));
|
||||||
p1.add(new Chunk("Autocertificazione possesso Requisiti ", boldSmallFont));
|
// p1.add(new Chunk("Autocertificazione possesso Requisiti ", boldSmallFont));
|
||||||
p1.add(new Chunk("ai sensi degli artt. 46 e 47 del DPR 445/2000", smallFont));
|
// p1.add(new Chunk("ai sensi degli artt. 46 e 47 del DPR 445/2000", smallFont));
|
||||||
document.add(p1);
|
// document.add(p1);
|
||||||
document.add(new Paragraph(" "));
|
// document.add(new Paragraph(" "));
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
// 2. Informativa Privacy relativa al trattamento dei dati personali
|
//// 2. Informativa Privacy relativa al trattamento dei dati personali
|
||||||
Paragraph p2 = new Paragraph();
|
// Paragraph p2 = new Paragraph();
|
||||||
p2.add(new Chunk("2. ", boldSmallFont));
|
// p2.add(new Chunk("2. ", boldSmallFont));
|
||||||
p2.add(new Chunk("Informativa Privacy relativa al trattamento dei dati personali", boldSmallFont));
|
// p2.add(new Chunk("Informativa Privacy relativa al trattamento dei dati personali", boldSmallFont));
|
||||||
document.add(p2);
|
// document.add(p2);
|
||||||
document.add(new Paragraph(" "));
|
// document.add(new Paragraph(" "));
|
||||||
|
//
|
||||||
|
//
|
||||||
// 3. Dati richiesti per la valutazione dell’adeguatezza dei flussi finanziari
|
//// 3. Dati richiesti per la valutazione dell’adeguatezza dei flussi finanziari
|
||||||
Paragraph p3 = new Paragraph();
|
// Paragraph p3 = new Paragraph();
|
||||||
p3.add(new Chunk("3. ", boldSmallFont));
|
// p3.add(new Chunk("3. ", boldSmallFont));
|
||||||
p3.add(new Chunk("Dati richiesti per la valutazione dell’adeguatezza dei flussi finanziari prospettici come da tabella di cui all’Appendice 9", boldSmallFont));
|
// p3.add(new Chunk("Dati richiesti per la valutazione dell’adeguatezza dei flussi finanziari prospettici come da tabella di cui all’Appendice 9", boldSmallFont));
|
||||||
document.add(p3);
|
// document.add(p3);
|
||||||
document.add(new Paragraph(" "));
|
// document.add(new Paragraph(" "));
|
||||||
|
//
|
||||||
|
//
|
||||||
// 4. Rilevazione Centrale dei Rischi
|
//// 4. Rilevazione Centrale dei Rischi
|
||||||
Paragraph p4 = new Paragraph();
|
// Paragraph p4 = new Paragraph();
|
||||||
p4.add(new Chunk("4. ", boldSmallFont));
|
// p4.add(new Chunk("4. ", boldSmallFont));
|
||||||
p4.add(new Chunk("Rilevazione Centrale dei Rischi riferita agli ultimi 36 mesi disponibili alla data di presentazione della Domanda", boldSmallFont));
|
// p4.add(new Chunk("Rilevazione Centrale dei Rischi riferita agli ultimi 36 mesi disponibili alla data di presentazione della Domanda", boldSmallFont));
|
||||||
document.add(p4);
|
// document.add(p4);
|
||||||
document.add(new Paragraph(" "));
|
// document.add(new Paragraph(" "));
|
||||||
|
//
|
||||||
|
//
|
||||||
// 5. Schema di presentazione dei dati di bilancio
|
//// 5. Schema di presentazione dei dati di bilancio
|
||||||
Paragraph p5 = new Paragraph();
|
// Paragraph p5 = new Paragraph();
|
||||||
p5.add(new Chunk("5. ", boldSmallFont));
|
// p5.add(new Chunk("5. ", boldSmallFont));
|
||||||
p5.add(new Chunk("Schema di presentazione dei dati di bilancio", boldSmallFont));
|
// p5.add(new Chunk("Schema di presentazione dei dati di bilancio", boldSmallFont));
|
||||||
document.add(p5);
|
// document.add(p5);
|
||||||
document.add(new Paragraph(" "));
|
// document.add(new Paragraph(" "));
|
||||||
|
//
|
||||||
|
//
|
||||||
// 6. Dettagli bilanci in forma abbreviata
|
//// 6. Dettagli bilanci in forma abbreviata
|
||||||
Paragraph p6 = new Paragraph();
|
// Paragraph p6 = new Paragraph();
|
||||||
p6.add(new Chunk("6. ", boldSmallFont));
|
// p6.add(new Chunk("6. ", boldSmallFont));
|
||||||
p6.add(new Chunk("Dettagli bilanci in forma abbreviata", boldSmallFont));
|
// p6.add(new Chunk("Dettagli bilanci in forma abbreviata", boldSmallFont));
|
||||||
document.add(p6);
|
// document.add(p6);
|
||||||
document.add(new Paragraph(" "));
|
// document.add(new Paragraph(" "));
|
||||||
|
//
|
||||||
|
//
|
||||||
// 7. Relazione aziendale illustrativa
|
//// 7. Relazione aziendale illustrativa
|
||||||
Paragraph p7 = new Paragraph();
|
// Paragraph p7 = new Paragraph();
|
||||||
p7.add(new Chunk("7. ", boldSmallFont));
|
// p7.add(new Chunk("7. ", boldSmallFont));
|
||||||
p7.add(new Chunk("Relazione aziendale illustrativa", boldSmallFont));
|
// p7.add(new Chunk("Relazione aziendale illustrativa", boldSmallFont));
|
||||||
document.add(p7);
|
// document.add(p7);
|
||||||
document.add(new Paragraph(" "));
|
// document.add(new Paragraph(" "));
|
||||||
|
//
|
||||||
addColoredLines(writer,document,greenColor);
|
// addColoredLines(writer,document,greenColor);
|
||||||
|
|
||||||
document.close();
|
document.close();
|
||||||
|
|
||||||
@@ -272,14 +273,17 @@ public class PdfDao {
|
|||||||
document.add(valueTable);
|
document.add(valueTable);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PdfPCell valueCell = new PdfPCell(new Phrase(String.valueOf(value), valueFont));
|
String fieldValue1= (String) value;
|
||||||
|
if(Utils.isValidDateString(fieldValue1)){
|
||||||
|
fieldValue1=Utils.formatDateString(String.valueOf(value));
|
||||||
|
}
|
||||||
|
PdfPCell valueCell = new PdfPCell(new Phrase(fieldValue1, valueFont));
|
||||||
valueCell.setPadding(5f); // Increase padding for better spacing
|
valueCell.setPadding(5f); // Increase padding for better spacing
|
||||||
valueCell.setPaddingLeft(leftMargin); // Increase left margin for value
|
valueCell.setPaddingLeft(leftMargin); // Increase left margin for value
|
||||||
valueCell.setBorder(Rectangle.NO_BORDER); // Remove border for value cell
|
valueCell.setBorder(Rectangle.NO_BORDER); // Remove border for value cell
|
||||||
valueCell.setMinimumHeight(30f);
|
valueCell.setMinimumHeight(30f);
|
||||||
valueCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
valueCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
||||||
valueCell.setCellEvent(new RoundedCorners()); // Apply rounded corners
|
valueCell.setCellEvent(new RoundedCorners()); // Apply rounded corners
|
||||||
|
|
||||||
valueTable.addCell(valueCell);
|
valueTable.addCell(valueCell);
|
||||||
document.add(valueTable);
|
document.add(valueTable);
|
||||||
}
|
}
|
||||||
@@ -356,6 +360,7 @@ public class PdfDao {
|
|||||||
PdfPCell headerCell = new PdfPCell(new Phrase(headerValue)); // Create a new PdfPCell for the header
|
PdfPCell headerCell = new PdfPCell(new Phrase(headerValue)); // Create a new PdfPCell for the header
|
||||||
headerCell.setHorizontalAlignment(Element.ALIGN_CENTER); // Center align
|
headerCell.setHorizontalAlignment(Element.ALIGN_CENTER); // Center align
|
||||||
headerCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
headerCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
||||||
|
headerCell.setFixedHeight(rowHeight);
|
||||||
headerCell.setBackgroundColor(new BaseColor(178, 190, 181)); // Light gray background for header
|
headerCell.setBackgroundColor(new BaseColor(178, 190, 181)); // Light gray background for header
|
||||||
|
|
||||||
table.addCell(headerCell); // Add the header cell to the table
|
table.addCell(headerCell); // Add the header cell to the table
|
||||||
@@ -364,16 +369,15 @@ public class PdfDao {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add data rows matching stateFieldMap keys
|
// Add data rows matching stateFieldMap keys
|
||||||
for (Map.Entry<String, String> stateField : stateFieldMap.entrySet()) {
|
for (String key : orderedKeys) {
|
||||||
for (String key : orderedKeys) { // Iterate over the ordered keys
|
|
||||||
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
|
||||||
PdfPCell dynamicCell = new PdfPCell(new Phrase(value != null ? value.toString() : "", textFont));
|
PdfPCell dataCell = new PdfPCell(new Phrase(value != null ? value.toString() : "", textFont));
|
||||||
dynamicCell.setBackgroundColor(new BaseColor(239, 243, 248)); // Light blue for the cell
|
dataCell.setBackgroundColor(new BaseColor(239, 243, 248)); // Light blue for the cell
|
||||||
dynamicCell.setMinimumHeight(rowHeight);
|
dataCell.setMinimumHeight(rowHeight);
|
||||||
dynamicCell.setPadding(7f);
|
dataCell.setFixedHeight(rowHeight);
|
||||||
|
dataCell.setPadding(7f);
|
||||||
|
|
||||||
table.addCell(dynamicCell); // Add the dynamically created cell to the table
|
table.addCell(dataCell); // Add the cell to the table
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if adding another row would exceed max height
|
// Check if adding another row would exceed max height
|
||||||
@@ -494,7 +498,9 @@ public class PdfDao {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if((contentLabel!=null && Boolean.FALSE.equals(contentLabel.isEmpty())) || (fieldValue!=null && !StringUtils.isEmpty((CharSequence) fieldValue))) {
|
||||||
addLabelValuePair(writer, document, contentLabel, fieldValue, labelFont, valueFont, content);
|
addLabelValuePair(writer, document, contentLabel, fieldValue, labelFont, valueFont, content);
|
||||||
|
}
|
||||||
} catch (DocumentException e) {
|
} catch (DocumentException e) {
|
||||||
log.error("Error checking object: " + e.getMessage(), e);
|
log.error("Error checking object: " + e.getMessage(), e);
|
||||||
|
|
||||||
|
|||||||
@@ -4,12 +4,18 @@ import java.lang.reflect.Field;
|
|||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.time.format.DateTimeParseException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import com.itextpdf.styledxmlparser.jsoup.Jsoup;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import org.apache.commons.collections4.MapUtils;
|
import org.apache.commons.collections4.MapUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -369,5 +375,25 @@ public class Utils {
|
|||||||
throw new RuntimeException("Error converting map to string", e);
|
throw new RuntimeException("Error converting map to string", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public static boolean isValidDateString(String dateStr) {
|
||||||
|
Pattern datePattern = Pattern.compile("\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}");
|
||||||
|
return datePattern.matcher(dateStr).matches();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Method to convert a valid date string to the "dd-MM-yyyy" format
|
||||||
|
public static String formatDateString(String dateStr) {
|
||||||
|
String originalFormatPattern = "yyyy-MM-dd'T'HH:mm:ss";
|
||||||
|
String targetFormatPattern = "dd-MM-yyyy";
|
||||||
|
|
||||||
|
try {
|
||||||
|
SimpleDateFormat originalFormat = new SimpleDateFormat(originalFormatPattern);
|
||||||
|
Date date = originalFormat.parse(dateStr);
|
||||||
|
SimpleDateFormat targetFormat = new SimpleDateFormat(targetFormatPattern);
|
||||||
|
|
||||||
|
return targetFormat.format(date);
|
||||||
|
} catch (ParseException e) {
|
||||||
|
log.error("error while prcoessing date formate");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user