diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIAvailability.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIAvailability.java index 14582d8..1553a18 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIAvailability.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIAvailability.java @@ -30,7 +30,7 @@ import org.openstreetmap.josm.tools.Logging; import org.openstreetmap.josm.tools.Territories; public final class MapWithAIAvailability { - private static String rapidReleases = "https://github.com/facebookmicrosites/Open-Mapping-At-Facebook/raw/master/data/rapid_realeases.geojson"; + private static String rapidReleases = "https://github.com/facebookmicrosites/Open-Mapping-At-Facebook/raw/master/data/rapid_releases.geojson"; private static final Map> COUNTRIES = new HashMap<>(); private static final Map POSSIBLE_DATA_POINTS = new TreeMap<>(); private static final Map COUNTRY_NAME_FIX = new HashMap<>(); @@ -49,6 +49,7 @@ public final class MapWithAIAvailability { private MapWithAIAvailability() { try (CachedFile cachedRapidReleases = new CachedFile(rapidReleases); JsonParser parser = Json.createParser(cachedRapidReleases.getContentReader())) { + cachedRapidReleases.setMaxAge(604800); parser.next(); final Stream> entries = parser.getObjectStream(); final Optional> objects = entries @@ -57,7 +58,8 @@ public final class MapWithAIAvailability { final JsonObject value = objects.get().getValue().asJsonObject(); final JsonObject centroid = value.getJsonObject("rapid_releases_1011_centroid"); final JsonArray countries = centroid.getJsonArray("geometries"); - parseForCountries(countries); + COUNTRIES.clear(); + COUNTRIES.putAll(parseForCountries(countries)); } } catch (IOException e) { Logging.debug(e); @@ -74,7 +76,8 @@ public final class MapWithAIAvailability { return InstanceHelper.instance; } - private static void parseForCountries(JsonArray countries) { + private static Map> parseForCountries(JsonArray countries) { + Map> returnCountries = new TreeMap<>(); for (int i = 0; i < countries.size(); i++) { final JsonObject country = countries.getJsonObject(i).getJsonObject("properties"); final String countryName = cornerCaseNames(country.getString("Country")); @@ -91,18 +94,19 @@ public final class MapWithAIAvailability { if (realCountry.isPresent()) { final String key = realCountry.get().get("ISO3166-1:alpha2"); // We need to handle cases like Alaska more elegantly - final Map data = COUNTRIES.getOrDefault(key, new TreeMap<>()); + final Map data = returnCountries.getOrDefault(key, new TreeMap<>()); for (final Entry entry : POSSIBLE_DATA_POINTS.entrySet()) { final boolean hasData = "yes".equals(country.getString(entry.getValue())); if (hasData || !data.containsKey(entry.getKey())) { data.put(entry.getKey(), hasData); } } - COUNTRIES.put(key, data); + returnCountries.put(key, data); } else { Logging.error(tr("{0}: We couldn''t find {1}", MapWithAIPlugin.NAME, countryName)); } } + return returnCountries; } private static String cornerCaseNames(String name) {