Merge pull request #304 from Kitzanos/visura-update-v1-prod

Cherry-pick (Updated code for visura response and added logs for better tracking.)
This commit is contained in:
Rinaldo
2025-06-05 13:08:55 +02:00
committed by GitHub

View File

@@ -772,19 +772,28 @@ public class AppointmentDao {
public AppointmentLoginResponse parseVisuraResponse(String jsonResponse) {
try {
// Log full raw JSON for debug purposes
log.info("Raw Visura JSON Response: {}", jsonResponse);
ObjectMapper objectMapper = new ObjectMapper();
JsonNode rootNode = objectMapper.readTree(jsonResponse);
JsonNode dataNode = rootNode.get(GepafinConstant.DATA_STRING);
if (dataNode != null) {
if (dataNode != null && dataNode.isObject()) {
AppointmentLoginResponse response = new AppointmentLoginResponse();
response.setIdVisura(normalizeNullValue(dataNode.get(GepafinConstant.ID_VISURA_STRING).asText()));
response.setNdg(normalizeNullValue(dataNode.get(GepafinConstant.NDG_STRING).asText()));
JsonNode idVisuraNode = dataNode.get(GepafinConstant.ID_VISURA_STRING);
JsonNode ndgNode = dataNode.get(GepafinConstant.NDG_STRING);
if (idVisuraNode == null || ndgNode == null) {
log.error("Missing expected fields in 'data' node. JSON: {}", dataNode);
}
response.setIdVisura(normalizeNullValue(idVisuraNode != null ? idVisuraNode.asText() : null));
response.setNdg(normalizeNullValue(ndgNode != null ? ndgNode.asText() : null));
return response;
} else {
throw new RuntimeException("Invalid JSON structure: Missing 'data' node.");
System.err.println("Invalid JSON: 'data' node is missing or not an object.");
throw new RuntimeException("Invalid JSON structure: Missing or malformed 'data' node.");
}
} catch (Exception e) {
System.err.println("Exception while parsing Visura response: " + e.getMessage());
throw new RuntimeException("Failed to parse response: " + e.getMessage(), e);
}
}