added pdf implementation demo files

This commit is contained in:
2025-09-12 01:24:24 +02:00
commit a28f3dcfdc
3 changed files with 519 additions and 0 deletions

142
PdfConverterReport.java Normal file
View File

@@ -0,0 +1,142 @@
package com.example.reporting.services.impl.pdf;
import static com.example.reporting.util.ResourceUtils.OTHER_RESOURCE_CODES;
import static com.example.reporting.util.DateUtil.formatDate;
import static com.example.reporting.util.ReportUtil.getRegionName;
import static com.example.reporting.util.Constants.*;
import static com.example.reporting.util.NumberUtils.getStringFromBigDecimal;
import static com.example.reporting.util.NumberUtils.getStringFromLong;
import static com.example.reporting.util.PdfUtil.formatDocumentType;
import static com.example.reporting.util.PdfUtil.getPdfPCell;
import static com.example.reporting.util.PdfUtil.getPdfPCellSpaningAcross;
import static com.example.reporting.util.PdfUtil.getPdfPTable;
import static com.example.reporting.util.ReferenceUtil.getResourceLabel;
import static com.example.reporting.util.StringUtils.getYesNo;
import static com.example.reporting.util.StringUtils.MONTHS;
import java.awt.Color;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.hibernate.HibernateException;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.server.ResponseStatusException;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;
import com.example.reporting.dto.ReportDataDto;
import com.example.reporting.dto.database.*;
import com.example.reporting.dto.reference.*;
import com.example.reporting.services.IReferenceListService;
import com.example.reporting.services.database.ITeamService;
/**
* Abstract class for PDF converter for reports
*/
public abstract class PdfConverterReport extends PdfConverter<ReportParameter> {
protected final ITeamService teamService;
protected final IReferenceListService referenceListService;
protected Map<String, ReferenceDetailDto> referenceList9498;
protected Map<String, ReferenceDto> referenceListResources4435;
protected Map<String, ReferenceDto> referenceList9480;
protected Map<String, SubstanceDto> referenceListSubstances9147;
protected Map<String, ComponentDto> referenceListComponents5193;
protected Map<String, ResourceDto> referenceListResources4860;
/**
* Creates a new instance of PdfConverterReport.
*/
public static PdfConverterReport of(ReportDto reportDto,
ITeamService teamService, IReferenceListService referenceListService)
throws DocumentException, IOException {
switch (reportDto.getType()) {
case TYPE_A:
return new PdfConverterTypeA(teamService, referenceListService);
case TYPE_B:
return new PdfConverterTypeB(teamService, referenceListService);
case TYPE_C:
return new PdfConverterTypeC(teamService, referenceListService);
default:
throw new ResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY,
"Unknown type: " + reportDto.getType());
}
}
protected PdfConverterReport(ITeamService teamService,
IReferenceListService referenceListService) throws DocumentException, IOException {
super();
this.teamService = teamService;
this.referenceListService = referenceListService;
}
@Override
public ResponseEntity<byte[]> convert(ReportParameter param) throws IOException {
return this.convert(param.submitDto(), param.headers(), param.isNotReadOnly());
}
ResponseEntity<byte[]> convert(ReportDataDto submitDto, HttpHeaders headers, boolean isNotReadOnly)
throws IOException {
PdfWriter writer = null;
try {
loadReferenceLists(submitDto.getReportDto().getReportRoot().getYear(), isNotReadOnly);
writer = PdfWriter.getInstance(document, baos);
generateTitlePage(submitDto.getReportDto(), writer);
generateStatusPage(submitDto.getReportDto());
generateMasterDataPage(submitDto.getReportDto(), submitDto.getContactPersonList());
generateEntityDataPage(submitDto.getReportDto(), submitDto.getCapacityDtoList(),
submitDto.getSubUnitDtoList(), submitDto.getClassificationDtoList(),
submitDto.getLineDtoList());
generateResourcesPage(submitDto.getResourceInputDtoList(), submitDto.getResourceComponentDtoList(),
submitDto.getReportDto(), submitDto.getResourceDesignationDtoList());
generateDataPage(submitDto);
generateValidationPage(submitDto.getReportDto(), submitDto.getExternalContributorDtoList());
generateAttachmentsPage(submitDto.getDocumentDtoList());
generateConclusionPage(submitDto.getReportDto());
} finally {
document.close();
if (writer != null) {
writer.close();
}
}
return new ResponseEntity<>(baos.toByteArray(), headers, HttpStatus.OK);
}
protected abstract void generateDataPage(ReportDataDto submitDto);
// Rest of the class follows similar pattern with generic naming...
// [Additional methods would continue with similar transformations]
private void loadReferenceLists(String year, boolean isNotReadOnly) {
this.referenceList9498 = referenceListService.getEntityTypes9498(year);
this.referenceListResources4435 = referenceListService.getReferenceListResourceComponents4435(year, isNotReadOnly);
this.referenceList9480 = referenceListService.getReferenceListSystems9480(year, isNotReadOnly);
// Additional reference list loading...
}
@Override
protected Paragraph getPdfTitle(ReportDto reportDto) {
return new Paragraph("Report for the year " + reportDto.getReportRoot().getYear(), fontBold22);
}
}