Updated code for appointment creation and added a column in hub for appointment template id..
This commit is contained in:
@@ -26,7 +26,7 @@ public class AppointmentApiConstant {
|
|||||||
|
|
||||||
//Appointment creation request body fields
|
//Appointment creation request body fields
|
||||||
public static final String MOTIVAZIONE = "motivazione";
|
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_ABI = "codAbi";
|
||||||
public static final String COD_CAB = "codCab";
|
public static final String COD_CAB = "codCab";
|
||||||
public static final String ID_NOTA = "idNota";
|
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_FORMATECNICA = "codFormaTecnica";
|
||||||
public static final String COD_OPERAZIONE = "codOperazione";
|
public static final String COD_OPERAZIONE = "codOperazione";
|
||||||
public static final String MOTIVAZIONE_ID = "id";
|
public static final String MOTIVAZIONE_ID = "id";
|
||||||
|
public static final String PRODOTTO_CODE = "code";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 FORMULA_AMOUNT_NOT_MATCHED="formula.amount.not.matches.requested.amount";
|
||||||
public static final String CRITERIA_TABLE_COLUMNS="criteria_table_columns";
|
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";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -384,6 +384,7 @@ public class AppointmentDao {
|
|||||||
// Validate and save token
|
// Validate and save token
|
||||||
if (parsedResponse.getTokenId() != null) {
|
if (parsedResponse.getTokenId() != null) {
|
||||||
hub.setAppointmentAuthTokenId(parsedResponse.getTokenId());
|
hub.setAppointmentAuthTokenId(parsedResponse.getTokenId());
|
||||||
|
hub.setAreaCode(parsedResponse.getAreaCode());
|
||||||
hubRepository.save(hub);
|
hubRepository.save(hub);
|
||||||
|
|
||||||
// /** This code is responsible for adding a version history log for the "inserting token and areaCode from login odessa response for
|
// /** 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
|
// Generate authorization token and fetch template data
|
||||||
String authorizationToken = getBearerToken(hub);
|
String authorizationToken = getBearerToken(hub);
|
||||||
int areaCode = Integer.parseInt(hub.getAreaCode());
|
Long appointmentTemplateId = hub.getAppointmentTemplateId();
|
||||||
ResponseEntity<Object> response = appointmentApiService.getAppointmentTemplateForTemplateCreation(authorizationToken, areaCode);
|
ResponseEntity<Object> response = appointmentApiService.getAppointmentTemplateForTemplateCreation(authorizationToken, appointmentTemplateId);
|
||||||
|
|
||||||
if (response.getStatusCode() != HttpStatus.OK) {
|
if (response.getStatusCode() != HttpStatus.OK) {
|
||||||
log.error("Failed to retrieve appointment template for appointment creation. Status: {}", response.getStatusCode());
|
log.error("Failed to retrieve appointment template for appointment creation. Status: {}", response.getStatusCode());
|
||||||
@@ -636,10 +637,10 @@ public class AppointmentDao {
|
|||||||
|
|
||||||
// Parse template data
|
// Parse template data
|
||||||
String responseDataForTemplate = Utils.convertObjectToJson(response.getBody());
|
String responseDataForTemplate = Utils.convertObjectToJson(response.getBody());
|
||||||
AppointmentCreationRequest templateRichiestaData = parseTemplateResponseData(responseDataForTemplate);
|
AppointmentCreationRequest templateRichiestaData = parseTemplateResponseData(responseDataForTemplate, application.getCall().getProductId());
|
||||||
|
|
||||||
// Build the appointment request body
|
// Build the appointment request body
|
||||||
AppointmentCreationRequest appointmentCreationRequest = buildAppointmentCreationRequest(applicationId, createAppointmentRequest, hub.getAreaCode(),
|
AppointmentCreationRequest appointmentCreationRequest = buildAppointmentCreationRequest(applicationId, createAppointmentRequest, hub.getAppointmentTemplateId(),
|
||||||
templateRichiestaData);
|
templateRichiestaData);
|
||||||
String appointmentRequestBody = Utils.convertObjectToJson(appointmentCreationRequest);
|
String appointmentRequestBody = Utils.convertObjectToJson(appointmentCreationRequest);
|
||||||
|
|
||||||
@@ -682,8 +683,12 @@ public class AppointmentDao {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AppointmentCreationRequest parseTemplateResponseData(String jsonResponse) {
|
public AppointmentCreationRequest parseTemplateResponseData(String jsonResponse, Long productId) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (productId == null) {
|
||||||
|
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPOINTMENT_CANNOT_BE_CREATED));
|
||||||
|
}
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
JsonNode rootNode = objectMapper.readTree(jsonResponse);
|
JsonNode rootNode = objectMapper.readTree(jsonResponse);
|
||||||
JsonNode richiesteClienteArray = rootNode.path(GepafinConstant.DATA_STRING).path(GepafinConstant.RICHIESTE_CLIENTE_STRING);
|
JsonNode richiesteClienteArray = rootNode.path(GepafinConstant.DATA_STRING).path(GepafinConstant.RICHIESTE_CLIENTE_STRING);
|
||||||
@@ -694,15 +699,22 @@ public class AppointmentDao {
|
|||||||
List<AppointmentCreationRequest.RichiestaCliente> richiestaClienteList = new ArrayList<>();
|
List<AppointmentCreationRequest.RichiestaCliente> richiestaClienteList = new ArrayList<>();
|
||||||
if (!richiesteClienteArray.isArray()) {
|
if (!richiesteClienteArray.isArray()) {
|
||||||
log.warn("richiesteCliente array is missing or not an array.");
|
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) {
|
for (JsonNode richiestaNode : richiesteClienteArray) {
|
||||||
if (richiestaNode.isNull()) continue;
|
if (richiestaNode.isNull())
|
||||||
|
continue;
|
||||||
|
|
||||||
AppointmentCreationRequest.RichiestaCliente richiestaCliente = new AppointmentCreationRequest.RichiestaCliente();
|
AppointmentCreationRequest.RichiestaCliente richiestaCliente = new AppointmentCreationRequest.RichiestaCliente();
|
||||||
|
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.setIdMotivazione(getIntValue(richiestaNode));
|
||||||
richiestaCliente.setCodProdotto(getTextValue(richiestaNode, AppointmentApiConstant.COD_PRODOTTO));
|
richiestaCliente.setCodProdotto(productId.toString());
|
||||||
richiestaCliente.setCodAbi(getTextValue(richiestaNode, AppointmentApiConstant.COD_ABI));
|
richiestaCliente.setCodAbi(getTextValue(richiestaNode, AppointmentApiConstant.COD_ABI));
|
||||||
richiestaCliente.setCodCab(getTextValue(richiestaNode, AppointmentApiConstant.COD_CAB));
|
richiestaCliente.setCodCab(getTextValue(richiestaNode, AppointmentApiConstant.COD_CAB));
|
||||||
richiestaCliente.setIdNota(getTextValue(richiestaNode, AppointmentApiConstant.ID_NOTA));
|
richiestaCliente.setIdNota(getTextValue(richiestaNode, AppointmentApiConstant.ID_NOTA));
|
||||||
@@ -715,6 +727,11 @@ public class AppointmentDao {
|
|||||||
|
|
||||||
richiestaClienteList.add(richiestaCliente);
|
richiestaClienteList.add(richiestaCliente);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isMatchedAtLeastOneId) {
|
||||||
|
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPOINTMENT_CANNOT_BE_CREATED_BY_TEMPLATE));
|
||||||
|
}
|
||||||
|
|
||||||
input.setRichiestaCliente(richiestaClienteList);
|
input.setRichiestaCliente(richiestaClienteList);
|
||||||
appointmentCreationRequest.setInput(input);
|
appointmentCreationRequest.setInput(input);
|
||||||
@@ -724,21 +741,20 @@ public class AppointmentDao {
|
|||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
log.error("JSON processing error: {}", e.getMessage(), e);
|
log.error("JSON processing error: {}", e.getMessage(), e);
|
||||||
throw new IllegalStateException("Invalid JSON structure in template response", 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) {
|
private String getTextValue(JsonNode node, String fieldName) {
|
||||||
|
|
||||||
return node.path(fieldName).isTextual() ? node.path(fieldName).asText() : null;
|
return node.path(fieldName).isTextual() ? node.path(fieldName).asText() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getIntValue(JsonNode node) {
|
private int getIntValue(JsonNode node) {
|
||||||
|
|
||||||
return node.path(AppointmentApiConstant.MOTIVAZIONE).path(AppointmentApiConstant.MOTIVAZIONE_ID).asInt();
|
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) {
|
AppointmentCreationRequest templateRichiestaData) {
|
||||||
|
|
||||||
ApplicationEntity application = applicationService.validateApplication(applicationId);
|
ApplicationEntity application = applicationService.validateApplication(applicationId);
|
||||||
|
|||||||
@@ -64,6 +64,9 @@ public class HubEntity extends BaseEntity{
|
|||||||
@Column(name = "AREA_CODE")
|
@Column(name = "AREA_CODE")
|
||||||
private String areaCode;
|
private String areaCode;
|
||||||
|
|
||||||
|
@Column(name = "APPOINTMENT_TEMPLATE_ID")
|
||||||
|
private Long appointmentTemplateId;
|
||||||
|
|
||||||
@Column(name = "EVALUATION_EXPIRATION_DAYS")
|
@Column(name = "EVALUATION_EXPIRATION_DAYS")
|
||||||
private Long evaluationExpirationDays;
|
private Long evaluationExpirationDays;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ public class AppointmentCreationRequest {
|
|||||||
|
|
||||||
@Data
|
@Data
|
||||||
public static class Input {
|
public static class Input {
|
||||||
private String id;
|
private Long id;
|
||||||
private String ndg;
|
private String ndg;
|
||||||
private List<RichiestaCliente> richiestaCliente;
|
private List<RichiestaCliente> richiestaCliente;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public interface AppointmentApiService {
|
|||||||
ResponseEntity<Object> getVisuraList(@RequestBody String visuraRequest, @RequestHeader("Authorization") String token);
|
ResponseEntity<Object> getVisuraList(@RequestBody String visuraRequest, @RequestHeader("Authorization") String token);
|
||||||
|
|
||||||
@GetMapping(value = AppointmentApiConstant.GET_APPOINTMENT_TEMPLATE, consumes = MediaType.APPLICATION_JSON_VALUE)
|
@GetMapping(value = AppointmentApiConstant.GET_APPOINTMENT_TEMPLATE, consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||||
ResponseEntity<Object> getAppointmentTemplateForTemplateCreation(@RequestHeader("Authorization") String token, @RequestParam("idAppuntamentoTemplate") int templateId);
|
ResponseEntity<Object> getAppointmentTemplateForTemplateCreation(@RequestHeader("Authorization") String token, @RequestParam("idAppuntamentoTemplate") Long templateId);
|
||||||
|
|
||||||
@PostMapping(value = AppointmentApiConstant.CREATE_APPOINTMENT_FROM_TEMPLATE, consumes = MediaType.APPLICATION_JSON_VALUE)
|
@PostMapping(value = AppointmentApiConstant.CREATE_APPOINTMENT_FROM_TEMPLATE, consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||||
ResponseEntity<Object> createAppointment(@RequestHeader("Authorization") String token, @RequestHeader("context") String context, String appointmentCreationRequest);
|
ResponseEntity<Object> createAppointment(@RequestHeader("Authorization") String token, @RequestHeader("context") String context, String appointmentCreationRequest);
|
||||||
|
|||||||
@@ -2418,4 +2418,12 @@
|
|||||||
<modifyDataType tableName="call" columnName="product_id" newDataType="INTEGER"/>
|
<modifyDataType tableName="call" columnName="product_id" newDataType="INTEGER"/>
|
||||||
</changeSet>
|
</changeSet>
|
||||||
|
|
||||||
|
<changeSet id="11-02-2025_PK_175119" author="Piyush Kag">
|
||||||
|
<update tableName="hub">
|
||||||
|
<column name="appointment_template_id"
|
||||||
|
value='7'/>
|
||||||
|
<where>UNIQUE_UUID = 'p4lk3bcx1RStqTaIVVbXs'</where>
|
||||||
|
</update>
|
||||||
|
</changeSet>
|
||||||
|
|
||||||
</databaseChangeLog>
|
</databaseChangeLog>
|
||||||
|
|||||||
@@ -371,4 +371,6 @@ validation.required.requested.amount=The Requested Amount configuration should b
|
|||||||
company.id.not.null=Company ID cannot be null.
|
company.id.not.null=Company ID cannot be null.
|
||||||
formula.amount.not.matches.requested.amount= The {0} does not matches to calculated amount.
|
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.
|
||||||
|
|
||||||
|
|||||||
@@ -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.
|
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.
|
formula.amount.not.matches.requested.amount=Il {0} non corrisponde all'importo calcolato.
|
||||||
|
|
||||||
|
appointment.cannot.be.created = Impossibile creare l'appuntamento perch<63> la chiamata non ha l'ID prodotto.
|
||||||
|
appointment.cannot.be.created.by.template = L'ID prodotto non corrisponde al modello di appuntamento.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user