Wiremock conflation servers

Signed-off-by: Taylor Smock <taylor.smock@kaart.com>
pull/1/head
Taylor Smock 2020-06-24 15:17:24 -06:00
rodzic 5b4d06b96a
commit 3565fcb232
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 625F6A74A3E4311A
3 zmienionych plików z 79 dodań i 15 usunięć

Wyświetl plik

@ -15,13 +15,15 @@ import org.openstreetmap.josm.tools.Logging;
public class MapWithAIConflationCategory {
private static final Map<MapWithAICategory, List<String>> CONFLATION_URLS = new EnumMap<>(MapWithAICategory.class);
private static final String EMPTY_URL = "";
protected static final String DEFAULT_CONFLATION_JSON = "https://gokaart.gitlab.io/JOSM_MapWithAI/json/conflation_servers.json";
private static final String DEFAULT_CONFLATION_JSON = "https://gokaart.gitlab.io/JOSM_MapWithAI/json/conflation_servers.json";
private static String conflationJson = DEFAULT_CONFLATION_JSON;
static {
initialize();
}
static void initialize() {
try (ConflationSourceReader reader = new ConflationSourceReader(DEFAULT_CONFLATION_JSON)) {
CONFLATION_URLS.clear();
try (ConflationSourceReader reader = new ConflationSourceReader(conflationJson)) {
CONFLATION_URLS.putAll(reader.parse());
} catch (IOException e) {
Logging.error(e);
@ -48,4 +50,30 @@ public class MapWithAIConflationCategory {
Collection<String> list = CONFLATION_URLS.computeIfAbsent(category, i -> new ArrayList<>(1));
list.add(url);
}
/**
* Set the URL to use to get conflation servers
*
* @param url The URL to use
*/
public static void setConflationJsonLocation(String url) {
conflationJson = url;
initialize();
}
/**
* Reset the conflation json location to the default location
*/
public static void resetConflationJsonLocation() {
setConflationJsonLocation(DEFAULT_CONFLATION_JSON);
}
/**
* Get the current conflation json location
*
* @return The URL that is used to build conflation information
*/
public static String getConflationJsonLocation() {
return conflationJson;
}
}

Wyświetl plik

@ -0,0 +1,24 @@
{
"id" : "fb2197f1-81fd-445d-bb90-b6219d187af6",
"name" : "josm_mapwithai_json_conflation_serversjson",
"request" : {
"url" : "/JOSM_MapWithAI/json/conflation_servers.json",
"method" : "GET"
},
"response" : {
"status" : 200,
"body" : "{\n \"Taylor's Address Conflation Server\" : {\n \"categories\" : [\n \"addresses\"\n ],\n \"description\" : \"Originally developed for use with local datasets, it now accepts external datasets for conflation purposes. In the event of a failure, the plugin will use the original dataset.\",\n \"license\" : \"AGPL\",\n \"source\" : \"https://gitlab.com/smocktaylor/serve_osm_files/\",\n \"url\" : \"https://importdata.riverviewtechnologies.com/conflate\"\n }\n}\n",
"headers" : {
"Accept-Ranges" : "bytes",
"Cache-Control" : "max-age=600",
"Content-Type" : "application/json",
"Expires" : "Wed, 24 Jun 2020 21:26:07 UTC",
"Last-Modified" : "Wed, 24 Jun 2020 17:33:46 GMT",
"Vary" : "Origin",
"Date" : "Wed, 24 Jun 2020 21:16:07 GMT"
}
},
"uuid" : "fb2197f1-81fd-445d-bb90-b6219d187af6",
"persistent" : true,
"insertionIndex" : 43
}

Wyświetl plik

@ -23,6 +23,7 @@ import org.openstreetmap.josm.io.OsmApiInitializationException;
import org.openstreetmap.josm.io.OsmTransferCanceledException;
import org.openstreetmap.josm.plugins.mapwithai.backend.DataAvailability;
import org.openstreetmap.josm.plugins.mapwithai.backend.MapWithAIDataUtils;
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIConflationCategory;
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAILayerInfo;
import org.openstreetmap.josm.spi.preferences.Config;
@ -90,22 +91,15 @@ public class MapWithAITestRules extends JOSMTestRules {
wireMock = new WireMockServer(options().usingFilesUnderDirectory("test/resources/wiremock")
.extensions(new WireMockUrlTransformer()).dynamicPort());
wireMock.start();
MapWithAIDataUtils.setPaintStyleUrl(MapWithAIDataUtils.getPaintStyleUrl()
.replace(Config.getUrls().getJOSMWebsite(), wireMock.baseUrl()));
MapWithAIDataUtils.setPaintStyleUrl(replaceUrl(wireMock, MapWithAIDataUtils.getPaintStyleUrl()));
currentReleaseUrl = DataAvailability.getReleaseUrl();
DataAvailability
.setReleaseUrl(wireMock.baseUrl() + "/gokaart/JOSM_MapWithAI/-/raw/pages/public/json/sources.json");
DataAvailability.setReleaseUrl(replaceUrl(wireMock, DataAvailability.getReleaseUrl()));
Config.getPref().put("osm-server.url", wireMock.baseUrl());
sourceSites = MapWithAILayerInfo.getImageryLayersSites();
MapWithAILayerInfo.setImageryLayersSites(sourceSites.stream().map(t -> {
try {
URL temp = new URL(t);
return wireMock.baseUrl() + temp.getFile();
} catch (MalformedURLException error) {
Logging.error(error);
}
return null;
}).filter(Objects::nonNull).collect(Collectors.toList()));
MapWithAILayerInfo.setImageryLayersSites(sourceSites.stream().map(t -> replaceUrl(wireMock, t))
.filter(Objects::nonNull).collect(Collectors.toList()));
MapWithAIConflationCategory.setConflationJsonLocation(
replaceUrl(wireMock, MapWithAIConflationCategory.getConflationJsonLocation()));
try {
OsmApi.getOsmApi().initialize(NullProgressMonitor.INSTANCE);
} catch (OsmTransferCanceledException | OsmApiInitializationException e) {
@ -135,6 +129,23 @@ public class MapWithAITestRules extends JOSMTestRules {
}
}
/**
* Replace URL servers with wiremock
*
* @param wireMock The wiremock to point to
* @param url The URL to fix
* @return A url that points at the wiremock server
*/
private static String replaceUrl(WireMockServer wireMock, String url) {
try {
URL temp = new URL(url);
return wireMock.baseUrl() + temp.getFile();
} catch (MalformedURLException error) {
Logging.error(error);
}
return null;
}
@Override
protected void after() throws ReflectiveOperationException {
super.after();
@ -146,6 +157,7 @@ public class MapWithAITestRules extends JOSMTestRules {
DataAvailability.setReleaseUrl(currentReleaseUrl);
Config.getPref().put("osm-server.url", null);
MapWithAILayerInfo.setImageryLayersSites(sourceSites);
MapWithAIConflationCategory.resetConflationJsonLocation();
resetMapWithAILayerInfo();
}
if (workerExceptions) {