Log geocode response in extracted data
All checks were successful
build-and-deploy / build-deploy (push) Successful in 33s
All checks were successful
build-and-deploy / build-deploy (push) Successful in 33s
This commit is contained in:
@@ -426,13 +426,19 @@ class DocumentExtractionService(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun applyBookingCityUpdates(document: GuestDocument, results: Map<String, String>) {
|
private fun applyBookingCityUpdates(document: GuestDocument, results: MutableMap<String, String>) {
|
||||||
val bookingId = document.booking?.id ?: return
|
val bookingId = document.booking?.id ?: return
|
||||||
val booking = bookingRepo.findById(bookingId).orElse(null) ?: return
|
val booking = bookingRepo.findById(bookingId).orElse(null) ?: return
|
||||||
if (booking.fromCity?.isNotBlank() == true && booking.toCity?.isNotBlank() == true) return
|
if (booking.fromCity?.isNotBlank() == true && booking.toCity?.isNotBlank() == true) return
|
||||||
val pin = cleanedValue(results[DocumentPrompts.PIN_CODE.first]) ?: return
|
val pin = cleanedValue(results[DocumentPrompts.PIN_CODE.first]) ?: return
|
||||||
if (!isValidPin(pin)) return
|
if (!isValidPin(pin)) return
|
||||||
val resolved = googleGeocodingClient.resolveCityState(pin) ?: return
|
val geocode = googleGeocodingClient.resolveCityState(pin)
|
||||||
|
geocode.status?.let { results["geoStatus"] = it }
|
||||||
|
if (geocode.rawResponse != null) {
|
||||||
|
results["geoResponse"] = geocode.rawResponse.take(4000)
|
||||||
|
}
|
||||||
|
val resolved = geocode.resolvedCityState ?: return
|
||||||
|
results["geoResolved"] = resolved
|
||||||
var updated = false
|
var updated = false
|
||||||
if (booking.fromCity.isNullOrBlank()) {
|
if (booking.fromCity.isNullOrBlank()) {
|
||||||
booking.fromCity = resolved
|
booking.fromCity = resolved
|
||||||
|
|||||||
@@ -18,8 +18,10 @@ class GoogleGeocodingClient(
|
|||||||
) {
|
) {
|
||||||
private val logger = LoggerFactory.getLogger(GoogleGeocodingClient::class.java)
|
private val logger = LoggerFactory.getLogger(GoogleGeocodingClient::class.java)
|
||||||
|
|
||||||
fun resolveCityState(pinCode: String): String? {
|
fun resolveCityState(pinCode: String): GeocodeResult {
|
||||||
if (apiKey.isBlank()) return null
|
if (apiKey.isBlank()) {
|
||||||
|
return GeocodeResult(null, null, "NO_API_KEY")
|
||||||
|
}
|
||||||
return try {
|
return try {
|
||||||
val url = UriComponentsBuilder.fromUriString(baseUrl)
|
val url = UriComponentsBuilder.fromUriString(baseUrl)
|
||||||
.queryParam("components", "postal_code:$pinCode|country:IN")
|
.queryParam("components", "postal_code:$pinCode|country:IN")
|
||||||
@@ -27,11 +29,12 @@ class GoogleGeocodingClient(
|
|||||||
.queryParam("key", apiKey)
|
.queryParam("key", apiKey)
|
||||||
.toUriString()
|
.toUriString()
|
||||||
val response = restTemplate.getForEntity(url, String::class.java)
|
val response = restTemplate.getForEntity(url, String::class.java)
|
||||||
val body = response.body ?: return null
|
val body = response.body ?: return GeocodeResult(null, null, "EMPTY_BODY")
|
||||||
parseCityState(body)
|
val parsed = parseCityState(body)
|
||||||
|
GeocodeResult(parsed, body, "OK")
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
logger.warn("Geocoding failed: {}", ex.message)
|
logger.warn("Geocoding failed: {}", ex.message)
|
||||||
null
|
GeocodeResult(null, null, "ERROR")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,3 +70,9 @@ class GoogleGeocodingClient(
|
|||||||
return listOfNotNull(preferredCity, state?.trim()?.ifBlank { null }).joinToString(", ")
|
return listOfNotNull(preferredCity, state?.trim()?.ifBlank { null }).joinToString(", ")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data class GeocodeResult(
|
||||||
|
val resolvedCityState: String?,
|
||||||
|
val rawResponse: String?,
|
||||||
|
val status: String?
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user