From d787fdcd0eccb55608ff98be6f7589efa3044d0e Mon Sep 17 00:00:00 2001 From: piyushkag Date: Tue, 11 Feb 2025 15:33:46 +0530 Subject: [PATCH 1/6] Updated Appointment code for creating appointment on external system. --- .../constants/AppointmentApiConstant.java | 16 ++++- .../constants/GepafinConstant.java | 2 +- .../tendermanagement/dao/AppointmentDao.java | 64 ++++++++++++++----- .../request/AppointmentCreationRequest.java | 4 +- .../feignClient/AppointmentApiService.java | 3 +- 5 files changed, 67 insertions(+), 22 deletions(-) diff --git a/src/main/java/net/gepafin/tendermanagement/constants/AppointmentApiConstant.java b/src/main/java/net/gepafin/tendermanagement/constants/AppointmentApiConstant.java index 15a3444e..c82687a5 100644 --- a/src/main/java/net/gepafin/tendermanagement/constants/AppointmentApiConstant.java +++ b/src/main/java/net/gepafin/tendermanagement/constants/AppointmentApiConstant.java @@ -6,7 +6,7 @@ public class AppointmentApiConstant { public static final String GET_NDG_BY_VAT_NUMBER = "/WSAnagrafica.getListaNdg"; public static final String CREATE_VISURA = "/WSAnagrafica.createVisura"; public static final String GET_VISURA_LIST = "/WSAnagrafica.getVisuraList"; - public static final String GET_APPOINTMENT_TEMPLATE = "/WSCrmConsulenza.getAppuntamentoTemplate?idAppuntamentoTemplate=7"; + public static final String GET_APPOINTMENT_TEMPLATE = "/WSCrmConsulenza.getAppuntamentoTemplate"; public static final String CREATE_APPOINTMENT_FROM_TEMPLATE = "/WSCrmConsulenza.createAppointmentFromTemplate"; public static final String UPLOAD_APOOINTMENT_DOCUMENT = "/WSDocumentDetail.createStream"; @@ -24,4 +24,18 @@ public class AppointmentApiConstant { public static final boolean IS_FROM_RATING = Boolean.FALSE; public static final boolean IS_ANAGRAFICA_LEGAME = Boolean.FALSE; + //Appointment creation request body fields + public static final String MOTIVAZIONE = "motivazione"; + public static final String COD_PRODOTTO = "codProdotto"; + public static final String COD_ABI = "codAbi"; + public static final String COD_CAB = "codCab"; + public static final String ID_NOTA = "idNota"; + public static final String IMPORTO_AGEVOLATO = "importoAgevolato"; + public static final String IMPORTO_MEDIOLUNGO_TERMINE = "importoMedioLungoTermine"; + public static final String COD_TIPO_PRODOTTO = "codTipoProdotto"; + public static final String COD_CATEGORIA_PRODOTTO = "codCategoriaProdotto"; + public static final String COD_FORMATECNICA = "codFormaTecnica"; + public static final String COD_OPERAZIONE = "codOperazione"; + public static final String MOTIVAZIONE_ID = "id"; + } diff --git a/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java b/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java index f696cdb0..5eb5128b 100644 --- a/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java +++ b/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java @@ -332,7 +332,7 @@ public class GepafinConstant { public static final String DATA_STRING = "data"; public static final String DOCUMENT_ATTACHMENT_ID_STRING = "documentAttachmentId"; public static final String TEMP_FILE_PATH = "/tmp/"; - public static final String RICHIESTA_CLIENTE_STRING = "richiestaCliente"; + public static final String RICHIESTE_CLIENTE_STRING = "richiesteCliente"; public static final String ID_STRING = "id"; public static final String NULL_STRING = "null"; public static final String NDG_STRING = "ndg"; diff --git a/src/main/java/net/gepafin/tendermanagement/dao/AppointmentDao.java b/src/main/java/net/gepafin/tendermanagement/dao/AppointmentDao.java index a45b142d..8bf0b4a4 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/AppointmentDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/AppointmentDao.java @@ -2,6 +2,7 @@ package net.gepafin.tendermanagement.dao; import com.amazonaws.services.s3.AmazonS3Client; import com.amazonaws.services.s3.model.GetObjectRequest; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import feign.FeignException; @@ -16,18 +17,14 @@ import net.gepafin.tendermanagement.entities.ApplicationEntity; import net.gepafin.tendermanagement.entities.CompanyEntity; import net.gepafin.tendermanagement.entities.DocumentEntity; import net.gepafin.tendermanagement.entities.HubEntity; -import net.gepafin.tendermanagement.entities.UserEntity; import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum; -import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum; import net.gepafin.tendermanagement.enums.NotificationTypeEnum; -import net.gepafin.tendermanagement.enums.RoleStatusEnum; import net.gepafin.tendermanagement.enums.VersionActionTypeEnum; import net.gepafin.tendermanagement.model.request.AppointmentCreationRequest; import net.gepafin.tendermanagement.model.request.AppointmentNdgRequest; import net.gepafin.tendermanagement.model.request.AppointmentVisuraListRequest; import net.gepafin.tendermanagement.model.request.AppointmentVisuraRequest; import net.gepafin.tendermanagement.model.request.CreateAppointmentRequest; -import net.gepafin.tendermanagement.model.request.NotificationReq; import net.gepafin.tendermanagement.model.request.UploadDocToExternalSystemRequest; import net.gepafin.tendermanagement.model.request.VersionHistoryRequest; import net.gepafin.tendermanagement.model.response.AppointmentCreationResponse; @@ -63,7 +60,6 @@ import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; @@ -388,7 +384,6 @@ public class AppointmentDao { // Validate and save token if (parsedResponse.getTokenId() != null) { hub.setAppointmentAuthTokenId(parsedResponse.getTokenId()); - hub.setAreaCode(parsedResponse.getAreaCode()); hubRepository.save(hub); // /** This code is responsible for adding a version history log for the "inserting token and areaCode from login odessa response for @@ -406,10 +401,15 @@ public class AppointmentDao { } // Handle non-OK response throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.ERROR_IN_GENERATING_NDG_TRY_AGAIN)); + } catch (FeignException.Forbidden forbiddenException) { + logForbiddenError(); + // Regenerate the token and retry + regenerateTokenAndSave(hub); } catch (Exception e) { log.error("Failed to authenticate user on Odessa : {}", e.getMessage(), e); throw new RuntimeException("Authentication failed on Odessa. try again", e); } + return null; } private AppointmentLoginResponse retrieveNdgByVatNumber(String vatNumber, String authorizationToken, HubEntity hub, ApplicationEntity application) { @@ -626,7 +626,8 @@ public class AppointmentDao { // Generate authorization token and fetch template data String authorizationToken = getBearerToken(hub); - ResponseEntity response = appointmentApiService.getAppointmentTemplateForTemplateCreation(authorizationToken); + int areaCode = Integer.parseInt(hub.getAreaCode()); + ResponseEntity response = appointmentApiService.getAppointmentTemplateForTemplateCreation(authorizationToken, areaCode); if (response.getStatusCode() != HttpStatus.OK) { log.error("Failed to retrieve appointment template for appointment creation. Status: {}", response.getStatusCode()); @@ -682,33 +683,61 @@ public class AppointmentDao { } public AppointmentCreationRequest parseTemplateResponseData(String jsonResponse) { - try { ObjectMapper objectMapper = new ObjectMapper(); JsonNode rootNode = objectMapper.readTree(jsonResponse); - JsonNode richiestaClienteArray = rootNode.path(GepafinConstant.DATA_STRING).path(GepafinConstant.RICHIESTA_CLIENTE_STRING); + JsonNode richiesteClienteArray = rootNode.path(GepafinConstant.DATA_STRING).path(GepafinConstant.RICHIESTE_CLIENTE_STRING); + // Initialize the result object AppointmentCreationRequest appointmentCreationRequest = new AppointmentCreationRequest(); AppointmentCreationRequest.Input input = new AppointmentCreationRequest.Input(); - - // Map `richiestaCliente` array List richiestaClienteList = new ArrayList<>(); - if (richiestaClienteArray.isArray()) { - for (JsonNode richiestaNode : richiestaClienteArray) { - richiestaClienteList.add(objectMapper.treeToValue(richiestaNode, AppointmentCreationRequest.RichiestaCliente.class)); - } + if (!richiesteClienteArray.isArray()) { + log.warn("richiesteCliente array is missing or not an array."); + return new AppointmentCreationRequest(); // Return empty object if array is missing + } + + for (JsonNode richiestaNode : richiesteClienteArray) { + if (richiestaNode.isNull()) continue; + + AppointmentCreationRequest.RichiestaCliente richiestaCliente = new AppointmentCreationRequest.RichiestaCliente(); + richiestaCliente.setIdMotivazione(getIntValue(richiestaNode)); + richiestaCliente.setCodProdotto(getTextValue(richiestaNode, AppointmentApiConstant.COD_PRODOTTO)); + richiestaCliente.setCodAbi(getTextValue(richiestaNode, AppointmentApiConstant.COD_ABI)); + richiestaCliente.setCodCab(getTextValue(richiestaNode, AppointmentApiConstant.COD_CAB)); + richiestaCliente.setIdNota(getTextValue(richiestaNode, AppointmentApiConstant.ID_NOTA)); + richiestaCliente.setImportoAgevolato(getTextValue(richiestaNode, AppointmentApiConstant.IMPORTO_AGEVOLATO)); + richiestaCliente.setImportoMedioLungoTermine(getTextValue(richiestaNode, AppointmentApiConstant.IMPORTO_MEDIOLUNGO_TERMINE)); + richiestaCliente.setCodTipoProdotto(getTextValue(richiestaNode, AppointmentApiConstant.COD_TIPO_PRODOTTO)); + richiestaCliente.setCodCategoriaProdotto(getTextValue(richiestaNode, AppointmentApiConstant.COD_CATEGORIA_PRODOTTO)); + richiestaCliente.setCodFormaTecnica(getTextValue(richiestaNode, AppointmentApiConstant.COD_FORMATECNICA)); + richiestaCliente.setCodOperazione(getTextValue(richiestaNode, AppointmentApiConstant.COD_OPERAZIONE)); + + richiestaClienteList.add(richiestaCliente); } input.setRichiestaCliente(richiestaClienteList); appointmentCreationRequest.setInput(input); + return appointmentCreationRequest; + } catch (JsonProcessingException e) { + log.error("JSON processing error: {}", e.getMessage(), e); + throw new IllegalStateException("Invalid JSON structure in template response", e); } catch (Exception e) { - log.error("Error parsing template response: {}", e.getMessage(), e); + log.error("Unexpected error while parsing template response: {}", e.getMessage(), e); throw new IllegalStateException("Failed to parse template response", e); } } + private String getTextValue(JsonNode node, String fieldName) { + return node.path(fieldName).isTextual() ? node.path(fieldName).asText() : null; + } + + private int getIntValue(JsonNode node) { + return node.path(AppointmentApiConstant.MOTIVAZIONE).path(AppointmentApiConstant.MOTIVAZIONE_ID).asInt(); + } + public AppointmentCreationRequest buildAppointmentCreationRequest(Long applicationId, CreateAppointmentRequest createAppointmentRequest, String areaCode, AppointmentCreationRequest templateRichiestaData) { @@ -733,7 +762,8 @@ public class AppointmentDao { requestNota.setTitolo(nota.getTitolo()); requestNota.setTesto(nota.getTesto()); richiestaCliente.setNota(requestNota); - + richiestaCliente.setDurataMesiFinanziamento(createAppointmentRequest.getDurataMesiFinanziamento()); + richiestaCliente.setImportoBreveTermine(createAppointmentRequest.getImportoBreveTermine()); richiestaClienteList.add(richiestaCliente); } diff --git a/src/main/java/net/gepafin/tendermanagement/model/request/AppointmentCreationRequest.java b/src/main/java/net/gepafin/tendermanagement/model/request/AppointmentCreationRequest.java index a877a620..0bd6b812 100644 --- a/src/main/java/net/gepafin/tendermanagement/model/request/AppointmentCreationRequest.java +++ b/src/main/java/net/gepafin/tendermanagement/model/request/AppointmentCreationRequest.java @@ -20,8 +20,8 @@ public class AppointmentCreationRequest { public static class RichiestaCliente { private String codAbi; private String codCab; - private Integer durataMesiFinanziamento; - private Integer idMotivazione; + private int durataMesiFinanziamento; + private int idMotivazione; private String idNota; private String importoAgevolato; private Double importoBreveTermine; diff --git a/src/main/java/net/gepafin/tendermanagement/service/feignClient/AppointmentApiService.java b/src/main/java/net/gepafin/tendermanagement/service/feignClient/AppointmentApiService.java index b193713b..1c3a44f7 100644 --- a/src/main/java/net/gepafin/tendermanagement/service/feignClient/AppointmentApiService.java +++ b/src/main/java/net/gepafin/tendermanagement/service/feignClient/AppointmentApiService.java @@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.multipart.MultipartFile; @@ -31,7 +32,7 @@ public interface AppointmentApiService { ResponseEntity getVisuraList(@RequestBody String visuraRequest, @RequestHeader("Authorization") String token); @GetMapping(value = AppointmentApiConstant.GET_APPOINTMENT_TEMPLATE, consumes = MediaType.APPLICATION_JSON_VALUE) - ResponseEntity getAppointmentTemplateForTemplateCreation(@RequestHeader("Authorization") String token); + ResponseEntity getAppointmentTemplateForTemplateCreation(@RequestHeader("Authorization") String token, @RequestParam("idAppuntamentoTemplate") int templateId); @PostMapping(value = AppointmentApiConstant.CREATE_APPOINTMENT_FROM_TEMPLATE, consumes = MediaType.APPLICATION_JSON_VALUE) ResponseEntity createAppointment(@RequestHeader("Authorization") String token, @RequestHeader("context") String context, String appointmentCreationRequest); From fcdea2c593566289340aefc983f8041a9367ac5f Mon Sep 17 00:00:00 2001 From: piyushkag Date: Wed, 12 Feb 2025 11:48:06 +0530 Subject: [PATCH 2/6] Updated code for appointment creation and added a column in hub for appointment template id.. --- .../constants/AppointmentApiConstant.java | 4 +- .../constants/GepafinConstant.java | 3 + .../tendermanagement/dao/AppointmentDao.java | 64 ++++++++++++------- .../tendermanagement/entities/HubEntity.java | 3 + .../request/AppointmentCreationRequest.java | 2 +- .../feignClient/AppointmentApiService.java | 2 +- .../db/changelog/db.changelog-1.0.0.xml | 8 +++ src/main/resources/message_en.properties | 2 + src/main/resources/message_it.properties | 2 + 9 files changed, 62 insertions(+), 28 deletions(-) diff --git a/src/main/java/net/gepafin/tendermanagement/constants/AppointmentApiConstant.java b/src/main/java/net/gepafin/tendermanagement/constants/AppointmentApiConstant.java index c82687a5..6e5ed97c 100644 --- a/src/main/java/net/gepafin/tendermanagement/constants/AppointmentApiConstant.java +++ b/src/main/java/net/gepafin/tendermanagement/constants/AppointmentApiConstant.java @@ -26,7 +26,7 @@ public class AppointmentApiConstant { //Appointment creation request body fields public static final String MOTIVAZIONE = "motivazione"; - public static final String COD_PRODOTTO = "codProdotto"; + public static final String PRODOTTO = "prodotto"; public static final String COD_ABI = "codAbi"; public static final String COD_CAB = "codCab"; public static final String ID_NOTA = "idNota"; @@ -37,5 +37,5 @@ public class AppointmentApiConstant { public static final String COD_FORMATECNICA = "codFormaTecnica"; public static final String COD_OPERAZIONE = "codOperazione"; public static final String MOTIVAZIONE_ID = "id"; - + public static final String PRODOTTO_CODE = "code"; } diff --git a/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java b/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java index 5eb5128b..0b29c773 100644 --- a/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java +++ b/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java @@ -423,6 +423,9 @@ public class GepafinConstant { public static final String FORMULA_AMOUNT_NOT_MATCHED="formula.amount.not.matches.requested.amount"; public static final String CRITERIA_TABLE_COLUMNS="criteria_table_columns"; + + public static final String APPOINTMENT_CANNOT_BE_CREATED = "appointment.cannot.be.created"; + public static final String APPOINTMENT_CANNOT_BE_CREATED_BY_TEMPLATE = "appointment.cannot.be.created.by.template"; } diff --git a/src/main/java/net/gepafin/tendermanagement/dao/AppointmentDao.java b/src/main/java/net/gepafin/tendermanagement/dao/AppointmentDao.java index 8bf0b4a4..f6fbd088 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/AppointmentDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/AppointmentDao.java @@ -384,6 +384,7 @@ public class AppointmentDao { // Validate and save token if (parsedResponse.getTokenId() != null) { hub.setAppointmentAuthTokenId(parsedResponse.getTokenId()); + hub.setAreaCode(parsedResponse.getAreaCode()); hubRepository.save(hub); // /** This code is responsible for adding a version history log for the "inserting token and areaCode from login odessa response for @@ -626,8 +627,8 @@ public class AppointmentDao { // Generate authorization token and fetch template data String authorizationToken = getBearerToken(hub); - int areaCode = Integer.parseInt(hub.getAreaCode()); - ResponseEntity response = appointmentApiService.getAppointmentTemplateForTemplateCreation(authorizationToken, areaCode); + Long appointmentTemplateId = hub.getAppointmentTemplateId(); + ResponseEntity response = appointmentApiService.getAppointmentTemplateForTemplateCreation(authorizationToken, appointmentTemplateId); if (response.getStatusCode() != HttpStatus.OK) { log.error("Failed to retrieve appointment template for appointment creation. Status: {}", response.getStatusCode()); @@ -636,10 +637,10 @@ public class AppointmentDao { // Parse template data String responseDataForTemplate = Utils.convertObjectToJson(response.getBody()); - AppointmentCreationRequest templateRichiestaData = parseTemplateResponseData(responseDataForTemplate); + AppointmentCreationRequest templateRichiestaData = parseTemplateResponseData(responseDataForTemplate, application.getCall().getProductId()); // Build the appointment request body - AppointmentCreationRequest appointmentCreationRequest = buildAppointmentCreationRequest(applicationId, createAppointmentRequest, hub.getAreaCode(), + AppointmentCreationRequest appointmentCreationRequest = buildAppointmentCreationRequest(applicationId, createAppointmentRequest, hub.getAppointmentTemplateId(), templateRichiestaData); String appointmentRequestBody = Utils.convertObjectToJson(appointmentCreationRequest); @@ -682,8 +683,12 @@ public class AppointmentDao { return null; } - public AppointmentCreationRequest parseTemplateResponseData(String jsonResponse) { + public AppointmentCreationRequest parseTemplateResponseData(String jsonResponse, Long productId) { + try { + if (productId == null) { + throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPOINTMENT_CANNOT_BE_CREATED)); + } ObjectMapper objectMapper = new ObjectMapper(); JsonNode rootNode = objectMapper.readTree(jsonResponse); JsonNode richiesteClienteArray = rootNode.path(GepafinConstant.DATA_STRING).path(GepafinConstant.RICHIESTE_CLIENTE_STRING); @@ -694,26 +699,38 @@ public class AppointmentDao { List richiestaClienteList = new ArrayList<>(); if (!richiesteClienteArray.isArray()) { log.warn("richiesteCliente array is missing or not an array."); - return new AppointmentCreationRequest(); // Return empty object if array is missing + return new AppointmentCreationRequest(); } - + boolean isMatchedAtLeastOneId = false; for (JsonNode richiestaNode : richiesteClienteArray) { - if (richiestaNode.isNull()) continue; + if (richiestaNode.isNull()) + continue; AppointmentCreationRequest.RichiestaCliente richiestaCliente = new AppointmentCreationRequest.RichiestaCliente(); - richiestaCliente.setIdMotivazione(getIntValue(richiestaNode)); - richiestaCliente.setCodProdotto(getTextValue(richiestaNode, AppointmentApiConstant.COD_PRODOTTO)); - richiestaCliente.setCodAbi(getTextValue(richiestaNode, AppointmentApiConstant.COD_ABI)); - richiestaCliente.setCodCab(getTextValue(richiestaNode, AppointmentApiConstant.COD_CAB)); - richiestaCliente.setIdNota(getTextValue(richiestaNode, AppointmentApiConstant.ID_NOTA)); - richiestaCliente.setImportoAgevolato(getTextValue(richiestaNode, AppointmentApiConstant.IMPORTO_AGEVOLATO)); - richiestaCliente.setImportoMedioLungoTermine(getTextValue(richiestaNode, AppointmentApiConstant.IMPORTO_MEDIOLUNGO_TERMINE)); - richiestaCliente.setCodTipoProdotto(getTextValue(richiestaNode, AppointmentApiConstant.COD_TIPO_PRODOTTO)); - richiestaCliente.setCodCategoriaProdotto(getTextValue(richiestaNode, AppointmentApiConstant.COD_CATEGORIA_PRODOTTO)); - richiestaCliente.setCodFormaTecnica(getTextValue(richiestaNode, AppointmentApiConstant.COD_FORMATECNICA)); - richiestaCliente.setCodOperazione(getTextValue(richiestaNode, AppointmentApiConstant.COD_OPERAZIONE)); + JsonNode prodottoNode = richiestaNode.path(AppointmentApiConstant.PRODOTTO); + String prodottoCode = prodottoNode.path(AppointmentApiConstant.PRODOTTO_CODE).asText(); - richiestaClienteList.add(richiestaCliente); + if (productId.toString().equals(prodottoCode)) { + isMatchedAtLeastOneId = true; + richiestaCliente.setCodProdotto(prodottoCode); + richiestaCliente.setIdMotivazione(getIntValue(richiestaNode)); + richiestaCliente.setCodProdotto(productId.toString()); + richiestaCliente.setCodAbi(getTextValue(richiestaNode, AppointmentApiConstant.COD_ABI)); + richiestaCliente.setCodCab(getTextValue(richiestaNode, AppointmentApiConstant.COD_CAB)); + richiestaCliente.setIdNota(getTextValue(richiestaNode, AppointmentApiConstant.ID_NOTA)); + richiestaCliente.setImportoAgevolato(getTextValue(richiestaNode, AppointmentApiConstant.IMPORTO_AGEVOLATO)); + richiestaCliente.setImportoMedioLungoTermine(getTextValue(richiestaNode, AppointmentApiConstant.IMPORTO_MEDIOLUNGO_TERMINE)); + richiestaCliente.setCodTipoProdotto(getTextValue(richiestaNode, AppointmentApiConstant.COD_TIPO_PRODOTTO)); + richiestaCliente.setCodCategoriaProdotto(getTextValue(richiestaNode, AppointmentApiConstant.COD_CATEGORIA_PRODOTTO)); + richiestaCliente.setCodFormaTecnica(getTextValue(richiestaNode, AppointmentApiConstant.COD_FORMATECNICA)); + richiestaCliente.setCodOperazione(getTextValue(richiestaNode, AppointmentApiConstant.COD_OPERAZIONE)); + + richiestaClienteList.add(richiestaCliente); + } + } + + if (!isMatchedAtLeastOneId) { + throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPOINTMENT_CANNOT_BE_CREATED_BY_TEMPLATE)); } input.setRichiestaCliente(richiestaClienteList); @@ -724,21 +741,20 @@ public class AppointmentDao { } catch (JsonProcessingException e) { log.error("JSON processing error: {}", e.getMessage(), e); throw new IllegalStateException("Invalid JSON structure in template response", e); - } catch (Exception e) { - log.error("Unexpected error while parsing template response: {}", e.getMessage(), e); - throw new IllegalStateException("Failed to parse template response", e); } } private String getTextValue(JsonNode node, String fieldName) { + return node.path(fieldName).isTextual() ? node.path(fieldName).asText() : null; } private int getIntValue(JsonNode node) { + return node.path(AppointmentApiConstant.MOTIVAZIONE).path(AppointmentApiConstant.MOTIVAZIONE_ID).asInt(); } - public AppointmentCreationRequest buildAppointmentCreationRequest(Long applicationId, CreateAppointmentRequest createAppointmentRequest, String areaCode, + public AppointmentCreationRequest buildAppointmentCreationRequest(Long applicationId, CreateAppointmentRequest createAppointmentRequest, Long areaCode, AppointmentCreationRequest templateRichiestaData) { ApplicationEntity application = applicationService.validateApplication(applicationId); diff --git a/src/main/java/net/gepafin/tendermanagement/entities/HubEntity.java b/src/main/java/net/gepafin/tendermanagement/entities/HubEntity.java index ccd6c325..ff6db1a6 100644 --- a/src/main/java/net/gepafin/tendermanagement/entities/HubEntity.java +++ b/src/main/java/net/gepafin/tendermanagement/entities/HubEntity.java @@ -64,6 +64,9 @@ public class HubEntity extends BaseEntity{ @Column(name = "AREA_CODE") private String areaCode; + @Column(name = "APPOINTMENT_TEMPLATE_ID") + private Long appointmentTemplateId; + @Column(name = "EVALUATION_EXPIRATION_DAYS") private Long evaluationExpirationDays; } diff --git a/src/main/java/net/gepafin/tendermanagement/model/request/AppointmentCreationRequest.java b/src/main/java/net/gepafin/tendermanagement/model/request/AppointmentCreationRequest.java index 0bd6b812..a1c0bb12 100644 --- a/src/main/java/net/gepafin/tendermanagement/model/request/AppointmentCreationRequest.java +++ b/src/main/java/net/gepafin/tendermanagement/model/request/AppointmentCreationRequest.java @@ -11,7 +11,7 @@ public class AppointmentCreationRequest { @Data public static class Input { - private String id; + private Long id; private String ndg; private List richiestaCliente; } diff --git a/src/main/java/net/gepafin/tendermanagement/service/feignClient/AppointmentApiService.java b/src/main/java/net/gepafin/tendermanagement/service/feignClient/AppointmentApiService.java index 1c3a44f7..036a2904 100644 --- a/src/main/java/net/gepafin/tendermanagement/service/feignClient/AppointmentApiService.java +++ b/src/main/java/net/gepafin/tendermanagement/service/feignClient/AppointmentApiService.java @@ -32,7 +32,7 @@ public interface AppointmentApiService { ResponseEntity getVisuraList(@RequestBody String visuraRequest, @RequestHeader("Authorization") String token); @GetMapping(value = AppointmentApiConstant.GET_APPOINTMENT_TEMPLATE, consumes = MediaType.APPLICATION_JSON_VALUE) - ResponseEntity getAppointmentTemplateForTemplateCreation(@RequestHeader("Authorization") String token, @RequestParam("idAppuntamentoTemplate") int templateId); + ResponseEntity getAppointmentTemplateForTemplateCreation(@RequestHeader("Authorization") String token, @RequestParam("idAppuntamentoTemplate") Long templateId); @PostMapping(value = AppointmentApiConstant.CREATE_APPOINTMENT_FROM_TEMPLATE, consumes = MediaType.APPLICATION_JSON_VALUE) ResponseEntity createAppointment(@RequestHeader("Authorization") String token, @RequestHeader("context") String context, String appointmentCreationRequest); 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 37c34586..6acccf72 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 @@ -2418,4 +2418,12 @@ + + + + UNIQUE_UUID = 'p4lk3bcx1RStqTaIVVbXs' + + + diff --git a/src/main/resources/message_en.properties b/src/main/resources/message_en.properties index 7aab6f08..87163fb4 100644 --- a/src/main/resources/message_en.properties +++ b/src/main/resources/message_en.properties @@ -371,4 +371,6 @@ validation.required.requested.amount=The Requested Amount configuration should b company.id.not.null=Company ID cannot be null. formula.amount.not.matches.requested.amount= The {0} does not matches to calculated amount. +appointment.cannot.be.created = Appointment cannot be created because call doesn't have the productId. +appointment.cannot.be.created.by.template = Product ID does not match with appointment template. diff --git a/src/main/resources/message_it.properties b/src/main/resources/message_it.properties index c1794a8d..66da42e2 100644 --- a/src/main/resources/message_it.properties +++ b/src/main/resources/message_it.properties @@ -362,4 +362,6 @@ validation.required.requested.amount=La configurazione dell'importo richiesto company.id.not.null=L'ID dell'azienda non pu? essere nullo. formula.amount.not.matches.requested.amount=Il {0} non corrisponde all'importo calcolato. +appointment.cannot.be.created = Impossibile creare l'appuntamento perch� la chiamata non ha l'ID prodotto. +appointment.cannot.be.created.by.template = L'ID prodotto non corrisponde al modello di appuntamento. From b317d97de9e2361c64604d7552489396e6089e0d Mon Sep 17 00:00:00 2001 From: piyushkag Date: Mon, 17 Feb 2025 16:17:07 +0530 Subject: [PATCH 3/6] Updated code for appointment creation flow and productId field to appointmentTemplateId. --- .../constants/GepafinConstant.java | 2 +- .../dao/ApplicationEvaluationDao.java | 5 +-- .../tendermanagement/dao/AppointmentDao.java | 43 ++++++++----------- .../dao/AssignedApplicationsDao.java | 4 +- .../gepafin/tendermanagement/dao/CallDao.java | 8 ++-- .../tendermanagement/entities/CallEntity.java | 4 +- .../tendermanagement/entities/HubEntity.java | 3 -- .../model/request/CreateCallRequestStep1.java | 2 +- .../model/request/UpdateCallRequestStep1.java | 3 +- .../ApplicationEvaluationFormResponse.java | 2 - .../ApplicationEvaluationResponse.java | 2 +- .../AssignedApplicationsResponse.java | 3 +- .../response/CallDetailsResponseBean.java | 2 +- .../model/response/CallResponse.java | 2 +- .../db/changelog/db.changelog-1.0.0.xml | 7 +++ src/main/resources/message_en.properties | 5 +-- src/main/resources/message_it.properties | 5 +-- 17 files changed, 45 insertions(+), 57 deletions(-) diff --git a/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java b/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java index 0b29c773..8e469734 100644 --- a/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java +++ b/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java @@ -425,7 +425,7 @@ public class GepafinConstant { public static final String CRITERIA_TABLE_COLUMNS="criteria_table_columns"; public static final String APPOINTMENT_CANNOT_BE_CREATED = "appointment.cannot.be.created"; - public static final String APPOINTMENT_CANNOT_BE_CREATED_BY_TEMPLATE = "appointment.cannot.be.created.by.template"; + public static final String APPOINTMENT_NOT_CREATED = "appointment.not.created"; } diff --git a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationEvaluationDao.java b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationEvaluationDao.java index ef01dea6..6f326e2c 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationEvaluationDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationEvaluationDao.java @@ -23,7 +23,6 @@ import org.springframework.util.CollectionUtils; import java.math.BigDecimal; import java.text.MessageFormat; -import java.time.Duration; import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; import java.util.*; @@ -296,7 +295,7 @@ public class ApplicationEvaluationDao { response.setCreatedDate(entity.getCreatedDate()); response.setUpdatedDate(entity.getUpdatedDate()); response.setNumberOfCheck(entity.getAssignedApplicationsEntity().getApplication().getCall().getNumberOfCheck()); - response.setProductId(entity.getAssignedApplicationsEntity().getApplication().getCall().getProductId()); + response.setAppointmentTemplateId(entity.getAssignedApplicationsEntity().getApplication().getCall().getAppointmentTemplateId()); } @@ -1157,7 +1156,7 @@ public class ApplicationEvaluationDao { LocalDateTime callEndDate = application.getCall().getEndDate(); response.setCallEndDate(callEndDate); response.setNumberOfCheck(call.getNumberOfCheck()); - response.setProductId(call.getProductId()); + response.setAppointmentTemplateId(call.getAppointmentTemplateId()); setCriteriaResponses(entity, application.getId(), response, evaluationCriterias); setChecklistResponses(entity, application.getId(), response, checklistEntities); setFileResponses(entity, application.getId(), response, applicationFormEntities); diff --git a/src/main/java/net/gepafin/tendermanagement/dao/AppointmentDao.java b/src/main/java/net/gepafin/tendermanagement/dao/AppointmentDao.java index f6fbd088..876ac53d 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/AppointmentDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/AppointmentDao.java @@ -627,7 +627,10 @@ public class AppointmentDao { // Generate authorization token and fetch template data String authorizationToken = getBearerToken(hub); - Long appointmentTemplateId = hub.getAppointmentTemplateId(); + Long appointmentTemplateId = application.getCall().getAppointmentTemplateId(); + if (appointmentTemplateId == null) { + throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPOINTMENT_CANNOT_BE_CREATED)); + } ResponseEntity response = appointmentApiService.getAppointmentTemplateForTemplateCreation(authorizationToken, appointmentTemplateId); if (response.getStatusCode() != HttpStatus.OK) { @@ -637,10 +640,10 @@ public class AppointmentDao { // Parse template data String responseDataForTemplate = Utils.convertObjectToJson(response.getBody()); - AppointmentCreationRequest templateRichiestaData = parseTemplateResponseData(responseDataForTemplate, application.getCall().getProductId()); + AppointmentCreationRequest templateRichiestaData = parseTemplateResponseData(responseDataForTemplate); // Build the appointment request body - AppointmentCreationRequest appointmentCreationRequest = buildAppointmentCreationRequest(applicationId, createAppointmentRequest, hub.getAppointmentTemplateId(), + AppointmentCreationRequest appointmentCreationRequest = buildAppointmentCreationRequest(applicationId, createAppointmentRequest, appointmentTemplateId, templateRichiestaData); String appointmentRequestBody = Utils.convertObjectToJson(appointmentCreationRequest); @@ -648,16 +651,17 @@ public class AppointmentDao { ResponseEntity appointmentResponse = appointmentApiService.createAppointment(authorizationToken, context, appointmentRequestBody); String appointmentId = extractAppointmentIdFromResponse(appointmentResponse); - if (appointmentId != null) { - // Update application with the appointment ID - application.setAppointmentId(appointmentId); - application.setStatus(ApplicationStatusTypeEnum.APPOINTMENT.getValue()); - applicationRepository.save(application); - - // Log version history - loggingUtil.addVersionHistory( - VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldApplicationData).newData(application).build()); + if (appointmentId == null) { + throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPOINTMENT_NOT_CREATED)); } + // Update application with the appointment ID + application.setAppointmentId(appointmentId); + application.setStatus(ApplicationStatusTypeEnum.APPOINTMENT.getValue()); + applicationRepository.save(application); + + // Log version history + loggingUtil.addVersionHistory( + VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldApplicationData).newData(application).build()); appointmentCreationResponse.setAppointmentId(appointmentId); return appointmentCreationResponse; @@ -683,12 +687,10 @@ public class AppointmentDao { return null; } - public AppointmentCreationRequest parseTemplateResponseData(String jsonResponse, Long productId) { + public AppointmentCreationRequest parseTemplateResponseData(String jsonResponse) { try { - if (productId == null) { - throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPOINTMENT_CANNOT_BE_CREATED)); - } + ObjectMapper objectMapper = new ObjectMapper(); JsonNode rootNode = objectMapper.readTree(jsonResponse); JsonNode richiesteClienteArray = rootNode.path(GepafinConstant.DATA_STRING).path(GepafinConstant.RICHIESTE_CLIENTE_STRING); @@ -701,7 +703,6 @@ public class AppointmentDao { log.warn("richiesteCliente array is missing or not an array."); return new AppointmentCreationRequest(); } - boolean isMatchedAtLeastOneId = false; for (JsonNode richiestaNode : richiesteClienteArray) { if (richiestaNode.isNull()) continue; @@ -710,11 +711,8 @@ public class AppointmentDao { JsonNode prodottoNode = richiestaNode.path(AppointmentApiConstant.PRODOTTO); String prodottoCode = prodottoNode.path(AppointmentApiConstant.PRODOTTO_CODE).asText(); - if (productId.toString().equals(prodottoCode)) { - isMatchedAtLeastOneId = true; richiestaCliente.setCodProdotto(prodottoCode); richiestaCliente.setIdMotivazione(getIntValue(richiestaNode)); - richiestaCliente.setCodProdotto(productId.toString()); richiestaCliente.setCodAbi(getTextValue(richiestaNode, AppointmentApiConstant.COD_ABI)); richiestaCliente.setCodCab(getTextValue(richiestaNode, AppointmentApiConstant.COD_CAB)); richiestaCliente.setIdNota(getTextValue(richiestaNode, AppointmentApiConstant.ID_NOTA)); @@ -727,11 +725,6 @@ public class AppointmentDao { richiestaClienteList.add(richiestaCliente); } - } - - if (!isMatchedAtLeastOneId) { - throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPOINTMENT_CANNOT_BE_CREATED_BY_TEMPLATE)); - } input.setRichiestaCliente(richiestaClienteList); appointmentCreationRequest.setInput(input); diff --git a/src/main/java/net/gepafin/tendermanagement/dao/AssignedApplicationsDao.java b/src/main/java/net/gepafin/tendermanagement/dao/AssignedApplicationsDao.java index 05c65292..92f2154f 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/AssignedApplicationsDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/AssignedApplicationsDao.java @@ -10,7 +10,6 @@ import net.gepafin.tendermanagement.model.request.ApplicationEvaluationRequest; import net.gepafin.tendermanagement.model.request.AssignedApplicationsRequest; import net.gepafin.tendermanagement.model.request.UpdateAssignedApplicationRequest; import net.gepafin.tendermanagement.model.request.VersionHistoryRequest; -import net.gepafin.tendermanagement.model.response.ApplicationResponse; import net.gepafin.tendermanagement.model.response.AssignedApplicationsResponse; import net.gepafin.tendermanagement.repositories.ApplicationEvaluationRepository; import net.gepafin.tendermanagement.repositories.ApplicationRepository; @@ -31,7 +30,6 @@ import org.springframework.stereotype.Component; import java.time.LocalDateTime; import java.util.List; -import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; @@ -201,7 +199,7 @@ public class AssignedApplicationsDao { assignedApplicationsResponse.setEvaluationEndDate(applicationEvaluationEntity.get().getEndDate()); } assignedApplicationsResponse.setNumberOfCheck(application.getCall().getNumberOfCheck()); - assignedApplicationsResponse.setProductId(application.getCall().getProductId()); + assignedApplicationsResponse.setAppointmentTemplateId(application.getCall().getAppointmentTemplateId()); return assignedApplicationsResponse; } diff --git a/src/main/java/net/gepafin/tendermanagement/dao/CallDao.java b/src/main/java/net/gepafin/tendermanagement/dao/CallDao.java index 277fb68c..a913713f 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/CallDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/CallDao.java @@ -202,7 +202,7 @@ public class CallDao { callEntity.setEndTime(DateTimeUtil.parseTime(createCallRequest.getEndTime())); callEntity.setHub(userEntity.getHub()); callEntity.setNumberOfCheck(createCallRequest.getNumberOfCheck()); - callEntity.setProductId(createCallRequest.getProductId()); + callEntity.setAppointmentTemplateId(createCallRequest.getAppointmentTemplateId()); callEntity = callRepository.save(callEntity); /** This code is responsible for adding a version history log for the "Create Call" operation. **/ @@ -610,7 +610,7 @@ public class CallDao { setIfUpdated(callEntity::getConfidi, callEntity::setConfidi, updateCallRequest.getConfidi()); setIfUpdated(callEntity::getEvaluationVersion, callEntity::setEvaluationVersion, updateCallRequest.getEvaluationVersion().getValue()); setIfUpdated(callEntity::getNumberOfCheck, callEntity::setNumberOfCheck, updateCallRequest.getNumberOfCheck()); - setIfUpdated(callEntity::getProductId, callEntity::setProductId, updateCallRequest.getProductId()); + setIfUpdated(callEntity::getAppointmentTemplateId, callEntity::setAppointmentTemplateId, updateCallRequest.getAppointmentTemplateId()); callEntity = callRepository.save(callEntity); /** This code is responsible for adding a version history log for the "update call step 1" operation **/ @@ -718,7 +718,7 @@ public class CallDao { callDetailsResponseBean.setCreatedDate(callEntity.getCreatedDate()); callDetailsResponseBean.setUpdatedDate(callEntity.getUpdatedDate()); callDetailsResponseBean.setNumberOfCheck(callEntity.getNumberOfCheck()); - callDetailsResponseBean.setProductId(callEntity.getProductId()); + callDetailsResponseBean.setAppointmentTemplateId(callEntity.getAppointmentTemplateId()); return callDetailsResponseBean; } @@ -743,7 +743,7 @@ public class CallDao { createCallResponseBean.setAimedTo(amiedTo); createCallResponseBean.setCheckList(checkList); createCallResponseBean.setNumberOfCheck(callEntity.getNumberOfCheck()); - createCallResponseBean.setProductId(callEntity.getProductId()); + createCallResponseBean.setAppointmentTemplateId(callEntity.getAppointmentTemplateId()); return createCallResponseBean; } diff --git a/src/main/java/net/gepafin/tendermanagement/entities/CallEntity.java b/src/main/java/net/gepafin/tendermanagement/entities/CallEntity.java index 36c370d1..25388138 100644 --- a/src/main/java/net/gepafin/tendermanagement/entities/CallEntity.java +++ b/src/main/java/net/gepafin/tendermanagement/entities/CallEntity.java @@ -95,7 +95,7 @@ public class CallEntity extends BaseEntity { @Column(name = "NUMBER_OF_CHECK") private Long numberOfCheck; - @Column(name = "PRODUCT_ID") - private Long productId; + @Column(name = "APPOINTMENT_TEMPLATE_ID") + private Long appointmentTemplateId; } diff --git a/src/main/java/net/gepafin/tendermanagement/entities/HubEntity.java b/src/main/java/net/gepafin/tendermanagement/entities/HubEntity.java index ff6db1a6..ccd6c325 100644 --- a/src/main/java/net/gepafin/tendermanagement/entities/HubEntity.java +++ b/src/main/java/net/gepafin/tendermanagement/entities/HubEntity.java @@ -64,9 +64,6 @@ public class HubEntity extends BaseEntity{ @Column(name = "AREA_CODE") private String areaCode; - @Column(name = "APPOINTMENT_TEMPLATE_ID") - private Long appointmentTemplateId; - @Column(name = "EVALUATION_EXPIRATION_DAYS") private Long evaluationExpirationDays; } diff --git a/src/main/java/net/gepafin/tendermanagement/model/request/CreateCallRequestStep1.java b/src/main/java/net/gepafin/tendermanagement/model/request/CreateCallRequestStep1.java index c54a1454..7d4bf8cf 100644 --- a/src/main/java/net/gepafin/tendermanagement/model/request/CreateCallRequestStep1.java +++ b/src/main/java/net/gepafin/tendermanagement/model/request/CreateCallRequestStep1.java @@ -26,7 +26,7 @@ public class CreateCallRequestStep1 { private Long numberOfCheck; - private Long productId; + private Long appointmentTemplateId; private List aimedTo; diff --git a/src/main/java/net/gepafin/tendermanagement/model/request/UpdateCallRequestStep1.java b/src/main/java/net/gepafin/tendermanagement/model/request/UpdateCallRequestStep1.java index ad55d544..01a0ea39 100644 --- a/src/main/java/net/gepafin/tendermanagement/model/request/UpdateCallRequestStep1.java +++ b/src/main/java/net/gepafin/tendermanagement/model/request/UpdateCallRequestStep1.java @@ -2,7 +2,6 @@ package net.gepafin.tendermanagement.model.request; import java.math.BigDecimal; import java.time.LocalDateTime; -import java.time.LocalTime; import java.util.List; import lombok.Data; @@ -43,7 +42,7 @@ public class UpdateCallRequestStep1 { private Long numberOfCheck; - private Long productId; + private Long appointmentTemplateId; private EvaluationVersionEnum evaluationVersion; diff --git a/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationEvaluationFormResponse.java b/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationEvaluationFormResponse.java index f71cf808..f51378e0 100644 --- a/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationEvaluationFormResponse.java +++ b/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationEvaluationFormResponse.java @@ -44,7 +44,5 @@ public class ApplicationEvaluationFormResponse { private LocalDateTime dateAccepted; private LocalDateTime dateRejected; private EvaluationVersionEnum evaluationVersion; - private BigDecimal numberOfCheck; - private BigDecimal productId; } diff --git a/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationEvaluationResponse.java b/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationEvaluationResponse.java index 44f27c13..6ad84281 100644 --- a/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationEvaluationResponse.java +++ b/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationEvaluationResponse.java @@ -45,7 +45,7 @@ public class ApplicationEvaluationResponse { private LocalDateTime dateAccepted; private LocalDateTime dateRejected; private Long numberOfCheck; - private Long productId; + private Long appointmentTemplateId; private EvaluationVersionEnum evaluationVersion; } diff --git a/src/main/java/net/gepafin/tendermanagement/model/response/AssignedApplicationsResponse.java b/src/main/java/net/gepafin/tendermanagement/model/response/AssignedApplicationsResponse.java index 37311ff6..664bc946 100644 --- a/src/main/java/net/gepafin/tendermanagement/model/response/AssignedApplicationsResponse.java +++ b/src/main/java/net/gepafin/tendermanagement/model/response/AssignedApplicationsResponse.java @@ -5,7 +5,6 @@ import net.gepafin.tendermanagement.enums.AssignedApplicationEnum; import net.gepafin.tendermanagement.enums.EvaluationVersionEnum; import net.gepafin.tendermanagement.model.BaseBean; -import java.math.BigDecimal; import java.time.LocalDateTime; @Data @@ -25,7 +24,7 @@ public class AssignedApplicationsResponse extends BaseBean { private String companyName; private LocalDateTime evaluationEndDate; private Long numberOfCheck; - private Long productId; + private Long appointmentTemplateId; private EvaluationVersionEnum evaluationVersion; } diff --git a/src/main/java/net/gepafin/tendermanagement/model/response/CallDetailsResponseBean.java b/src/main/java/net/gepafin/tendermanagement/model/response/CallDetailsResponseBean.java index 76e892d1..7ee0b620 100644 --- a/src/main/java/net/gepafin/tendermanagement/model/response/CallDetailsResponseBean.java +++ b/src/main/java/net/gepafin/tendermanagement/model/response/CallDetailsResponseBean.java @@ -59,7 +59,7 @@ public class CallDetailsResponseBean { private Long numberOfCheck; - private Long productId; + private Long appointmentTemplateId; private EvaluationVersionEnum evaluationVersion; } diff --git a/src/main/java/net/gepafin/tendermanagement/model/response/CallResponse.java b/src/main/java/net/gepafin/tendermanagement/model/response/CallResponse.java index a566ab37..76289b06 100644 --- a/src/main/java/net/gepafin/tendermanagement/model/response/CallResponse.java +++ b/src/main/java/net/gepafin/tendermanagement/model/response/CallResponse.java @@ -52,7 +52,7 @@ public class CallResponse { private Long numberOfCheck; - private Long productId; + private Long appointmentTemplateId; @JsonSerialize(using = DynamicLocalTimeSerializer.class) private LocalTime startTime; 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 6acccf72..beab6aac 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 @@ -2426,4 +2426,11 @@ + + + + + diff --git a/src/main/resources/message_en.properties b/src/main/resources/message_en.properties index 87163fb4..c3b03dd7 100644 --- a/src/main/resources/message_en.properties +++ b/src/main/resources/message_en.properties @@ -371,6 +371,5 @@ validation.required.requested.amount=The Requested Amount configuration should b company.id.not.null=Company ID cannot be null. formula.amount.not.matches.requested.amount= The {0} does not matches to calculated amount. -appointment.cannot.be.created = Appointment cannot be created because call doesn't have the productId. -appointment.cannot.be.created.by.template = Product ID does not match with appointment template. - +appointment.cannot.be.created = Appointment cannot be created because call doesn't have the template id. +appointment.not.created = Appointment not created please try again. diff --git a/src/main/resources/message_it.properties b/src/main/resources/message_it.properties index 66da42e2..20705aa8 100644 --- a/src/main/resources/message_it.properties +++ b/src/main/resources/message_it.properties @@ -362,6 +362,5 @@ validation.required.requested.amount=La configurazione dell'importo richiesto company.id.not.null=L'ID dell'azienda non pu? essere nullo. formula.amount.not.matches.requested.amount=Il {0} non corrisponde all'importo calcolato. -appointment.cannot.be.created = Impossibile creare l'appuntamento perch� la chiamata non ha l'ID prodotto. -appointment.cannot.be.created.by.template = L'ID prodotto non corrisponde al modello di appuntamento. - +appointment.cannot.be.created = Impossibile creare l'appuntamento perché la chiamata non ha l'ID del modello di appuntamento. +appointment.not.created = Appuntamento non creato, riprova From 47c4eb774a86f0b810e2444a184416bc939fe7bf Mon Sep 17 00:00:00 2001 From: piyushkag Date: Mon, 17 Feb 2025 16:22:29 +0530 Subject: [PATCH 4/6] Updated code. --- src/main/resources/db/changelog/db.changelog-1.0.0.xml | 9 --------- 1 file changed, 9 deletions(-) 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 beab6aac..47b4fd1a 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 @@ -2418,19 +2418,10 @@ - - - - UNIQUE_UUID = 'p4lk3bcx1RStqTaIVVbXs' - - - - From 812f13b523137d35b0a5b36c1e7d39f178b2b6be Mon Sep 17 00:00:00 2001 From: Piyush Date: Fri, 14 Feb 2025 12:37:13 +0530 Subject: [PATCH 5/6] Resolved conflicts. --- .../tendermanagement/dao/CompanyDao.java | 41 ++++++++++++++++--- .../entities/CompanyEntity.java | 3 ++ .../entities/UserWithCompanyEntity.java | 3 -- .../db/changelog/db.changelog-1.0.0.xml | 11 +++++ ...json_column_in_company_data_06_02_2025.sql | 18 ++++++++ 5 files changed, 68 insertions(+), 8 deletions(-) create mode 100644 src/main/resources/db/dump/insert_json_column_in_company_data_06_02_2025.sql diff --git a/src/main/java/net/gepafin/tendermanagement/dao/CompanyDao.java b/src/main/java/net/gepafin/tendermanagement/dao/CompanyDao.java index 3a527d9f..1f0446a0 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/CompanyDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/CompanyDao.java @@ -122,10 +122,40 @@ public class CompanyDao { userWithCompanyEntity.setPec(companyRequest.getPec()); userWithCompanyEntity.setContactName(companyRequest.getContactName()); userWithCompanyEntity.setContactEmail(companyRequest.getContactEmail()); - userWithCompanyEntity.setJson(Utils.convertMapIntoJsonString(companyRequest.getVatCheckResponse()) ); UserWithCompanyEntity userWithCompany = userWithCompanyRepository.save(userWithCompanyEntity); /** This code is responsible for adding a version history log for the "adding user with company" operation. **/ loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.INSERT).oldData(null).newData(userWithCompany).build()); + if (StringUtils.isEmpty(companyEntity.getJson())) { + companyEntity.setJson(Utils.convertMapIntoJsonString(companyRequest.getVatCheckResponse())); + Map vatCheckResponse = companyRequest.getVatCheckResponse(); + Map data = (Map) vatCheckResponse.get("data"); + if (data != null) { + if (data.containsKey("dettaglio")) { + Map dettaglio = (Map) data.get("dettaglio"); + if (dettaglio != null) { + if (dettaglio.containsKey("codice_ateco")) { + Object codiceAtecoObj = dettaglio.get("codice_ateco"); + String codiceAteco = (codiceAtecoObj != null) ? codiceAtecoObj.toString() : null; + + if (codiceAteco != null) { + companyEntity.setCodiceAteco(codiceAteco); + } + } + } + } + } + + companyEntity = companyRepository.save(companyEntity); + + /** This code is responsible for adding a version history log for "updating company json field" operation. **/ + loggingUtil.addVersionHistory(VersionHistoryRequest.builder() + .request(request) + .actionType(VersionActionTypeEnum.INSERT) + .oldData(null) + .newData(companyEntity) + .build()); + } + return userWithCompany; } @@ -143,6 +173,7 @@ public class CompanyDao { entity.setNumberOfEmployees(request.getNumberOfEmployees()); entity.setAnnualRevenue(request.getAnnualRevenue()); entity.setHub(userEntity.getHub()); + entity.setJson(Utils.convertMapIntoJsonString(request.getVatCheckResponse())); if (request.getVatCheckResponse() != null) { Map vatCheckResponse = request.getVatCheckResponse(); Map data = (Map) vatCheckResponse.get("data"); @@ -226,10 +257,10 @@ public class CompanyDao { UserWithCompanyEntity userWithCompanyEntity = getUserWithCompany(userEntity.getId(), companyId); //cloned entity for old data UserWithCompanyEntity oldUserWithCompanyData = Utils.getClonedEntityForData(userWithCompanyEntity); - if(StringUtils.isNotBlank(companyRequest.getVatNumber())) { - String responseJson = companyRequest.getVatCheckResponse() != null ? Utils.convertMapIntoJsonString(companyRequest.getVatCheckResponse()) : null; - setIfUpdated(userWithCompanyEntity::getJson, userWithCompanyEntity::setJson, responseJson); - } +// if(StringUtils.isNotBlank(companyRequest.getVatNumber())) { +// String responseJson = companyRequest.getVatCheckResponse() != null ? Utils.convertMapIntoJsonString(companyRequest.getVatCheckResponse()) : null; +// setIfUpdated(companyEntity::getJson, companyEntity::setJson, responseJson); +// } setIfUpdated(userWithCompanyEntity::getPec, userWithCompanyEntity::setPec, companyRequest.getPec()); setIfUpdated(userWithCompanyEntity::getEmail, userWithCompanyEntity::setEmail, companyRequest.getEmail()); setIfUpdated(userWithCompanyEntity::getContactName, userWithCompanyEntity::setContactName, companyRequest.getContactName()); diff --git a/src/main/java/net/gepafin/tendermanagement/entities/CompanyEntity.java b/src/main/java/net/gepafin/tendermanagement/entities/CompanyEntity.java index 932a8758..12dc2a15 100644 --- a/src/main/java/net/gepafin/tendermanagement/entities/CompanyEntity.java +++ b/src/main/java/net/gepafin/tendermanagement/entities/CompanyEntity.java @@ -59,4 +59,7 @@ public class CompanyEntity extends BaseEntity{ @Column(name = "CODICE_ATECO") private String codiceAteco; + + @Column(name = "JSON") + private String json; } diff --git a/src/main/java/net/gepafin/tendermanagement/entities/UserWithCompanyEntity.java b/src/main/java/net/gepafin/tendermanagement/entities/UserWithCompanyEntity.java index 1f067a90..65afbe76 100644 --- a/src/main/java/net/gepafin/tendermanagement/entities/UserWithCompanyEntity.java +++ b/src/main/java/net/gepafin/tendermanagement/entities/UserWithCompanyEntity.java @@ -35,9 +35,6 @@ public class UserWithCompanyEntity extends BaseEntity{ @Column(name = "EMAIL") private String email; - @Column(name = "JSON") - private String json; - @Column(name = "IS_DELETED") private Boolean isDeleted = false; 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 47b4fd1a..7fec2eb4 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 @@ -2423,5 +2423,16 @@ oldColumnName="product_id" newColumnName="appointment_template_id"/> + + + + + + + + + + diff --git a/src/main/resources/db/dump/insert_json_column_in_company_data_06_02_2025.sql b/src/main/resources/db/dump/insert_json_column_in_company_data_06_02_2025.sql new file mode 100644 index 00000000..42c00d43 --- /dev/null +++ b/src/main/resources/db/dump/insert_json_column_in_company_data_06_02_2025.sql @@ -0,0 +1,18 @@ +UPDATE COMPANY C +SET JSON = ( + SELECT U.JSON + FROM USER_WITH_COMPANY U + WHERE U.COMPANY_ID = C.ID + AND U.IS_DELETED = false + AND U.JSON IS NOT NULL + AND U.JSON <> '' + ORDER BY U.ID ASC + LIMIT 1 +) +WHERE EXISTS ( + SELECT 1 FROM USER_WITH_COMPANY U + WHERE U.COMPANY_ID = C.ID + AND U.IS_DELETED = false + AND U.JSON IS NOT NULL + AND U.JSON <> '' +); From 967c53fa9963ad08ab9c5ccb9fecfc8b573aee8a Mon Sep 17 00:00:00 2001 From: rajesh Date: Mon, 17 Feb 2025 15:46:59 +0530 Subject: [PATCH 6/6] Updated company json script --- .../db/dump/insert_json_column_in_company_data_06_02_2025.sql | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/resources/db/dump/insert_json_column_in_company_data_06_02_2025.sql b/src/main/resources/db/dump/insert_json_column_in_company_data_06_02_2025.sql index 42c00d43..42fa12b7 100644 --- a/src/main/resources/db/dump/insert_json_column_in_company_data_06_02_2025.sql +++ b/src/main/resources/db/dump/insert_json_column_in_company_data_06_02_2025.sql @@ -3,7 +3,6 @@ SET JSON = ( SELECT U.JSON FROM USER_WITH_COMPANY U WHERE U.COMPANY_ID = C.ID - AND U.IS_DELETED = false AND U.JSON IS NOT NULL AND U.JSON <> '' ORDER BY U.ID ASC @@ -12,7 +11,6 @@ SET JSON = ( WHERE EXISTS ( SELECT 1 FROM USER_WITH_COMPANY U WHERE U.COMPANY_ID = C.ID - AND U.IS_DELETED = false AND U.JSON IS NOT NULL AND U.JSON <> '' );