Skip to content

Commit

Permalink
'#1487 Adds tree node to represent the georeferenced items that the
Browse files Browse the repository at this point in the history
nominatim server was unable to GEOCODE (error).
  • Loading branch information
patrickdalla committed Sep 21, 2023
1 parent 38350bf commit 832a113
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class NominatimTask extends AbstractTask {

private static Logger LOGGER = LoggerFactory.getLogger(NominatimTask.class);

static final String NOMINATIM_METADATA = "nominatim:geojson";
public static final String NOMINATIM_METADATA = "nominatim:geojson";
protected static final long CUSTOM_KEEP_ALIVE = 5000;

public static final String NOMINATIM_COUNTRY_METADATA = "nominatim:country";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class NominatimTreeModel implements TreeModel {

IMultiSearchResultProvider app;
static String ROOT = "Nominatim Entities";
static String UNABLETOGEOCODE = "(Unable to GeoCode)";

private static boolean modelLoaded = false;

Expand Down Expand Up @@ -131,6 +132,32 @@ public Suburb(Country country, State state, City city, String name) {
TreeMap<State, City[]> citiesMap = new TreeMap<>();
TreeMap<City, Suburb[]> suburbsMap = new TreeMap<>();

private Boolean hasUnableToGeoCode = null;

public boolean hasUnableToGeoCode() {
if (hasUnableToGeoCode == null) {
try {
LeafReader reader = app.getIPEDSource().getLeafReader();

SortedSetDocValues ssdv = reader.getSortedSetDocValues(NominatimTask.NOMINATIM_METADATA);
TermsEnum te = ssdv.termsEnum();
BytesRef br = te.next();
if (br != null) {
if (br.utf8ToString().startsWith("{\"error\"")) {
hasUnableToGeoCode = true;
} else {
hasUnableToGeoCode = false;
}

}
} catch (IOException e) {
// TODO: handle exception
}
}

return hasUnableToGeoCode;
}

public ArrayList<Country> getCountries() {
if (countries == null) {
countries = new ArrayList<>();
Expand Down Expand Up @@ -287,7 +314,15 @@ public Object getChild(Object parent, int index) {
return null;
}
if (parent == ROOT) {
return getCountries().get(index);
if (hasUnableToGeoCode()) {
if (index == getCountries().size()) {
return UNABLETOGEOCODE;
} else {
return getCountries().get(index);
}
} else {
return getCountries().get(index);
}
}
if (parent instanceof Country) {
return getStates((Country) parent)[index];
Expand All @@ -307,7 +342,11 @@ public int getChildCount(Object parent) {
return 0;
}
if (parent == ROOT) {
return getCountries().size();
if (hasUnableToGeoCode()) {
return getCountries().size() + 1;
} else {
return getCountries().size();
}
}
if (parent instanceof Country) {
return getStates((Country) parent).length;
Expand All @@ -327,7 +366,11 @@ public boolean isLeaf(Object node) {
return true;
}
if (node == ROOT) {
return getCountries().size() == 0;
if (hasUnableToGeoCode()) {
return false;
} else {
return getCountries().size() == 0;
}
}
if (node instanceof Country) {
return getStates((Country) node).length == 0;
Expand Down

0 comments on commit 832a113

Please sign in to comment.