Created new endpoint to upload company documents in application
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user