diff --git a/src/main/java/net/gepafin/tendermanagement/dao/PdfDao.java b/src/main/java/net/gepafin/tendermanagement/dao/PdfDao.java index afde01ab..d1ed9317 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/PdfDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/PdfDao.java @@ -40,7 +40,7 @@ import java.util.stream.Collectors; @Component public class PdfDao { - @Value("${default.hub.pdf.banner}") + @Value("${default.pdf.banner}") private String defaultLogoUrl; @Autowired @@ -77,16 +77,20 @@ public class PdfDao { // CustomPageEvent pageEvent = new CustomPageEvent(call.getName(), 0); // writer.setPageEvent(pageEvent); document.open(); - String logoUrl=defaultLogoUrl; + String logoUrl=null; Optional hubEntity=hubRepository.findById(applicationEntity.getHubId()); - if(hubEntity.isPresent()) { + if (Boolean.TRUE.equals(validator.isProductionProfileActivated()) && applicationEntity.getCall().getId().equals(23l)) { + logoUrl=defaultLogoUrl; + } + else if(hubEntity.isPresent()) { if (hubEntity.get().getUniqueUuid().equals("p4lk3bcx1RStqTaIVVbXs")) { defaultLogoUrl = hubEntity.get().getPdfBanner(); } if (hubEntity.get().getUniqueUuid().equals("t7jh5wfg9QXylNaTZkPoE")) { defaultLogoUrl = hubEntity.get().getPdfBanner(); } + logoUrl=defaultLogoUrl; } // pageEvent.setTotalPages(writer.getPageNumber()); // addLogo(document, "logo.jpg"); // Add your image path here the migration code after cherry-pick @@ -112,7 +116,7 @@ public class PdfDao { ApplicationGetResponseBean applicationGetResponseBean=applicationDao.getApplicationByFormId(request, applicationId, null); for(FormApplicationResponse formApplicationResponse: applicationGetResponseBean.getForm()) { - List fieldLabelValuePairRequests = getFormFieldsToLabels(formApplicationResponse,writer,document); + List fieldLabelValuePairRequests = getFormFieldsToLabels(formApplicationResponse,writer,document,applicationEntity); addColoredLines(writer,document,greenColor); document.add(new Paragraph(" ")); // Add line break } @@ -132,10 +136,16 @@ public class PdfDao { return null; } - private void addLabelValuePair(PdfWriter writer,Document document, String label, Object value, Font labelFont,Font valueFont,ContentResponseBean contentResponseBean) throws DocumentException { + private void addLabelValuePair(PdfWriter writer,Document document, String label, Object value, Font labelFont,Font valueFont,ContentResponseBean contentResponseBean, ApplicationEntity applicationEntity) throws DocumentException { // Add label Map stateFieldMap= new HashMap<>(); - + if (Boolean.TRUE.equals(validator.isProductionProfileActivated()) && applicationEntity.getCall().getId().equals(23l)) { + for (SettingResponseBean settingResponseBean : contentResponseBean.getSettings()) { + if (settingResponseBean.getName().equals("isRequestedAmount") && settingResponseBean.getValue().equals(Boolean.TRUE)) { + return; + } + } + } Paragraph labelParagraph = new Paragraph(label, labelFont); labelParagraph.setSpacingAfter(-10f); document.add(labelParagraph); @@ -151,10 +161,10 @@ public class PdfDao { // Define start and end points for the line (relative to the page size and margins) - if (yPos <= 140) { - // If xEnd is less than or equal to 200, generate a new page - document.newPage(); - } // Add a gap between the label and value +// if (yPos <= 140) { +// // If xEnd is less than or equal to 200, generate a new page +// document.newPage(); +// } // Add a gap between the label and value document.add(new Paragraph(" ")); // Adding an empty paragraph for spacing // Create value cell with rounded corners PdfPTable valueTable = new PdfPTable(1); @@ -268,6 +278,7 @@ public class PdfDao { document.add(valueTable); } else { + if (value instanceof String) { String fieldValue1 = (String) value; if (Utils.isValidDateString(fieldValue1)) { @@ -503,7 +514,7 @@ public class PdfDao { canvas.stroke(); } } - public List getFormFieldsToLabels(FormApplicationResponse responseBean,PdfWriter writer,Document document) { + public List getFormFieldsToLabels(FormApplicationResponse responseBean,PdfWriter writer,Document document,ApplicationEntity applicationEntity) { List labelValuePairs = new ArrayList<>(); Font labelFont = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12,new BaseColor(113,121,126)); // Light grey); @@ -521,7 +532,7 @@ public class PdfDao { String name = content.getName(); // Content name Object fieldValue = ""; - String contentLabel = content.getSettings().stream() + String contentLabel = content.getSettings().stream() .filter(setting -> "label".equals(setting.getName())) // Filter settings by name .map(SettingResponseBean::getValue) // Extract the value from the matching setting .map(Object::toString) // Convert the value to a string @@ -547,13 +558,20 @@ public class PdfDao { labelCell.setBorder(Rectangle.NO_BORDER); labelCell.setGrayFill(7); labelCell.setPadding(5); - labelParagraph.setSpacingAfter(-10f); + labelCell.setNoWrap(false); // wrap long text + labelCell.setUseAscender(true); + labelCell.setUseDescender(true); // allow text wrapping // Create a PdfPTable with 1 column and add the PdfPCell to it PdfPTable table = new PdfPTable(1); table.setWidthPercentage(100); table.addCell(labelCell); + table.setSplitLate(false); + table.setSplitRows(true); + table.setKeepTogether(false); + labelCell.setMinimumHeight(0); + labelParagraph.add(table); try { document.add(labelParagraph); @@ -618,7 +636,7 @@ public class PdfDao { if((contentLabel==null || StringUtils.isEmpty(contentLabel)) && (fieldValue==null || StringUtils.isEmpty(fieldValue.toString()))) { continue; } - addLabelValuePair(writer, document, contentLabel, fieldValue, labelFont, valueFont, content); + addLabelValuePair(writer, document, contentLabel, fieldValue, labelFont, valueFont, content,applicationEntity); } catch (DocumentException e) { log.error("Error checking object: " + e.getMessage(), e); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index ed60af77..f2db0c1e 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -67,7 +67,7 @@ api.pecUrl=https://ws.pecmassiva.com application.amendment.expiration.days=30 default.email.signature=Gepafin S.p.a -default.hub.pdf.banner=https://mementoresources.s3.amazonaws.com/gepafin/staging/template/gepafin-logo.jpg +default.pdf.banner=https://mementoresources.s3.amazonaws.com/gepafin/production/template/gepafin-logo-only.jpg #feign client config spring.cloud.openfeign.client.config.default.connectTimeout=300000