kopia lustrzana https://github.com/JOSM/MapWithAI
Porównaj commity
16 Commity
Autor | SHA1 | Data |
---|---|---|
![]() |
f3659fc3ed | |
![]() |
cdb1889864 | |
![]() |
3bca38d512 | |
![]() |
9b7d424f7b | |
![]() |
551e26ef8e | |
![]() |
87274baa62 | |
![]() |
629e34f413 | |
![]() |
817b633660 | |
![]() |
5d9df1fba4 | |
![]() |
cecb9f40be | |
![]() |
7f725f7e4c | |
![]() |
f7c1d3d8b0 | |
![]() |
fbd3f10541 | |
![]() |
faa031e49c | |
![]() |
ca0b8e479f | |
![]() |
ad6ec16acd |
|
@ -10,20 +10,18 @@ on:
|
||||||
branches:
|
branches:
|
||||||
- master
|
- master
|
||||||
- $default-branch
|
- $default-branch
|
||||||
schedule:
|
|
||||||
- cron: "1 5 * * 6"
|
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
call-workflow:
|
call-workflow:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
josm-revision: ["", "r18877"]
|
josm-revision: ["", "r19067"]
|
||||||
uses: JOSM/JOSMPluginAction/.github/workflows/ant.yml@v1
|
uses: JOSM/JOSMPluginAction/.github/workflows/ant.yml@v3
|
||||||
with:
|
with:
|
||||||
java-version: 17
|
java-version: 17
|
||||||
josm-revision: ${{ matrix.josm-revision }}
|
josm-revision: ${{ matrix.josm-revision }}
|
||||||
plugin-jar-name: 'mapwithai'
|
plugin-jar-name: 'mapwithai'
|
||||||
perform-revision-tagging: ${{ matrix.josm-revision == 'r18877' && github.repository == 'JOSM/MapWithAI' && github.ref_type == 'branch' && github.ref_name == 'master' && github.event_name != 'schedule' && github.event_name != 'pull_request' }}
|
perform-revision-tagging: ${{ matrix.josm-revision == 'r19067' && github.repository == 'JOSM/MapWithAI' && github.ref_type == 'branch' && github.ref_name == 'master' && github.event_name != 'schedule' && github.event_name != 'pull_request' }}
|
||||||
secrets: inherit
|
secrets: inherit
|
||||||
|
|
||||||
|
|
|
@ -10,4 +10,4 @@ permissions:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
call-workflow:
|
call-workflow:
|
||||||
uses: JOSM/JOSMPluginAction/.github/workflows/reports.yaml@v1
|
uses: JOSM/JOSMPluginAction/.github/workflows/reports.yaml@v3
|
||||||
|
|
18
build.gradle
18
build.gradle
|
@ -1,9 +1,9 @@
|
||||||
import groovy.xml.XmlParser
|
import groovy.xml.XmlParser
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id "com.diffplug.spotless" version "6.20.0"
|
id "com.diffplug.spotless" version "6.25.0"
|
||||||
id "com.github.ben-manes.versions" version "0.47.0"
|
id "com.github.ben-manes.versions" version "0.51.0"
|
||||||
id "com.github.spotbugs" version "5.0.14"
|
id "com.github.spotbugs" version "6.0.8"
|
||||||
// id "de.aaschmid.cpd" version "3.3"
|
// id "de.aaschmid.cpd" version "3.3"
|
||||||
id "eclipse"
|
id "eclipse"
|
||||||
id "jacoco"
|
id "jacoco"
|
||||||
|
@ -12,7 +12,7 @@ plugins {
|
||||||
id "maven-publish"
|
id "maven-publish"
|
||||||
id "net.ltgt.errorprone" version "3.1.0"
|
id "net.ltgt.errorprone" version "3.1.0"
|
||||||
id "org.openstreetmap.josm" version "0.8.2"
|
id "org.openstreetmap.josm" version "0.8.2"
|
||||||
id "org.sonarqube" version "4.2.1.3168"
|
id "org.sonarqube" version "4.4.1.3373"
|
||||||
id "pmd"
|
id "pmd"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,15 +29,15 @@ repositories {
|
||||||
|
|
||||||
def versions = [
|
def versions = [
|
||||||
awaitility: "4.2.0",
|
awaitility: "4.2.0",
|
||||||
equalsverifier: "3.15",
|
equalsverifier: "3.15.8",
|
||||||
errorprone: "2.20.0",
|
errorprone: "2.26.0",
|
||||||
findsecbugs: "1.12.0",
|
findsecbugs: "1.13.0",
|
||||||
jacoco: "0.8.10",
|
jacoco: "0.8.10",
|
||||||
jmockit: "1.49.a",
|
jmockit: "1.49.a",
|
||||||
josm: properties.get("plugin.compile.version"),
|
josm: properties.get("plugin.compile.version"),
|
||||||
junit: "5.9.1",
|
junit: "5.10.2",
|
||||||
pmd: "6.20.0",
|
pmd: "6.20.0",
|
||||||
spotbugs: "4.7.3",
|
spotbugs: "4.8.3",
|
||||||
wiremock: "2.35.0",
|
wiremock: "2.35.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
# The minimum JOSM version this plugin is compatible with (can be any numeric version
|
# The minimum JOSM version this plugin is compatible with (can be any numeric version
|
||||||
plugin.main.version = 18877
|
plugin.main.version = 19067
|
||||||
# The JOSM version this plugin is currently compiled against
|
# The JOSM version this plugin is currently compiled against
|
||||||
# Please make sure this version is available at https://josm.openstreetmap.de/download
|
# Please make sure this version is available at https://josm.openstreetmap.de/download
|
||||||
# The special values "latest" and "tested" are also possible here, but not recommended.
|
# The special values "latest" and "tested" are also possible here, but not recommended.
|
||||||
plugin.compile.version = 18877
|
plugin.compile.version = 19067
|
||||||
plugin.canloadatruntime = true
|
plugin.canloadatruntime = true
|
||||||
plugin.author = Taylor Smock
|
plugin.author = Taylor Smock
|
||||||
plugin.class = org.openstreetmap.josm.plugins.mapwithai.MapWithAIPlugin
|
plugin.class = org.openstreetmap.josm.plugins.mapwithai.MapWithAIPlugin
|
||||||
|
|
Plik binarny nie jest wyświetlany.
|
@ -1,7 +1,8 @@
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionSha256Sum=03ec176d388f2aa99defcadc3ac6adf8dd2bce5145a129659537c0874dea5ad1
|
distributionSha256Sum=9631d53cf3e74bfa726893aee1f8994fee4e060c401335946dba2156f440f24c
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|
|
@ -85,9 +85,6 @@ done
|
||||||
APP_BASE_NAME=${0##*/}
|
APP_BASE_NAME=${0##*/}
|
||||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||||
|
|
||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
|
||||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
MAX_FD=maximum
|
MAX_FD=maximum
|
||||||
|
|
||||||
|
@ -133,10 +130,13 @@ location of your Java installation."
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
JAVACMD=java
|
JAVACMD=java
|
||||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
if ! command -v java >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
location of your Java installation."
|
location of your Java installation."
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Increase the maximum file descriptors if we can.
|
# Increase the maximum file descriptors if we can.
|
||||||
|
@ -144,7 +144,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||||
case $MAX_FD in #(
|
case $MAX_FD in #(
|
||||||
max*)
|
max*)
|
||||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||||
# shellcheck disable=SC3045
|
# shellcheck disable=SC3045
|
||||||
MAX_FD=$( ulimit -H -n ) ||
|
MAX_FD=$( ulimit -H -n ) ||
|
||||||
warn "Could not query maximum file descriptor limit"
|
warn "Could not query maximum file descriptor limit"
|
||||||
esac
|
esac
|
||||||
|
@ -152,7 +152,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||||
'' | soft) :;; #(
|
'' | soft) :;; #(
|
||||||
*)
|
*)
|
||||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||||
# shellcheck disable=SC3045
|
# shellcheck disable=SC3045
|
||||||
ulimit -n "$MAX_FD" ||
|
ulimit -n "$MAX_FD" ||
|
||||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||||
esac
|
esac
|
||||||
|
@ -197,6 +197,10 @@ if "$cygwin" || "$msys" ; then
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
|
|
||||||
# Collect all arguments for the java command;
|
# Collect all arguments for the java command;
|
||||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||||
# shell script including quotes and variable substitutions, so put them in
|
# shell script including quotes and variable substitutions, so put them in
|
||||||
|
|
|
@ -0,0 +1,193 @@
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>org.openstreetmap.josm.plugins</groupId>
|
||||||
|
<artifactId>MapWithAI</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<properties>
|
||||||
|
<jmockit.version>1.49.a</jmockit.version>
|
||||||
|
<pmd.version>7.5.0</pmd.version>
|
||||||
|
<jacoco.version>0.8.12</jacoco.version>
|
||||||
|
<checkstyle.version>10.18.1</checkstyle.version>
|
||||||
|
<spotbugs.version>4.8.6</spotbugs.version>
|
||||||
|
</properties>
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>JOSM-releases</id>
|
||||||
|
<url>https://josm.openstreetmap.de/repository/releases/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>JOSM-snapshots</id>
|
||||||
|
<url>https://josm.openstreetmap.de/repository/snapshots/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit</groupId>
|
||||||
|
<artifactId>junit-bom</artifactId>
|
||||||
|
<version>5.11.1</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.openstreetmap.josm</groupId>
|
||||||
|
<artifactId>josm</artifactId>
|
||||||
|
<version>1.5-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.openstreetmap.josm.plugins</groupId>
|
||||||
|
<artifactId>pmtiles</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.openstreetmap.josm.plugins</groupId>
|
||||||
|
<artifactId>utilsplugin2</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.openstreetmap.josm</groupId>
|
||||||
|
<artifactId>josm-unittest</artifactId>
|
||||||
|
<version>1.5-SNAPSHOT</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wiremock</groupId>
|
||||||
|
<artifactId>wiremock</artifactId>
|
||||||
|
<version>3.9.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-api</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-params</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency> <!-- needed until JOSM core removes Junit4 support -->
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.13.2</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.awaitility</groupId>
|
||||||
|
<artifactId>awaitility</artifactId>
|
||||||
|
<version>4.2.2</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>nl.jqno.equalsverifier</groupId>
|
||||||
|
<artifactId>equalsverifier</artifactId>
|
||||||
|
<version>3.17</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jmockit</groupId>
|
||||||
|
<artifactId>jmockit</artifactId>
|
||||||
|
<version>1.49.a</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>jakarta.json</groupId>
|
||||||
|
<artifactId>jakarta.json-api</artifactId>
|
||||||
|
<version>2.1.3</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<testSourceDirectory>src/test/unit</testSourceDirectory>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.13.0</version>
|
||||||
|
<configuration>
|
||||||
|
<release>17</release>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>com.diffplug.spotless</groupId>
|
||||||
|
<artifactId>spotless-maven-plugin</artifactId>
|
||||||
|
<version>2.43.0</version>
|
||||||
|
<configuration>
|
||||||
|
<java>
|
||||||
|
<eclipse>
|
||||||
|
<version>4.21</version>
|
||||||
|
<file>${project.basedir}/../00_core_tools/eclipse/formatter.xml</file>
|
||||||
|
</eclipse>
|
||||||
|
<removeUnusedImports/>
|
||||||
|
<licenseHeader>
|
||||||
|
<content>// License: GPL. For details, see LICENSE file.</content>
|
||||||
|
</licenseHeader>
|
||||||
|
<includes>
|
||||||
|
<include>src/main/java/**/*.java</include>
|
||||||
|
<include>src/test/unit/**/*.java</include>
|
||||||
|
<include>src/test/integration/**/*.java</include>
|
||||||
|
</includes>
|
||||||
|
</java>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>check</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-enforcer-plugin</artifactId>
|
||||||
|
<version>3.5.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>enforce-maven</id>
|
||||||
|
<goals>
|
||||||
|
<goal>enforce</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<rules>
|
||||||
|
<requireMavenVersion>
|
||||||
|
<version>3.6.3</version>
|
||||||
|
</requireMavenVersion>
|
||||||
|
</rules>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<!-- Configure the test plugin, specifically enable autodetection of global extensions -->
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>3.2.5</version>
|
||||||
|
<configuration>
|
||||||
|
<skipAfterFailureCount>1</skipAfterFailureCount>
|
||||||
|
<argLine>-javaagent:"${settings.localRepository}"/org/jmockit/jmockit/${jmockit.version}/jmockit-${jmockit.version}.jar</argLine>
|
||||||
|
<properties>
|
||||||
|
<configurationParameters>
|
||||||
|
file.encoding = UTF-8
|
||||||
|
java.locale.providers = SPI,CLDR
|
||||||
|
junit.jupiter.extensions.autodetection.enabled = true
|
||||||
|
junit.jupiter.execution.parallel.enabled = true
|
||||||
|
</configurationParameters>
|
||||||
|
</properties>
|
||||||
|
<systemPropertyVariables>
|
||||||
|
<josm.home>src/test/build/config/josm.home</josm.home>
|
||||||
|
<josm.test.data>src/test/resources</josm.test.data>
|
||||||
|
<java.awt.headless>true</java.awt.headless>
|
||||||
|
<glass.platform>Monocle</glass.platform>
|
||||||
|
<monocle.platform>Headless</monocle.platform>
|
||||||
|
<prism.order>sw</prism.order>
|
||||||
|
</systemPropertyVariables>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
|
@ -84,10 +84,17 @@ public class AddMapWithAILayerAction extends JosmAction implements AdaptableActi
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
if (!isEnabled()) {
|
if (isEnabled()) {
|
||||||
return;
|
MainApplication.worker.execute(() -> realRun(this.info));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run the download tasks. This should be run off of the EDT, see #23529.
|
||||||
|
*
|
||||||
|
* @param info The external data to download
|
||||||
|
*/
|
||||||
|
private static void realRun(MapWithAIInfo info) {
|
||||||
MapWithAILayer layer = MapWithAIDataUtils.getLayer(false);
|
MapWithAILayer layer = MapWithAIDataUtils.getLayer(false);
|
||||||
final DataSet ds;
|
final DataSet ds;
|
||||||
final OsmData<?, ?, ?, ?> boundsSource;
|
final OsmData<?, ?, ?, ?> boundsSource;
|
||||||
|
|
|
@ -23,6 +23,7 @@ import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
@ -73,6 +74,7 @@ import org.openstreetmap.josm.spi.preferences.Config;
|
||||||
import org.openstreetmap.josm.tools.HttpClient;
|
import org.openstreetmap.josm.tools.HttpClient;
|
||||||
import org.openstreetmap.josm.tools.JosmRuntimeException;
|
import org.openstreetmap.josm.tools.JosmRuntimeException;
|
||||||
import org.openstreetmap.josm.tools.Logging;
|
import org.openstreetmap.josm.tools.Logging;
|
||||||
|
import org.openstreetmap.josm.tools.Utils;
|
||||||
|
|
||||||
import jakarta.json.Json;
|
import jakarta.json.Json;
|
||||||
import jakarta.json.JsonValue;
|
import jakarta.json.JsonValue;
|
||||||
|
@ -130,14 +132,20 @@ public class BoundingBoxMapWithAIDownloader extends BoundingBoxDownloader {
|
||||||
final var tile = TileXYZ.tileFromBBox(lon1, lat1, lon2, lat2);
|
final var tile = TileXYZ.tileFromBBox(lon1, lat1, lon2, lat2);
|
||||||
return getRequestForTile(tile);
|
return getRequestForTile(tile);
|
||||||
}
|
}
|
||||||
return url.replace("{bbox}", Double.toString(lon1) + ',' + lat1 + ',' + lon2 + ',' + lat2)
|
var current = url.replace("{bbox}", Double.toString(lon1) + ',' + lat1 + ',' + lon2 + ',' + lat2)
|
||||||
.replace("{xmin}", Double.toString(lon1)).replace("{ymin}", Double.toString(lat1))
|
.replace("{xmin}", Double.toString(lon1)).replace("{ymin}", Double.toString(lat1))
|
||||||
.replace("{xmax}", Double.toString(lon2)).replace("{ymax}", Double.toString(lat2))
|
.replace("{xmax}", Double.toString(lon2)).replace("{ymax}", Double.toString(lat2));
|
||||||
+ (crop ? "&crop_bbox=" + DetectTaskingManagerUtils.getTaskingManagerBounds().toBBox().toStringCSV(",")
|
boolean hasQuery = !Optional.ofNullable(URI.create(current).getRawQuery()).map(String::isEmpty).orElse(true);
|
||||||
: "")
|
|
||||||
+ (this.info.getSourceType() == MapWithAIType.ESRI_FEATURE_SERVER && !this.info.isConflated()
|
if (crop) {
|
||||||
? "&resultOffset=" + this.start
|
current += (hasQuery ? '&' : '?') + "crop_bbox="
|
||||||
: "");
|
+ DetectTaskingManagerUtils.getTaskingManagerBounds().toBBox().toStringCSV(",");
|
||||||
|
hasQuery = true;
|
||||||
|
}
|
||||||
|
if (this.info.getSourceType() == MapWithAIType.ESRI_FEATURE_SERVER && !this.info.isConflated()) {
|
||||||
|
current += (hasQuery ? '&' : '?') + "resultOffset=" + this.start;
|
||||||
|
}
|
||||||
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getRequestForTile(TileXYZ tile) {
|
private String getRequestForTile(TileXYZ tile) {
|
||||||
|
@ -361,30 +369,33 @@ public class BoundingBoxMapWithAIDownloader extends BoundingBoxDownloader {
|
||||||
}
|
}
|
||||||
final var ds = new DataSet();
|
final var ds = new DataSet();
|
||||||
final var primitiveMap = new HashMap<PrimitiveId, OsmPrimitive>(tile.getData().getAllPrimitives().size());
|
final var primitiveMap = new HashMap<PrimitiveId, OsmPrimitive>(tile.getData().getAllPrimitives().size());
|
||||||
for (VectorPrimitive p : tile.getData().getAllPrimitives()) {
|
for (Class<? extends VectorPrimitive> clazz : Arrays.asList(VectorNode.class, VectorWay.class,
|
||||||
final OsmPrimitive osmPrimitive;
|
VectorRelation.class)) {
|
||||||
if (p instanceof VectorNode node) {
|
for (VectorPrimitive p : Utils.filteredCollection(tile.getData().getAllPrimitives(), clazz)) {
|
||||||
osmPrimitive = new Node(node.getCoor());
|
final OsmPrimitive osmPrimitive;
|
||||||
osmPrimitive.putAll(node.getKeys());
|
if (p instanceof VectorNode node) {
|
||||||
} else if (p instanceof VectorWay way) {
|
osmPrimitive = new Node(node.getCoor());
|
||||||
final var tWay = new Way();
|
osmPrimitive.putAll(node.getKeys());
|
||||||
for (VectorNode node : way.getNodes()) {
|
} else if (p instanceof VectorWay way) {
|
||||||
tWay.addNode((Node) primitiveMap.get(node));
|
final var tWay = new Way();
|
||||||
|
for (VectorNode node : way.getNodes()) {
|
||||||
|
tWay.addNode((Node) primitiveMap.get(node));
|
||||||
|
}
|
||||||
|
tWay.putAll(way.getKeys());
|
||||||
|
osmPrimitive = tWay;
|
||||||
|
} else if (p instanceof VectorRelation vectorRelation) {
|
||||||
|
final var tRelation = new Relation();
|
||||||
|
for (VectorRelationMember member : vectorRelation.getMembers()) {
|
||||||
|
tRelation.addMember(new RelationMember(member.getRole(), primitiveMap.get(member.getMember())));
|
||||||
|
}
|
||||||
|
tRelation.putAll(vectorRelation.getKeys());
|
||||||
|
osmPrimitive = tRelation;
|
||||||
|
} else {
|
||||||
|
throw new IllegalDataException("Unknown vector data type: " + p);
|
||||||
}
|
}
|
||||||
tWay.putAll(way.getKeys());
|
ds.addPrimitive(osmPrimitive);
|
||||||
osmPrimitive = tWay;
|
primitiveMap.put(p, osmPrimitive);
|
||||||
} else if (p instanceof VectorRelation vectorRelation) {
|
|
||||||
final var tRelation = new Relation();
|
|
||||||
for (VectorRelationMember member : vectorRelation.getMembers()) {
|
|
||||||
tRelation.addMember(new RelationMember(member.getRole(), primitiveMap.get(member.getMember())));
|
|
||||||
}
|
|
||||||
tRelation.putAll(vectorRelation.getKeys());
|
|
||||||
osmPrimitive = tRelation;
|
|
||||||
} else {
|
|
||||||
throw new IllegalDataException("Unknown vector data type: " + p);
|
|
||||||
}
|
}
|
||||||
ds.addPrimitive(osmPrimitive);
|
|
||||||
primitiveMap.put(p, osmPrimitive);
|
|
||||||
}
|
}
|
||||||
return ds;
|
return ds;
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ public class DataConflationSender implements RunnableFuture<DataSet> {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
String url = MapWithAIConflationCategory.conflationUrlFor(category);
|
String url = MapWithAIConflationCategory.conflationUrlFor(category);
|
||||||
if (!Utils.isBlank(url) && !NetworkManager.isOffline(url)) {
|
if (!Utils.isStripEmpty(url) && !NetworkManager.isOffline(url)) {
|
||||||
this.client = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(10)).build();
|
this.client = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(10)).build();
|
||||||
try {
|
try {
|
||||||
final var form = new TreeMap<String, String>();
|
final var form = new TreeMap<String, String>();
|
||||||
|
|
|
@ -403,7 +403,7 @@ public class GetDataRunnable extends RecursiveTask<DataSet> {
|
||||||
.map(entry -> new Pair<>(Tag.ofString(entry.getKey()), Tag.ofString(entry.getValue())))
|
.map(entry -> new Pair<>(Tag.ofString(entry.getKey()), Tag.ofString(entry.getValue())))
|
||||||
.collect(Collectors.toMap(pair -> pair.a, pair -> pair.b));
|
.collect(Collectors.toMap(pair -> pair.a, pair -> pair.b));
|
||||||
MapWithAIPreferenceHelper.getReplacementTags().entrySet().stream()
|
MapWithAIPreferenceHelper.getReplacementTags().entrySet().stream()
|
||||||
.filter(entry -> !entry.getKey().equals(EQUALS) && Utils.isBlank(entry.getValue()))
|
.filter(entry -> !entry.getKey().equals(EQUALS) && Utils.isStripEmpty(entry.getValue()))
|
||||||
.map(entry -> new Tag(entry.getKey(), null)).forEach(tag -> replaceTags.put(tag, tag));
|
.map(entry -> new Tag(entry.getKey(), null)).forEach(tag -> replaceTags.put(tag, tag));
|
||||||
replaceTags(dataSet, replaceTags);
|
replaceTags(dataSet, replaceTags);
|
||||||
}
|
}
|
||||||
|
@ -417,7 +417,7 @@ public class GetDataRunnable extends RecursiveTask<DataSet> {
|
||||||
public static void replaceTags(DataSet dataSet, Map<Tag, Tag> replaceTags) {
|
public static void replaceTags(DataSet dataSet, Map<Tag, Tag> replaceTags) {
|
||||||
replaceTags.forEach((orig, replace) -> dataSet.allNonDeletedPrimitives().stream()
|
replaceTags.forEach((orig, replace) -> dataSet.allNonDeletedPrimitives().stream()
|
||||||
.filter(prim -> prim.hasTag(orig.getKey(), orig.getValue())
|
.filter(prim -> prim.hasTag(orig.getKey(), orig.getValue())
|
||||||
|| (prim.hasKey(orig.getKey()) && Utils.isBlank(orig.getValue())))
|
|| (prim.hasKey(orig.getKey()) && Utils.isStripEmpty(orig.getValue())))
|
||||||
.forEach(prim -> prim.put(replace)));
|
.forEach(prim -> prim.put(replace)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ import java.util.Optional;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.concurrent.ForkJoinPool;
|
import java.util.concurrent.ForkJoinPool;
|
||||||
import java.util.concurrent.ForkJoinTask;
|
import java.util.concurrent.ForkJoinTask;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.openstreetmap.josm.data.Bounds;
|
import org.openstreetmap.josm.data.Bounds;
|
||||||
|
@ -127,7 +128,7 @@ public final class MapWithAIDataUtils {
|
||||||
realBounds.size() * urls.size());
|
realBounds.size() * urls.size());
|
||||||
for (var bound : realBounds) {
|
for (var bound : realBounds) {
|
||||||
for (var url : urls) {
|
for (var url : urls) {
|
||||||
if (url.getUrl() != null && !Utils.isBlank(url.getUrl())) {
|
if (url.getUrl() != null && !Utils.isStripEmpty(url.getUrl())) {
|
||||||
final var ds = download(monitor, bound, url, maximumDimensions);
|
final var ds = download(monitor, bound, url, maximumDimensions);
|
||||||
downloadedDataSets.add(ds);
|
downloadedDataSets.add(ds);
|
||||||
MapWithAIDataUtils.getForkJoinPool().execute(ds);
|
MapWithAIDataUtils.getForkJoinPool().execute(ds);
|
||||||
|
@ -197,9 +198,14 @@ public final class MapWithAIDataUtils {
|
||||||
original.mergeFrom(ds.join());
|
original.mergeFrom(ds.join());
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
final String notificationMessage;
|
final String notificationMessage;
|
||||||
final var cause = e.getCause();
|
Throwable cause = e.getCause();
|
||||||
if (cause instanceof IllegalDataException illegalDataException) {
|
if (cause != null) {
|
||||||
notificationMessage = ExceptionUtil.explainException(illegalDataException);
|
while (cause.getCause() != null && RuntimeException.class.equals(cause.getClass())) {
|
||||||
|
cause = cause.getCause();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (cause instanceof IllegalDataException) {
|
||||||
|
notificationMessage = ExceptionUtil.explainException((Exception) cause);
|
||||||
Logging.trace(e);
|
Logging.trace(e);
|
||||||
final var notification = new Notification();
|
final var notification = new Notification();
|
||||||
GuiHelper.runInEDT(() -> notification.setContent(notificationMessage));
|
GuiHelper.runInEDT(() -> notification.setContent(notificationMessage));
|
||||||
|
@ -213,37 +219,26 @@ public final class MapWithAIDataUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean confirmBigDownload(List<Bounds> realBounds) {
|
/**
|
||||||
final var confirmation = new ConfirmBigDownload(realBounds);
|
* Confirm a large download
|
||||||
GuiHelper.runInEDTAndWait(confirmation);
|
*
|
||||||
return confirmation.confirmed();
|
* @param realBounds The list of bounds that will be downloaded
|
||||||
}
|
* @return {@code true} if the user still wants to download data
|
||||||
|
*/
|
||||||
private static class ConfirmBigDownload implements Runnable {
|
private static synchronized boolean confirmBigDownload(List<Bounds> realBounds) {
|
||||||
Boolean bool;
|
final var confirmation = new AtomicBoolean(false);
|
||||||
final List<?> realBounds;
|
// This is not a separate class since we don't want to show multiple
|
||||||
|
// confirmation dialogs
|
||||||
public ConfirmBigDownload(List<?> realBounds) {
|
// which is why this method is synchronized.
|
||||||
this.realBounds = realBounds;
|
GuiHelper.runInEDTAndWait(() -> {
|
||||||
}
|
final var confirmed = ConditionalOptionPaneUtil.showConfirmationDialog(
|
||||||
|
MapWithAIPlugin.NAME.concat(".alwaysdownload"), null,
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
bool = ConditionalOptionPaneUtil.showConfirmationDialog(MapWithAIPlugin.NAME.concat(".alwaysdownload"),
|
|
||||||
null,
|
|
||||||
tr("You are going to make {0} requests to the MapWithAI server. This may take some time. <br /> Continue?",
|
tr("You are going to make {0} requests to the MapWithAI server. This may take some time. <br /> Continue?",
|
||||||
realBounds.size()),
|
realBounds.size()),
|
||||||
null, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, JOptionPane.YES_OPTION);
|
null, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, JOptionPane.YES_OPTION);
|
||||||
}
|
confirmation.set(confirmed);
|
||||||
|
});
|
||||||
/**
|
return confirmation.get();
|
||||||
* Check if the user confirmed the download
|
|
||||||
*
|
|
||||||
* @return {@code true} if the user wants to continue
|
|
||||||
*/
|
|
||||||
public boolean confirmed() {
|
|
||||||
return bool;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -41,6 +41,7 @@ import org.openstreetmap.josm.plugins.mapwithai.backend.MapWithAIDataUtils;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo.MapWithAIPreferenceEntry;
|
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo.MapWithAIPreferenceEntry;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.io.mapwithai.ESRISourceReader;
|
import org.openstreetmap.josm.plugins.mapwithai.io.mapwithai.ESRISourceReader;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.io.mapwithai.MapWithAISourceReader;
|
import org.openstreetmap.josm.plugins.mapwithai.io.mapwithai.MapWithAISourceReader;
|
||||||
|
import org.openstreetmap.josm.plugins.mapwithai.io.mapwithai.OvertureSourceReader;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.spi.preferences.MapWithAIConfig;
|
import org.openstreetmap.josm.plugins.mapwithai.spi.preferences.MapWithAIConfig;
|
||||||
import org.openstreetmap.josm.spi.preferences.Config;
|
import org.openstreetmap.josm.spi.preferences.Config;
|
||||||
import org.openstreetmap.josm.tools.ListenerList;
|
import org.openstreetmap.josm.tools.ListenerList;
|
||||||
|
@ -213,9 +214,13 @@ public class MapWithAILayerInfo {
|
||||||
if (this.finishListenerListenerList == null) {
|
if (this.finishListenerListenerList == null) {
|
||||||
this.finishListenerListenerList = ListenerList.create();
|
this.finishListenerListenerList = ListenerList.create();
|
||||||
}
|
}
|
||||||
|
boolean running = this.finishListenerListenerList.hasListeners();
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
this.finishListenerListenerList.addListener(listener);
|
this.finishListenerListenerList.addListener(listener);
|
||||||
}
|
}
|
||||||
|
if (running) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (worker == null) {
|
if (worker == null) {
|
||||||
final var pleaseWaitRunnable = new PleaseWaitRunnable(tr("Update default entries")) {
|
final var pleaseWaitRunnable = new PleaseWaitRunnable(tr("Update default entries")) {
|
||||||
@Override
|
@Override
|
||||||
|
@ -329,6 +334,7 @@ public class MapWithAILayerInfo {
|
||||||
// This is called here to "pre-cache" the layer information, to avoid blocking
|
// This is called here to "pre-cache" the layer information, to avoid blocking
|
||||||
// the EDT
|
// the EDT
|
||||||
this.updateEsriLayers(result);
|
this.updateEsriLayers(result);
|
||||||
|
this.updateOvertureLayers(result);
|
||||||
newLayers.addAll(result);
|
newLayers.addAll(result);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
loadError = true;
|
loadError = true;
|
||||||
|
@ -342,11 +348,12 @@ public class MapWithAILayerInfo {
|
||||||
* @param layers The layers to update
|
* @param layers The layers to update
|
||||||
*/
|
*/
|
||||||
private void updateEsriLayers(@Nonnull final Collection<MapWithAIInfo> layers) {
|
private void updateEsriLayers(@Nonnull final Collection<MapWithAIInfo> layers) {
|
||||||
|
final var esriInfo = new ArrayList<MapWithAIInfo>(300);
|
||||||
for (var layer : layers) {
|
for (var layer : layers) {
|
||||||
if (MapWithAIType.ESRI == layer.getSourceType()) {
|
if (MapWithAIType.ESRI == layer.getSourceType()) {
|
||||||
for (var future : parseEsri(layer)) {
|
for (var future : parseEsri(layer)) {
|
||||||
try {
|
try {
|
||||||
allDefaultLayers.add(future.get());
|
esriInfo.add(future.get());
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Logging.error(e);
|
Logging.error(e);
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
|
@ -354,10 +361,27 @@ public class MapWithAILayerInfo {
|
||||||
Logging.error(e);
|
Logging.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
allDefaultLayers.add(layer);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
layers.addAll(esriInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the overture layers
|
||||||
|
* @param layers The layers to iterate through and modify
|
||||||
|
* @throws IOException If something happens while parsing overture layers
|
||||||
|
*/
|
||||||
|
private void updateOvertureLayers(@Nonnull final Collection<MapWithAIInfo> layers) throws IOException {
|
||||||
|
final var overtureLayers = new ArrayList<MapWithAIInfo>(4);
|
||||||
|
for (var layer : layers) {
|
||||||
|
if (MapWithAIType.OVERTURE == layer.getSourceType()) {
|
||||||
|
try (var reader = new OvertureSourceReader(layer)) {
|
||||||
|
reader.parse().ifPresent(overtureLayers::addAll);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
layers.removeIf(layer -> MapWithAIType.OVERTURE == layer.getSourceType());
|
||||||
|
layers.addAll(overtureLayers);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void finish() {
|
protected void finish() {
|
||||||
|
@ -365,7 +389,7 @@ public class MapWithAILayerInfo {
|
||||||
synchronized (allDefaultLayers) {
|
synchronized (allDefaultLayers) {
|
||||||
allDefaultLayers.clear();
|
allDefaultLayers.clear();
|
||||||
defaultLayers.addAll(newLayers);
|
defaultLayers.addAll(newLayers);
|
||||||
this.updateEsriLayers(newLayers);
|
allDefaultLayers.addAll(newLayers);
|
||||||
allDefaultLayers.sort(new MapWithAIInfo.MapWithAIInfoCategoryComparator());
|
allDefaultLayers.sort(new MapWithAIInfo.MapWithAIInfoCategoryComparator());
|
||||||
allDefaultLayers.sort(Comparator.comparing(TileSourceInfo::getName));
|
allDefaultLayers.sort(Comparator.comparing(TileSourceInfo::getName));
|
||||||
allDefaultLayers.sort(Comparator.comparing(info -> info.getCategory().getDescription()));
|
allDefaultLayers.sort(Comparator.comparing(info -> info.getCategory().getDescription()));
|
||||||
|
@ -501,7 +525,7 @@ public class MapWithAILayerInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changed) {
|
if (changed) {
|
||||||
save();
|
MainApplication.worker.execute(this::save);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ import jakarta.annotation.Nonnull;
|
||||||
*/
|
*/
|
||||||
public enum MapWithAIType implements ISourceType<MapWithAIType> {
|
public enum MapWithAIType implements ISourceType<MapWithAIType> {
|
||||||
FACEBOOK("facebook"), THIRD_PARTY("thirdParty"), ESRI("esri"), ESRI_FEATURE_SERVER(
|
FACEBOOK("facebook"), THIRD_PARTY("thirdParty"), ESRI("esri"), ESRI_FEATURE_SERVER(
|
||||||
"esriFeatureServer"), MAPBOX_VECTOR_TILE("mvt"), PMTILES("pmtiles");
|
"esriFeatureServer"), MAPBOX_VECTOR_TILE("mvt"), PMTILES("pmtiles"), OVERTURE("overture");
|
||||||
|
|
||||||
private final String typeString;
|
private final String typeString;
|
||||||
|
|
||||||
|
|
|
@ -44,8 +44,8 @@ public class StreetAddressTest extends Test {
|
||||||
public static final double BBOX_EXPANSION = 0.002;
|
public static final double BBOX_EXPANSION = 0.002;
|
||||||
private static final String ADDR_STREET = "addr:street";
|
private static final String ADDR_STREET = "addr:street";
|
||||||
private final Set<OsmPrimitive> namePrimitiveMap = new HashSet<>();
|
private final Set<OsmPrimitive> namePrimitiveMap = new HashSet<>();
|
||||||
private final Map<Point2D, Set<String>> nameMap = new HashMap<>();
|
private final Map<Point, Set<String>> nameMap = new HashMap<>();
|
||||||
private final Map<Point2D, List<OsmPrimitive>> primitiveCellMap = new HashMap<>();
|
private final Map<Point, List<OsmPrimitive>> primitiveCellMap = new HashMap<>();
|
||||||
/**
|
/**
|
||||||
* Classified highways. This uses a {@link Set} instead of a {@link List} since
|
* Classified highways. This uses a {@link Set} instead of a {@link List} since
|
||||||
* the MapWithAI code doesn't care about order.
|
* the MapWithAI code doesn't care about order.
|
||||||
|
@ -146,7 +146,8 @@ public class StreetAddressTest extends Test {
|
||||||
final var n1 = nodes.get(i);
|
final var n1 = nodes.get(i);
|
||||||
final var n2 = nodes.get(i + 1);
|
final var n2 = nodes.get(i + 1);
|
||||||
for (Point2D cell : ValUtil.getSegmentCells(n1, n2, gridDetail)) {
|
for (Point2D cell : ValUtil.getSegmentCells(n1, n2, gridDetail)) {
|
||||||
this.nameMap.computeIfAbsent(cell, k -> new HashSet<>()).addAll(names);
|
this.nameMap.computeIfAbsent(new Point(cell.getX(), cell.getY()), k -> new HashSet<>())
|
||||||
|
.addAll(names);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (hasStreetAddressTags(primitive) && !primitive.isOutsideDownloadArea()) {
|
} else if (hasStreetAddressTags(primitive) && !primitive.isOutsideDownloadArea()) {
|
||||||
|
@ -159,7 +160,7 @@ public class StreetAddressTest extends Test {
|
||||||
if (en != null) {
|
if (en != null) {
|
||||||
long x = (long) Math.floor(en.getX() * gridDetail);
|
long x = (long) Math.floor(en.getX() * gridDetail);
|
||||||
long y = (long) Math.floor(en.getY() * gridDetail);
|
long y = (long) Math.floor(en.getY() * gridDetail);
|
||||||
final var point = new Point2D.Double(x, y);
|
final var point = new Point(x, y);
|
||||||
primitiveCellMap.computeIfAbsent(point, p -> new ArrayList<>()).add(primitive);
|
primitiveCellMap.computeIfAbsent(point, p -> new ArrayList<>()).add(primitive);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -174,7 +175,7 @@ public class StreetAddressTest extends Test {
|
||||||
.filter(s -> !s.isEmpty()).collect(Collectors.toSet());
|
.filter(s -> !s.isEmpty()).collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Collection<String> getSurroundingHighwayNames(Point2D point2D) {
|
private Collection<String> getSurroundingHighwayNames(Point point2D) {
|
||||||
if (this.nameMap.isEmpty()) {
|
if (this.nameMap.isEmpty()) {
|
||||||
return Collections.emptySet();
|
return Collections.emptySet();
|
||||||
}
|
}
|
||||||
|
@ -183,8 +184,9 @@ public class StreetAddressTest extends Test {
|
||||||
while (surroundingWays.isEmpty()) {
|
while (surroundingWays.isEmpty()) {
|
||||||
for (int x = -surrounding; x <= surrounding; x++) {
|
for (int x = -surrounding; x <= surrounding; x++) {
|
||||||
for (int y = -surrounding; y <= surrounding; y++) {
|
for (int y = -surrounding; y <= surrounding; y++) {
|
||||||
final var key = new Point2D.Double((long) Math.floor(point2D.getX() + x),
|
final var xPoint = (long) Math.floor(point2D.x() + x);
|
||||||
(long) Math.floor(point2D.getY() + y));
|
final var yPoint = (long) Math.floor(point2D.y() + y);
|
||||||
|
final var key = new Point(xPoint, yPoint);
|
||||||
if (this.nameMap.containsKey(key)) {
|
if (this.nameMap.containsKey(key)) {
|
||||||
surroundingWays.addAll(this.nameMap.get(key));
|
surroundingWays.addAll(this.nameMap.get(key));
|
||||||
}
|
}
|
||||||
|
@ -303,4 +305,20 @@ public class StreetAddressTest extends Test {
|
||||||
bbox.add(bbox.getTopLeftLon() - degree, bbox.getTopLeftLat() + degree);
|
bbox.add(bbox.getTopLeftLon() - degree, bbox.getTopLeftLat() + degree);
|
||||||
return bbox;
|
return bbox;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
private record Point(double x, double y) implements Comparable<Point> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(Point other) {
|
||||||
|
if (other.x == this.x && other.y == this.y) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (other.x < this.x) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (other.x > this.x) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return Double.compare(other.y, this.y);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
|
|
@ -51,6 +51,7 @@ class MapWithAIDefaultLayerTableModel extends DefaultTableModel {
|
||||||
columnDataRetrieval.add(info -> Optional.ofNullable(info.getTermsOfUseURL()).orElse(""));
|
columnDataRetrieval.add(info -> Optional.ofNullable(info.getTermsOfUseURL()).orElse(""));
|
||||||
columnDataRetrieval.add(i -> MapWithAILayerInfo.getInstance().getLayers().contains(i));
|
columnDataRetrieval.add(i -> MapWithAILayerInfo.getInstance().getLayers().contains(i));
|
||||||
MapWithAILayerInfo.getInstance().addFinishListener(() -> GuiHelper.runInEDT(this::fireTableDataChanged));
|
MapWithAILayerInfo.getInstance().addFinishListener(() -> GuiHelper.runInEDT(this::fireTableDataChanged));
|
||||||
|
MapWithAILayerInfo.SHOW_PREVIEW.addWeakListener(l -> GuiHelper.runInEDT(this::fireTableDataChanged));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -60,10 +61,11 @@ class MapWithAIDefaultLayerTableModel extends DefaultTableModel {
|
||||||
* @return The imagery info at the given row number
|
* @return The imagery info at the given row number
|
||||||
*/
|
*/
|
||||||
public static MapWithAIInfo getRow(int row) {
|
public static MapWithAIInfo getRow(int row) {
|
||||||
if (row == 0 && MapWithAILayerInfo.getInstance().getAllDefaultLayers().isEmpty()) {
|
final var layers = MapWithAILayerInfo.getInstance().getAllDefaultLayers();
|
||||||
|
if (row == 0 && layers.isEmpty()) {
|
||||||
return new MapWithAIInfo(tr("Loading"), "");
|
return new MapWithAIInfo(tr("Loading"), "");
|
||||||
}
|
}
|
||||||
return MapWithAILayerInfo.getInstance().getAllDefaultLayers().get(row);
|
return layers.get(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -6,13 +6,12 @@ import java.util.Optional;
|
||||||
|
|
||||||
import org.openstreetmap.josm.io.CachedFile;
|
import org.openstreetmap.josm.io.CachedFile;
|
||||||
import org.openstreetmap.josm.tools.HttpClient;
|
import org.openstreetmap.josm.tools.HttpClient;
|
||||||
|
import org.openstreetmap.josm.tools.Logging;
|
||||||
import org.openstreetmap.josm.tools.Utils;
|
import org.openstreetmap.josm.tools.Utils;
|
||||||
|
|
||||||
import jakarta.json.Json;
|
import jakarta.json.Json;
|
||||||
import jakarta.json.JsonObject;
|
import jakarta.json.stream.JsonParser;
|
||||||
import jakarta.json.JsonReader;
|
import jakarta.json.stream.JsonParsingException;
|
||||||
import jakarta.json.JsonStructure;
|
|
||||||
import jakarta.json.JsonValue;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read sources for MapWithAI
|
* Read sources for MapWithAI
|
||||||
|
@ -42,24 +41,26 @@ public abstract class CommonSourceReader<T> implements AutoCloseable {
|
||||||
this.cachedFile = new CachedFile(this.source);
|
this.cachedFile = new CachedFile(this.source);
|
||||||
}
|
}
|
||||||
this.cachedFile.setFastFail(this.fastFail);
|
this.cachedFile.setFastFail(this.fastFail);
|
||||||
try (JsonReader reader = Json.createReader(cachedFile.setMaxAge(CachedFile.DAYS)
|
try (JsonParser reader = Json.createParser(cachedFile.setMaxAge(CachedFile.DAYS)
|
||||||
.setCachingStrategy(CachedFile.CachingStrategy.IfModifiedSince).getContentReader())) {
|
.setCachingStrategy(CachedFile.CachingStrategy.IfModifiedSince).getContentReader())) {
|
||||||
JsonStructure struct = reader.read();
|
while (reader.hasNext()) {
|
||||||
if (JsonValue.ValueType.OBJECT == struct.getValueType()) {
|
if (reader.hasNext() && reader.next() == JsonParser.Event.START_OBJECT) {
|
||||||
final var jsonObject = struct.asJsonObject();
|
return Optional.ofNullable(this.parseJson(reader));
|
||||||
return Optional.ofNullable(this.parseJson(jsonObject));
|
}
|
||||||
}
|
}
|
||||||
return Optional.empty();
|
} catch (JsonParsingException jsonParsingException) {
|
||||||
|
Logging.error(jsonParsingException);
|
||||||
}
|
}
|
||||||
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses MapWithAI entry sources
|
* Parses MapWithAI entry sources
|
||||||
*
|
*
|
||||||
* @param jsonObject The json of the data sources
|
* @param parser The json of the data sources. This will be in the {@link JsonParser.Event#START_OBJECT} state.
|
||||||
* @return The parsed entries
|
* @return The parsed entries
|
||||||
*/
|
*/
|
||||||
public abstract T parseJson(JsonObject jsonObject);
|
public abstract T parseJson(JsonParser parser);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets whether opening HTTP connections should fail fast, i.e., whether a
|
* Sets whether opening HTTP connections should fail fast, i.e., whether a
|
||||||
|
|
|
@ -10,9 +10,9 @@ import java.util.stream.Collectors;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAICategory;
|
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAICategory;
|
||||||
import org.openstreetmap.josm.tools.Pair;
|
import org.openstreetmap.josm.tools.Pair;
|
||||||
|
|
||||||
import jakarta.json.JsonObject;
|
|
||||||
import jakarta.json.JsonString;
|
import jakarta.json.JsonString;
|
||||||
import jakarta.json.JsonValue;
|
import jakarta.json.JsonValue;
|
||||||
|
import jakarta.json.stream.JsonParser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read conflation entries from JSON
|
* Read conflation entries from JSON
|
||||||
|
@ -44,12 +44,12 @@ public class ConflationSourceReader extends CommonSourceReader<Map<MapWithAICate
|
||||||
/**
|
/**
|
||||||
* Parses MapWithAI entry sources
|
* Parses MapWithAI entry sources
|
||||||
*
|
*
|
||||||
* @param jsonObject The json of the data sources
|
* @param parser The json of the data sources
|
||||||
* @return The parsed entries
|
* @return The parsed entries
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Map<MapWithAICategory, List<String>> parseJson(JsonObject jsonObject) {
|
public Map<MapWithAICategory, List<String>> parseJson(JsonParser parser) {
|
||||||
return jsonObject.entrySet().stream().flatMap(i -> parse(i).stream())
|
return parser.getObjectStream().flatMap(i -> parse(i).stream())
|
||||||
.collect(Collectors.groupingBy(p -> p.a, Collectors.mapping(p -> p.b, Collectors.toList())));
|
.collect(Collectors.groupingBy(p -> p.a, Collectors.mapping(p -> p.b, Collectors.toList())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -164,7 +164,7 @@ public class ESRISourceReader {
|
||||||
newInfo.setName(feature.getString("title", feature.getString("name")));
|
newInfo.setName(feature.getString("title", feature.getString("name")));
|
||||||
final var extent = feature.getJsonArray("extent").getValuesAs(JsonArray.class).stream()
|
final var extent = feature.getJsonArray("extent").getValuesAs(JsonArray.class).stream()
|
||||||
.flatMap(array -> array.getValuesAs(JsonNumber.class).stream()).map(JsonNumber::doubleValue)
|
.flatMap(array -> array.getValuesAs(JsonNumber.class).stream()).map(JsonNumber::doubleValue)
|
||||||
.map(Object::toString).toArray(String[]::new);
|
.map(d -> Double.toString(d)).toArray(String[]::new);
|
||||||
final var imageryBounds = new ImageryBounds(String.join(",", extent[1], extent[0], extent[3], extent[2]), ",");
|
final var imageryBounds = new ImageryBounds(String.join(",", extent[1], extent[0], extent[3], extent[2]), ",");
|
||||||
newInfo.setBounds(imageryBounds);
|
newInfo.setBounds(imageryBounds);
|
||||||
newInfo.setSourceType(MapWithAIType.ESRI_FEATURE_SERVER);
|
newInfo.setSourceType(MapWithAIType.ESRI_FEATURE_SERVER);
|
||||||
|
|
|
@ -17,9 +17,9 @@ import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIType;
|
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIType;
|
||||||
import org.openstreetmap.josm.tools.Territories;
|
import org.openstreetmap.josm.tools.Territories;
|
||||||
|
|
||||||
import jakarta.json.JsonObject;
|
|
||||||
import jakarta.json.JsonString;
|
import jakarta.json.JsonString;
|
||||||
import jakarta.json.JsonValue;
|
import jakarta.json.JsonValue;
|
||||||
|
import jakarta.json.stream.JsonParser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reader to parse the list of available MapWithAI servers from an JSON
|
* Reader to parse the list of available MapWithAI servers from an JSON
|
||||||
|
@ -54,12 +54,12 @@ public class MapWithAISourceReader extends CommonSourceReader<List<MapWithAIInfo
|
||||||
/**
|
/**
|
||||||
* Parses MapWithAI entry sources
|
* Parses MapWithAI entry sources
|
||||||
*
|
*
|
||||||
* @param jsonObject The json of the data sources
|
* @param parser The json of the data sources
|
||||||
* @return The parsed entries
|
* @return The parsed entries
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<MapWithAIInfo> parseJson(JsonObject jsonObject) {
|
public List<MapWithAIInfo> parseJson(JsonParser parser) {
|
||||||
return jsonObject.entrySet().stream().map(MapWithAISourceReader::parse).collect(Collectors.toList());
|
return parser.getObjectStream().map(MapWithAISourceReader::parse).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MapWithAIInfo parse(Map.Entry<String, JsonValue> entry) {
|
private static MapWithAIInfo parse(Map.Entry<String, JsonValue> entry) {
|
||||||
|
|
|
@ -0,0 +1,146 @@
|
||||||
|
// License: GPL. For details, see LICENSE file.
|
||||||
|
package org.openstreetmap.josm.plugins.mapwithai.io.mapwithai;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.EnumSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import org.openstreetmap.josm.data.Bounds;
|
||||||
|
import org.openstreetmap.josm.data.imagery.ImageryInfo;
|
||||||
|
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAICategory;
|
||||||
|
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
|
||||||
|
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIType;
|
||||||
|
import org.openstreetmap.josm.plugins.pmtiles.lib.PMTiles;
|
||||||
|
import org.openstreetmap.josm.tools.Logging;
|
||||||
|
|
||||||
|
import jakarta.annotation.Nullable;
|
||||||
|
import jakarta.json.JsonArray;
|
||||||
|
import jakarta.json.JsonObject;
|
||||||
|
import jakarta.json.JsonString;
|
||||||
|
import jakarta.json.JsonValue;
|
||||||
|
import jakarta.json.stream.JsonParser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read data from overture sources
|
||||||
|
*/
|
||||||
|
public class OvertureSourceReader extends CommonSourceReader<List<MapWithAIInfo>> implements Closeable {
|
||||||
|
private final MapWithAIInfo source;
|
||||||
|
|
||||||
|
public OvertureSourceReader(MapWithAIInfo source) {
|
||||||
|
super(source.getUrl());
|
||||||
|
this.source = source;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<MapWithAIInfo> parseJson(JsonParser jsonParser) {
|
||||||
|
final var jsonObject = jsonParser.getObject();
|
||||||
|
if (jsonObject.containsKey("releases")) {
|
||||||
|
return parseRoot(jsonObject);
|
||||||
|
}
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<MapWithAIInfo> parseRoot(JsonObject jsonObject) {
|
||||||
|
final var info = new ArrayList<MapWithAIInfo>(6 * 4);
|
||||||
|
final var releases = jsonObject.get("releases");
|
||||||
|
final var baseUri = URI.create(this.source.getUrl()).resolve("./"); // safe since we created an URI from the source to get to this point
|
||||||
|
if (releases instanceof JsonArray rArray) {
|
||||||
|
rArray.parallelStream().flatMap(value -> parseReleases(baseUri, value)).filter(Objects::nonNull)
|
||||||
|
.forEachOrdered(info::add);
|
||||||
|
}
|
||||||
|
info.trimToSize();
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Stream<MapWithAIInfo> parseReleases(URI baseUri, JsonValue value) {
|
||||||
|
if (value instanceof JsonObject release && release.containsKey("release_id") && release.containsKey("files")) {
|
||||||
|
final var id = release.get("release_id");
|
||||||
|
final var files = release.get("files");
|
||||||
|
if (id instanceof JsonString sId && files instanceof JsonArray fArray) {
|
||||||
|
final String releaseId = sId.getString();
|
||||||
|
return fArray.parallelStream().map(file -> parseFile(baseUri, releaseId, file));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Stream.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse the individual file from the files array
|
||||||
|
* @param baseUri The base URI (if the href is relative)
|
||||||
|
* @param releaseId The release id to differentiate it from other releases with the same theme
|
||||||
|
* @param file The file object
|
||||||
|
* @return The info, if it was parsed. Otherwise {@code null}.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
private MapWithAIInfo parseFile(URI baseUri, String releaseId, JsonValue file) {
|
||||||
|
if (file instanceof JsonObject fObj && fObj.containsKey("theme") && fObj.containsKey("href")) {
|
||||||
|
final JsonValue vTheme = fObj.get("theme");
|
||||||
|
final JsonValue vHref = fObj.get("href");
|
||||||
|
try {
|
||||||
|
if (vTheme instanceof JsonString sTheme && vHref instanceof JsonString href) {
|
||||||
|
final var theme = sTheme.getString();
|
||||||
|
final URI uri;
|
||||||
|
if (href.getString().startsWith("./") || href.getString().startsWith("../")) {
|
||||||
|
uri = baseUri.resolve(href.getString());
|
||||||
|
} else {
|
||||||
|
uri = new URI(href.getString());
|
||||||
|
}
|
||||||
|
return buildSource(uri, releaseId, theme);
|
||||||
|
}
|
||||||
|
} catch (URISyntaxException uriSyntaxException) {
|
||||||
|
Logging.debug(uriSyntaxException);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private MapWithAIInfo buildSource(URI uri, String releaseId, String theme) {
|
||||||
|
final var info = new MapWithAIInfo(this.source);
|
||||||
|
info.setUrl(uri.toString());
|
||||||
|
info.setName(this.source.getName() + ": " + theme + " - " + releaseId);
|
||||||
|
if ("addresses".equals(theme)) {
|
||||||
|
info.setCategory(MapWithAICategory.ADDRESS);
|
||||||
|
} else if ("buildings".equals(theme)) {
|
||||||
|
info.setCategory(MapWithAICategory.BUILDING);
|
||||||
|
} else {
|
||||||
|
info.setCategory(MapWithAICategory.OTHER);
|
||||||
|
}
|
||||||
|
// Addresses and places are "interesting". Only removing "transportation" since that currently causes crashes.
|
||||||
|
if ("transportation".equals(theme)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
final var categories = EnumSet.of(this.source.getCategory(),
|
||||||
|
this.source.getAdditionalCategories().toArray(MapWithAICategory[]::new));
|
||||||
|
categories.removeIf(MapWithAICategory.OTHER::equals);
|
||||||
|
info.setAdditionalCategories(new ArrayList<>(categories));
|
||||||
|
info.setId(info.getName());
|
||||||
|
if (uri.getPath().endsWith(".pmtiles")) {
|
||||||
|
info.setSourceType(MapWithAIType.PMTILES);
|
||||||
|
// Set additional information
|
||||||
|
try {
|
||||||
|
final var header = PMTiles.readHeader(uri);
|
||||||
|
final var metadata = PMTiles.readMetadata(header);
|
||||||
|
final var bounds = new Bounds(header.minLatitude(), header.minLongitude(), header.maxLatitude(),
|
||||||
|
header.maxLongitude());
|
||||||
|
info.setBounds(new ImageryInfo.ImageryBounds(bounds.encodeAsString(","), ","));
|
||||||
|
if (metadata.containsKey("name") && metadata.get("name")instanceof JsonString name) {
|
||||||
|
info.setName(name.getString() + " - " + releaseId);
|
||||||
|
}
|
||||||
|
if (metadata.containsKey("description")
|
||||||
|
&& metadata.get("description")instanceof JsonString description) {
|
||||||
|
info.setDescription(description.getString());
|
||||||
|
}
|
||||||
|
} catch (IOException ioException) {
|
||||||
|
Logging.error(ioException);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
}
|
|
@ -160,7 +160,7 @@ public final class MapPaintUtils {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<String> sources = ds.allPrimitives().stream().map(MapPaintUtils::getSourceValue).filter(Objects::nonNull)
|
List<String> sources = ds.allPrimitives().stream().map(MapPaintUtils::getSourceValue).filter(Objects::nonNull)
|
||||||
.distinct().collect(Collectors.toList());
|
.map(s -> s.replace('.', '_')).distinct().collect(Collectors.toList());
|
||||||
if (!styleSource.isLoaded()) {
|
if (!styleSource.isLoaded()) {
|
||||||
styleSource.loadStyleSource();
|
styleSource.loadStyleSource();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
resources
|
|
@ -7,7 +7,20 @@
|
||||||
},
|
},
|
||||||
"response" : {
|
"response" : {
|
||||||
"status" : 200,
|
"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",
|
"jsonBody": {
|
||||||
|
"Taylor's Address Conflation Server": {
|
||||||
|
"categories": [
|
||||||
|
"addresses"
|
||||||
|
],
|
||||||
|
"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.",
|
||||||
|
"license": "AGPL",
|
||||||
|
"source": "{{ request.baseUrl }}/smocktaylor/serve_osm_files/",
|
||||||
|
"url": "{{ request.baseUrl }}/conflate"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"transformers": [
|
||||||
|
"response-template"
|
||||||
|
],
|
||||||
"headers" : {
|
"headers" : {
|
||||||
"Accept-Ranges" : "bytes",
|
"Accept-Ranges" : "bytes",
|
||||||
"Cache-Control" : "max-age=600",
|
"Cache-Control" : "max-age=600",
|
|
@ -0,0 +1,641 @@
|
||||||
|
{
|
||||||
|
"id" : "23497750-675c-440a-986a-34dd14b047f8",
|
||||||
|
"name" : "josm_mapwithai_json_sourcesjson",
|
||||||
|
"request" : {
|
||||||
|
"urlPattern" : "\/MapWithAI\/?json\/sources.json",
|
||||||
|
"method" : "GET"
|
||||||
|
},
|
||||||
|
"response" : {
|
||||||
|
"status" : 200,
|
||||||
|
"jsonBody": {
|
||||||
|
"Statewide Aggregate Addresses in Colorado 2019 (Public)": {
|
||||||
|
"countries": {
|
||||||
|
"US-CO": [
|
||||||
|
"addr:housenumber"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"license": "Public Domain",
|
||||||
|
"osm_compatible": "yes",
|
||||||
|
"parameters": [],
|
||||||
|
"permission_url": "{{ request.baseUrl }}/wiki/Import/Colorado_Addresses",
|
||||||
|
"url": "{{ request.baseUrl }}/coloradoAddresses/map?bbox={bbox}"
|
||||||
|
},
|
||||||
|
"MapWithAI": {
|
||||||
|
"countries": {
|
||||||
|
"AE": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"AF": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"AG": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"AI": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"AL": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"AM": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"AO": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"AR": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"AT": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"AU": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"AZ": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"BA": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"BB": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"BD": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"BE": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"BF": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"BG": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"BI": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"BJ": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"BL": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"BN": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"BO": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"BR": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"BS": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"BT": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"BW": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"BY": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"BZ": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"CA": [
|
||||||
|
"building",
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"CD": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"CF": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"CG": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"CH": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"CI": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"CL": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"CM": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"CN": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"CO": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"CR": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"CU": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"CY": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"CZ": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"DE": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"DJ": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"DK": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"DM": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"DO": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"DZ": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"EC": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"EE": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"EG": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"EH": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"ER": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"ES": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"ET": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"FK": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"FI": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"FJ": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"FR": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"GA": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"GB": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"GD": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"GE": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"GF": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"GH": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"GM": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"GN": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"GP": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"GQ": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"GR": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"GT": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"GW": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"GY": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"HN": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"HR": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"HT": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"HU": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"ID": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"IE": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"IL": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"IN": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"IQ": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"IS": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"IT": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"JM": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"JO": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"JP": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"KE": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"KG": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"KH": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"KN": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"KY": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"KR": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"KW": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"KZ": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"LA": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"LB": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"LC": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"LK": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"LR": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"LS": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"LT": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"LU": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"LV": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"LY": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"MA": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"MD": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"ME": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"MF": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"MG": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"MK": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"ML": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"MM": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"MN": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"MQ": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"MR": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"MS": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"MW": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"MX": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"MY": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"MZ": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"NA": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"NE": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"NG": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"NI": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"NL": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"NL-BQ2": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"NL-BQ3": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"NO": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"NP": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"NZ": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"OM": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"PA": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"PE": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"PF": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"PG": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"PH": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"PK": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"PL": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"PR": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"PS": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"PT": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"PY": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"QA": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"RO": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"RS": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"RS-KM": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"RU": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"RW": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"SA": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"SB": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"SD": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"SE": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"SG": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"SI": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"SK": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"SL": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"SN": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"SO": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"SR": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"SS": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"ST": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"SV": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"SX": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"SZ": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"TC": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"TD": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"TG": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"TH": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"TJ": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"TL": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"TM": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"TN": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"TR": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"TT": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"TW": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"TZ": [
|
||||||
|
"building",
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"UA": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"UG": [
|
||||||
|
"building",
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"US": [
|
||||||
|
"building",
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"US-AK": [
|
||||||
|
"building"
|
||||||
|
],
|
||||||
|
"US-HI": [
|
||||||
|
"building"
|
||||||
|
],
|
||||||
|
"UY": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"UZ": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"VC": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"VE": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"VG": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"VN": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"VU": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"YE": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"ZA": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"ZM": [
|
||||||
|
"highway"
|
||||||
|
],
|
||||||
|
"ZW": [
|
||||||
|
"highway"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"default": true,
|
||||||
|
"license": "ODBL",
|
||||||
|
"osm_compatible": "yes",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"description": "buildings",
|
||||||
|
"enabled": true,
|
||||||
|
"parameter": "result_type=road_building_vector_xml"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"permission_url": "{{ request.baseUrl }}/facebookmicrosites/Open-Mapping-At-Facebook/wiki/FAQ",
|
||||||
|
"terms_of_use_url": "{{ request.baseUrl }}/doc/license/MapWithAILicense.pdf",
|
||||||
|
"privacy_policy_url": "{{ request.baseUrl }}/doc/license/MapWithAIPrivacyPolicy.pdf#page=3",
|
||||||
|
"url": "{{ request.baseUrl }}/maps/ml_roads?conflate_with_osm=true&theme=ml_road_vector&collaborator=josm&token=ASb3N5o9HbX8QWn8G_NtHIRQaYv3nuG2r7_f3vnGld3KhZNCxg57IsaQyssIaEw5rfRNsPpMwg4TsnrSJtIJms5m&hash=ASawRla3rBcwEjY4HIY&bbox={bbox}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"transformers": [
|
||||||
|
"response-template"
|
||||||
|
],
|
||||||
|
"headers" : {
|
||||||
|
"Accept-Ranges" : "bytes",
|
||||||
|
"Cache-Control" : "max-age=600",
|
||||||
|
"Content-Type" : "application/json",
|
||||||
|
"Expires" : "Tue, 21 Apr 2020 19:51:40 UTC",
|
||||||
|
"Last-Modified" : "Tue, 21 Apr 2020 17:34:08 GMT",
|
||||||
|
"Vary" : "Origin",
|
||||||
|
"Date" : "Tue, 21 Apr 2020 19:41:40 GMT"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"uuid" : "23497750-675c-440a-986a-34dd14b047f8",
|
||||||
|
"persistent" : true,
|
||||||
|
"insertionIndex" : 1
|
||||||
|
}
|
File diff suppressed because one or more lines are too long
|
@ -24,6 +24,7 @@ import javax.imageio.ImageIO;
|
||||||
import javax.swing.Action;
|
import javax.swing.Action;
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
|
|
||||||
|
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
|
@ -40,13 +41,11 @@ import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIType;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.MapWithAISources;
|
import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.MapWithAISources;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.NoExceptions;
|
import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.NoExceptions;
|
||||||
import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
|
import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
|
||||||
import org.openstreetmap.josm.testutils.annotations.BasicWiremock;
|
|
||||||
import org.openstreetmap.josm.testutils.annotations.Projection;
|
import org.openstreetmap.josm.testutils.annotations.Projection;
|
||||||
import org.openstreetmap.josm.testutils.annotations.ThreadSync;
|
import org.openstreetmap.josm.testutils.annotations.ThreadSync;
|
||||||
import org.openstreetmap.josm.tools.ImageProvider;
|
import org.openstreetmap.josm.tools.ImageProvider;
|
||||||
import org.openstreetmap.josm.tools.Logging;
|
import org.openstreetmap.josm.tools.Logging;
|
||||||
|
|
||||||
import com.github.tomakehurst.wiremock.WireMockServer;
|
|
||||||
import com.github.tomakehurst.wiremock.client.WireMock;
|
import com.github.tomakehurst.wiremock.client.WireMock;
|
||||||
import com.github.tomakehurst.wiremock.matching.AnythingPattern;
|
import com.github.tomakehurst.wiremock.matching.AnythingPattern;
|
||||||
import com.github.tomakehurst.wiremock.matching.EqualToPattern;
|
import com.github.tomakehurst.wiremock.matching.EqualToPattern;
|
||||||
|
@ -74,14 +73,11 @@ class AddMapWithAILayerActionTest {
|
||||||
@RegisterExtension
|
@RegisterExtension
|
||||||
static ThreadSyncMWAI threadSync = new ThreadSyncMWAI();
|
static ThreadSyncMWAI threadSync = new ThreadSyncMWAI();
|
||||||
|
|
||||||
@BasicWiremock
|
|
||||||
WireMockServer wireMockServer;
|
|
||||||
|
|
||||||
private static MapWithAIInfo info;
|
private static MapWithAIInfo info;
|
||||||
private static MapWithAIInfo backupInfo;
|
private static MapWithAIInfo backupInfo;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setup() {
|
void setup(WireMockRuntimeInfo wireMockRuntimeInfo) {
|
||||||
final Map<String, StringValuePattern> parameterMap = new HashMap<>();
|
final Map<String, StringValuePattern> parameterMap = new HashMap<>();
|
||||||
final AnythingPattern anythingPattern = new AnythingPattern();
|
final AnythingPattern anythingPattern = new AnythingPattern();
|
||||||
parameterMap.put("geometryType", anythingPattern);
|
parameterMap.put("geometryType", anythingPattern);
|
||||||
|
@ -91,8 +87,9 @@ class AddMapWithAILayerActionTest {
|
||||||
parameterMap.put("outfields", new EqualToPattern("*"));
|
parameterMap.put("outfields", new EqualToPattern("*"));
|
||||||
parameterMap.put("result_type", new EqualToPattern("road_building_vector_xml"));
|
parameterMap.put("result_type", new EqualToPattern("road_building_vector_xml"));
|
||||||
parameterMap.put("resultOffset", anythingPattern);
|
parameterMap.put("resultOffset", anythingPattern);
|
||||||
wireMockServer.stubFor(
|
wireMockRuntimeInfo.getWireMock()
|
||||||
WireMock.get(new UrlPathPattern(new EqualToPattern("/query"), false)).withQueryParams(parameterMap)
|
.register(WireMock.get(new UrlPathPattern(new EqualToPattern("/query"), false))
|
||||||
|
.withQueryParams(parameterMap)
|
||||||
.willReturn(WireMock.aResponse()
|
.willReturn(WireMock.aResponse()
|
||||||
.withBody(Json.createObjectBuilder().add("type", "FeatureCollection")
|
.withBody(Json.createObjectBuilder().add("type", "FeatureCollection")
|
||||||
.add("features", Json.createArrayBuilder().build()).build().toString()))
|
.add("features", Json.createArrayBuilder().build()).build().toString()))
|
||||||
|
@ -142,7 +139,7 @@ class AddMapWithAILayerActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testRemoteIcon() throws IOException {
|
void testRemoteIcon(WireMockRuntimeInfo wireMockRuntimeInfo) throws IOException {
|
||||||
final ImageIcon blankImage = ImageProvider.createBlankIcon(ImageProvider.ImageSizes.LARGEICON);
|
final ImageIcon blankImage = ImageProvider.createBlankIcon(ImageProvider.ImageSizes.LARGEICON);
|
||||||
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||||
// BufferedImage is what the current implementation uses. Otherwise, we will
|
// BufferedImage is what the current implementation uses. Otherwise, we will
|
||||||
|
@ -150,10 +147,10 @@ class AddMapWithAILayerActionTest {
|
||||||
final BufferedImage bi = assertInstanceOf(BufferedImage.class, blankImage.getImage());
|
final BufferedImage bi = assertInstanceOf(BufferedImage.class, blankImage.getImage());
|
||||||
ImageIO.write(bi, "png", byteArrayOutputStream);
|
ImageIO.write(bi, "png", byteArrayOutputStream);
|
||||||
byte[] originalImage = byteArrayOutputStream.toByteArray();
|
byte[] originalImage = byteArrayOutputStream.toByteArray();
|
||||||
wireMockServer.addStubMapping(
|
wireMockRuntimeInfo.getWireMock()
|
||||||
wireMockServer.stubFor(WireMock.get("/icon").willReturn(WireMock.aResponse().withBody(originalImage))));
|
.register(WireMock.get("/icon").willReturn(WireMock.aResponse().withBody(originalImage)));
|
||||||
final MapWithAIInfo remoteInfo = new MapWithAIInfo(info);
|
final MapWithAIInfo remoteInfo = new MapWithAIInfo(info);
|
||||||
remoteInfo.setIcon(wireMockServer.baseUrl() + "/icon");
|
remoteInfo.setIcon(wireMockRuntimeInfo.getHttpBaseUrl() + "/icon");
|
||||||
final AddMapWithAILayerAction action = new AddMapWithAILayerAction(remoteInfo);
|
final AddMapWithAILayerAction action = new AddMapWithAILayerAction(remoteInfo);
|
||||||
threadSync.threadSync();
|
threadSync.threadSync();
|
||||||
final Object image = action.getValue(Action.LARGE_ICON_KEY);
|
final Object image = action.getValue(Action.LARGE_ICON_KEY);
|
||||||
|
@ -166,7 +163,7 @@ class AddMapWithAILayerActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testNonRegression22683() {
|
void testNonRegression22683(WireMockRuntimeInfo wireMockRuntimeInfo) {
|
||||||
final OsmDataLayer layer = new OsmDataLayer(new DataSet(), "testNonRegression22683", null);
|
final OsmDataLayer layer = new OsmDataLayer(new DataSet(), "testNonRegression22683", null);
|
||||||
layer.getDataSet().addDataSource(new DataSource(new Bounds(0, 0, 0.001, 0.001), "Area 1"));
|
layer.getDataSet().addDataSource(new DataSource(new Bounds(0, 0, 0.001, 0.001), "Area 1"));
|
||||||
layer.getDataSet().addDataSource(new DataSource(new Bounds(-0.001, -0.001, 0, 0), "Area 2"));
|
layer.getDataSet().addDataSource(new DataSource(new Bounds(-0.001, -0.001, 0, 0), "Area 2"));
|
||||||
|
@ -190,7 +187,7 @@ class AddMapWithAILayerActionTest {
|
||||||
};
|
};
|
||||||
Logging.getLogger().addHandler(testHandler);
|
Logging.getLogger().addHandler(testHandler);
|
||||||
try {
|
try {
|
||||||
info.setUrl(wireMockServer.baseUrl());
|
info.setUrl(wireMockRuntimeInfo.getHttpBaseUrl());
|
||||||
info.setSourceType(MapWithAIType.ESRI_FEATURE_SERVER);
|
info.setSourceType(MapWithAIType.ESRI_FEATURE_SERVER);
|
||||||
final AddMapWithAILayerAction action = new AddMapWithAILayerAction(info);
|
final AddMapWithAILayerAction action = new AddMapWithAILayerAction(info);
|
||||||
Logging.clearLastErrorAndWarnings();
|
Logging.clearLastErrorAndWarnings();
|
||||||
|
|
|
@ -5,8 +5,11 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
|
||||||
|
import com.github.tomakehurst.wiremock.stubbing.ServeEvent;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.openstreetmap.josm.data.Bounds;
|
import org.openstreetmap.josm.data.Bounds;
|
||||||
import org.openstreetmap.josm.data.osm.DataSet;
|
import org.openstreetmap.josm.data.osm.DataSet;
|
||||||
|
@ -17,12 +20,9 @@ import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIType;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.MapWithAIConfig;
|
import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.MapWithAIConfig;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.Wiremock;
|
import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.Wiremock;
|
||||||
import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
|
import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
|
||||||
import org.openstreetmap.josm.testutils.annotations.BasicWiremock;
|
|
||||||
import org.openstreetmap.josm.testutils.annotations.HTTP;
|
import org.openstreetmap.josm.testutils.annotations.HTTP;
|
||||||
import org.openstreetmap.josm.testutils.annotations.OsmApi;
|
import org.openstreetmap.josm.testutils.annotations.OsmApi;
|
||||||
|
|
||||||
import com.github.tomakehurst.wiremock.WireMockServer;
|
|
||||||
import com.github.tomakehurst.wiremock.admin.model.GetServeEventsResult;
|
|
||||||
import com.github.tomakehurst.wiremock.admin.model.ServeEventQuery;
|
import com.github.tomakehurst.wiremock.admin.model.ServeEventQuery;
|
||||||
import com.github.tomakehurst.wiremock.client.WireMock;
|
import com.github.tomakehurst.wiremock.client.WireMock;
|
||||||
import com.github.tomakehurst.wiremock.http.Request;
|
import com.github.tomakehurst.wiremock.http.Request;
|
||||||
|
@ -46,35 +46,32 @@ import com.github.tomakehurst.wiremock.verification.LoggedRequest;
|
||||||
class BoundingBoxMapWithAIDownloaderTest {
|
class BoundingBoxMapWithAIDownloaderTest {
|
||||||
private static final String TEST_DATA = "<osm version=\"0.6\"><node id=\"1\" lat=\"0\" lon=\"0\" version=\"1\"/><node id=\"2\" lat=\"1\" lon=\"1\" version=\"1\"/></osm>";
|
private static final String TEST_DATA = "<osm version=\"0.6\"><node id=\"1\" lat=\"0\" lon=\"0\" version=\"1\"/><node id=\"2\" lat=\"1\" lon=\"1\" version=\"1\"/></osm>";
|
||||||
|
|
||||||
@BasicWiremock
|
|
||||||
public WireMockServer wireMockServer;
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testThirdPartyConflation() {
|
void testThirdPartyConflation(WireMockRuntimeInfo wireMockRuntimeInfo) {
|
||||||
MapWithAIInfo.THIRD_PARTY_CONFLATE.put(true);
|
MapWithAIInfo.THIRD_PARTY_CONFLATE.put(true);
|
||||||
final MapWithAIInfo info = new MapWithAIInfo("testThirdPartyConflation",
|
final MapWithAIInfo info = new MapWithAIInfo("testThirdPartyConflation",
|
||||||
this.wireMockServer.baseUrl() + "/testThirdPartyConflation");
|
wireMockRuntimeInfo.getHttpBaseUrl() + "/testThirdPartyConflation");
|
||||||
// ADDRESS has a default /conflate endpoint from a mocked copy of conflation
|
// ADDRESS has a default /conflate endpoint from a mocked copy of conflation
|
||||||
// servers.
|
// servers.
|
||||||
info.setCategory(MapWithAICategory.ADDRESS);
|
info.setCategory(MapWithAICategory.ADDRESS);
|
||||||
final Bounds downloadBounds = new Bounds(-10, -10, 10, 10);
|
final Bounds downloadBounds = new Bounds(-10, -10, 10, 10);
|
||||||
final BoundingBoxMapWithAIDownloader boundingBoxMapWithAIDownloader = new BoundingBoxMapWithAIDownloader(
|
final BoundingBoxMapWithAIDownloader boundingBoxMapWithAIDownloader = new BoundingBoxMapWithAIDownloader(
|
||||||
downloadBounds, info, false);
|
downloadBounds, info, false);
|
||||||
this.wireMockServer.stubFor(
|
wireMockRuntimeInfo.getWireMock().register(
|
||||||
WireMock.get("/testThirdPartyConflation").willReturn(WireMock.aResponse().withBody(TEST_DATA)));
|
WireMock.get("/testThirdPartyConflation").willReturn(WireMock.aResponse().withBody(TEST_DATA)));
|
||||||
|
|
||||||
final StubMapping conflationStub = this.wireMockServer
|
final StubMapping conflationStub = wireMockRuntimeInfo.getWireMock()
|
||||||
.stubFor(WireMock.post("/conflate").willReturn(WireMock.aResponse()
|
.register(WireMock.post("/conflate").willReturn(WireMock.aResponse()
|
||||||
.withBody("<osm version=\"0.6\"><node id=\"1\" lat=\"0\" lon=\"0\" version=\"1\"/></osm>")));
|
.withBody("<osm version=\"0.6\"><node id=\"1\" lat=\"0\" lon=\"0\" version=\"1\"/></osm>")));
|
||||||
final DataSet ds = assertDoesNotThrow(
|
final DataSet ds = assertDoesNotThrow(
|
||||||
() -> boundingBoxMapWithAIDownloader.parseOsm(NullProgressMonitor.INSTANCE));
|
() -> boundingBoxMapWithAIDownloader.parseOsm(NullProgressMonitor.INSTANCE));
|
||||||
assertEquals(1, ds.allPrimitives().size());
|
assertEquals(1, ds.allPrimitives().size());
|
||||||
assertEquals(1L, ds.allPrimitives().iterator().next().getPrimitiveId().getUniqueId());
|
assertEquals(1L, ds.allPrimitives().iterator().next().getPrimitiveId().getUniqueId());
|
||||||
|
|
||||||
final GetServeEventsResult serveEvents = this.wireMockServer
|
final List<ServeEvent> serveEvents = wireMockRuntimeInfo.getWireMock()
|
||||||
.getServeEvents(ServeEventQuery.forStubMapping(conflationStub));
|
.getServeEvents(ServeEventQuery.forStubMapping(conflationStub));
|
||||||
assertEquals(1, serveEvents.getRequests().size());
|
assertEquals(1, serveEvents.size());
|
||||||
final LoggedRequest request = serveEvents.getRequests().get(0).getRequest();
|
final LoggedRequest request = serveEvents.get(0).getRequest();
|
||||||
assertEquals(1, request.getParts().size(),
|
assertEquals(1, request.getParts().size(),
|
||||||
request.getParts().stream().map(Request.Part::getName).collect(Collectors.joining(",")));
|
request.getParts().stream().map(Request.Part::getName).collect(Collectors.joining(",")));
|
||||||
assertNotNull(request.getPart("external"));
|
assertNotNull(request.getPart("external"));
|
||||||
|
@ -85,29 +82,35 @@ class BoundingBoxMapWithAIDownloaderTest {
|
||||||
* MapWithAI servers
|
* MapWithAI servers
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
void testNonRegression22624() {
|
void testNonRegression22624(WireMockRuntimeInfo wireMockRuntimeInfo) {
|
||||||
MapWithAIInfo.THIRD_PARTY_CONFLATE.put(true);
|
MapWithAIInfo.THIRD_PARTY_CONFLATE.put(true);
|
||||||
MapWithAIInfo info = new MapWithAIInfo("testNonRegression22624",
|
MapWithAIInfo info = new MapWithAIInfo("testNonRegression22624",
|
||||||
this.wireMockServer.baseUrl() + "/no-conflation?bbox={bbox}",
|
wireMockRuntimeInfo.getHttpBaseUrl() + "/no-conflation?bbox={bbox}",
|
||||||
MapWithAIType.ESRI_FEATURE_SERVER.getTypeString(), null, "testNonRegression22624");
|
MapWithAIType.ESRI_FEATURE_SERVER.getTypeString(), null, "testNonRegression22624");
|
||||||
info.setConflationUrl(this.wireMockServer.baseUrl() + "/conflation?bbox={bbox}");
|
info.setConflationUrl(wireMockRuntimeInfo.getHttpBaseUrl() + "/conflation?bbox={bbox}");
|
||||||
info.setConflation(true);
|
info.setConflation(true);
|
||||||
final Bounds downloadBounds = new Bounds(-10, -10, 10, 10);
|
final Bounds downloadBounds = new Bounds(-10, -10, 10, 10);
|
||||||
final BoundingBoxMapWithAIDownloader boundingBoxMapWithAIDownloader = new BoundingBoxMapWithAIDownloader(
|
final BoundingBoxMapWithAIDownloader boundingBoxMapWithAIDownloader = new BoundingBoxMapWithAIDownloader(
|
||||||
downloadBounds, info, false);
|
downloadBounds, info, false);
|
||||||
|
|
||||||
StubMapping noConflation = this.wireMockServer
|
StubMapping noConflation = wireMockRuntimeInfo.getWireMock()
|
||||||
.stubFor(WireMock.get("/no-conflation").willReturn(WireMock.badRequest()));
|
.register(WireMock.get("/no-conflation").willReturn(WireMock.badRequest()));
|
||||||
StubMapping resultOffset = this.wireMockServer.stubFor(
|
StubMapping resultOffset = wireMockRuntimeInfo.getWireMock()
|
||||||
WireMock.get(WireMock.urlPathEqualTo("/conflation")).withQueryParam("bbox", new AnythingPattern())
|
.register(WireMock.get(WireMock.urlPathEqualTo("/conflation"))
|
||||||
|
.withQueryParam("bbox", new AnythingPattern())
|
||||||
.withQueryParam("resultOffset", new EqualToPattern("0")).willReturn(WireMock.badRequest()));
|
.withQueryParam("resultOffset", new EqualToPattern("0")).willReturn(WireMock.badRequest()));
|
||||||
StubMapping noResultOffset = this.wireMockServer.stubFor(WireMock.get(WireMock.urlPathEqualTo("/conflation"))
|
StubMapping noResultOffset = wireMockRuntimeInfo.getWireMock()
|
||||||
.withQueryParam("bbox", new AnythingPattern()).withQueryParam("resultOffset", AbsentPattern.ABSENT)
|
.register(WireMock.get(WireMock.urlPathEqualTo("/conflation"))
|
||||||
.willReturn(WireMock.aResponse().withBody(TEST_DATA)));
|
.withQueryParam("bbox", new AnythingPattern())
|
||||||
|
.withQueryParam("resultOffset", AbsentPattern.ABSENT)
|
||||||
|
.willReturn(WireMock.aResponse().withBody(TEST_DATA)));
|
||||||
|
|
||||||
assertDoesNotThrow(() -> boundingBoxMapWithAIDownloader.parseOsm(NullProgressMonitor.INSTANCE));
|
assertDoesNotThrow(() -> boundingBoxMapWithAIDownloader.parseOsm(NullProgressMonitor.INSTANCE));
|
||||||
this.wireMockServer.verify(0, RequestPatternBuilder.forCustomMatcher(noConflation.getRequest()));
|
wireMockRuntimeInfo.getWireMock().verifyThat(0,
|
||||||
this.wireMockServer.verify(0, RequestPatternBuilder.forCustomMatcher(resultOffset.getRequest()));
|
RequestPatternBuilder.forCustomMatcher(noConflation.getRequest()));
|
||||||
this.wireMockServer.verify(1, RequestPatternBuilder.forCustomMatcher(noResultOffset.getRequest()));
|
wireMockRuntimeInfo.getWireMock().verifyThat(0,
|
||||||
|
RequestPatternBuilder.forCustomMatcher(resultOffset.getRequest()));
|
||||||
|
wireMockRuntimeInfo.getWireMock().verifyThat(1,
|
||||||
|
RequestPatternBuilder.forCustomMatcher(noResultOffset.getRequest()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,8 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
|
||||||
|
import com.github.tomakehurst.wiremock.matching.RequestPatternBuilder;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.function.ThrowingSupplier;
|
import org.junit.jupiter.api.function.ThrowingSupplier;
|
||||||
|
@ -24,10 +26,8 @@ import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIConflati
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.MapWithAISources;
|
import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.MapWithAISources;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.Wiremock;
|
import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.Wiremock;
|
||||||
import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
|
import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
|
||||||
import org.openstreetmap.josm.testutils.annotations.BasicWiremock;
|
|
||||||
import org.openstreetmap.josm.testutils.annotations.HTTP;
|
import org.openstreetmap.josm.testutils.annotations.HTTP;
|
||||||
|
|
||||||
import com.github.tomakehurst.wiremock.WireMockServer;
|
|
||||||
import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder;
|
import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder;
|
||||||
import com.github.tomakehurst.wiremock.client.WireMock;
|
import com.github.tomakehurst.wiremock.client.WireMock;
|
||||||
import com.github.tomakehurst.wiremock.stubbing.StubMapping;
|
import com.github.tomakehurst.wiremock.stubbing.StubMapping;
|
||||||
|
@ -46,9 +46,6 @@ import mockit.MockUp;
|
||||||
@Wiremock
|
@Wiremock
|
||||||
@MapWithAISources
|
@MapWithAISources
|
||||||
class DataConflationSenderTest {
|
class DataConflationSenderTest {
|
||||||
@BasicWiremock
|
|
||||||
WireMockServer wireMockServer;
|
|
||||||
|
|
||||||
static class MapWithAIConflationCategoryMock extends MockUp<MapWithAIConflationCategory> {
|
static class MapWithAIConflationCategoryMock extends MockUp<MapWithAIConflationCategory> {
|
||||||
static String url;
|
static String url;
|
||||||
|
|
||||||
|
@ -81,10 +78,10 @@ class DataConflationSenderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testWorkingUrl() {
|
void testWorkingUrl(WireMockRuntimeInfo wireMockRuntimeInfo) {
|
||||||
MapWithAIConflationCategoryMock.url = wireMockServer.baseUrl() + "/conflate";
|
MapWithAIConflationCategoryMock.url = wireMockRuntimeInfo.getHttpBaseUrl() + "/conflate";
|
||||||
final StubMapping stubMapping = wireMockServer
|
final StubMapping stubMapping = wireMockRuntimeInfo.getWireMock()
|
||||||
.stubFor(WireMock.post("/conflate").willReturn(WireMock.aResponse().withBody(
|
.register(WireMock.post("/conflate").willReturn(WireMock.aResponse().withBody(
|
||||||
"<?xml version='1.0' encoding='UTF-8'?><osm version='0.6' generator='DataConflationSenderTest#testWorkingUrl'><node id='1' version='1' visible='true' lat='89.0' lon='0.1' /></osm>")));
|
"<?xml version='1.0' encoding='UTF-8'?><osm version='0.6' generator='DataConflationSenderTest#testWorkingUrl'><node id='1' version='1' visible='true' lat='89.0' lon='0.1' /></osm>")));
|
||||||
new MapWithAIConflationCategoryMock();
|
new MapWithAIConflationCategoryMock();
|
||||||
|
|
||||||
|
@ -99,15 +96,14 @@ class DataConflationSenderTest {
|
||||||
assertEquals(1, conflated.getNodes().size());
|
assertEquals(1, conflated.getNodes().size());
|
||||||
final Node conflatedNode = conflated.getNodes().iterator().next();
|
final Node conflatedNode = conflated.getNodes().iterator().next();
|
||||||
assertEquals(new LatLon(89, 0.1), conflatedNode.getCoor());
|
assertEquals(new LatLon(89, 0.1), conflatedNode.getCoor());
|
||||||
assertEquals(1, wireMockServer.getAllServeEvents().stream()
|
wireMockRuntimeInfo.getWireMock().verifyThat(1, RequestPatternBuilder.like(stubMapping.getRequest()));
|
||||||
.filter(serveEvent -> stubMapping.equals(serveEvent.getStubMapping())).count());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testWorkingUrlTimeout() {
|
void testWorkingUrlTimeout(WireMockRuntimeInfo wireMockRuntimeInfo) {
|
||||||
MapWithAIConflationCategoryMock.url = wireMockServer.baseUrl() + "/conflate";
|
MapWithAIConflationCategoryMock.url = wireMockRuntimeInfo.getHttpBaseUrl() + "/conflate";
|
||||||
final StubMapping stubMapping = wireMockServer.stubFor(WireMock.post("/conflate")
|
final StubMapping stubMapping = wireMockRuntimeInfo.getWireMock()
|
||||||
.willReturn(WireMock.aResponse().withBody(
|
.register(WireMock.post("/conflate").willReturn(WireMock.aResponse().withBody(
|
||||||
"<?xml version='1.0' encoding='UTF-8'?><osm version='0.6' generator='DataConflationSenderTest#testWorkingUrl'><node id='1' version='1' visible='true' lat='89.0' lon='0.1' /></osm>")
|
"<?xml version='1.0' encoding='UTF-8'?><osm version='0.6' generator='DataConflationSenderTest#testWorkingUrl'><node id='1' version='1' visible='true' lat='89.0' lon='0.1' /></osm>")
|
||||||
.withFixedDelay(500)));
|
.withFixedDelay(500)));
|
||||||
new MapWithAIConflationCategoryMock();
|
new MapWithAIConflationCategoryMock();
|
||||||
|
@ -123,8 +119,7 @@ class DataConflationSenderTest {
|
||||||
assertEquals(1, conflated.getNodes().size());
|
assertEquals(1, conflated.getNodes().size());
|
||||||
final Node conflatedNode = conflated.getNodes().iterator().next();
|
final Node conflatedNode = conflated.getNodes().iterator().next();
|
||||||
assertEquals(new LatLon(89, 0.1), conflatedNode.getCoor());
|
assertEquals(new LatLon(89, 0.1), conflatedNode.getCoor());
|
||||||
assertEquals(1, wireMockServer.getAllServeEvents().stream()
|
wireMockRuntimeInfo.getWireMock().verifyThat(1, RequestPatternBuilder.like(stubMapping.getRequest()));
|
||||||
.filter(serveEvent -> stubMapping.equals(serveEvent.getStubMapping())).count());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Stream<Arguments> testNonWorkingUrl() {
|
static Stream<Arguments> testNonWorkingUrl() {
|
||||||
|
@ -135,9 +130,10 @@ class DataConflationSenderTest {
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource
|
@MethodSource
|
||||||
void testNonWorkingUrl(final ResponseDefinitionBuilder response) {
|
void testNonWorkingUrl(final ResponseDefinitionBuilder response, final WireMockRuntimeInfo wireMockRuntimeInfo) {
|
||||||
MapWithAIConflationCategoryMock.url = wireMockServer.baseUrl() + "/conflate";
|
MapWithAIConflationCategoryMock.url = wireMockRuntimeInfo.getHttpBaseUrl() + "/conflate";
|
||||||
final StubMapping stubMapping = wireMockServer.stubFor(WireMock.post("/conflate").willReturn(response));
|
final StubMapping stubMapping = wireMockRuntimeInfo.getWireMock()
|
||||||
|
.register(WireMock.post("/conflate").willReturn(response));
|
||||||
new MapWithAIConflationCategoryMock();
|
new MapWithAIConflationCategoryMock();
|
||||||
|
|
||||||
final DataSet external = new DataSet(new Node(LatLon.NORTH_POLE));
|
final DataSet external = new DataSet(new Node(LatLon.NORTH_POLE));
|
||||||
|
@ -147,7 +143,6 @@ class DataConflationSenderTest {
|
||||||
dataConflationSender.run();
|
dataConflationSender.run();
|
||||||
final DataSet conflated = assertDoesNotThrow((ThrowingSupplier<DataSet>) dataConflationSender::get);
|
final DataSet conflated = assertDoesNotThrow((ThrowingSupplier<DataSet>) dataConflationSender::get);
|
||||||
assertNull(conflated);
|
assertNull(conflated);
|
||||||
assertEquals(1, wireMockServer.getAllServeEvents().stream()
|
wireMockRuntimeInfo.getWireMock().verifyThat(1, RequestPatternBuilder.like(stubMapping.getRequest()));
|
||||||
.filter(serveEvent -> stubMapping.equals(serveEvent.getStubMapping())).count());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,8 @@ import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
|
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
|
||||||
import org.awaitility.Awaitility;
|
import org.awaitility.Awaitility;
|
||||||
import org.awaitility.Durations;
|
import org.awaitility.Durations;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
@ -21,19 +21,13 @@ import org.openstreetmap.josm.gui.MainApplication;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
|
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIType;
|
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIType;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.Wiremock;
|
import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.Wiremock;
|
||||||
import org.openstreetmap.josm.testutils.annotations.BasicWiremock;
|
|
||||||
import org.openstreetmap.josm.testutils.annotations.Projection;
|
import org.openstreetmap.josm.testutils.annotations.Projection;
|
||||||
import org.openstreetmap.josm.tools.JosmRuntimeException;
|
import org.openstreetmap.josm.tools.JosmRuntimeException;
|
||||||
|
|
||||||
import com.github.tomakehurst.wiremock.WireMockServer;
|
|
||||||
|
|
||||||
@Projection
|
@Projection
|
||||||
@Wiremock
|
@Wiremock
|
||||||
class ESRISourceReaderTest {
|
class ESRISourceReaderTest {
|
||||||
|
|
||||||
@BasicWiremock
|
|
||||||
public WireMockServer wireMockServer;
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setUp() {
|
void setUp() {
|
||||||
ESRISourceReader.SOURCE_CACHE.clear();
|
ESRISourceReader.SOURCE_CACHE.clear();
|
||||||
|
@ -51,11 +45,11 @@ class ESRISourceReaderTest {
|
||||||
* file/wiremocked file
|
* file/wiremocked file
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
void testAddEsriLayer() throws IOException {
|
void testAddEsriLayer(WireMockRuntimeInfo wireMockRuntimeInfo) throws IOException {
|
||||||
// TODO wiremock
|
// TODO wiremock
|
||||||
MapWithAIInfo info = new MapWithAIInfo("TEST", "test_url", "bdf6c800b3ae453b9db239e03d7c1727");
|
MapWithAIInfo info = new MapWithAIInfo("TEST", "test_url", "bdf6c800b3ae453b9db239e03d7c1727");
|
||||||
info.setSourceType(MapWithAIType.ESRI);
|
info.setSourceType(MapWithAIType.ESRI);
|
||||||
String tUrl = wireMockServer.url("/sharing/rest");
|
String tUrl = wireMockRuntimeInfo.getHttpBaseUrl() + "/sharing/rest";
|
||||||
for (String url : Arrays.asList(tUrl, tUrl + "/")) {
|
for (String url : Arrays.asList(tUrl, tUrl + "/")) {
|
||||||
info.setUrl(url);
|
info.setUrl(url);
|
||||||
final ESRISourceReader reader = new ESRISourceReader(info);
|
final ESRISourceReader reader = new ESRISourceReader(info);
|
||||||
|
@ -65,7 +59,7 @@ class ESRISourceReaderTest {
|
||||||
} catch (ExecutionException | InterruptedException e) {
|
} catch (ExecutionException | InterruptedException e) {
|
||||||
throw new JosmRuntimeException(e);
|
throw new JosmRuntimeException(e);
|
||||||
}
|
}
|
||||||
}).collect(Collectors.toList());
|
}).toList();
|
||||||
Future<?> workerQueue = MainApplication.worker.submit(() -> {
|
Future<?> workerQueue = MainApplication.worker.submit(() -> {
|
||||||
/* Sync threads */});
|
/* Sync threads */});
|
||||||
Awaitility.await().atMost(Durations.FIVE_SECONDS).until(workerQueue::isDone);
|
Awaitility.await().atMost(Durations.FIVE_SECONDS).until(workerQueue::isDone);
|
||||||
|
|
|
@ -5,6 +5,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.StringReader;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -20,6 +21,7 @@ import jakarta.json.Json;
|
||||||
import jakarta.json.JsonArrayBuilder;
|
import jakarta.json.JsonArrayBuilder;
|
||||||
import jakarta.json.JsonObjectBuilder;
|
import jakarta.json.JsonObjectBuilder;
|
||||||
import jakarta.json.JsonValue;
|
import jakarta.json.JsonValue;
|
||||||
|
import jakarta.json.stream.JsonParser;
|
||||||
|
|
||||||
@BasicPreferences
|
@BasicPreferences
|
||||||
@Territories
|
@Territories
|
||||||
|
@ -29,8 +31,12 @@ class MapWithAISourceReaderTest {
|
||||||
void testParseSimple() throws IOException {
|
void testParseSimple() throws IOException {
|
||||||
JsonObjectBuilder builder = Json.createObjectBuilder();
|
JsonObjectBuilder builder = Json.createObjectBuilder();
|
||||||
builder.add("nowhere", JsonValue.NULL);
|
builder.add("nowhere", JsonValue.NULL);
|
||||||
try (var reader = new MapWithAISourceReader("")) {
|
final String json = builder.build().toString();
|
||||||
List<MapWithAIInfo> infoList = reader.parseJson(builder.build());
|
try (var reader = new MapWithAISourceReader("");
|
||||||
|
StringReader sr = new java.io.StringReader(json);
|
||||||
|
JsonParser parser = Json.createParser(sr)) {
|
||||||
|
parser.next();
|
||||||
|
List<MapWithAIInfo> infoList = reader.parseJson(parser);
|
||||||
assertEquals(1, infoList.size());
|
assertEquals(1, infoList.size());
|
||||||
assertEquals("nowhere", infoList.get(0).getName());
|
assertEquals("nowhere", infoList.get(0).getName());
|
||||||
}
|
}
|
||||||
|
@ -45,9 +51,12 @@ class MapWithAISourceReaderTest {
|
||||||
JsonArrayBuilder coCountriesArray = Json.createArrayBuilder(Collections.singleton("addr:housenumber"));
|
JsonArrayBuilder coCountriesArray = Json.createArrayBuilder(Collections.singleton("addr:housenumber"));
|
||||||
coCountries.add("US-CO", coCountriesArray.build());
|
coCountries.add("US-CO", coCountriesArray.build());
|
||||||
co.add("countries", coCountries.build());
|
co.add("countries", coCountries.build());
|
||||||
builder.add("Colorado", co);
|
String json = builder.add("Colorado", co).build().toString();
|
||||||
try (var reader = new MapWithAISourceReader("")) {
|
try (var reader = new MapWithAISourceReader("");
|
||||||
List<MapWithAIInfo> infoList = reader.parseJson(builder.build());
|
StringReader sr = new StringReader(json);
|
||||||
|
JsonParser parser = Json.createParser(sr)) {
|
||||||
|
parser.next();
|
||||||
|
List<MapWithAIInfo> infoList = reader.parseJson(parser);
|
||||||
assertEquals(1, infoList.size());
|
assertEquals(1, infoList.size());
|
||||||
MapWithAIInfo info = infoList.stream().filter(i -> "Colorado".equals(i.getName())).findFirst().orElse(null);
|
MapWithAIInfo info = infoList.stream().filter(i -> "Colorado".equals(i.getName())).findFirst().orElse(null);
|
||||||
assertNotNull(info);
|
assertNotNull(info);
|
||||||
|
|
|
@ -8,14 +8,13 @@ import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
|
||||||
import org.junit.jupiter.api.extension.AfterEachCallback;
|
import org.junit.jupiter.api.extension.AfterEachCallback;
|
||||||
import org.junit.jupiter.api.extension.BeforeEachCallback;
|
import org.junit.jupiter.api.extension.BeforeEachCallback;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.spi.preferences.IMapWithAIUrls;
|
import org.openstreetmap.josm.plugins.mapwithai.spi.preferences.IMapWithAIUrls;
|
||||||
|
|
||||||
import com.github.tomakehurst.wiremock.WireMockServer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the MapWithAI config for the test
|
* Set the MapWithAI config for the test
|
||||||
*
|
*
|
||||||
|
@ -29,7 +28,7 @@ import com.github.tomakehurst.wiremock.WireMockServer;
|
||||||
public @interface MapWithAIConfig {
|
public @interface MapWithAIConfig {
|
||||||
class MapWithAIConfigExtension extends Wiremock.WiremockExtension implements BeforeEachCallback, AfterEachCallback {
|
class MapWithAIConfigExtension extends Wiremock.WiremockExtension implements BeforeEachCallback, AfterEachCallback {
|
||||||
@Override
|
@Override
|
||||||
public void beforeEach(ExtensionContext context) throws Exception {
|
public void beforeEach(ExtensionContext context) {
|
||||||
org.openstreetmap.josm.plugins.mapwithai.spi.preferences.MapWithAIConfig
|
org.openstreetmap.josm.plugins.mapwithai.spi.preferences.MapWithAIConfig
|
||||||
.setUrlsProvider(new WireMockMapWithAIUrls(getWiremock(context)));
|
.setUrlsProvider(new WireMockMapWithAIUrls(getWiremock(context)));
|
||||||
}
|
}
|
||||||
|
@ -42,25 +41,25 @@ public @interface MapWithAIConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class WireMockMapWithAIUrls implements IMapWithAIUrls {
|
private static final class WireMockMapWithAIUrls implements IMapWithAIUrls {
|
||||||
private final WireMockServer wireMockServer;
|
private final WireMockRuntimeInfo wireMockServer;
|
||||||
|
|
||||||
public WireMockMapWithAIUrls(final WireMockServer wireMockServer) {
|
public WireMockMapWithAIUrls(final WireMockRuntimeInfo wireMockServer) {
|
||||||
this.wireMockServer = wireMockServer;
|
this.wireMockServer = wireMockServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getConflationServerJson() {
|
public String getConflationServerJson() {
|
||||||
return this.wireMockServer.baseUrl() + "/MapWithAI/json/conflation_servers.json";
|
return this.wireMockServer.getHttpBaseUrl() + "/MapWithAI/json/conflation_servers.json";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getMapWithAISourcesJson() {
|
public String getMapWithAISourcesJson() {
|
||||||
return this.wireMockServer.baseUrl() + "/MapWithAI/json/sources.json";
|
return this.wireMockServer.getHttpBaseUrl() + "/MapWithAI/json/sources.json";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getMapWithAIPaintStyle() {
|
public String getMapWithAIPaintStyle() {
|
||||||
return this.wireMockServer.baseUrl() + "/josmfile?page=Styles/MapWithAI&zip=1";
|
return this.wireMockServer.getHttpBaseUrl() + "/josmfile?page=Styles/MapWithAI&zip=1";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,25 @@
|
||||||
// License: GPL. For details, see LICENSE file.
|
// License: GPL. For details, see LICENSE file.
|
||||||
package org.openstreetmap.josm.plugins.mapwithai.testutils.annotations;
|
package org.openstreetmap.josm.plugins.mapwithai.testutils.annotations;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
|
||||||
import org.awaitility.Awaitility;
|
import org.awaitility.Awaitility;
|
||||||
import org.awaitility.Durations;
|
import org.awaitility.Durations;
|
||||||
|
import org.junit.jupiter.api.extension.AfterAllCallback;
|
||||||
|
import org.junit.jupiter.api.extension.AfterEachCallback;
|
||||||
|
import org.junit.jupiter.api.extension.BeforeAllCallback;
|
||||||
|
import org.junit.jupiter.api.extension.BeforeEachCallback;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||||
import org.junit.platform.commons.support.AnnotationSupport;
|
import org.junit.platform.commons.support.AnnotationSupport;
|
||||||
|
@ -29,11 +39,8 @@ import org.openstreetmap.josm.testutils.annotations.Territories;
|
||||||
|
|
||||||
import com.github.tomakehurst.wiremock.WireMockServer;
|
import com.github.tomakehurst.wiremock.WireMockServer;
|
||||||
import com.github.tomakehurst.wiremock.client.WireMock;
|
import com.github.tomakehurst.wiremock.client.WireMock;
|
||||||
import com.github.tomakehurst.wiremock.common.FileSource;
|
import org.openstreetmap.josm.tools.Logging;
|
||||||
import com.github.tomakehurst.wiremock.extension.Parameters;
|
import org.openstreetmap.josm.tools.ReflectionUtils;
|
||||||
import com.github.tomakehurst.wiremock.extension.ResponseTransformer;
|
|
||||||
import com.github.tomakehurst.wiremock.http.Request;
|
|
||||||
import com.github.tomakehurst.wiremock.http.Response;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test annotation to ensure that wiremock is used
|
* Test annotation to ensure that wiremock is used
|
||||||
|
@ -44,8 +51,8 @@ import com.github.tomakehurst.wiremock.http.Response;
|
||||||
@Target({ ElementType.PARAMETER, ElementType.TYPE, ElementType.METHOD })
|
@Target({ ElementType.PARAMETER, ElementType.TYPE, ElementType.METHOD })
|
||||||
@BasicPreferences
|
@BasicPreferences
|
||||||
@HTTP
|
@HTTP
|
||||||
|
@BasicWiremock(value = "src/test/resources/wiremock")
|
||||||
@ExtendWith(Wiremock.TestMapWithAIUrls.class)
|
@ExtendWith(Wiremock.TestMapWithAIUrls.class)
|
||||||
@BasicWiremock(value = "src/test/resources/wiremock", responseTransformers = Wiremock.WireMockUrlTransformer.class)
|
|
||||||
public @interface Wiremock {
|
public @interface Wiremock {
|
||||||
/**
|
/**
|
||||||
* Set to {@code false} to turn off wiremock (use only in integration tests)
|
* Set to {@code false} to turn off wiremock (use only in integration tests)
|
||||||
|
@ -54,72 +61,34 @@ public @interface Wiremock {
|
||||||
*/
|
*/
|
||||||
boolean value() default true;
|
boolean value() default true;
|
||||||
|
|
||||||
/**
|
|
||||||
* Replace URL's with the wiremock URL
|
|
||||||
*
|
|
||||||
* @author Taylor Smock
|
|
||||||
*/
|
|
||||||
class WireMockUrlTransformer extends ResponseTransformer {
|
|
||||||
private final ExtensionContext context;
|
|
||||||
|
|
||||||
public WireMockUrlTransformer(ExtensionContext context) {
|
|
||||||
this.context = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return "Convert urls in responses to wiremock url";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Response transform(Request request, Response response, FileSource files, Parameters parameters) {
|
|
||||||
if (!request.getUrl().endsWith("/capabilities")
|
|
||||||
&& response.getHeaders().getContentTypeHeader().mimeTypePart() != null
|
|
||||||
&& !response.getHeaders().getContentTypeHeader().mimeTypePart().contains("application/zip")) {
|
|
||||||
String origBody = response.getBodyAsString();
|
|
||||||
String newBody = origBody.replaceAll("https?://.*?/",
|
|
||||||
WiremockExtension.getWiremock(context).baseUrl() + "/");
|
|
||||||
return Response.Builder.like(response).but().body(newBody).build();
|
|
||||||
}
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the base wiremock extension class
|
* This is the base wiremock extension class
|
||||||
*/
|
*/
|
||||||
class WiremockExtension extends BasicWiremock.WireMockExtension {
|
class WiremockExtension {
|
||||||
/**
|
/**
|
||||||
* Get the default wiremock server
|
* Get the default wiremock server
|
||||||
*
|
*
|
||||||
* @param context The context to search
|
* @param context The context to search
|
||||||
* @return The wiremock server
|
* @return The wiremock server
|
||||||
*/
|
*/
|
||||||
public static WireMockServer getWiremock(ExtensionContext context) {
|
public static WireMockRuntimeInfo getWiremock(ExtensionContext context) {
|
||||||
ExtensionContext.Namespace namespace = ExtensionContext.Namespace.create(BasicWiremock.class);
|
return context.getStore(ExtensionContext.Namespace.create(BasicWiremock.WireMockExtension.class))
|
||||||
return context.getStore(namespace).get(WireMockServer.class, WireMockServer.class);
|
.get(BasicWiremock.WireMockExtension.class, BasicWiremock.WireMockExtension.class).getRuntimeInfo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extension for {@link MapWithAILayerInfo}
|
* Extension for {@link MapWithAILayerInfo}
|
||||||
*/
|
*/
|
||||||
class MapWithAILayerInfoExtension extends WiremockExtension {
|
class MapWithAILayerInfoExtension extends WiremockExtension implements BeforeAllCallback, AfterAllCallback {
|
||||||
private static int hashCode;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterAll(ExtensionContext context) throws Exception {
|
public void afterAll(ExtensionContext context) {
|
||||||
try {
|
resetMapWithAILayerInfo(context);
|
||||||
super.afterAll(context);
|
|
||||||
} finally {
|
|
||||||
resetMapWithAILayerInfo(context);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void beforeAll(ExtensionContext context) throws Exception {
|
public void beforeAll(ExtensionContext context) {
|
||||||
super.beforeAll(context);
|
|
||||||
|
|
||||||
MapWithAILayerInfo.setImageryLayersSites(null);
|
MapWithAILayerInfo.setImageryLayersSites(null);
|
||||||
AtomicBoolean finished = new AtomicBoolean();
|
AtomicBoolean finished = new AtomicBoolean();
|
||||||
MapWithAILayerInfo.getInstance().clear();
|
MapWithAILayerInfo.getInstance().clear();
|
||||||
|
@ -141,29 +110,49 @@ public @interface Wiremock {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestMapWithAIUrls extends WiremockExtension implements IMapWithAIUrls {
|
class TestMapWithAIUrls extends WiremockExtension
|
||||||
|
implements IMapWithAIUrls, BeforeAllCallback, BeforeEachCallback, AfterAllCallback, AfterEachCallback {
|
||||||
ExtensionContext context;
|
ExtensionContext context;
|
||||||
private static boolean conflationServerInitialized;
|
private static boolean conflationServerInitialized;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replace URL servers with wiremock
|
||||||
|
*
|
||||||
|
* @param baseUrl The wiremock to point to
|
||||||
|
* @param url The URL to fix
|
||||||
|
* @return A url that points at the wiremock server
|
||||||
|
*/
|
||||||
|
public static String replaceUrl(String baseUrl, String url) {
|
||||||
|
try {
|
||||||
|
URL temp = new URL(url);
|
||||||
|
return baseUrl + temp.getFile();
|
||||||
|
} catch (MalformedURLException error) {
|
||||||
|
Logging.error(error);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getConflationServerJson() {
|
public String getConflationServerJson() {
|
||||||
conflationServerInitialized = true;
|
conflationServerInitialized = true;
|
||||||
return replaceUrl(getWiremock(this.context), MapWithAIUrls.getInstance().getConflationServerJson());
|
return replaceUrl(getWiremock(this.context).getHttpBaseUrl(),
|
||||||
|
MapWithAIUrls.getInstance().getConflationServerJson());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getMapWithAISourcesJson() {
|
public String getMapWithAISourcesJson() {
|
||||||
return replaceUrl(getWiremock(this.context), MapWithAIUrls.getInstance().getMapWithAISourcesJson());
|
return replaceUrl(getWiremock(this.context).getHttpBaseUrl(),
|
||||||
|
MapWithAIUrls.getInstance().getMapWithAISourcesJson());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getMapWithAIPaintStyle() {
|
public String getMapWithAIPaintStyle() {
|
||||||
return replaceUrl(getWiremock(this.context), MapWithAIUrls.getInstance().getMapWithAIPaintStyle());
|
return replaceUrl(getWiremock(this.context).getHttpBaseUrl(),
|
||||||
|
MapWithAIUrls.getInstance().getMapWithAIPaintStyle());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void beforeAll(ExtensionContext context) throws Exception {
|
public void beforeAll(ExtensionContext context) {
|
||||||
super.beforeAll(context);
|
|
||||||
final Optional<Wiremock> annotation = AnnotationUtils.findFirstParentAnnotation(context, Wiremock.class);
|
final Optional<Wiremock> annotation = AnnotationUtils.findFirstParentAnnotation(context, Wiremock.class);
|
||||||
this.context = context;
|
this.context = context;
|
||||||
if (Boolean.FALSE.equals(annotation.map(Wiremock::value).orElse(Boolean.TRUE))) {
|
if (Boolean.FALSE.equals(annotation.map(Wiremock::value).orElse(Boolean.TRUE))) {
|
||||||
|
@ -174,44 +163,48 @@ public @interface Wiremock {
|
||||||
if (conflationServerInitialized) {
|
if (conflationServerInitialized) {
|
||||||
MapWithAIConflationCategory.initialize();
|
MapWithAIConflationCategory.initialize();
|
||||||
}
|
}
|
||||||
AnnotationUtils.resetStaticClass(DataAvailability.class);
|
assertDoesNotThrow(() -> AnnotationUtils.resetStaticClass(DataAvailability.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void beforeEach(ExtensionContext context) throws Exception {
|
public void beforeEach(ExtensionContext context) {
|
||||||
final Optional<Wiremock> annotation = AnnotationUtils.findFirstParentAnnotation(context, Wiremock.class);
|
final Optional<Wiremock> annotation = AnnotationUtils.findFirstParentAnnotation(context, Wiremock.class);
|
||||||
this.context = context;
|
this.context = context;
|
||||||
if (annotation.isPresent()) {
|
if (annotation.isPresent()) {
|
||||||
this.beforeAll(context);
|
this.beforeAll(context);
|
||||||
}
|
}
|
||||||
final WireMockServer wireMockServer = getWiremock(context);
|
final WireMock wireMockServer = getWiremock(context).getWireMock();
|
||||||
|
|
||||||
super.beforeEach(context);
|
if (wireMockServer.allStubMappings().getMappings().stream()
|
||||||
|
.filter(mapping -> mapping.getRequest().getUrl() != null).noneMatch(mapping -> mapping.getRequest()
|
||||||
if (wireMockServer.getStubMappings().stream().filter(mapping -> mapping.getRequest().getUrl() != null)
|
.getUrl().equals("/MapWithAI/json/conflation_servers.json"))) {
|
||||||
.noneMatch(mapping -> mapping.getRequest().getUrl()
|
wireMockServer.register(WireMock.get("/MapWithAI/json/conflation_servers.json")
|
||||||
.equals("/MapWithAI/json/conflation_servers.json"))) {
|
|
||||||
wireMockServer.stubFor(WireMock.get("/MapWithAI/json/conflation_servers.json")
|
|
||||||
.willReturn(WireMock.aResponse().withBody("{}")).atPriority(-5));
|
.willReturn(WireMock.aResponse().withBody("{}")).atPriority(-5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterAll(ExtensionContext context) throws Exception {
|
public void afterEach(ExtensionContext extensionContext) {
|
||||||
|
this.context = extensionContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterAll(ExtensionContext context) {
|
||||||
|
this.context = context;
|
||||||
// @Wiremock stops the WireMockServer prior to this method being called
|
// @Wiremock stops the WireMockServer prior to this method being called
|
||||||
getWiremock(context).start();
|
final WireMockServer wireMockServer = assertDoesNotThrow(() -> {
|
||||||
MapPaintUtils.removeMapWithAIPaintStyles();
|
final Field serverField = WireMockRuntimeInfo.class.getDeclaredField("wireMockServer");
|
||||||
|
ReflectionUtils.setObjectsAccessible(serverField);
|
||||||
|
return (WireMockServer) serverField.get(getWiremock(context));
|
||||||
|
});
|
||||||
try {
|
try {
|
||||||
// This stops the WireMockServer again.
|
wireMockServer.start();
|
||||||
super.afterAll(context);
|
MapPaintUtils.removeMapWithAIPaintStyles();
|
||||||
|
wireMockServer.stop();
|
||||||
} finally {
|
} finally {
|
||||||
MapWithAIConfig.setUrlsProvider(new InvalidMapWithAIUrls());
|
MapWithAIConfig.setUrlsProvider(new InvalidMapWithAIUrls());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public WireMockServer getWireMockServer() {
|
|
||||||
return getWiremock(context);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class InvalidMapWithAIUrls implements IMapWithAIUrls {
|
class InvalidMapWithAIUrls implements IMapWithAIUrls {
|
||||||
|
|
Ładowanie…
Reference in New Issue