Done Ticket GEPAFINBE-171
This commit is contained in:
@@ -198,13 +198,16 @@ public class ApplicationDao {
|
||||
|
||||
|
||||
public ApplicationResponseBean createApplication(HttpServletRequest request, ApplicationRequestBean applicationRequestBean, Long formId, Long applicationId) {
|
||||
log.info("Starting createApplication: formId={}, applicationId={}", formId, applicationId);
|
||||
FormEntity formEntity = formService.validateForm(formId);
|
||||
// callService.validatePublishedCall(formEntity.getCall().getId());
|
||||
validateFormFields(applicationRequestBean,formEntity);
|
||||
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
||||
checkCallEndDate(applicationEntity.getCall());
|
||||
validator.validateUserWithCompany(request, applicationEntity.getCompanyId());
|
||||
log.info("Validated user-company association for company ID: {}", applicationEntity.getCompanyId());
|
||||
if(Boolean.FALSE.equals(applicationEntity.getStatus().equals(ApplicationStatusTypeEnum.DRAFT.getValue()))) {
|
||||
log.warn("Application ID {} is not in DRAFT status", applicationId);
|
||||
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.APPLICATION_NOT_IN_DRAFT_STATUS));
|
||||
}
|
||||
formService.validateFormField(applicationRequestBean.getFormFields(),applicationEntity,formEntity);
|
||||
@@ -231,10 +234,12 @@ public class ApplicationDao {
|
||||
}
|
||||
|
||||
public ApplicationFormEntity createApplicationFormEntity(ApplicationEntity application, FormEntity formEntity) {
|
||||
log.info("Creating ApplicationFormEntity for applicationId: {}, formId: {}", application.getId(), formEntity.getId());
|
||||
ApplicationFormEntity applicationFormEntity = new ApplicationFormEntity();
|
||||
applicationFormEntity.setApplication(application);
|
||||
applicationFormEntity.setForm(formEntity);
|
||||
applicationFormEntity = saveApplicationFormEntity(applicationFormEntity);
|
||||
log.info("Created ApplicationFormEntity with id: {}", applicationFormEntity.getId());
|
||||
return applicationFormEntity;
|
||||
}
|
||||
|
||||
@@ -286,6 +291,7 @@ public class ApplicationDao {
|
||||
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
|
||||
if (fileUploadContent.isPresent()) {
|
||||
String documentId = applicationFormFieldEntity.getFieldValue();
|
||||
log.debug("Field is file upload/select type. Document IDs: {}", documentId);
|
||||
if (documentId != null && !documentId.isEmpty()) {
|
||||
documentResponseBeans = Arrays.stream(documentId.split(","))
|
||||
.map(String::trim)
|
||||
@@ -293,6 +299,7 @@ public class ApplicationDao {
|
||||
.map(docId -> {
|
||||
DocumentEntity documentEntity = documentService.validateDocument(docId);
|
||||
if (Boolean.FALSE.equals(DocumentSourceTypeEnum.APPLICATION.getValue().equals(documentEntity.getSource()))) {
|
||||
log.warn("Document {} source type invalid: {}", docId, documentEntity.getSource());
|
||||
throw new CustomValidationException(Status.NOT_FOUND,Translator.toLocale(GepafinConstant.DOCUMENT_NOT_FOUND));
|
||||
}
|
||||
return documentEntity;
|
||||
@@ -318,6 +325,7 @@ public class ApplicationDao {
|
||||
|
||||
ApplicationEntity applicationEntity= validateApplication(id);
|
||||
if (Boolean.FALSE.equals(ApplicationStatusTypeEnum.DRAFT.getValue().equals(applicationEntity.getStatus()))) {
|
||||
log.warn("Application with ID: {} is not in DRAFT status, cannot delete. Current status: {}", id, applicationEntity.getStatus());
|
||||
throw new CustomValidationException(
|
||||
Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.APPLICATION_NOT_IN_DRAFT_STATUS)
|
||||
@@ -328,6 +336,7 @@ public class ApplicationDao {
|
||||
validator.validateUserWithCompany(request, applicationEntity.getCompanyId());
|
||||
applicationEntity.setIsDeleted(true);
|
||||
applicationEntity = applicationRepository.save(applicationEntity);
|
||||
log.info("Marked application as deleted and saved for ID: {}", id);
|
||||
|
||||
/** This code is responsible for adding a version history log for the "Delete application" operation. **/
|
||||
loggingUtil.addVersionHistory(
|
||||
@@ -415,6 +424,7 @@ public class ApplicationDao {
|
||||
}
|
||||
|
||||
private ApplicationResponse getApplicationResponse(ApplicationEntity applicationEntity) {
|
||||
log.info("Generating ApplicationResponse for application ID: {}", applicationEntity.getId());
|
||||
ApplicationResponse responseBean = new ApplicationResponse();
|
||||
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByCallId(applicationEntity.getCall().getId());
|
||||
Long totalFormSteps = flowFormDao.calculateTotalSteps(flowEdgesList);
|
||||
@@ -455,9 +465,13 @@ public class ApplicationDao {
|
||||
}
|
||||
|
||||
public ApplicationEntity validateApplication(Long id) {
|
||||
log.info("Validating existence of Application with ID: {}", id);
|
||||
ApplicationEntity applicationEntity = applicationRepository.findById(id)
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
Translator.toLocale(GepafinConstant.APPLICATION_NOT_FOUND_MSG)));
|
||||
.orElseThrow(() -> {
|
||||
log.warn("Application not found for ID: {}", id);
|
||||
return new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
Translator.toLocale(GepafinConstant.APPLICATION_NOT_FOUND_MSG));
|
||||
});
|
||||
return applicationEntity;
|
||||
}
|
||||
|
||||
@@ -481,10 +495,12 @@ public class ApplicationDao {
|
||||
}
|
||||
|
||||
private ApplicationFormEntity getApplicationFormOrCreate(FormEntity formEntity, ApplicationEntity applicationEntity) {
|
||||
log.info("Fetching ApplicationForm for Application ID: {} and Form ID: {}", applicationEntity.getId(), formEntity.getId());
|
||||
|
||||
ApplicationFormEntity applicationFormEntity = applicationFormRepository.findByApplicationIdAndFormId(applicationEntity.getId(), formEntity.getId());
|
||||
ApplicationFormEntity oldApplicationFormEntity = Utils.getClonedEntityForData(applicationFormEntity);
|
||||
if (applicationFormEntity == null) {
|
||||
log.info("No existing ApplicationForm found. Creating new ApplicationForm for Application ID: {}, Form ID: {}", applicationEntity.getId(), formEntity.getId());
|
||||
applicationFormEntity = createApplicationFormEntity(applicationEntity, formEntity);
|
||||
|
||||
/** This code is responsible for adding a version history log for the "Create application form" operation. **/
|
||||
@@ -510,6 +526,8 @@ public class ApplicationDao {
|
||||
public ApplicationFormFieldEntity createOrUpdateApplicationFormField(ApplicationFormFieldRequestBean applicationFormFieldRequestBean,
|
||||
ApplicationFormEntity applicationFormEntity, List<ApplicationFormFieldEntity> applicationFormFieldEntities, FormEntity formEntity,FieldValidator fieldValidator) {
|
||||
|
||||
log.info("Starting createOrUpdateApplicationFormField for ApplicationForm ID: {}", applicationFormEntity.getId());
|
||||
|
||||
ApplicationFormFieldEntity applicationFormFieldEntity = new ApplicationFormFieldEntity();
|
||||
|
||||
List<Long> newDocumentIds = validateFileUploadDocuments(applicationFormFieldRequestBean, formEntity);
|
||||
@@ -529,7 +547,9 @@ public class ApplicationDao {
|
||||
try {
|
||||
BigDecimal amountRequested = new BigDecimal(fieldValue.toString());
|
||||
applicationFormEntity.getApplication().setAmountRequested(amountRequested);
|
||||
log.info("Set amountRequested to {} for Application ID: {}", amountRequested, applicationFormEntity.getApplication().getId());
|
||||
} catch (NumberFormatException e) {
|
||||
log.error("Invalid number format for requested amount: {}", fieldValue, e);
|
||||
throw new IllegalArgumentException("Field value is not a valid number: " + fieldValue, e);
|
||||
}
|
||||
}
|
||||
@@ -670,6 +690,8 @@ public class ApplicationDao {
|
||||
List<Long> documentIds=null;
|
||||
// List<ContentResponseBean> contentResponseBeans=Utils.convertJsonStringToList(formEntity.getContent(),ContentResponseBean.class);
|
||||
List<ContentResponseBean> contentResponseBeans=formDao.convertFormEntityToFormResponseBean(formEntity).getContent();
|
||||
log.debug("Validating file upload documents for field ID: {} in form ID: {}", applicationFormFieldRequestBean.getFieldId(), formEntity.getId());
|
||||
|
||||
for (ContentResponseBean contentResponseBean:contentResponseBeans){
|
||||
if(Boolean.TRUE.equals(contentResponseBean.getName().equals("fileupload")) || Boolean.TRUE.equals(contentResponseBean.getName().equals("fileselect"))) {
|
||||
if (contentResponseBean.getId().equals(applicationFormFieldRequestBean.getFieldId())) {
|
||||
@@ -679,6 +701,7 @@ public class ApplicationDao {
|
||||
String documentId = (String) fieldValueObject;
|
||||
// Now you can use documentId as needed
|
||||
documentIds = validateDocumentIds(documentId);
|
||||
log.info("Validated document IDs: {}", documentIds);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -688,6 +711,7 @@ public class ApplicationDao {
|
||||
|
||||
public List<Long> validateDocumentIds(String documentId) {
|
||||
if (documentId != null && !documentId.isEmpty()) {
|
||||
log.info("Validating document IDs: {}", documentId);
|
||||
return Arrays.stream(documentId.split(","))
|
||||
.map(Long::parseLong)
|
||||
.peek(docId -> documentService.validateDocument(docId))
|
||||
@@ -740,6 +764,7 @@ public class ApplicationDao {
|
||||
}
|
||||
|
||||
public ApplicationGetResponseBean getApplicationByFormId(HttpServletRequest request, Long applicationId, Long formId) {
|
||||
log.info("Received request to get application by formId. ApplicationId: {}, FormId: {}", applicationId, formId);
|
||||
List<FormApplicationResponse> formApplicationResponses = new ArrayList<>();
|
||||
List<FormEntity> formEntities = new ArrayList<>();
|
||||
UserEntity userEntity = validator.validateUser(request);
|
||||
@@ -890,6 +915,7 @@ public class ApplicationDao {
|
||||
|
||||
public ApplicationResponse createApplicationByCallId(CompanyEntity companyEntity,
|
||||
ApplicationRequest applicationRequest, Long callId, UserEntity userEntity) {
|
||||
log.info("Start creating application for CallId: {}, UserId: {}, CompanyId: {}", callId, userEntity.getId(), companyEntity.getId());
|
||||
CallEntity call = callService.validateCall(callId);
|
||||
UserWithCompanyEntity userWithCompanyEntity=companyService.getUserWithCompany(userEntity.getId(),companyEntity.getId());
|
||||
checkCallEndDate(call);
|
||||
@@ -913,11 +939,15 @@ public class ApplicationDao {
|
||||
|
||||
public void checkIfApplicationExists(CallEntity call, UserWithCompanyEntity userWithCompanyEntity, UserEntity userEntity){
|
||||
|
||||
log.info("Checking existing applications for UserId: {}, UserWithCompanyId: {}, CallId: {}",
|
||||
userEntity.getId(), userWithCompanyEntity.getId(), call.getId());
|
||||
List<ApplicationEntity> applications = applicationRepository.findByUserIdAndUserWithCompany_IdAndCall_IdAndIsDeletedFalseAndStatusNot(
|
||||
userEntity.getId(), userWithCompanyEntity.getId(), call.getId(), ApplicationStatusTypeEnum.REJECTED.name()
|
||||
);
|
||||
|
||||
if (!applications.isEmpty()) {
|
||||
log.warn("Application already exists for UserId: {}, UserWithCompanyId: {}, CallId: {}. Applications found: {}",
|
||||
userEntity.getId(), userWithCompanyEntity.getId(), call.getId(), applications.size());
|
||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_ALREADY_EXISTS));
|
||||
}
|
||||
}
|
||||
@@ -935,10 +965,12 @@ public class ApplicationDao {
|
||||
UserEntity userEntity = userService.validateUser(applicationEntity.getUserId());
|
||||
validator.validateUserWithCompany(request, applicationEntity.getCompanyId());
|
||||
if (ApplicationStatusTypeEnum.SUBMIT.getValue().equals(applicationEntity.getStatus())) {
|
||||
log.warn("Attempt to change status after submission denied | applicationId: {}", applicationId);
|
||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_SUBMITTED_CANNOT_CHANGE));
|
||||
}
|
||||
|
||||
if (Boolean.TRUE.equals(applicationEntity.getStatus().equals(status.getValue()))) {
|
||||
log.warn("Requested status is the same as current status | applicationId: {}, status: {}", applicationId, status);
|
||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_ALREADY_IN_PREVIOUS_STATUS));
|
||||
}
|
||||
if (status.equals(ApplicationStatusTypeEnum.SUBMIT) && Boolean.TRUE.equals(applicationEntity.getStatus().equals(ApplicationStatusTypeEnum.READY.getValue()))) {
|
||||
@@ -1068,6 +1100,7 @@ public class ApplicationDao {
|
||||
}
|
||||
|
||||
private void sendMailToUserAndCompany(UserEntity userEntity, ApplicationEntity applicationEntity) {
|
||||
log.info("Preparing to send submission email | applicationId: {}, userId: {}", applicationEntity.getId(), userEntity.getId());
|
||||
CallEntity call =applicationEntity.getCall();
|
||||
CompanyEntity company=companyService.validateCompany(applicationEntity.getCompanyId());
|
||||
UserWithCompanyEntity userWithCompany=companyService.getUserWithCompany(userEntity.getId(),company.getId());
|
||||
@@ -1176,6 +1209,7 @@ public class ApplicationDao {
|
||||
}
|
||||
public ApplicationSignedDocumentResponse uploadSignedDocument(HttpServletRequest request, Long applicationId,
|
||||
MultipartFile file) {
|
||||
log.info("Received request to upload signed document | applicationId: {}, fileName: {}", applicationId, file.getOriginalFilename());
|
||||
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
||||
checkCallEndDate(applicationEntity.getCall());
|
||||
//cloned entity for old data
|
||||
@@ -1188,9 +1222,11 @@ public class ApplicationDao {
|
||||
ApplicationSignedDocumentEntity oldApplicationSingedDocumentData = Utils.getClonedEntityForData(applicationSignedDocument);
|
||||
|
||||
if (applicationSignedDocument != null) {
|
||||
log.info("Existing active signed document found and will be deleted | applicationId: {}, fileName: {}", applicationId, applicationSignedDocument.getFileName());
|
||||
deleteSignedDocumentFromS3(applicationSignedDocument);
|
||||
}
|
||||
UploadFileOnAmazonS3Response uploadFileOnAmazonS3 = uploadFileOnAmazonS3ForUserSignedDocument(file, applicationEntity.getCall().getId(), applicationId);
|
||||
log.info("File uploaded to S3 successfully | applicationId: {}", applicationId);
|
||||
applicationSignedDocument = new ApplicationSignedDocumentEntity();
|
||||
applicationSignedDocument.setApplication(applicationEntity);
|
||||
applicationSignedDocument.setFileName(uploadFileOnAmazonS3.getFileName());
|
||||
@@ -1204,6 +1240,8 @@ public class ApplicationDao {
|
||||
|
||||
applicationEntity.setStatus(ApplicationStatusTypeEnum.READY.getValue());
|
||||
applicationEntity = applicationRepository.save(applicationEntity);
|
||||
log.info("Application status updated to READY | applicationId: {}", applicationEntity.getId());
|
||||
|
||||
|
||||
/** This code is responsible for adding a version history log for the "Create Call" operation. **/
|
||||
loggingUtil.addVersionHistory(
|
||||
@@ -1212,16 +1250,22 @@ public class ApplicationDao {
|
||||
return convertApplicationSignedDocumentToApplicationSignedDocumentResponse(applicationSignedDocument);
|
||||
}
|
||||
public void deleteSignedDocumentFromS3(ApplicationSignedDocumentEntity applicationSignedDocumentEntity){
|
||||
log.info("Starting soft delete of signed document | applicationSignedDocumentId: {}, fileName: {}",
|
||||
applicationSignedDocumentEntity.getId(), applicationSignedDocumentEntity.getFileName());
|
||||
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);
|
||||
log.debug("Generated new S3 path for deleted document: {}", newS3Path);
|
||||
|
||||
UploadFileOnAmazonS3Response response = amazonS3Service.moveFile(applicationSignedDocumentEntity.getFileName(), oldS3Path, newS3Path);
|
||||
log.info("Moved file in S3 from {} to {} | fileName: {}", oldS3Path, newS3Path, response.getFileName());
|
||||
applicationSignedDocumentEntity.setStatus(ApplicationSignedDocumentStatusEnum.INACTIVE.getValue());
|
||||
applicationSignedDocumentEntity.setFileName(response.getFileName());
|
||||
applicationSignedDocumentEntity.setFilePath(response.getFilePath());
|
||||
|
||||
applicationSignedDocumentRepository.save(applicationSignedDocumentEntity);
|
||||
log.info("Updated signed document entity status to INACTIVE and saved | applicationSignedDocumentId: {}", applicationSignedDocumentEntity.getId());
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.SOFT_DELETE).oldData(oldApplicationSignedDocument).newData(applicationSignedDocumentEntity).build());
|
||||
}
|
||||
|
||||
@@ -1240,6 +1284,7 @@ public class ApplicationDao {
|
||||
log.info("S3 Path {}", s3Path);
|
||||
return amazonS3Service.uploadFileOnAmazonS3(s3Path, file);
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to upload user signed document | callId: {}, applicationId: {}, error: {}", callId, applicationId, e.getMessage(), e);
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.UPLOAD_ERROR_S3));
|
||||
}
|
||||
}
|
||||
@@ -1247,6 +1292,7 @@ public class ApplicationDao {
|
||||
try {
|
||||
return s3ConfigBean.generateDocumentPathForOther(DocOtherSourceTypeEnum.USER_SIGNED_DOCUMENT, callId, applicationId,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));
|
||||
}
|
||||
}
|
||||
@@ -1271,13 +1317,14 @@ public class ApplicationDao {
|
||||
}
|
||||
String filename = file.getOriginalFilename();
|
||||
if (filename == null || !filename.endsWith(".p7m")) {
|
||||
log.warn("Invalid file type detected | filename: {}", filename);
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.VALIDATION_ERROR_FILE_INVALIDTYPE));
|
||||
}
|
||||
}
|
||||
|
||||
public ApplicationSignedDocumentResponse getSignedDocument(HttpServletRequest request, Long applicationId) {
|
||||
|
||||
log.info("Fetching signed document for applicationId: {}", applicationId);
|
||||
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
||||
// validator.validateUserWithCompany(request, applicationEntity.getCompanyId());
|
||||
|
||||
@@ -1291,6 +1338,7 @@ public class ApplicationDao {
|
||||
ApplicationSignedDocumentEntity applicationSignedDocument = applicationSignedDocumentRepository
|
||||
.findByApplicationIdAndStatus(applicationId, ApplicationSignedDocumentStatusEnum.ACTIVE.getValue());
|
||||
if(applicationSignedDocument == null) {
|
||||
log.warn("No active signed document found for applicationId: {}", applicationId);
|
||||
throw new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
Translator.toLocale(GepafinConstant.APPLICATION_SIGNED_DOCUMENT_NOT_FOUND));
|
||||
}
|
||||
@@ -1298,6 +1346,7 @@ public class ApplicationDao {
|
||||
}
|
||||
|
||||
public void deleteSignedDocument(HttpServletRequest request, Long applicationId) {
|
||||
log.info("Initiating deletion of signed document for applicationId: {}", applicationId);
|
||||
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
||||
validator.validateUserWithCompany(request, applicationEntity.getCompanyId());
|
||||
|
||||
@@ -1306,6 +1355,7 @@ public class ApplicationDao {
|
||||
//cloned entity for old data
|
||||
ApplicationSignedDocumentEntity oldApplicationSignedDocument = Utils.getClonedEntityForData(applicationSignedDocument);
|
||||
if(applicationSignedDocument == null) {
|
||||
log.warn("No active signed document found to delete for applicationId: {}", applicationId);
|
||||
throw new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
Translator.toLocale(GepafinConstant.APPLICATION_SIGNED_DOCUMENT_NOT_FOUND));
|
||||
}
|
||||
@@ -1318,7 +1368,7 @@ public class ApplicationDao {
|
||||
}
|
||||
|
||||
public ApplicationResponse validateApplication(HttpServletRequest request, Long applicationId) {
|
||||
|
||||
log.info("Starting application validation process | applicationId: {}", applicationId);
|
||||
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
||||
ApplicationEntity oldApplicationEntity = Utils.getClonedEntityForData(applicationEntity);
|
||||
checkCallEndDate(applicationEntity.getCall());
|
||||
@@ -1326,15 +1376,18 @@ public class ApplicationDao {
|
||||
UserEntity userEntity = userService.validateUser(applicationEntity.getUserId());
|
||||
validator.validateUserWithCompany(request, applicationEntity.getCompanyId());
|
||||
if (Boolean.FALSE.equals(ApplicationStatusTypeEnum.DRAFT.getValue().equals(applicationEntity.getStatus()))) {
|
||||
log.warn("Application not in draft status | applicationId: {}, status: {}", applicationId, applicationEntity.getStatus());
|
||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_NOT_IN_DRAFT_STATUS));
|
||||
}
|
||||
if (applicationEntity.getAmountRequested() == null || applicationEntity.getAmountRequested().compareTo(BigDecimal.ZERO) <= 0 ) {
|
||||
log.warn("Invalid amount requested | amount: {}", applicationEntity.getAmountRequested());
|
||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.AMOUNT_REQUEST_SHOULD_GREATED_THEN_ZERO));
|
||||
}
|
||||
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByCallId(applicationEntity.getCall().getId());
|
||||
Long totalSteps = flowFormDao.calculateTotalSteps(flowEdgesList);
|
||||
Integer completedSteps = flowFormDao.getCompletedSteps(applicationEntity, true);
|
||||
if (totalSteps.intValue() != completedSteps) {
|
||||
log.warn("Application incomplete | applicationId: {}", applicationId);
|
||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_IS_INCOMPLETE_MSG));
|
||||
}
|
||||
|
||||
@@ -1349,7 +1402,7 @@ public class ApplicationDao {
|
||||
}
|
||||
|
||||
public byte[] downloadApplicationDocumentsAsZip(HttpServletRequest request, Long applicationId) {
|
||||
|
||||
log.info("Starting ZIP download process for applicationId: {}", applicationId);
|
||||
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
||||
validateAssignedUser(request, applicationId);
|
||||
Set<Long> documentIds = extractDocumentIdsFromApplicationForms(applicationId);
|
||||
@@ -1359,13 +1412,14 @@ public class ApplicationDao {
|
||||
List<DocumentEntity> amendmentDocuments = fetchAmendmentDocuments(applicationId);
|
||||
List<DocumentEntity> evaluationDocuments = fetchEvaluationDocuments(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);
|
||||
}
|
||||
|
||||
private void validateAssignedUser(HttpServletRequest request, Long applicationId) {
|
||||
|
||||
log.info("Validating assigned user for applicationId: {}", applicationId);
|
||||
AssignedApplicationsEntity assignedApplications = assignedApplicationsRepository.findByApplicationIdAndIsDeletedFalse(applicationId).orElse(null);
|
||||
if (assignedApplications != null) {
|
||||
validator.validatePreInstructor(request, assignedApplications.getUserId());
|
||||
@@ -1373,7 +1427,7 @@ public class ApplicationDao {
|
||||
}
|
||||
|
||||
private Set<Long> extractDocumentIdsFromApplicationForms(Long applicationId) {
|
||||
|
||||
log.info("Extracting document IDs from application forms | applicationId: {}", applicationId);
|
||||
Set<Long> documentIds = new HashSet<>();
|
||||
List<ApplicationFormEntity> applicationForms = applicationFormRepository.findByApplicationId(applicationId);
|
||||
applicationForms.forEach(applicationForm -> {
|
||||
@@ -1395,16 +1449,17 @@ public class ApplicationDao {
|
||||
}
|
||||
|
||||
private List<DocumentEntity> fetchAmendmentDocuments(Long applicationId) {
|
||||
|
||||
log.info("Fetching amendment documents for applicationId: {}", applicationId);
|
||||
List<ApplicationAmendmentRequestEntity> amendmentRequests = applicationAmendmentRequestRepository.findByApplicationIdAndIsDeletedFalse(applicationId);
|
||||
Set<Long> amendmentIds = amendmentRequests.stream().map(ApplicationAmendmentRequestEntity::getId).collect(Collectors.toSet());
|
||||
return documentRepository.findBySourceIdInAndSourceAndIsDeletedFalse(amendmentIds, DocumentSourceTypeEnum.AMENDMENT.getValue());
|
||||
}
|
||||
private List<DocumentEntity> fetchEvaluationDocuments(Long applicationId) {
|
||||
|
||||
log.info("Fetching evaluation documents for applicationId: {}", applicationId);
|
||||
Optional<ApplicationEvaluationEntity> evaluationEntity = applicationEvaluationRepository.findByApplicationIdAndIsDeletedFalse(applicationId);
|
||||
if (evaluationEntity.isPresent()) {
|
||||
Long evaluationId = evaluationEntity.get().getId();
|
||||
log.debug("Found evaluation entity with id: {}", evaluationId);
|
||||
return documentRepository.findBySourceIdInAndSourceAndIsDeletedFalse(Collections.singleton(evaluationId), DocumentSourceTypeEnum.EVALUATION.getValue());
|
||||
}
|
||||
return Collections.emptyList();
|
||||
@@ -1418,12 +1473,14 @@ public class ApplicationDao {
|
||||
return "unknown";
|
||||
}
|
||||
private void addDocumentToZip(ZipOutputStream zos, String s3Folder, String filePath, String fullPath) {
|
||||
|
||||
log.info("Attempting to add file to ZIP. S3 folder: {}, file path: {}", s3Folder, filePath);
|
||||
try (InputStream fileInputStream = amazonS3Service.getFile(s3Folder, filePath)) {
|
||||
zos.putNextEntry(new ZipEntry(fullPath));
|
||||
IOUtils.copy(fileInputStream, zos);
|
||||
zos.closeEntry();
|
||||
} catch (IOException e) {
|
||||
log.error("Failed to add file to ZIP. S3 folder: {}, file path: {}, error: {}",
|
||||
s3Folder, filePath, e.getMessage(), e);
|
||||
throw new RuntimeException("Error downloading or adding document to ZIP: " + fullPath, e);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user