Done ticket GEPAFINBE-6143

This commit is contained in:
rajesh
2025-11-04 16:46:25 +05:30
parent fcee98a228
commit 5171c69df4
30 changed files with 837 additions and 44 deletions

View File

@@ -93,6 +93,9 @@ public class DocumentDao {
@Autowired
private CommunicationRepository communicationRepository;
@Autowired
private ApplicationContractRepository applicationContractRepository;
// @Value("${aws.s3.url.folder}")
// private String s3Folder;
@@ -172,6 +175,7 @@ public class DocumentDao {
Long amendmentId = 0L;
Long evaluationId = 0L;
Long communicationId = 0L;
Long contractId=0L;
Long callId = sourceId;
if (type == DocumentSourceTypeEnum.APPLICATION) {
applicationId = sourceId;
@@ -197,9 +201,16 @@ public class DocumentDao {
applicationId=applicationAmendmentRequestEntity.get().getApplicationId();
callId = applicationAmendmentRequestEntity.get().getApplicationEvaluationEntity().getAssignedApplicationsEntity().getApplication().getCall().getId();
log.info("Processing document of type COMMUNICATION .Resolved evaluationId={}, applicationId={}, callId={}", evaluationId, applicationId, callId);
}else if (type == DocumentSourceTypeEnum.CONTRACT) {
contractId = sourceId;
ApplicationContractEntity applicationContractEntity=applicationContractRepository.findByIdAndIsDeletedFalse(contractId);
ApplicationEntity applicationEntity=applicationService.validateApplication(applicationContractEntity.getApplicationId());
applicationId=applicationEntity.getId();
callId = applicationEntity.getCall().getId();
log.info("Processing document of type CONTRACT .Resolved evaluationId={}, applicationId={}, callId={}, contractId={}", evaluationId, applicationId, callId,contractId);
}
try {
String s3Path = generateS3Path(type, callId, applicationId, amendmentId,communicationId);
String s3Path = generateS3Path(type, callId, applicationId, amendmentId,communicationId,contractId);
log.info("Generated S3 path {}", s3Path);
return amazonS3Service.uploadFileOnAmazonS3(s3Path, file);
} catch (Exception e) {
@@ -210,9 +221,9 @@ public class DocumentDao {
}
public String generateS3Path(DocumentSourceTypeEnum typeOfDocument, Long callId, Long applicationId, Long amendmentId,Long communicationId) {
public String generateS3Path(DocumentSourceTypeEnum typeOfDocument, Long callId, Long applicationId, Long amendmentId,Long communicationId,Long contractId) {
try {
return s3ConfigBean.generateDocumentPath(typeOfDocument, callId, applicationId, amendmentId,communicationId);
return s3ConfigBean.generateDocumentPath(typeOfDocument, callId, applicationId, amendmentId,communicationId,contractId);
} catch (IllegalArgumentException e) {
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.S3_PATH_GENERATION_ERROR_MSG));
}
@@ -245,6 +256,7 @@ public class DocumentDao {
Long amendmentId = null;
Long evaluationId = null;
Long communicationId=null;
Long contractId=null;
if (DocumentSourceTypeEnum.CALL.getValue().equalsIgnoreCase(documentEntity.getSource())) {
callId = documentEntity.getSourceId();
@@ -340,9 +352,20 @@ public class DocumentDao {
communicationEntity1.setDocuments(updatedValue);
communicationRepository.save(communicationEntity1);
}
}
else if(DocumentSourceTypeEnum.CONTRACT.getValue().equalsIgnoreCase(documentEntity.getSource())) {
contractId = documentEntity.getSourceId();
ApplicationContractEntity applicationContractEntity=applicationContractRepository.findByIdAndIsDeletedFalse(contractId);
ApplicationEntity applicationEntity=applicationService.validateApplication(applicationContractEntity.getApplicationId());
String beneficiaryDocument=applicationContractEntity.getBeneficiaryDocument();
if(beneficiaryDocument!=null) {
String updatedValue = removeDocumentIdFromFieldValue(beneficiaryDocument, documentId);
applicationContractEntity.setBeneficiaryDocument(updatedValue);
applicationContractRepository.save(applicationContractEntity);
}
}
deleteFileFromS3(documentEntity, callId, applicationId,amendmentId,communicationId);
deleteFileFromS3(documentEntity, callId, applicationId,amendmentId,communicationId,contractId);
log.info("Successfully deleted file from S3 for documentId={}", documentId);
}
@@ -387,6 +410,7 @@ public class DocumentDao {
Long amendmentId=null;
Long evaluationId=null;
Long communicationId=null;
Long contractId=null;
if (type.equals(DocumentSourceTypeEnum.APPLICATION)) {
callId = applicationRepository.findCallIdById(id);
applicationId = id;
@@ -412,6 +436,13 @@ public class DocumentDao {
applicationId=applicationAmendmentRequestEntity.get().getApplicationId();
callId = applicationAmendmentRequestEntity.get().getApplicationEvaluationEntity().getAssignedApplicationsEntity().getApplication().getCall().getId();
log.info("Processing document of type EVALUATION .Resolved evaluationId={}, applicationId={}, callId={}", evaluationId, applicationId, callId);
}else if (type == DocumentSourceTypeEnum.CONTRACT) {
contractId = id;
ApplicationContractEntity applicationContractEntity=applicationContractRepository.findByIdAndIsDeletedFalse(contractId);
ApplicationEntity applicationEntity=applicationService.validateApplication(applicationContractEntity.getApplicationId());
applicationId=applicationContractEntity.getApplicationId();
callId = applicationEntity.getCall().getId();
log.info("Processing document of type CONTRACT .Resolved evaluationId={}, applicationId={}, callId={}, contractId={}", evaluationId, applicationId, callId,contractId);
}
else {
@@ -419,7 +450,7 @@ public class DocumentDao {
applicationId = 0L;
log.info("Processing document of type CALL . Resolved callId={}", callId);
}
String s3Path = generateS3Path(type, callId, applicationId,amendmentId,communicationId);
String s3Path = generateS3Path(type, callId, applicationId,amendmentId,communicationId,contractId);
log.info("Generated S3 path {}", s3Path);
return amazonS3Service.uploadFileOnAmazonS3(s3Path, file);
} catch (Exception e) {
@@ -432,12 +463,12 @@ public class DocumentDao {
return callDao.convertToDocumentResponseBean(documentEntity);
}
public void deleteFileFromS3(DocumentEntity documentEntity, Long callId, Long applicationId,Long amendmentId,Long communicationId) {
public void deleteFileFromS3(DocumentEntity documentEntity, Long callId, Long applicationId,Long amendmentId,Long communicationId,Long contractId) {
try {
DocumentEntity oldDocumentEntity = Utils.getClonedEntityForData(documentEntity);
String oldS3Path = documentEntity.getFilePath();
String newS3Path = s3ConfigBean.generateDocumentPathForOther(DocOtherSourceTypeEnum.valueOf("DELETED_" + documentEntity.getSource().toUpperCase()), callId, applicationId,amendmentId,communicationId);
String newS3Path = s3ConfigBean.generateDocumentPathForOther(DocOtherSourceTypeEnum.valueOf("DELETED_" + documentEntity.getSource().toUpperCase()), callId, applicationId,amendmentId,communicationId,contractId);
log.info("Moving file to deleted path: oldS3Path={}, newS3Path={}", oldS3Path, newS3Path);
UploadFileOnAmazonS3Response response = amazonS3Service.moveFile(documentEntity.getFileName(), oldS3Path, newS3Path);
documentEntity.setFileName(response.getFileName());