Merge pull request #372 from Kitzanos/feature/GEPAFINBE-6158-prod

Cherry-pick (GEPAFINBE-6158 (Managed company documents for application))
This commit is contained in:
Rinaldo
2025-11-19 08:51:53 +01:00
committed by GitHub
18 changed files with 142 additions and 18 deletions

View File

@@ -634,8 +634,8 @@ public class GepafinConstant {
public static final String MAIL_SENT_SUCCESSFULLY="mail.send.successfully";
public static final String EMAIL_LOG_FETCHED="email.log.fetched";
public static final String APPLICATION_AMENDMENT_APPROPIATE_STATUS="amendment.appropiate.status";
public static final String UPLOAD_COMPANY_DOCUMENT_TO_APPLICATION_MSG="upload.company.document.to.application";
public static final String COMPANY_DOCUMENT_NOT_FOUND_WITH_IDS="company.document.not.found.with.ids";
}

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.findByIdInAndIsDeletedFalseAndStatusNot(ids,CompanyDocumentStatusEnum.EXPIRED.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

@@ -170,7 +170,7 @@ public class ApplicationEvaluationDao {
Long hubId = application.getHubId();
HubEntity hub = hubService.valdateHub(hubId);
Long initialDays = (hub != null) ? hub.getEvaluationExpirationDays() : 30L;
Long initialDays = (hub != null) ? hub.getEvaluationExpirationDays() : 365L;
entity.setApplicationId(application.getId());
entity.setAssignedApplicationsEntity(assignedApplications);
@@ -205,7 +205,7 @@ public class ApplicationEvaluationDao {
CompanyEntity company=companyService.validateCompany(entity.getAssignedApplicationsEntity().getApplication().getCompanyId());
setAmendmentDetails(entity,response);
response.setCompanyId(company.getId());
response.setCompanyVatNumber(company.getVatNumber());
response.setCompanyCodiceAteco(company.getCodiceAteco());
setCriteriaResponses(entity, response, evaluationCriterias);
@@ -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);
}
@@ -2424,6 +2434,7 @@ public class ApplicationEvaluationDao {
if (evaluationFormEntity != null) {
response.setApplicationEvaluationFormResponse(convertEvaluationFormToResponse(evaluationFormEntity, evaluationEntity));
}
response.setCompanyId(company.getId());
response.setCompanyVatNumber(company.getVatNumber());
response.setCompanyCodiceAteco(company.getCodiceAteco());
response.setSignedDocument(getApplicationSignedDocument(evaluationEntity));

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

@@ -333,6 +333,11 @@ public class CompanyDocumentDao {
predicate = builder.and(predicate, builder.isFalse(root.get("isDeleted")));
predicate = builder.and(
predicate,
builder.notEqual(root.get("status"), CompanyDocumentStatusEnum.EXPIRED.getValue())
);
if (typeEnum != null) {
if (typeEnum == CompanyDocumentTypeEnum.COMPANY_DOCUMENT) {
// Case 1: Fetch only COMPANY_DOCUMENT type documents for the given company
@@ -346,15 +351,15 @@ public class CompanyDocumentDao {
builder.equal(root.get("userWithCompany").get("userId"), userId)
);
}
}else {
// Case 3: If typeEnum is null, fetch all documents for the company and personal documents for the user
Predicate companyPredicate = builder.equal(root.get("companyId"), companyId);
Predicate personalPredicate = builder.and(
builder.equal(root.get("type"), CompanyDocumentTypeEnum.PERSONAL_DOCUMENT.getValue()),
builder.equal(root.get("userWithCompany").get("userId"), userId)
);
predicate = builder.and(predicate, builder.or(companyPredicate, personalPredicate));
}
// Case 3: If typeEnum is null, fetch all documents for the company and personal documents for the user
Predicate companyPredicate = builder.equal(root.get("companyId"), companyId);
Predicate personalPredicate = builder.and(
builder.equal(root.get("type"), CompanyDocumentTypeEnum.PERSONAL_DOCUMENT.getValue()),
builder.equal(root.get("userWithCompany").get("userId"), userId)
);
predicate = builder.and(predicate, builder.or(companyPredicate, personalPredicate));
return predicate;
};
}

View File

@@ -87,4 +87,7 @@ public class ApplicationEntity extends BaseEntity {
@Column(name = "REJECTED_DOCUMENT")
private String rejectedDocument;
@Column(name = "COMPANY_DOCUMENT")
private String companyDocument;
}

View File

@@ -232,7 +232,8 @@ public enum UserActionContextEnum {
FETCH_APPLICATION_CONTRACT_BY_BENEFICIARY_USER_ID("FETCH_APPLICATION_CONTRACT_BY_BENEFICIARY_USER_ID"),
SEND_PEC_MAIL("SEND_PEC_MAIL"),
FETCH_EMAIL_LOG("FETCH_EMAIL_LOG"),
FETCH_ALL_EMAIL_LOG("FETCH_ALL_EMAIL_LOG");
FETCH_ALL_EMAIL_LOG("FETCH_ALL_EMAIL_LOG"),
UPLOAD_COMPANY_DOCUMENT_TO_APPLICATION("UPLOAD_COMPANY_DOCUMENT_TO_APPLICATION");
private final String value;

View File

@@ -15,6 +15,7 @@ public class ApplicationEvaluationFormResponse {
private Long id;
private Long applicationId;
private Long companyId;
private ApplicationStatusTypeEnum applicationStatus;
private Long assignedApplicationId;
private String note;

View File

@@ -15,6 +15,7 @@ public class ApplicationEvaluationResponse {
private Long id;
private Long applicationId;
private Long companyId;
private ApplicationStatusTypeEnum applicationStatus;
private Long assignedApplicationId;
private String note;

View File

@@ -35,7 +35,7 @@ public interface CompanyDocumentRepository extends JpaRepository<CompanyDocument
List<CompanyDocumentEntity> findByCategoryEntityId(Long categoryId);
List<CompanyDocumentEntity> findByIdInAndIsDeletedFalseAndStatusNot(List<Long> ids, String status);
}

View File

@@ -45,7 +45,7 @@ public class ApplicationEvaluationScheduler {
private static final Logger log = LoggerFactory.getLogger(ApplicationEvaluationScheduler.class);
@Scheduled(cron = "0 0 2 * * ?") // Runs daily at midnight
// @Scheduled(cron = "0 0 2 * * ?") // Runs daily at midnight
public void updateExpiredEvaluations() {
log.info("Starting the Application Evaluation Expiration scheduler...");
try {

View File

@@ -54,5 +54,5 @@ public interface ApplicationService {
public byte[] downloadRankingCsv(HttpServletRequest request, Long callId);
public void uploadCompanyDocumentsToApplication(HttpServletRequest request, Long applicationId, List<Long> companyDocumentIds);
}

View File

@@ -182,4 +182,10 @@ public class ApplicationServiceImpl implements ApplicationService {
UserEntity userEntity = validator.validateUser(request);
return applicationDao.downloadRankingCsv(callId,userEntity);
}
@Override
public void uploadCompanyDocumentsToApplication(HttpServletRequest request, Long applicationId, List<Long> companyDocumentIds) {
UserEntity userEntity = validator.validateUser(request);
applicationDao.uploadCompanyDocumentsToApplication(applicationId,companyDocumentIds,userEntity);
}
}

View File

@@ -267,6 +267,19 @@ public interface ApplicationApi {
public ResponseEntity<byte[]> downloadRankingCsv(
HttpServletRequest request, @Parameter(description = "The call id", required = true) @PathVariable(value = "callId", required = true) Long callId);
@Operation(summary = "Api to upload company documents in application",
responses = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE)})),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE)})),
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE)}))
})
@GetMapping(value = "/{applicationId}/companyDocuments")
public ResponseEntity<Response<Void>> uploadCompanyDocumentsToApplication(
HttpServletRequest request,@Parameter(description = "The application id", required = true) @PathVariable(value = "applicationId", required = true) Long applicationId, @Parameter(description = "The company document id", required = true) @RequestParam("companyDocumentIds") List<Long> companyDocumentIds);
}

View File

@@ -275,4 +275,15 @@ public class ApplicationApiController implements ApplicationApi {
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.body(csvBytes);
}
@Override
public ResponseEntity<Response<Void>> uploadCompanyDocumentsToApplication(HttpServletRequest request, Long applicationId,List<Long> companyDocumentIds) {
loggingUtil.logUserAction(
UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.UPDATE).actionContext(UserActionContextEnum.UPLOAD_COMPANY_DOCUMENT_TO_APPLICATION).build());
applicationService.uploadCompanyDocumentsToApplication(request, applicationId,companyDocumentIds);
return ResponseEntity.status(HttpStatus.OK).body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.UPLOAD_COMPANY_DOCUMENT_TO_APPLICATION_MSG)));
}
}

View File

@@ -3167,4 +3167,10 @@
<column name="attachments" type="TEXT"></column>
</addColumn>
</changeSet>
<changeSet id="18-11-2025_RK_132242" author="Rajesh Khore">
<addColumn tableName="application">
<column name="company_document" type="VARCHAR(255)"></column>
</addColumn>
</changeSet>
</databaseChangeLog>

View File

@@ -427,5 +427,8 @@ subject.body.required=Subject and body is required to create contract.
mail.send.successfully=Mail sent succesfully.
email.log.fetched=Email log fetched successfully.
amendment.appropiate.status=Application amendment is not in appropiate status for this operation.
upload.company.document.to.application=Uploaded company document to application successfully.
company.document.not.found.with.ids=Company document not found. Missing IDs: {0}

View File

@@ -418,3 +418,5 @@ subject.body.required=Per creare un contratto sono necessari oggetto e corpo.
mail.send.successfully=Email inviata con successo.
email.log.fetched=Registro email recuperato correttamente.
amendment.appropiate.status=L'emendamento dell'applicazione non <20> in stato appropriato per questa operazione.
upload.company.document.to.application=Documento aziendale caricato correttamente nell'applicazione.
company.document.not.found.with.ids=Documento aziendale non trovato. ID mancanti: {0}