Merge pull request #209 from Kitzanos/feature/GEPAFINBE-126

GEPAFINBE-126 (Production Create Appointments (Only for Hub Gepafin))
This commit is contained in:
Rinaldo
2025-02-17 13:00:11 +01:00
committed by GitHub
19 changed files with 116 additions and 58 deletions

View File

@@ -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 PRODOTTO = "prodotto";
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";
public static final String PRODOTTO_CODE = "code";
}

View File

@@ -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";
@@ -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_NOT_CREATED = "appointment.not.created";
}

View File

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

View File

@@ -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;
@@ -406,10 +402,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 +627,11 @@ public class AppointmentDao {
// Generate authorization token and fetch template data
String authorizationToken = getBearerToken(hub);
ResponseEntity<Object> response = appointmentApiService.getAppointmentTemplateForTemplateCreation(authorizationToken);
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) {
log.error("Failed to retrieve appointment template for appointment creation. Status: {}", response.getStatusCode());
@@ -638,7 +643,7 @@ public class AppointmentDao {
AppointmentCreationRequest templateRichiestaData = parseTemplateResponseData(responseDataForTemplate);
// Build the appointment request body
AppointmentCreationRequest appointmentCreationRequest = buildAppointmentCreationRequest(applicationId, createAppointmentRequest, hub.getAreaCode(),
AppointmentCreationRequest appointmentCreationRequest = buildAppointmentCreationRequest(applicationId, createAppointmentRequest, appointmentTemplateId,
templateRichiestaData);
String appointmentRequestBody = Utils.convertObjectToJson(appointmentCreationRequest);
@@ -646,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;
@@ -684,32 +690,64 @@ 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<AppointmentCreationRequest.RichiestaCliente> 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();
}
for (JsonNode richiestaNode : richiesteClienteArray) {
if (richiestaNode.isNull())
continue;
AppointmentCreationRequest.RichiestaCliente richiestaCliente = new AppointmentCreationRequest.RichiestaCliente();
JsonNode prodottoNode = richiestaNode.path(AppointmentApiConstant.PRODOTTO);
String prodottoCode = prodottoNode.path(AppointmentApiConstant.PRODOTTO_CODE).asText();
richiestaCliente.setCodProdotto(prodottoCode);
richiestaCliente.setIdMotivazione(getIntValue(richiestaNode));
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 (Exception e) {
log.error("Error parsing template response: {}", e.getMessage(), e);
throw new IllegalStateException("Failed to parse template response", e);
} catch (JsonProcessingException e) {
log.error("JSON processing error: {}", e.getMessage(), e);
throw new IllegalStateException("Invalid JSON structure in template response", e);
}
}
public AppointmentCreationRequest buildAppointmentCreationRequest(Long applicationId, CreateAppointmentRequest createAppointmentRequest, String areaCode,
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, Long areaCode,
AppointmentCreationRequest templateRichiestaData) {
ApplicationEntity application = applicationService.validateApplication(applicationId);
@@ -733,7 +771,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);
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -11,7 +11,7 @@ public class AppointmentCreationRequest {
@Data
public static class Input {
private String id;
private Long id;
private String ndg;
private List<RichiestaCliente> richiestaCliente;
}
@@ -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;

View File

@@ -26,7 +26,7 @@ public class CreateCallRequestStep1 {
private Long numberOfCheck;
private Long productId;
private Long appointmentTemplateId;
private List<LookUpDataReq> aimedTo;

View File

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

View File

@@ -44,7 +44,5 @@ public class ApplicationEvaluationFormResponse {
private LocalDateTime dateAccepted;
private LocalDateTime dateRejected;
private EvaluationVersionEnum evaluationVersion;
private BigDecimal numberOfCheck;
private BigDecimal productId;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -59,7 +59,7 @@ public class CallDetailsResponseBean {
private Long numberOfCheck;
private Long productId;
private Long appointmentTemplateId;
private EvaluationVersionEnum evaluationVersion;
}

View File

@@ -52,7 +52,7 @@ public class CallResponse {
private Long numberOfCheck;
private Long productId;
private Long appointmentTemplateId;
@JsonSerialize(using = DynamicLocalTimeSerializer.class)
private LocalTime startTime;

View File

@@ -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<Object> getVisuraList(@RequestBody String visuraRequest, @RequestHeader("Authorization") String token);
@GetMapping(value = AppointmentApiConstant.GET_APPOINTMENT_TEMPLATE, consumes = MediaType.APPLICATION_JSON_VALUE)
ResponseEntity<Object> getAppointmentTemplateForTemplateCreation(@RequestHeader("Authorization") String token);
ResponseEntity<Object> getAppointmentTemplateForTemplateCreation(@RequestHeader("Authorization") String token, @RequestParam("idAppuntamentoTemplate") Long templateId);
@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);

View File

@@ -2429,4 +2429,10 @@
<modifyDataType tableName="call" columnName="product_id" newDataType="INTEGER"/>
</changeSet>
<changeSet id="17-02-2025_PK_025237" author="Piyush Kag">
<renameColumn tableName="call"
oldColumnName="product_id"
newColumnName="appointment_template_id"/>
</changeSet>
</databaseChangeLog>

View File

@@ -371,4 +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 template id.
appointment.not.created = Appointment not created please try again.

View File

@@ -362,4 +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 del modello di appuntamento.
appointment.not.created = Appuntamento non creato, riprova