diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/DataAvailability.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/DataAvailability.java index 50ff54c..ff513bd 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/DataAvailability.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/DataAvailability.java @@ -14,7 +14,6 @@ import java.util.TreeMap; import java.util.stream.Collectors; import javax.json.Json; -import javax.json.JsonArray; import javax.json.JsonException; import javax.json.JsonObject; import javax.json.JsonValue; @@ -131,10 +130,10 @@ public class DataAvailability { */ private static void parseCountries(Map> countriesMap, JsonValue countries, JsonValue information) { - if (JsonValue.ValueType.ARRAY.equals(countries.getValueType())) { - parseCountriesArray(countriesMap, countries.asJsonArray(), information); - } else if (JsonValue.ValueType.OBJECT.equals(countries.getValueType())) { + if (JsonValue.ValueType.OBJECT.equals(countries.getValueType())) { parseCountriesObject(countriesMap, countries.asJsonObject(), information); + } else { + Logging.error("MapWithAI: Check format of countries map from MapWithAI"); } } @@ -169,33 +168,6 @@ public class DataAvailability { } } - /** - * Parse a JsonArray for countries - * - * @param countriesMap The countries map (will be modified) - * @param countryArray The country array (JsonArray) - * @param information The information for the source - */ - private static void parseCountriesArray(Map> countriesMap, JsonArray countryArray, - JsonValue information) { - List array = countryArray.parallelStream() - .filter(c -> JsonValue.ValueType.STRING.equals(c.getValueType())).map(JsonValue::toString) - .map(DataAvailability::stripQuotes).collect(Collectors.toList()); - if (JsonValue.ValueType.OBJECT.equals(information.getValueType()) - && information.asJsonObject().containsKey(PROVIDES)) { - List provides = information.asJsonObject().getJsonArray(PROVIDES).parallelStream() - .filter(p -> JsonValue.ValueType.STRING.equals(p.getValueType())).map(JsonValue::toString) - .map(DataAvailability::stripQuotes).collect(Collectors.toList()); - for (String countryValue : array) { - for (String provide : provides) { - Map providesMap = countriesMap.getOrDefault(countryValue, new TreeMap<>()); - countriesMap.putIfAbsent(countryValue, providesMap); - providesMap.put(provide, true); - } - } - } - } - /** * Strip double quotes (") from a string * diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIPreferenceHelper.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIPreferenceHelper.java index a4489ba..c49137f 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIPreferenceHelper.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIPreferenceHelper.java @@ -78,27 +78,6 @@ public final class MapWithAIPreferenceHelper { returnMap.add(layerMap); } } - if (returnMap.isEmpty()) { - final List defaultAPIs = Collections.singletonList(DEFAULT_MAPWITHAI_API); - final List defaultList = Config.getPref().getList(API_CONFIG).isEmpty() ? defaultAPIs - : Config.getPref().getList(API_CONFIG); - returnMap.addAll(defaultList.stream().map(string -> { - final TreeMap map = new TreeMap<>(); - map.put(URL_STRING, string); - return map; - }).collect(Collectors.toList())); - } - returnMap.parallelStream().forEach(map -> { - final String url = map.get(URL_STRING); - if (DEFAULT_MAPWITHAI_API.equals(url)) { - map.putIfAbsent(SOURCE_STRING, MapWithAIPlugin.NAME); - map.putIfAbsent(ENABLED_STRING, "true"); - map.putIfAbsent(PARAMETERS_STRING, DEFAULT_MAPWITHAI_API_PARAMETERS); - } else { - map.putIfAbsent(SOURCE_STRING, url); - map.putIfAbsent(ENABLED_STRING, Boolean.FALSE.toString()); - } - }); return returnMap; } diff --git a/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIDataUtilsTest.java b/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIDataUtilsTest.java index 43a3d52..f1f3536 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIDataUtilsTest.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIDataUtilsTest.java @@ -200,14 +200,6 @@ public class MapWithAIDataUtilsTest { MapWithAIPreferenceHelper.setMapWithAIUrl("Fake2", fakeUrl, true, true); assertEquals(1, MapWithAIPreferenceHelper.getMapWithAIUrl().parallelStream() .filter(map -> fakeUrl.equals(map.get("url"))).count(), "There should only be one fakeUrl"); - MapWithAIPreferenceHelper.setMapWithAIURLs(urls.parallelStream() - .filter(map -> !fakeUrl.equalsIgnoreCase(map.getOrDefault("url", ""))).collect(Collectors.toList())); - assertEquals(1, MapWithAIPreferenceHelper.getMapWithAIUrl().size(), - "The MapWithAI URLs should have been reset (essentially)"); - assertTrue(MapWithAIPreferenceHelper.getMapWithAIUrl().parallelStream() - .anyMatch(map -> getDefaultMapWithAIAPIForTest(MapWithAIPreferenceHelper.DEFAULT_MAPWITHAI_API) - .equals(map.get("url"))), - "The MapWithAI URLs should have been reset"); } @Test