From 4ebb7705ff765063d0787d7730e4f3c85d9beea0 Mon Sep 17 00:00:00 2001 From: harish Date: Mon, 4 Nov 2024 16:56:21 +0530 Subject: [PATCH 1/2] Rename 'updatedFormFields' to 'applicationFormFields' in request and also fix the bug --- .../dao/ApplicationAmendmentRequestDao.java | 74 ++++++++++++++----- .../ApplicationAmendmentRequestBean.java | 2 +- ...pplicationAmendmentRequestServiceImpl.java | 3 +- 3 files changed, 57 insertions(+), 22 deletions(-) diff --git a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationAmendmentRequestDao.java b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationAmendmentRequestDao.java index b5d36dac..921990a7 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationAmendmentRequestDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationAmendmentRequestDao.java @@ -21,6 +21,8 @@ import net.gepafin.tendermanagement.model.response.ApplicationAmendmentRequestRe import net.gepafin.tendermanagement.repositories.*; import net.gepafin.tendermanagement.service.*; import net.gepafin.tendermanagement.util.DateTimeUtil; +import net.gepafin.tendermanagement.util.Validator; +import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException; import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException; import net.gepafin.tendermanagement.web.rest.api.errors.Status; import org.springframework.beans.factory.annotation.Autowired; @@ -28,7 +30,6 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Component; -import java.time.ZoneId; import java.time.temporal.ChronoUnit; @@ -84,6 +85,9 @@ public class ApplicationAmendmentRequestDao { @Autowired private AssignedApplicationsRepository assignedApplicationsRepository; + @Autowired + private Validator validator; + public ApplicationAmendmentRequestResponse getApplicationDataForAmendment(HttpServletRequest request, Long applicationEvaluationId) { log.info("Fetching the application data for the Amendment process {}", applicationEvaluationId); ApplicationEvaluationEntity applicationEvaluationEntity = applicationEvaluationService.validateApplicationEvaluation(applicationEvaluationId); @@ -326,7 +330,14 @@ public class ApplicationAmendmentRequestDao { return response; } - public List getAllApplicationAmendmentRequest(Long userId) { + 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)); + } + if(userId != null) { + validator.validatePreInstructor(request, userId); + } Specification spec = search(userId); List applicationAmendmentRequestEntities = applicationAmendmentRequestRepository.findAll(spec); @@ -357,8 +368,8 @@ public class ApplicationAmendmentRequestDao { ApplicationAmendmentRequestEntity existingApplicationAmendment = validateApplicationAmendmentRequest(id); setIfUpdated(existingApplicationAmendment::getNote, existingApplicationAmendment::setNote, updateRequest.getNote()); - if (updateRequest.getUpdatedFormFields() != null) { - updateApplicationFormFields(existingApplicationAmendment, updateRequest.getUpdatedFormFields()); + if (updateRequest.getApplicationFormFields() != null) { + updateApplicationFormFields(existingApplicationAmendment, updateRequest.getApplicationFormFields()); } existingApplicationAmendment.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now())); @@ -368,27 +379,52 @@ public class ApplicationAmendmentRequestDao { return response; } - private void updateApplicationFormFields(ApplicationAmendmentRequestEntity applicationAmendment, ApplicationFormFieldRequestBean updatedFormField) { + if (updatedFormField.getFieldValue() == null || "".equals(updatedFormField.getFieldValue().toString().trim())) { + List applicationForms = applicationFormRepository.findByApplicationId(applicationAmendment.getApplicationId()); + + boolean fieldUpdated = false; + + for (ApplicationFormEntity applicationForm : applicationForms) { + Optional formFieldEntityOptional = applicationFormFieldRepository + .findByApplicationFormIdAndFieldId(applicationForm.getId(), updatedFormField.getFieldId()); + + if (formFieldEntityOptional.isPresent()) { + ApplicationFormFieldEntity formEntity = formFieldEntityOptional.get(); + formEntity.setFieldValue(null); // Set field value to null + applicationFormFieldRepository.save(formEntity); + log.info("Set field value to null for application ID {} and field ID {}", applicationAmendment.getApplicationId(), updatedFormField.getFieldId()); + fieldUpdated = true; + break; + } + } + + if (!fieldUpdated) { + throw new CustomValidationException(Status.NOT_FOUND, "No ApplicationFormField found for application ID " + applicationAmendment.getApplicationId() + " and field ID " + updatedFormField.getFieldId()); + } + return; + } + List documentIds; - // Check if fieldValue is an array - if (updatedFormField.getFieldValue() instanceof List) { - documentIds = ((List) updatedFormField.getFieldValue()).stream() - .map(Object::toString) - .collect(Collectors.toList()); + if (updatedFormField.getFieldValue() instanceof String && updatedFormField.getFieldValue() != null) { + documentIds = Arrays.asList(((String) updatedFormField.getFieldValue()).split(",")); } else { - log.warn("Expected fieldValue as a list but got: {}", updatedFormField.getFieldValue()); + log.warn("Expected fieldValue as a comma-separated String but got: {}", updatedFormField.getFieldValue()); return; } List validDocumentIds = new ArrayList<>(); for (String documentId : documentIds) { - DocumentEntity documentEntity = documentService.validateDocument(Long.parseLong(documentId)); - if (documentEntity != null) { - validDocumentIds.add(documentId); - } else { - log.warn("Document with ID {} does not exist. Skipping this ID.", documentId); + try { + DocumentEntity documentEntity = documentService.validateDocument(Long.parseLong(documentId.trim())); + if (documentEntity != null) { + validDocumentIds.add(documentId.trim()); + } else { + log.warn("Document with ID {} does not exist. Skipping this ID.", documentId); + } + } catch (NumberFormatException e) { + log.error("Invalid document ID format: {}. Error: {}", documentId, e.getMessage()); } } @@ -413,8 +449,7 @@ public class ApplicationAmendmentRequestDao { } if (!fieldUpdated) { - log.warn("No ApplicationFormFieldEntity found for application ID {} and field ID {}. Skipping update.", - applicationAmendment.getApplicationId(), updatedFormField.getFieldId()); + throw new CustomValidationException(Status.NOT_FOUND,"No ApplicationFormField found for application ID {} and field ID {}. Skipping update."); } } else { log.warn("No valid document IDs found for update. Skipping field ID {}", updatedFormField.getFieldId()); @@ -422,8 +457,9 @@ public class ApplicationAmendmentRequestDao { } - public List getAllAmendmentRequestByBeneficiaryId(Long beneficiaryId) { + public List getAllAmendmentRequestByBeneficiaryId(Long beneficiaryId) { + UserEntity userEntity = userService.validateUser(beneficiaryId); List entities = applicationAmendmentRequestRepository.findByUserId(beneficiaryId); diff --git a/src/main/java/net/gepafin/tendermanagement/model/request/ApplicationAmendmentRequestBean.java b/src/main/java/net/gepafin/tendermanagement/model/request/ApplicationAmendmentRequestBean.java index b845fe0e..c3c5aeb5 100644 --- a/src/main/java/net/gepafin/tendermanagement/model/request/ApplicationAmendmentRequestBean.java +++ b/src/main/java/net/gepafin/tendermanagement/model/request/ApplicationAmendmentRequestBean.java @@ -5,5 +5,5 @@ import lombok.Data; @Data public class ApplicationAmendmentRequestBean { private String note; - private ApplicationFormFieldRequestBean updatedFormFields; + private ApplicationFormFieldRequestBean applicationFormFields; } 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 d8a93d36..d00f244a 100644 --- a/src/main/java/net/gepafin/tendermanagement/service/impl/ApplicationAmendmentRequestServiceImpl.java +++ b/src/main/java/net/gepafin/tendermanagement/service/impl/ApplicationAmendmentRequestServiceImpl.java @@ -5,7 +5,6 @@ import net.gepafin.tendermanagement.dao.ApplicationAmendmentRequestDao; import net.gepafin.tendermanagement.entities.ApplicationAmendmentRequestEntity; import net.gepafin.tendermanagement.entities.UserEntity; import net.gepafin.tendermanagement.enums.ApplicationAmendmentRequestEnum; -import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum; import net.gepafin.tendermanagement.model.request.ApplicationAmendmentRequest; import net.gepafin.tendermanagement.model.request.ApplicationAmendmentRequestBean; import net.gepafin.tendermanagement.model.request.CloseAmendmentRequest; @@ -50,7 +49,7 @@ public class ApplicationAmendmentRequestServiceImpl implements ApplicationAmendm @Override public List getAllApplicationAmendmentRequest(HttpServletRequest request,Long userId) { - return applicationAmendmentRequestDao.getAllApplicationAmendmentRequest(userId); + return applicationAmendmentRequestDao.getAllApplicationAmendmentRequest(request,userId); } @Override From 84d2d778b56a38743dd57fb7467dddad9c0f985e Mon Sep 17 00:00:00 2001 From: piyuskag Date: Mon, 4 Nov 2024 17:21:06 +0530 Subject: [PATCH 2/2] Updated Code. --- .../db/changelog/db.changelog-1.0.0.xml | 9 +- ...plate_for_notification_mail_31_10_2024.sql | 95 +++++++++++++++---- ...ate_for_notification_mail_04_11_2024_1.sql | 78 +++++++++++++++ 3 files changed, 164 insertions(+), 18 deletions(-) create mode 100644 src/main/resources/db/dump/update_system_email_template_for_notification_mail_04_11_2024_1.sql 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 52a0910f..37b87d81 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 @@ -1702,7 +1702,7 @@ UNIQUE_UUID = 't7jh5wfg9QXylNaTZkPoE' - + select setval('gepafin_schema.system_email_template_id_seq', (select max(id)+1 @@ -1710,5 +1710,10 @@ - + + + + + diff --git a/src/main/resources/db/dump/insert_system_email_template_for_notification_mail_31_10_2024.sql b/src/main/resources/db/dump/insert_system_email_template_for_notification_mail_31_10_2024.sql index fbb2c1c1..83cfc6c3 100644 --- a/src/main/resources/db/dump/insert_system_email_template_for_notification_mail_31_10_2024.sql +++ b/src/main/resources/db/dump/insert_system_email_template_for_notification_mail_31_10_2024.sql @@ -1,5 +1,14 @@ -UPDATE gepafin_schema.system_email_template -SET html_content = ' +INSERT INTO gepafin_schema.system_email_template +( + id, template_name, "type", html_content, subject, "json", "system", + is_deleted, created_date, updated_date +) +VALUES +( + 3, + 'Instructional Aid/Request for Documentation Integration Template', + 'DOCUMENTATION_INTEGRATION_REQUEST', + '

RICHIESTA INTEGRAZIONE DOCUMENTALE

@@ -22,11 +31,27 @@ SET html_content = '

{{email_signature}}

- ' -WHERE "type" = 'DOCUMENTATION_INTEGRATION_REQUEST' AND "system" = true; + ', + 'RICHIESTA INTEGRAZIONE DOCUMENTALE - {{call_name}}', + NULL, + true, + false, + '2024-10-26 20:00:00', + '2024-10-26 20:00:00' +); -UPDATE gepafin_schema.system_email_template -SET html_content = ' +-- Insert for INADMISSIBILITY_NOTIFICATION_DUE_TO_FAILURE +INSERT INTO gepafin_schema.system_email_template +( + id, template_name, "type", html_content, subject, "json", "system", + is_deleted, created_date, updated_date +) +VALUES +( + 4, + 'Notification of Inadmissibility Due to Failure to Respond Template', + 'INADMISSIBILITY_NOTIFICATION_DUE_TO_FAILURE', + '

Comunicazione di non ammissibilità per mancata risposta a richiesta integrazione documentale

@@ -40,11 +65,27 @@ SET html_content = '

{{email_signature}}

- ' -WHERE "type" = 'INADMISSIBILITY_NOTIFICATION_DUE_TO_FAILURE' AND "system" = true; + ', + 'BANDO {{call_name}} - Domanda di finanziamento non ammessa {{company_name}}', + NULL, + true, + false, + '2024-10-26 20:00:00', + '2024-10-26 20:00:00' +); -UPDATE gepafin_schema.system_email_template -SET html_content = ' +-- Insert for ADMISSIBILITY_NOTIFICATION +INSERT INTO gepafin_schema.system_email_template +( + id, template_name, "type", html_content, subject, "json", "system", + is_deleted, created_date, updated_date +) +VALUES +( + 5, + 'Notification of Admissibility Template', + 'ADMISSIBILITY_NOTIFICATION', + '

Buongiorno,

@@ -56,11 +97,27 @@ SET html_content = '

{{email_signature}}

- ' -WHERE "type" = 'ADMISSIBILITY_NOTIFICATION' AND "system" = true; + ', + 'BANDO {{call_name}} – Esito positivo istruttoria di ammissibilità {{company_name}}', + NULL, + true, + false, + '2024-10-26 20:00:00', + '2024-10-26 20:00:00' +); -UPDATE gepafin_schema.system_email_template -SET html_content = ' +-- Insert for INADMISSIBILITY_NOTIFICATION +INSERT INTO gepafin_schema.system_email_template +( + id, template_name, "type", html_content, subject, "json", "system", + is_deleted, created_date, updated_date +) +VALUES +( + 6, + 'Notification of Inadmissibility Template', + 'INADMISSIBILITY_NOTIFICATION', + '

Buongiorno,

@@ -74,5 +131,11 @@ SET html_content = '

{{email_signature}}

- ' -WHERE "type" = 'INADMISSIBILITY_NOTIFICATION' AND "system" = true; + ', + 'BANDO {{call_name}} – Esito negativo istruttoria di ammissibilità {{company_name}}', + NULL, + true, + false, + '2024-10-26 20:00:00', + '2024-10-26 20:00:00' +); \ No newline at end of file diff --git a/src/main/resources/db/dump/update_system_email_template_for_notification_mail_04_11_2024_1.sql b/src/main/resources/db/dump/update_system_email_template_for_notification_mail_04_11_2024_1.sql new file mode 100644 index 00000000..fbb2c1c1 --- /dev/null +++ b/src/main/resources/db/dump/update_system_email_template_for_notification_mail_04_11_2024_1.sql @@ -0,0 +1,78 @@ +UPDATE gepafin_schema.system_email_template +SET html_content = ' + +
+

RICHIESTA INTEGRAZIONE DOCUMENTALE

+

Buongiorno,

+

In riferimento alla domanda di concessione di Finanziamento agevolato a valere sul Fondo prestiti + {{call_name}} di cui al Protocollo n. {{protocol_number}} del + {{protocol_date}} e {{protocol_time}}, alla luce dell’attività istruttoria svolta, + segnaliamo quanto segue:

+
    +
  • {{form_dataInput}}
  • +
+

{{note}}

+

Vi invitiamo a fornire quanto sopra richiesto integrando la documentazione sia caricandola all’interno dello sportello + online {{platform_link}} che inviandola a mezzo PEC all’indirizzo + {{legal_mail}} entro e non oltre 10 giorni dal ricevimento della presente comunicazione, + precisando che, in caso di mancata ricezione nei termini indicati, saremo costretti a non prendere in considerazione la Vostra richiesta di finanziamento.

+

Vi informiamo che per la ricezione della PEC farà fede la ricevuta di avvenuta consegna che attesterà il buon esito + dell’invio. La documentazione trasmessa e le informazioni fornite saranno processate dall''istruttore assegnatario della pratica.

+

Distinti Saluti,

+

{{email_signature}}

+
+ + ' +WHERE "type" = 'DOCUMENTATION_INTEGRATION_REQUEST' AND "system" = true; + +UPDATE gepafin_schema.system_email_template +SET html_content = ' + +
+

Comunicazione di non ammissibilità per mancata risposta a richiesta integrazione documentale

+

Buongiorno,

+

Con posta elettronica certificata del {{date_time_emailSend}}, vi abbiamo comunicato che i documenti richiesti + dal Gestore sarebbero dovuti pervenire entro 10 giorni dal ricevimento di detta comunicazione. + Trascorso il termine senza la ricezione dei documenti richiesti, il Gestore non ha potuto prendere in considerazione la richiesta di finanziamento.

+

È possibile presentare ricorso tramite modello disponibile nello sportello online + {{platform_link}} entro 10 giorni dalla ricezione di questa comunicazione.

+

Distinti Saluti,

+

{{email_signature}}

+
+ + ' +WHERE "type" = 'INADMISSIBILITY_NOTIFICATION_DUE_TO_FAILURE' AND "system" = true; + +UPDATE gepafin_schema.system_email_template +SET html_content = ' + +
+

Buongiorno,

+

In riferimento alla domanda di concessione di Finanziamento agevolato “{{call_name}}” di cui al + Protocollo n. {{protocol_number}} del {{protocol_date}} alle {{protocol_time}}, l’istruttoria di ammissibilità + è stata completata con esito positivo.

+

Seguirà una comunicazione relativa alla valutazione tecnica ed economico-finanziaria ai fini della valutazione finale.

+

Distinti Saluti,

+

{{email_signature}}

+
+ + ' +WHERE "type" = 'ADMISSIBILITY_NOTIFICATION' AND "system" = true; + +UPDATE gepafin_schema.system_email_template +SET html_content = ' + +
+

Buongiorno,

+

In riferimento alla domanda di concessione di Finanziamento agevolato “{{call_name}}” di cui al + Protocollo n. {{protocol_number}} del {{protocol_date}} alle {{protocol_time}}, + l''istruttoria di ammissibilità è stata completata con esito negativo.

+

Motivazioni: {{form_text}}

+

È possibile presentare ricorso tramite modello disponibile nello sportello online + {{platform_link}} entro 10 giorni dalla ricezione di questa comunicazione.

+

Distinti Saluti,

+

{{email_signature}}

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