Bugfix: improve geocoding logic for Azure Maps API; enhance validation and address mapping in batch processing
This commit is contained in:
parent
2aaf820bdc
commit
23ee5fad79
4 changed files with 29 additions and 7 deletions
|
|
@ -3,6 +3,10 @@ package de.avatic.lcc.model.azuremaps.geocoding.batch;
|
|||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class BatchItem {
|
||||
|
||||
@JsonProperty("query")
|
||||
private String query;
|
||||
|
||||
@JsonProperty("addressLine")
|
||||
private String addressLine;
|
||||
|
||||
|
|
@ -18,8 +22,8 @@ public class BatchItem {
|
|||
public BatchItem() {
|
||||
}
|
||||
|
||||
public BatchItem(String addressLine) {
|
||||
this.addressLine = addressLine;
|
||||
public BatchItem(String query) {
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
public String getAddressLine() {
|
||||
|
|
@ -53,4 +57,12 @@ public class BatchItem {
|
|||
public void setPostalCode(String postalCode) {
|
||||
this.postalCode = postalCode;
|
||||
}
|
||||
|
||||
public String getQuery() {
|
||||
return query;
|
||||
}
|
||||
|
||||
public void setQuery(String query) {
|
||||
this.query = query;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import de.avatic.lcc.model.azuremaps.geocoding.batch.BatchGeocodingRequest;
|
|||
import de.avatic.lcc.model.azuremaps.geocoding.batch.BatchGeocodingResponse;
|
||||
import de.avatic.lcc.model.azuremaps.geocoding.batch.BatchItem;
|
||||
import de.avatic.lcc.model.bulk.BulkInstruction;
|
||||
import de.avatic.lcc.model.country.IsoCode;
|
||||
import de.avatic.lcc.util.exception.internalerror.ExcelValidationError;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
@ -69,10 +70,16 @@ public class BatchGeoApiService {
|
|||
var result = chunkResult.get().getBatchItems().get(itemIdx);
|
||||
var node = chunk.get(itemIdx).getEntity();
|
||||
|
||||
if (!result.getFeatures().isEmpty() && result.getFeatures().getFirst().getProperties().getConfidence().equalsIgnoreCase("high")) {
|
||||
if (!result.getFeatures().isEmpty() &&
|
||||
(result.getFeatures().getFirst().getProperties().getConfidence().equalsIgnoreCase("high") ||
|
||||
result.getFeatures().getFirst().getProperties().getConfidence().equalsIgnoreCase("medium") ||
|
||||
result.getFeatures().getFirst().getProperties().getMatchCodes().stream().anyMatch(s -> s.equalsIgnoreCase("good")))) {
|
||||
var geometry = result.getFeatures().getFirst().getGeometry();
|
||||
var properties = result.getFeatures().getFirst().getProperties();
|
||||
node.setGeoLng(BigDecimal.valueOf(geometry.getCoordinates().get(0)));
|
||||
node.setGeoLat(BigDecimal.valueOf(geometry.getCoordinates().get(1)));
|
||||
node.setAddress(properties.getAddress().getFormattedAddress());
|
||||
node.setCountryId(IsoCode.valueOf(properties.getAddress().getCountryRegion().getIso()));
|
||||
} else {
|
||||
logger.warn("Geocoding failed for address {}", node.getAddress());
|
||||
throw new ExcelValidationError("Unable to geocode " + node.getName() + ". Please check your address or enter geo position yourself.");
|
||||
|
|
|
|||
|
|
@ -51,9 +51,10 @@ public class GeoApiService {
|
|||
try {
|
||||
URI uri = UriComponentsBuilder.fromUriString(AZURE_MAPS_GEOCODING_URL)
|
||||
.queryParam("api-version", "2025-01-01")
|
||||
.queryParam("query", address)
|
||||
.queryParam("query", "{address}")
|
||||
.queryParam("subscription-key", subscriptionKey)
|
||||
.build()
|
||||
.buildAndExpand(address)
|
||||
.encode()
|
||||
.toUri();
|
||||
|
||||
logger.info("Calling Azure Maps API for address: {}", address);
|
||||
|
|
|
|||
|
|
@ -156,7 +156,8 @@ public class ConstraintGenerator {
|
|||
|
||||
public void validateDecimalConstraint(Row row, int columnIdx, double min, double max, boolean allowEmpty) {
|
||||
|
||||
checkEmptyCell(row, columnIdx, allowEmpty);
|
||||
if(checkEmptyCell(row, columnIdx, allowEmpty))
|
||||
return;
|
||||
|
||||
CellType cellType = row.getCell(columnIdx).getCellType();
|
||||
|
||||
|
|
@ -240,7 +241,8 @@ public class ConstraintGenerator {
|
|||
|
||||
public void validateNumericCell(Row row, int columnIdx, boolean allowEmpty) {
|
||||
|
||||
checkEmptyCell(row, columnIdx, allowEmpty);
|
||||
if(checkEmptyCell(row, columnIdx, allowEmpty))
|
||||
return;
|
||||
|
||||
CellType cellType = row.getCell(columnIdx).getCellType();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue