diff --git a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationAmendmentRequestDao.java b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationAmendmentRequestDao.java index 03ebcbd6..9a369047 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationAmendmentRequestDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationAmendmentRequestDao.java @@ -98,7 +98,7 @@ public class ApplicationAmendmentRequestDao { @Autowired private Validator validator; - public ApplicationAmendmentRequestResponse getApplicationDataForAmendment(HttpServletRequest request, Long applicationEvaluationId) { + public ApplicationAmendmentRequestResponse getApplicationDataForAmendment(Long applicationEvaluationId) { log.info("Fetching the application data for the Amendment process {}", applicationEvaluationId); ApplicationEvaluationEntity applicationEvaluationEntity = applicationEvaluationService.validateApplicationEvaluation(applicationEvaluationId); Long applicationId = applicationEvaluationEntity.getApplicationId(); @@ -228,8 +228,6 @@ public class ApplicationAmendmentRequestDao { applicationEvaluationEntity.getAssignedApplicationsEntity().getApplication(), protocolNumber, userEntity.getHub().getId()); applicationAmendmentRequestEntity.setProtocol(protocolEntity); - applicationAmendmentRequestEntity.setIsEmail(false); - applicationAmendmentRequestEntity.setIsNotification(false); ApplicationAmendmentRequestEntity applicationAmendment = saveApplicationAmendmentRequestEntity(applicationAmendmentRequestEntity); //Set Status @@ -341,7 +339,6 @@ public class ApplicationAmendmentRequestDao { } public List getAllApplicationAmendmentRequest(HttpServletRequest request,Long userId) { - UserEntity user = validator.validateUser(request); if(validator.checkIsPreInstructor() && userId == null) { throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.USER_ID_NOT_NULL_MSG)); } diff --git a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationEvaluationDao.java b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationEvaluationDao.java index cd1654bb..75e6bcc4 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationEvaluationDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationEvaluationDao.java @@ -897,12 +897,13 @@ public class ApplicationEvaluationDao { assignedApplicationsRepository.save(assignedApplicationsEntity); ApplicationAmendmentRequestEntity amendmentRequest = applicationAmendmentRequestRepository.findByApplicationEvaluationIdAndIsDeletedFalse(entity.getId()); + if(amendmentRequest!=null){ if (Boolean.TRUE.equals(statusType.equals((ApplicationStatusTypeEnum.APPROVED.getValue())))) { emailNotificationDao.sendAdmissibilityNotificationEmailForApprovedApplication(amendmentRequest); } if (Boolean.TRUE.equals(statusType.equals((ApplicationStatusTypeEnum.REJECTED.getValue())))) { emailNotificationDao.sendInadmissibilityEmailForRejectedApplication(amendmentRequest); - } + }} return convertToResponse(entity); } return null; diff --git a/src/main/java/net/gepafin/tendermanagement/dao/EmailNotificationDao.java b/src/main/java/net/gepafin/tendermanagement/dao/EmailNotificationDao.java index f75e5796..43f3b4e4 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/EmailNotificationDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/EmailNotificationDao.java @@ -77,9 +77,15 @@ public class EmailNotificationDao { UserEntity userEntity = userService.validateUser(applicationEntity.getUserId()); List recipientEmails = new ArrayList<>(); - if (applicationEntity.getCompany().getEmail() != null) { - recipientEmails.add(applicationEntity.getCompany().getEmail()); + String companyEmail = applicationEntity.getCompany().getEmail(); + String contactEmail = applicationEntity.getCompany().getContactEmail(); + if (companyEmail != null && !companyEmail.isEmpty()) { + recipientEmails.add(companyEmail); } + if (contactEmail != null && !contactEmail.isEmpty() && !contactEmail.equals(companyEmail)) { + recipientEmails.add(contactEmail); + } + if (userEntity.getBeneficiary().getEmail() != null) { recipientEmails.add(userEntity.getBeneficiary().getEmail()); } diff --git a/src/main/java/net/gepafin/tendermanagement/dao/PdfDao.java b/src/main/java/net/gepafin/tendermanagement/dao/PdfDao.java index 7fe594f3..550bd240 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/PdfDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/PdfDao.java @@ -31,6 +31,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.*; import java.util.List; +import java.util.stream.Collectors; @Component public class PdfDao { @@ -476,7 +477,7 @@ public class PdfDao { String contentId = content.getId(); // Content ID String label = content.getLabel(); // Content label String name = content.getName(); // Content name - Object fieldValue = null; + Object fieldValue = ""; String contentLabel = content.getSettings().stream() .filter(setting -> "label".equals(setting.getName())) // Filter settings by name @@ -485,6 +486,32 @@ public class PdfDao { .findFirst() // Get the first matching value .orElse(null); // If no match is found, set label to null // Find the form field in the response that matches the contentId + if (name.equals("paragraph")){ + String paragraph = content.getSettings().stream() + .filter(setting -> "text".equals(setting.getName())) // Filter settings by name + .map(SettingResponseBean::getValue) // Extract the value from the matching setting + .map(Object::toString) // Convert the value to a string + .findFirst() // Get the first matching value + .orElse(null); + Paragraph labelParagraph = new Paragraph(); + PdfPCell labelCell = new PdfPCell(PdfUtils.htmlToPdfPCell(paragraph,labelFont)); + labelCell.setBorder(Rectangle.NO_BORDER); + labelCell.setGrayFill(7); + labelCell.setPadding(5); + + // Create a PdfPTable with 1 column and add the PdfPCell to it + PdfPTable table = new PdfPTable(1); + table.setWidthPercentage(100); + table.addCell(labelCell); + labelParagraph.add(table); + try { + document.add(labelParagraph); + document.add(new Paragraph(" ")); + + } catch (DocumentException e) { + throw new RuntimeException(e); + } + } Optional matchingFormField = formFields.stream() .filter(formField -> formField.getFieldId().equals(contentId)) .findFirst(); @@ -501,7 +528,13 @@ public class PdfDao { // Process 'fileupload' and 'checkboxes' cases as in the original logic if (name.equals("fileupload")) { - continue; + if (fieldValue instanceof List && ((List) fieldValue).stream().allMatch(item -> item instanceof DocumentResponseBean)) { + List documentList = (List) fieldValue; + List names = documentList.stream() + .map(DocumentResponseBean::getName) + .collect(Collectors.toList()); + fieldValue = names; + } } else if (name.equals("checkboxes") && fieldValue instanceof List) { List check = (List) fieldValue; List settingResponseBeans = content.getSettings(); @@ -529,15 +562,12 @@ public class PdfDao { // Further processing of field value (e.g., finding labels in options) fieldValue = findLabelInOptions(content.getSettings(), fieldValue); - } else { - // If no matching form field is found, store contentId with an empty string - fieldValue = ""; } - try { - if((contentLabel!=null && Boolean.FALSE.equals(contentLabel.isEmpty())) || (fieldValue!=null && !StringUtils.isEmpty((CharSequence) fieldValue))) { - addLabelValuePair(writer, document, contentLabel, fieldValue, labelFont, valueFont, content); + if((contentLabel==null || StringUtils.isEmpty(contentLabel)) && (fieldValue==null || StringUtils.isEmpty(fieldValue.toString()))) { + continue; } + addLabelValuePair(writer, document, contentLabel, fieldValue, labelFont, valueFont, content); } catch (DocumentException e) { log.error("Error checking object: " + e.getMessage(), e); diff --git a/src/main/java/net/gepafin/tendermanagement/repositories/ApplicationRepository.java b/src/main/java/net/gepafin/tendermanagement/repositories/ApplicationRepository.java index 158c43fd..38d73e8d 100644 --- a/src/main/java/net/gepafin/tendermanagement/repositories/ApplicationRepository.java +++ b/src/main/java/net/gepafin/tendermanagement/repositories/ApplicationRepository.java @@ -29,15 +29,15 @@ public interface ApplicationRepository extends JpaRepository findByIdAndUserIdAndCallIdAndIsDeletedFalse(Long applicationId, Long userId, Long callId); - @Query("SELECT COUNT(a) FROM ApplicationEntity a WHERE a.userId = :userId AND a.company.id = :companyId AND a.status = 'SUBMIT' ") + @Query("SELECT COUNT(a) FROM ApplicationEntity a WHERE a.userId = :userId AND a.company.id = :companyId AND a.status = 'SUBMIT' AND a.isDeleted = false") Long countSubmittedApplicationsByUserId(@Param("userId") Long userId, @Param("companyId") Long companyId); List findByCompanyIdAndUserIdAndIsDeletedFalse(Long companyId,Long userId); - @Query("SELECT COUNT(a) FROM ApplicationEntity a WHERE a.status = 'SUBMIT' And a.hubId = :hubId") + @Query("SELECT COUNT(a) FROM ApplicationEntity a WHERE a.status = 'SUBMIT' And a.hubId = :hubId AND a.isDeleted = false") public Long countSubmittedApplicationsByHubId(@Param("hubId") Long hubId); - @Query("SELECT COUNT(a) FROM ApplicationEntity a WHERE a.status = 'DRAFT' And a.hubId = :hubId") + @Query("SELECT COUNT(a) FROM ApplicationEntity a WHERE a.status = 'DRAFT' And a.hubId = :hubId AND a.isDeleted = false") public Long countDraftApplicationsByHubId(@Param("hubId") Long hubId); @Query("SELECT a.call.id FROM ApplicationEntity a WHERE a.id = :id") diff --git a/src/main/java/net/gepafin/tendermanagement/service/impl/ApplicationAmendmentRequestServiceImpl.java b/src/main/java/net/gepafin/tendermanagement/service/impl/ApplicationAmendmentRequestServiceImpl.java index 4d212377..fa059d57 100644 --- a/src/main/java/net/gepafin/tendermanagement/service/impl/ApplicationAmendmentRequestServiceImpl.java +++ b/src/main/java/net/gepafin/tendermanagement/service/impl/ApplicationAmendmentRequestServiceImpl.java @@ -39,60 +39,105 @@ public class ApplicationAmendmentRequestServiceImpl implements ApplicationAmendm @Override public ApplicationAmendmentRequestResponse getApplicationDataForAmendment(HttpServletRequest request, Long applicationEvaluationId) { - UserEntity user= validator.validateUser(request); - return applicationAmendmentRequestDao.getApplicationDataForAmendment(request,applicationEvaluationId); + Optional entityOptional = applicationEvaluationRepository.findByIdAndIsDeletedFalse(applicationEvaluationId); + entityOptional.ifPresent(applicationEvaluationEntity -> validator.validatePreInstructor(request, applicationEvaluationEntity.getUserId())); + return applicationAmendmentRequestDao.getApplicationDataForAmendment(applicationEvaluationId); } @Override public ApplicationAmendmentRequestResponse createApplicationAmendmentRequest(HttpServletRequest request, Long applicationEvaluationId , ApplicationAmendmentRequest applicationAmendmentRequest) { - UserEntity user= validator.validateUser(request); + Optional entityOptional = applicationEvaluationRepository.findByIdAndIsDeletedFalse(applicationEvaluationId); + entityOptional.ifPresent(applicationEvaluationEntity -> validator.validatePreInstructor(request, applicationEvaluationEntity.getUserId())); return applicationAmendmentRequestDao.createApplicationAmendmentRequest(applicationEvaluationId,applicationAmendmentRequest); } @Override public void deleteApplicationAmendmentRequest(HttpServletRequest request, Long id) { - applicationAmendmentRequestDao.deleteById(id); + ApplicationAmendmentRequestEntity amendment = applicationAmendmentRequestRepository.findByIdAndIsDeletedFalse(id) + .orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, + Translator.toLocale(GepafinConstant.APPLICATION_AMENDMENT_NOT_FOUND_MSG))); + + Optional entityOptional = applicationEvaluationRepository.findByIdAndIsDeletedFalse(amendment.getApplicationEvaluationEntity().getId()); + if (entityOptional.isPresent()) { + UserEntity user = validator.validatePreInstructor(request, entityOptional.get().getUserId()); + + applicationAmendmentRequestDao.deleteById(id); + } } @Override public ApplicationAmendmentRequestResponse getApplicationAmendmentRequestById(HttpServletRequest request,Long id) { - return applicationAmendmentRequestDao.getApplicationAmendmentRequestById(id); + ApplicationAmendmentRequestEntity amendment = applicationAmendmentRequestRepository.findByIdAndIsDeletedFalse(id) + .orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, + Translator.toLocale(GepafinConstant.APPLICATION_AMENDMENT_NOT_FOUND_MSG))); + + Optional entityOptional = applicationEvaluationRepository.findByIdAndIsDeletedFalse(amendment.getApplicationEvaluationEntity().getId()); + if (entityOptional.isPresent()) { + UserEntity user = validator.validatePreInstructor(request, entityOptional.get().getUserId()); + } + return applicationAmendmentRequestDao.getApplicationAmendmentRequestById(id); + } @Override public List getAllApplicationAmendmentRequest(HttpServletRequest request,Long userId) { + UserEntity user = validator.validatePreInstructor(request, userId); return applicationAmendmentRequestDao.getAllApplicationAmendmentRequest(request,userId); } @Override public ApplicationAmendmentRequestResponse updateApplicationAmendment(HttpServletRequest request, Long id, ApplicationAmendmentRequestBean applicationAmendmentRequestBean) { - UserEntity updatedByUser= validator.validateUser(request); - return applicationAmendmentRequestDao.updateApplicationAmendment(id,applicationAmendmentRequestBean); + ApplicationAmendmentRequestEntity amendment = applicationAmendmentRequestRepository.findByIdAndIsDeletedFalse(id) + .orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, + Translator.toLocale(GepafinConstant.APPLICATION_AMENDMENT_NOT_FOUND_MSG))); + + Optional entityOptional = applicationEvaluationRepository.findByIdAndIsDeletedFalse(amendment.getApplicationEvaluationEntity().getId()); + if (entityOptional.isPresent()) { + UserEntity user = validator.validatePreInstructor(request, entityOptional.get().getUserId()); + } + return applicationAmendmentRequestDao.updateApplicationAmendment(id,applicationAmendmentRequestBean); } @Override public ApplicationAmendmentRequestEntity validateApplicationAmendmentRequest(Long applicationAmendmentId) { + return applicationAmendmentRequestDao.validateApplicationAmendmentRequest(applicationAmendmentId); } @Override public List getAllAmendmentRequestByBeneficiaryId(HttpServletRequest request, Long beneficiaryId) { + UserEntity user= validator.validateUser(request); return applicationAmendmentRequestDao.getAllAmendmentRequestByBeneficiaryId(beneficiaryId); } @Override public ApplicationAmendmentRequestResponse closeAmendmentRequest(HttpServletRequest request, Long id, CloseAmendmentRequest closeAmendmentRequest) { - return applicationAmendmentRequestDao.closeAmendmentRequest(id,closeAmendmentRequest); + ApplicationAmendmentRequestEntity amendment = applicationAmendmentRequestRepository.findByIdAndIsDeletedFalse(id) + .orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, + Translator.toLocale(GepafinConstant.APPLICATION_AMENDMENT_NOT_FOUND_MSG))); + + Optional entityOptional = applicationEvaluationRepository.findByIdAndIsDeletedFalse(amendment.getApplicationEvaluationEntity().getId()); + if (entityOptional.isPresent()) { + UserEntity user = validator.validatePreInstructor(request, entityOptional.get().getUserId()); + } + return applicationAmendmentRequestDao.closeAmendmentRequest(id,closeAmendmentRequest); } @Override public ApplicationAmendmentRequestResponse extendResponseDays(HttpServletRequest request, Long id, Long addedDays) { - return applicationAmendmentRequestDao.extendResponseDays(id, addedDays); + UserEntity user= validator.validateUser(request); + return applicationAmendmentRequestDao.extendResponseDays(id, addedDays); } public ApplicationAmendmentRequestResponse getAmendmentByApplicationId(HttpServletRequest request, Long applicationId) { - UserEntity user= validator.validateUser(request); - return applicationAmendmentRequestDao.getAmendmentByApplicationId(request,applicationId); + ApplicationAmendmentRequestEntity amendment = applicationAmendmentRequestRepository.findByApplicationIdAndIsDeletedFalse(applicationId); + if(amendment!=null) { + + Optional entityOptional = applicationEvaluationRepository.findByIdAndIsDeletedFalse(amendment.getApplicationEvaluationEntity().getId()); + if (entityOptional.isPresent()) { + UserEntity user = validator.validatePreInstructor(request, entityOptional.get().getUserId()); + }} + return applicationAmendmentRequestDao.getAmendmentByApplicationId(request,applicationId); } @Override public ApplicationAmendmentRequestResponse updateApplicationStatus(HttpServletRequest request, Long applicationId, ApplicationAmendmentRequestEnum status) { diff --git a/src/main/resources/db/changelog/db.changelog-1.0.0.xml b/src/main/resources/db/changelog/db.changelog-1.0.0.xml index 37b87d81..9aa2ec42 100644 --- a/src/main/resources/db/changelog/db.changelog-1.0.0.xml +++ b/src/main/resources/db/changelog/db.changelog-1.0.0.xml @@ -1716,4 +1716,8 @@ + + + diff --git a/src/main/resources/db/dump/update_system_email_template_for_notification_mail_05_11_2024_4.sql b/src/main/resources/db/dump/update_system_email_template_for_notification_mail_05_11_2024_4.sql new file mode 100644 index 00000000..1b43db33 --- /dev/null +++ b/src/main/resources/db/dump/update_system_email_template_for_notification_mail_05_11_2024_4.sql @@ -0,0 +1,16 @@ +UPDATE gepafin_schema.system_email_template +SET + subject = 'BANDO {{call_name}}- Domanda di concessione di finanziamento agevolato {{company_name}}', + html_content = ' + +
+

In riferimento alla domanda di concessione di Finanziamento agevolato a valere sul Fondo prestiti + {{call_name}} di cui all’oggetto, la stessa è stata regolarmente acquisita ed è stata + registrata con Protocollo n. {{protocol_number}} del {{protocol_date}} + alle {{protocol_time}}.

+

Distinti Saluti,

+

{{email_signature}}

+
+ + ' +WHERE "type" = 'DOCUMENTATION_INTEGRATION_REQUEST' AND "system" = true;