From cf4be10b721277ff8c8b02118782c4a9777eb3ea Mon Sep 17 00:00:00 2001 From: mohamed tizaoui Date: Tue, 19 Sep 2023 11:03:31 +0200 Subject: [PATCH] BUG #11777 fix download boredereau --- .../service/IngestGeneratorODTFile.java | 149 +++++++++--------- 1 file changed, 77 insertions(+), 72 deletions(-) diff --git a/api/api-ingest/ingest-internal/src/main/java/fr/gouv/vitamui/ingest/internal/server/service/IngestGeneratorODTFile.java b/api/api-ingest/ingest-internal/src/main/java/fr/gouv/vitamui/ingest/internal/server/service/IngestGeneratorODTFile.java index b29219c2793..dc23763c63b 100644 --- a/api/api-ingest/ingest-internal/src/main/java/fr/gouv/vitamui/ingest/internal/server/service/IngestGeneratorODTFile.java +++ b/api/api-ingest/ingest-internal/src/main/java/fr/gouv/vitamui/ingest/internal/server/service/IngestGeneratorODTFile.java @@ -94,7 +94,7 @@ public class IngestGeneratorODTFile { private static final VitamUILogger LOGGER = VitamUILoggerFactory.getInstance(IngestGeneratorODTFile.class); public static final String FIRST_TITLE = "Bordereau de versement d'archives"; public static final String SECOND_TITLE = "Détail des unités archivistiques de type répertoire et dossier:"; - private static final String NO_TEXT = "_ _ _ _" ; + private static final String NO_TEXT = "_ _ _ _"; private static final String LOGO_PATH = "/logo_ministere."; @Value("${tmp_folder_path}") @@ -110,14 +110,14 @@ public void generateDocumentHeader(TextDocument document, CustomerDto myCustomer Table headerTable = document.addTable(1, 2); headerTable.getRowByIndex(0).setHeight(35, false); headerTable.getColumnByIndex(1).setWidth(35); - Font font = headerTable.getCellByPosition(0,0).getFont(); + Font font = headerTable.getCellByPosition(0, 0).getFont(); font.setSize(11); - headerTable.getCellByPosition(0,0).setFont(font); - headerTable.getCellByPosition(0,0).setBorders(StyleTypeDefinitions.CellBordersType.NONE, border); - headerTable.getCellByPosition(1,0).setBorders(StyleTypeDefinitions.CellBordersType.NONE, border); + headerTable.getCellByPosition(0, 0).setFont(font); + headerTable.getCellByPosition(0, 0).setBorders(StyleTypeDefinitions.CellBordersType.NONE, border); + headerTable.getCellByPosition(1, 0).setBorders(StyleTypeDefinitions.CellBordersType.NONE, border); - if(myCustomer != null) { - Cell cell = headerTable.getCellByPosition(0,0); + if (myCustomer != null) { + Cell cell = headerTable.getCellByPosition(0, 0); cell.addParagraph(myCustomer.getName()); cell.addParagraph(myCustomer.getCompanyName()); cell.addParagraph(""); @@ -127,7 +127,7 @@ public void generateDocumentHeader(TextDocument document, CustomerDto myCustomer cell.addParagraph(myCustomer.getAddress().getCountry()); } - if (myCustomer != null && myCustomer.isHasCustomGraphicIdentity() + if (myCustomer != null && myCustomer.isHasCustomGraphicIdentity() && customerLogo != null) { byte[] customerLogoBytes = customerLogo.getInputStream().readAllBytes(); @@ -136,9 +136,9 @@ public void generateDocumentHeader(TextDocument document, CustomerDto myCustomer .getDecoder() .decode(customerLogoBase64Image); - imgFile = tmpFolderPath + LOGO_PATH+ getExtensionByCustomerLogo(customerLogoBase64Image).toLowerCase(); + imgFile = tmpFolderPath + LOGO_PATH + getExtensionByCustomerLogo(customerLogoBase64Image).toLowerCase(); FileUtils.writeByteArrayToFile(new File(imgFile), customerLogoDecodedBytes); - headerTable.getCellByPosition(1,0).setImage(new URI(imgFile)); + headerTable.getCellByPosition(1, 0).setImage(new URI(imgFile)); FileUtils.forceDelete(new File(imgFile)); @@ -147,6 +147,7 @@ public void generateDocumentHeader(TextDocument document, CustomerDto myCustomer addSpace(document); } + public void generateFirstTitle(TextDocument document) { addSpace(document); generateTile(document, 22, FIRST_TITLE, StyleTypeDefinitions.HorizontalAlignmentType.CENTER); @@ -163,32 +164,31 @@ public void generateSecondtTitle(TextDocument document) { * Le service producteur et le service versant * * */ - public void generateServicesTable(TextDocument document, Document manifest) - { + public void generateServicesTable(TextDocument document, Document manifest) { - addSpace(document); + addSpace(document); - Table table = document.addTable(2, 2); - Cell cellOne = table.getColumnByIndex(0).getCellByIndex(0); - Cell cellTwo = table.getColumnByIndex(0).getCellByIndex(1); - cellOne.setStringValue("Service producteur :"); - cellTwo.setStringValue("Service versant :"); - table.getColumnByIndex(0).setWidth(50); + Table table = document.addTable(2, 2); + Cell cellOne = table.getColumnByIndex(0).getCellByIndex(0); + Cell cellTwo = table.getColumnByIndex(0).getCellByIndex(1); + cellOne.setStringValue("Service producteur :"); + cellTwo.setStringValue("Service versant :"); + table.getColumnByIndex(0).setWidth(50); - Font fontCellOne = cellOne.getFont(); - fontCellOne.setFontStyle(StyleTypeDefinitions.FontStyle.BOLD); - cellOne.setFont(fontCellOne); + Font fontCellOne = cellOne.getFont(); + fontCellOne.setFontStyle(StyleTypeDefinitions.FontStyle.BOLD); + cellOne.setFont(fontCellOne); - Font fontCellTwo = cellTwo.getFont(); - fontCellTwo.setFontStyle(StyleTypeDefinitions.FontStyle.BOLD); - cellTwo.setFont(fontCellTwo); + Font fontCellTwo = cellTwo.getFont(); + fontCellTwo.setFontStyle(StyleTypeDefinitions.FontStyle.BOLD); + cellTwo.setFont(fontCellTwo); - table.getColumnByIndex(1).getCellByIndex(0) - .setStringValue(getManifestPrincipalData(manifest,"OriginatingAgencyIdentifier")); - table.getColumnByIndex(1).getCellByIndex(1) - .setStringValue(getServiceVersant(manifest)); + table.getColumnByIndex(1).getCellByIndex(0) + .setStringValue(getManifestPrincipalData(manifest, "OriginatingAgencyIdentifier")); + table.getColumnByIndex(1).getCellByIndex(1) + .setStringValue(getServiceVersant(manifest)); - addSpace( document); + addSpace(document); @@ -200,9 +200,10 @@ public void generateServicesTable(TextDocument document, Document manifest) * Numéro du versement, Présentation du contenu, Dates extrêmes et l'historique de conservation * * */ - public void generateDepositDataTable(TextDocument document, Document manifest, List archiveUnitDtoList) { + public void generateDepositDataTable(TextDocument document, Document manifest, + List archiveUnitDtoList) { - addSpace( document); + addSpace(document); Table table = document.addTable(4, 2); table.getColumnByIndex(0).setWidth(50); @@ -231,17 +232,19 @@ public void generateDepositDataTable(TextDocument document, Document manifest, L tableCellFour.setFont(fontCellFour); - table.getColumnByIndex(1).getCellByIndex(0).setStringValue(getManifestPrincipalData(manifest,"MessageIdentifier")); - table.getColumnByIndex(1).getCellByIndex(1).setStringValue(getManifestPrincipalData(manifest,"Comment")); - if(!archiveUnitDtoList.isEmpty()) { + table.getColumnByIndex(1).getCellByIndex(0) + .setStringValue(getManifestPrincipalData(manifest, "MessageIdentifier")); + + table.getColumnByIndex(1).getCellByIndex(1).setStringValue(getManifestPrincipalData(manifest, "Comment")); + if (!archiveUnitDtoList.isEmpty()) { table.getColumnByIndex(1).getCellByIndex(2).addParagraph( "Date de début : " + getStartedDate(getArchiveUnitStartDatesList(archiveUnitDtoList))); table.getColumnByIndex(1).getCellByIndex(2).addParagraph( "Date de fin : " + getEndDate(getArchiveUnitEndDatesList(archiveUnitDtoList))); } - table.getColumnByIndex(1).getCellByIndex(3).setStringValue(getCustodialHistory(manifest)); + table.getColumnByIndex(1).getCellByIndex(3).setStringValue(getCustodialHistory(manifest)); - addSpace( document); + addSpace(document); } @@ -253,7 +256,7 @@ public void generateDepositDataTable(TextDocument document, Document manifest, L * */ public void generateOperationDataTable(TextDocument document, Document manifest, String id) { - addSpace( document); + addSpace(document); Table table = document.addTable(2, 2); table.getColumnByIndex(0).setWidth(50); @@ -273,8 +276,8 @@ public void generateOperationDataTable(TextDocument document, Document manifest, .setStringValue(getBinaryFileNumber(manifest) + " fichiers"); table.getColumnByIndex(1).getCellByIndex(1).setStringValue(id); - addSpace( document); - addSpace( document); + addSpace(document); + addSpace(document); } @@ -286,7 +289,7 @@ public void generateOperationDataTable(TextDocument document, Document manifest, * */ public void generateResponsibleSignatureTable(TextDocument document) { - addSpace( document); + addSpace(document); Border border = new Border(Color.WHITE, 1.0, StyleTypeDefinitions.SupportedLinearMeasure.PT); Table table = document.addTable(2, 2); @@ -324,15 +327,15 @@ public void generateResponsibleSignatureTable(TextDocument document) { * */ public void generateArchiveUnitDetailsTable(TextDocument document, List archiveUnitDtoList) { - Table dynamicTable = document.addTable(1,4); + Table dynamicTable = document.addTable(1, 4); - dynamicTable.getCellByPosition(0,0).addParagraph("Identifiant SAE VAS").setHorizontalAlignment( + dynamicTable.getCellByPosition(0, 0).addParagraph("Identifiant SAE VAS").setHorizontalAlignment( StyleTypeDefinitions.HorizontalAlignmentType.CENTER); - dynamicTable.getCellByPosition(1,0).addParagraph("Titre").setHorizontalAlignment( + dynamicTable.getCellByPosition(1, 0).addParagraph("Titre").setHorizontalAlignment( StyleTypeDefinitions.HorizontalAlignmentType.CENTER); - dynamicTable.getCellByPosition(2,0).addParagraph("Date de début").setHorizontalAlignment( + dynamicTable.getCellByPosition(2, 0).addParagraph("Date de début").setHorizontalAlignment( StyleTypeDefinitions.HorizontalAlignmentType.CENTER); - dynamicTable.getCellByPosition(3,0).addParagraph("Date de fin").setHorizontalAlignment( + dynamicTable.getCellByPosition(3, 0).addParagraph("Date de fin").setHorizontalAlignment( StyleTypeDefinitions.HorizontalAlignmentType.CENTER); // the Width of each row is 170 @@ -378,10 +381,10 @@ public void generateArchiveUnitDetailsTable(TextDocument document, List getValuesForDynamicTable(Document atr, Document mani Element eElement = (Element) nNode; if (map.get(((Element) eElement.getParentNode()).getAttribute("id")) != null) { archiveUnitDto.setId(((Element) eElement.getParentNode()).getAttribute("id")); - archiveUnitDto.setTitle(getData(eElement,"Title")); - archiveUnitDto.setEndDate(getData(eElement,"EndDate")); - archiveUnitDto.setStartDate(getData(eElement,"StartDate")); + archiveUnitDto.setTitle(getData(eElement, "Title")); + archiveUnitDto.setEndDate(getData(eElement, "EndDate")); + archiveUnitDto.setStartDate(getData(eElement, "StartDate")); archiveUnitDto.setSystemId(map.get(((Element) eElement.getParentNode()).getAttribute("id"))); archiveUnitDtoList.add(archiveUnitDto); } @@ -430,17 +433,17 @@ public String resourceAsString(Resource resource) { return FileCopyUtils.copyToString(reader); } catch (IOException e) { LOGGER.error("Error while converting string to Resource Document {}", e.getMessage()); - throw new UncheckedIOException("Error while converting string to Resource Document",e); + throw new UncheckedIOException("Error while converting string to Resource Document", e); } } private String getEndDate(List listOfDate) { - if(!CollectionUtils.isEmpty(listOfDate)) { + if (!CollectionUtils.isEmpty(listOfDate)) { String lastEndDate = listOfDate.stream().map( this::manageDateFormat) .sorted().collect(Collectors.toList()) - .get(listOfDate.size()-1); + .get(listOfDate.size() - 1); return transformDate(lastEndDate); } @@ -467,13 +470,16 @@ private Map getSystemIdValues(Document document) { private String getServiceVersant(Document document) { return document.getElementsByTagName("SubmissionAgencyIdentifier").getLength() == 0 ? - getManifestPrincipalData(document,"OriginatingAgencyIdentifier") : + getManifestPrincipalData(document, "OriginatingAgencyIdentifier") : document.getElementsByTagName("SubmissionAgencyIdentifier").item(0).getTextContent(); } private String getManifestPrincipalData(Document document, String tageName) { document.getDocumentElement().normalize(); - return document.getElementsByTagName(tageName).item(0).getTextContent(); + return (document.getElementsByTagName(tageName) != null && + document.getElementsByTagName(tageName).getLength() > 0) ? + document.getElementsByTagName(tageName).item(0).getTextContent() + : NO_TEXT; } private String getCustodialHistory(Document document) { @@ -487,40 +493,39 @@ private int getBinaryFileNumber(Document document) { } private List getArchiveUnitStartDatesList(List archiveUnitDtoList) { - return archiveUnitDtoList.stream().map(ArchiveUnitDto::getStartDate ).filter(startDate-> + return archiveUnitDtoList.stream().map(ArchiveUnitDto::getStartDate).filter(startDate -> !startDate.equals(NO_TEXT) ).collect(Collectors.toList()); } private List getArchiveUnitEndDatesList(List archiveUnitDtoList) { - return archiveUnitDtoList.stream().map(ArchiveUnitDto::getEndDate ).filter(endDate-> + return archiveUnitDtoList.stream().map(ArchiveUnitDto::getEndDate).filter(endDate -> !endDate.equals(NO_TEXT) ).collect(Collectors.toList()); } private String transformDate(String date) { - if(!date.equals(NO_TEXT)){ + if (!date.equals(NO_TEXT)) { LocalDate finalDate = LocalDate.parse(date); return finalDate.format(DateTimeFormatter.ofPattern("dd/MM/yyyy")); - } - else { + } else { return date; } } private void addSpace(TextDocument document) { - document.addParagraph(""); } private String getExtensionByCustomerLogo(String customerLogoBase64Image) { - return Extension.findExtensionFromValue(Character - .toString(customerLogoBase64Image.charAt(0))) - .toString(); + return Extension.findExtensionFromValue(Character + .toString(customerLogoBase64Image.charAt(0))) + .toString(); } - private void generateTile(TextDocument document, int size, String tilte, StyleTypeDefinitions.HorizontalAlignmentType horizontalAlignmentType) { + private void generateTile(TextDocument document, int size, String tilte, + StyleTypeDefinitions.HorizontalAlignmentType horizontalAlignmentType) { Paragraph paragraph = document.addParagraph(tilte); paragraph.setHorizontalAlignment(horizontalAlignmentType); @@ -533,10 +538,10 @@ private void generateTile(TextDocument document, int size, String tilte, StyleTy private String getStartedDate(List listOfDate) { - if(!CollectionUtils.isEmpty(listOfDate)) { - String firstStartDate = listOfDate.stream().map( - this::manageDateFormat) - .sorted().findFirst().get(); + if (!CollectionUtils.isEmpty(listOfDate)) { + String firstStartDate = listOfDate.stream().map( + this::manageDateFormat) + .sorted().findFirst().get(); return transformDate(firstStartDate); } return NO_TEXT;