Done ticket GEPAFINBE-6139

This commit is contained in:
rajesh
2025-10-13 21:50:26 +05:30
parent 2bf9fe368c
commit 38515ed38b
42 changed files with 561 additions and 150 deletions

View File

@@ -1,5 +1,6 @@
package net.gepafin.tendermanagement.dao;
import com.amazonaws.services.dynamodbv2.xspec.L;
import com.amazonaws.services.dynamodbv2.xspec.S;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
@@ -131,6 +132,9 @@ public class ApplicationDao {
@Autowired
private AssignedApplicationsRepository assignedApplicationsRepository;
@Autowired
private CommunicationRepository communicationRepository;
// @Value("${default_System_Receiver_Email}")
// private String defaultSystemReceiverEmail;
@@ -1372,7 +1376,7 @@ public class ApplicationDao {
ApplicationSignedDocumentEntity oldApplicationSignedDocument = Utils.getClonedEntityForData(applicationSignedDocumentEntity);
String oldS3Path = applicationSignedDocumentEntity.getFilePath();
log.debug("Old S3 path: {} ", oldS3Path);
String newS3Path = s3ConfigBean.generateDocumentPathForOther(DocOtherSourceTypeEnum.DELETED_USER_SIGNED_DOCUMENT,applicationSignedDocumentEntity.getApplication().getCall().getId(),applicationSignedDocumentEntity.getApplication().getId(),0L);
String newS3Path = s3ConfigBean.generateDocumentPathForOther(DocOtherSourceTypeEnum.DELETED_USER_SIGNED_DOCUMENT,applicationSignedDocumentEntity.getApplication().getCall().getId(),applicationSignedDocumentEntity.getApplication().getId(),0L,0L);
log.debug("Generated new S3 path for deleted document: {}", newS3Path);
UploadFileOnAmazonS3Response response = amazonS3Service.moveFile(applicationSignedDocumentEntity.getFileName(), oldS3Path, newS3Path);
@@ -1407,7 +1411,7 @@ public class ApplicationDao {
}
private String generateS3PathForDelegation(Long callId, Long applicationId) {
try {
return s3ConfigBean.generateDocumentPathForOther(DocOtherSourceTypeEnum.USER_SIGNED_DOCUMENT, callId, applicationId,0L);
return s3ConfigBean.generateDocumentPathForOther(DocOtherSourceTypeEnum.USER_SIGNED_DOCUMENT, callId, applicationId,0L,0L);
} catch (IllegalArgumentException e) {
log.error("Failed to generate S3 path for delegation | callId: {}, applicationId: {}, error: {}", callId, applicationId, e.getMessage(), e);
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.S3_PATH_GENERATION_ERROR_MSG));
@@ -1529,11 +1533,12 @@ public class ApplicationDao {
ApplicationSignedDocumentStatusEnum.ACTIVE.getValue());
List<DocumentEntity> amendmentDocuments = fetchAmendmentDocuments(applicationId);
List<DocumentEntity> evaluationDocuments = fetchEvaluationDocuments(applicationId);
List<DocumentEntity> communicationnDocuments = fetchCommunicationDocuments(applicationId);
if (documents.isEmpty() && signedDocument == null && amendmentDocuments.isEmpty() && evaluationDocuments.isEmpty()) {
log.warn("No documents found for applicationId: {}", applicationId);
throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.DOCUMENT_NOT_FOUND));
}
return createZipWithDocuments(applicationEntity, documents, signedDocument, amendmentDocuments, evaluationDocuments, applicationId);
return createZipWithDocuments(applicationEntity, documents, signedDocument, amendmentDocuments, evaluationDocuments, applicationId,communicationnDocuments);
}
private void validateAssignedUser(HttpServletRequest request, Long applicationId) {
@@ -1582,6 +1587,28 @@ public class ApplicationDao {
}
return Collections.emptyList();
}
private List<DocumentEntity> fetchCommunicationDocuments(Long applicationId) {
log.info("Fetching communication documents for applicationId: {}", applicationId);
List<ApplicationAmendmentRequestEntity> amendmentRequests = applicationAmendmentRequestRepository.findByApplicationIdAndIsDeletedFalse(applicationId);
List<Long> amendmentRequestIds = amendmentRequests.stream()
.map(ApplicationAmendmentRequestEntity::getId)
.collect(Collectors.toList());
List<CommunicationEntity> communicationEntities=communicationRepository.findByApplicationAmendmentRequestIdInAndIsDeletedFalse(amendmentRequestIds);
List<DocumentEntity> documentEntities=new ArrayList<>();
if (Boolean.FALSE.equals(communicationEntities.isEmpty())) {
for (CommunicationEntity communicationEntity : communicationEntities) {
{
Long communicationId = communicationEntity.getId();
log.debug("Found communication entity with id: {}", communicationId);
List<DocumentEntity> communicationDocuments= documentRepository.findBySourceIdInAndSourceAndIsDeletedFalse(Collections.singleton(communicationId), DocumentSourceTypeEnum.COMMUNICATION.getValue());
documentEntities.addAll(communicationDocuments);
}
}
return documentEntities;
}
return Collections.emptyList();
}
private String fetchProtocolNumberForAmendment(Long amendmentRequestId) {
ApplicationAmendmentRequestEntity amendmentRequest = applicationAmendmentRequestRepository.findByIdAndIsDeletedFalse(amendmentRequestId).orElse(null);
@@ -1603,12 +1630,12 @@ public class ApplicationDao {
}
}
private byte[] createZipWithDocuments(ApplicationEntity applicationEntity, List<DocumentEntity> documents, ApplicationSignedDocumentEntity signedDocument,
List<DocumentEntity> amendmentDocuments, List<DocumentEntity> evaluationDocuments, Long applicationId) {
List<DocumentEntity> amendmentDocuments, List<DocumentEntity> evaluationDocuments, Long applicationId,List<DocumentEntity> communicationDocuments) {
try (ByteArrayOutputStream zipOutputStream = new ByteArrayOutputStream(); ZipOutputStream zos = new ZipOutputStream(zipOutputStream)) {
Long callId = applicationEntity.getCall().getId();
// Add Application Documents
String appS3Folder = s3PathConfig.generateDocumentPath(DocumentSourceTypeEnum.APPLICATION, callId, applicationId, 0L);
String appS3Folder = s3PathConfig.generateDocumentPath(DocumentSourceTypeEnum.APPLICATION, callId, applicationId, 0L,0L);
for (DocumentEntity document : documents) {
String fileName = Utils.extractFileName(document.getFilePath());
addDocumentToZip(zos, appS3Folder, document.getFilePath(), fileName);
@@ -1616,7 +1643,7 @@ public class ApplicationDao {
// Add Signed Document
if (signedDocument != null) {
String signedFolder = "SIGNED_DOCUMENT/";
String signedDocS3Folder = s3PathConfig.generateDocumentPathForOther(DocOtherSourceTypeEnum.USER_SIGNED_DOCUMENT, callId, applicationId, 0L);
String signedDocS3Folder = s3PathConfig.generateDocumentPathForOther(DocOtherSourceTypeEnum.USER_SIGNED_DOCUMENT, callId, applicationId, 0L,0L);
String fileName = signedDocument.getFileName();
addDocumentToZip(zos, signedDocS3Folder, signedDocument.getFilePath(), signedFolder + fileName);
}
@@ -1624,17 +1651,24 @@ public class ApplicationDao {
for (DocumentEntity amendmentDocument : amendmentDocuments) {
String protocolNumber = fetchProtocolNumberForAmendment(amendmentDocument.getSourceId());
String amendmentFolder = "SOCCORSO_" + protocolNumber + "/";
String amendmentS3Folder = s3PathConfig.generateDocumentPath(DocumentSourceTypeEnum.AMENDMENT, callId, applicationId, amendmentDocument.getSourceId());
String amendmentS3Folder = s3PathConfig.generateDocumentPath(DocumentSourceTypeEnum.AMENDMENT, callId, applicationId, amendmentDocument.getSourceId(),0L);
String fileName = Utils.extractFileName(amendmentDocument.getFilePath());
addDocumentToZip(zos, amendmentS3Folder, amendmentDocument.getFilePath(), amendmentFolder + fileName);
}
// Add Evaluation Documents
for (DocumentEntity evaluationDocument : evaluationDocuments) {
String evaluationFolder = "EVALUATION/";
String evaluationS3Folder = s3PathConfig.generateDocumentPath(DocumentSourceTypeEnum.EVALUATION, callId, applicationId, evaluationDocument.getSourceId());
String evaluationS3Folder = s3PathConfig.generateDocumentPath(DocumentSourceTypeEnum.EVALUATION, callId, applicationId, evaluationDocument.getSourceId(),0L);
String fileName = Utils.extractFileName(evaluationDocument.getFilePath());
addDocumentToZip(zos, evaluationS3Folder, evaluationDocument.getFilePath(), evaluationFolder + fileName);
}
for (DocumentEntity communicationDocument : communicationDocuments) {
Optional<CommunicationEntity> communicationEntity=communicationRepository.findByIdAndIsDeletedFalse(communicationDocument.getSourceId());
String evaluationFolder = "COMMUNICATION/";
String evaluationS3Folder = s3PathConfig.generateDocumentPath(DocumentSourceTypeEnum.COMMUNICATION, callId, applicationId, communicationEntity.get().getApplicationAmendmentRequest().getId(),communicationDocument.getSourceId());
String fileName = Utils.extractFileName(communicationDocument.getFilePath());
addDocumentToZip(zos, evaluationS3Folder, communicationDocument.getFilePath(), evaluationFolder + fileName);
}
zos.finish();
return zipOutputStream.toByteArray();
} catch (IOException e) {