Created new endpoint to upload company documents in application

This commit is contained in:
rajesh
2025-11-18 15:01:45 +05:30
parent 326ce77e8c
commit 57c767cea6
15 changed files with 124 additions and 7 deletions

View File

@@ -232,6 +232,15 @@ public class ApplicationDao {
@Autowired
private ApplicationContractRepository applicationContractRepository;
@Autowired
private CompanyDocumentRepository companyDocumentRepository;
@Autowired
private AppointmentDao appointmentDao;
@Autowired
private DocumentDao documentDao;
public final Random random = new Random();
public ApplicationResponseBean createApplication(HttpServletRequest request, ApplicationRequestBean applicationRequestBean, Long formId, Long applicationId) {
@@ -2630,4 +2639,56 @@ public class ApplicationDao {
}
return Collections.emptyList();
}
public void uploadCompanyDocumentsToApplication( Long applicationId,List<Long> companyDocumentIds,UserEntity user) {
ApplicationEntity applicationEntity=validateApplication(applicationId);
ApplicationEntity oldApplication = Utils.getClonedEntityForData(applicationEntity);
List<CompanyDocumentEntity> companyDocumentEntities=validateCompanyDocuments(companyDocumentIds);
List<MultipartFile> multipartFiles=new ArrayList<>();
for(CompanyDocumentEntity companyDocumentEntity:companyDocumentEntities) {
try {
File localFile = appointmentDao.downloadFileFromS3(companyDocumentEntity.getFilePath());
MultipartFile multipartFile = appointmentDao.convertFileToMultipartFile(localFile);
multipartFiles.add(multipartFile);
} catch (Exception e) {
throw new RuntimeException(e);
}
List<DocumentResponseBean> documentResponseBeans=documentDao.uploadFiles(user.getId(),multipartFiles,applicationId,DocumentSourceTypeEnum.APPLICATION,DocumentTypeEnum.DOCUMENT);
List<Long> initialDocumentIds = documentResponseBeans.stream()
.map(DocumentResponseBean::getId)
.collect(Collectors.toList());
String initialDocumentId = initialDocumentIds.stream()
.map(String::valueOf)
.collect(Collectors.joining(","));
applicationEntity.setCompanyDocument(initialDocumentId);
applicationRepository.save(applicationEntity);
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldApplication).newData(applicationEntity).build());
}
}
public List<CompanyDocumentEntity> validateCompanyDocuments(List<Long> ids) {
List<CompanyDocumentEntity> documents =
companyDocumentRepository.findByIdInAndIsDeletedFalseAndStatus(ids,CompanyDocumentStatusEnum.VALID.getValue());
Set<Long> foundIds = documents.stream()
.map(CompanyDocumentEntity::getId)
.collect(Collectors.toSet());
List<Long> missingIds = ids.stream()
.filter(id -> !foundIds.contains(id))
.toList();
if (!missingIds.isEmpty()) {
log.warn("Company Document(s) not found with IDs {}", missingIds);
throw new ResourceNotFoundException(
Status.NOT_FOUND,
MessageFormat.format(
Translator.toLocale(GepafinConstant.COMPANY_DOCUMENT_NOT_FOUND_WITH_IDS),
missingIds
));
}
return documents;
}
}

View File

@@ -630,6 +630,16 @@ public class ApplicationEvaluationDao {
processedFieldIds.add(fieldResponse.getId());
});
List<DocumentResponseBean> companyDocuments=applicationAmendmentRequestDao.getDocumentResponseBean(applicationFormEntities.get(0).getApplication().getCompanyDocument());
for(DocumentResponseBean documentResponseBean:companyDocuments) {
FieldResponse companyFieldResponse = new FieldResponse();
companyFieldResponse.setId("COMPANY");
companyFieldResponse.setValid(Boolean.TRUE);
companyFieldResponse.setLabel(documentResponseBean.getName());
companyFieldResponse.setFileDetail(List.of(documentResponseBean));
validFieldResponses.add(companyFieldResponse);
}
response.setFiles(validFieldResponses);
}

View File

@@ -1355,13 +1355,13 @@ public class AppointmentDao {
return input;
}
public static MultipartFile convertFileToMultipartFile(File file) throws IOException {
public MultipartFile convertFileToMultipartFile(File file) throws IOException {
FileInputStream input = new FileInputStream(file);
return new MockMultipartFile(file.getName(), file.getName(), MediaType.APPLICATION_OCTET_STREAM_VALUE, input);
}
private File downloadFileFromS3(String fileUrl) throws Exception {
public File downloadFileFromS3(String fileUrl) throws Exception {
String key = amazonS3Service.extractS3KeyFromUrl(fileUrl);
String fileName = extractFileName(key);
String folderPath = key.substring(0, key.lastIndexOf("/"));

View File

@@ -354,7 +354,7 @@ public class CompanyDocumentDao {
builder.equal(root.get("userWithCompany").get("userId"), userId)
);
predicate = builder.and(predicate, builder.or(companyPredicate, personalPredicate));
predicate = builder.equal(root.get("status"), CompanyDocumentStatusEnum.VALID.getValue());
return predicate;
};
}