From 9635ec966ccb7c12c012982f93b3a74e3e9babff Mon Sep 17 00:00:00 2001 From: rajesh Date: Mon, 18 Nov 2024 12:54:10 +0530 Subject: [PATCH] Added signed documents in Zip --- .../tendermanagement/dao/ApplicationDao.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java index f63d2470..4a9fde43 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java @@ -1008,7 +1008,9 @@ public class ApplicationDao { } }); List documents = documentRepository.findAllById(documentIds); - if (documents.isEmpty()) { + ApplicationSignedDocumentEntity signedDocument = applicationSignedDocumentRepository + .findByApplicationIdAndStatus(applicationId, ApplicationSignedDocumentStatusEnum.ACTIVE.getValue()); + if (documents.isEmpty() && signedDocument == null) { throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.DOCUMENT_NOT_FOUND)); } try (ByteArrayOutputStream zipOutputStream = new ByteArrayOutputStream(); @@ -1025,6 +1027,17 @@ public class ApplicationDao { throw new RuntimeException("Error downloading or adding document to ZIP: " + document.getFileName(), e); } } + if (signedDocument != null) { + String s3Folder = s3PathConfig.generateDocumentPathForOther(DocOtherSourceTypeEnum.USER_SIGNED_DOCUMENT, applicationEntity.getCall().getId(), applicationId); + try (InputStream fileInputStream = amazonS3Service.getFile(s3Folder, signedDocument.getFilePath())) { + String fileName = signedDocument.getFileName(); + zos.putNextEntry(new ZipEntry(fileName)); + IOUtils.copy(fileInputStream, zos); + zos.closeEntry(); + } catch (IOException e) { + throw new RuntimeException("Error downloading or adding signed document to ZIP: " + signedDocument.getFileName(), e); + } + } zos.finish(); return zipOutputStream.toByteArray();