Updated code for adding list of document
This commit is contained in:
@@ -31,6 +31,7 @@ import java.io.ByteArrayOutputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class PdfDao {
|
public class PdfDao {
|
||||||
@@ -476,7 +477,7 @@ public class PdfDao {
|
|||||||
String contentId = content.getId(); // Content ID
|
String contentId = content.getId(); // Content ID
|
||||||
String label = content.getLabel(); // Content label
|
String label = content.getLabel(); // Content label
|
||||||
String name = content.getName(); // Content name
|
String name = content.getName(); // Content name
|
||||||
Object fieldValue = null;
|
Object fieldValue = "";
|
||||||
|
|
||||||
String contentLabel = content.getSettings().stream()
|
String contentLabel = content.getSettings().stream()
|
||||||
.filter(setting -> "label".equals(setting.getName())) // Filter settings by name
|
.filter(setting -> "label".equals(setting.getName())) // Filter settings by name
|
||||||
@@ -485,6 +486,32 @@ public class PdfDao {
|
|||||||
.findFirst() // Get the first matching value
|
.findFirst() // Get the first matching value
|
||||||
.orElse(null); // If no match is found, set label to null
|
.orElse(null); // If no match is found, set label to null
|
||||||
// Find the form field in the response that matches the contentId
|
// Find the form field in the response that matches the contentId
|
||||||
|
if (name.equals("paragraph")){
|
||||||
|
String paragraph = content.getSettings().stream()
|
||||||
|
.filter(setting -> "text".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
|
||||||
|
.findFirst() // Get the first matching value
|
||||||
|
.orElse(null);
|
||||||
|
Paragraph labelParagraph = new Paragraph();
|
||||||
|
PdfPCell labelCell = new PdfPCell(PdfUtils.htmlToPdfPCell(paragraph,labelFont));
|
||||||
|
labelCell.setBorder(Rectangle.NO_BORDER);
|
||||||
|
labelCell.setGrayFill(7);
|
||||||
|
labelCell.setPadding(5);
|
||||||
|
|
||||||
|
// Create a PdfPTable with 1 column and add the PdfPCell to it
|
||||||
|
PdfPTable table = new PdfPTable(1);
|
||||||
|
table.setWidthPercentage(100);
|
||||||
|
table.addCell(labelCell);
|
||||||
|
labelParagraph.add(table);
|
||||||
|
try {
|
||||||
|
document.add(labelParagraph);
|
||||||
|
document.add(new Paragraph(" "));
|
||||||
|
|
||||||
|
} catch (DocumentException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
Optional<ApplicationFormFieldResponseBean> matchingFormField = formFields.stream()
|
Optional<ApplicationFormFieldResponseBean> matchingFormField = formFields.stream()
|
||||||
.filter(formField -> formField.getFieldId().equals(contentId))
|
.filter(formField -> formField.getFieldId().equals(contentId))
|
||||||
.findFirst();
|
.findFirst();
|
||||||
@@ -501,7 +528,13 @@ public class PdfDao {
|
|||||||
|
|
||||||
// Process 'fileupload' and 'checkboxes' cases as in the original logic
|
// Process 'fileupload' and 'checkboxes' cases as in the original logic
|
||||||
if (name.equals("fileupload")) {
|
if (name.equals("fileupload")) {
|
||||||
continue;
|
if (fieldValue instanceof List<?> && ((List<?>) fieldValue).stream().allMatch(item -> item instanceof DocumentResponseBean)) {
|
||||||
|
List<DocumentResponseBean> documentList = (List<DocumentResponseBean>) fieldValue;
|
||||||
|
List<String> names = documentList.stream()
|
||||||
|
.map(DocumentResponseBean::getName)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
fieldValue = names;
|
||||||
|
}
|
||||||
} else if (name.equals("checkboxes") && fieldValue instanceof List<?>) {
|
} else if (name.equals("checkboxes") && fieldValue instanceof List<?>) {
|
||||||
List<String> check = (List<String>) fieldValue;
|
List<String> check = (List<String>) fieldValue;
|
||||||
List<SettingResponseBean> settingResponseBeans = content.getSettings();
|
List<SettingResponseBean> settingResponseBeans = content.getSettings();
|
||||||
@@ -529,15 +562,12 @@ public class PdfDao {
|
|||||||
|
|
||||||
// Further processing of field value (e.g., finding labels in options)
|
// Further processing of field value (e.g., finding labels in options)
|
||||||
fieldValue = findLabelInOptions(content.getSettings(), fieldValue);
|
fieldValue = findLabelInOptions(content.getSettings(), fieldValue);
|
||||||
} else {
|
|
||||||
// If no matching form field is found, store contentId with an empty string
|
|
||||||
fieldValue = "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if((contentLabel!=null && Boolean.FALSE.equals(contentLabel.isEmpty())) || (fieldValue!=null && !StringUtils.isEmpty((CharSequence) fieldValue))) {
|
if((contentLabel==null || StringUtils.isEmpty(contentLabel)) && (fieldValue==null || StringUtils.isEmpty(fieldValue.toString()))) {
|
||||||
addLabelValuePair(writer, document, contentLabel, fieldValue, labelFont, valueFont, content);
|
continue;
|
||||||
}
|
}
|
||||||
|
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);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user