Updated code for appointment creation flow and productId field to appointmentTemplateId.

This commit is contained in:
piyushkag
2025-02-17 16:17:07 +05:30
parent af97be663e
commit 5e360845a7
17 changed files with 45 additions and 57 deletions

View File

@@ -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<Object> 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<Object> 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);