kopia lustrzana https://github.com/JOSM/MapWithAI
Use jakarta.json instead of javax.json
Signed-off-by: Taylor Smock <tsmock@meta.com>pull/36/head v811
rodzic
dd3cb880a6
commit
6107e3b2c8
|
@ -18,12 +18,12 @@ jobs:
|
|||
call-workflow:
|
||||
strategy:
|
||||
matrix:
|
||||
josm-revision: ["", "r18589"]
|
||||
josm-revision: ["", "r18723"]
|
||||
uses: JOSM/JOSMPluginAction/.github/workflows/ant.yml@v1
|
||||
with:
|
||||
java-version: 17
|
||||
josm-revision: ${{ matrix.josm-revision }}
|
||||
plugin-jar-name: 'mapwithai'
|
||||
perform-revision-tagging: ${{ github.repository == 'JOSM/MapWithAI' && github.ref_type == 'branch' && github.ref_name == 'master' && github.event_name != 'schedule' && github.event_name != 'pull_request' && matrix.josm-revision == 'r18589' }}
|
||||
perform-revision-tagging: ${{ github.repository == 'JOSM/MapWithAI' && github.ref_type == 'branch' && github.ref_name == 'master' && github.event_name != 'schedule' && github.event_name != 'pull_request' && matrix.josm-revision == 'r18723' }}
|
||||
secrets: inherit
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
<target name="additional-manifest">
|
||||
<manifest file="MANIFEST" mode="update">
|
||||
<attribute name="18590_Plugin-Url" value="810;https://github.com/JOSM/MapWithAI/releases/download/v810/mapwithai.jar" />
|
||||
<attribute name="18218_Plugin-Url" value="v1.9.20;https://github.com/JOSM/MapWithAI/releases/download/v1.9.20/mapwithai.jar" />
|
||||
<attribute name="17903_Plugin-Url" value="v1.8.7;https://github.com/JOSM/MapWithAI/releases/download/v1.8.7/mapwithai.jar" />
|
||||
<attribute name="17084_Plugin-Url" value="v1.7.1.6;https://github.com/JOSM/MapWithAI/releases/download/v1.7.1.6/mapwithai.jar" />
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
# The minimum JOSM version this plugin is compatible with (can be any numeric version
|
||||
plugin.main.version = 18589
|
||||
plugin.main.version = 18723
|
||||
# The JOSM version this plugin is currently compiled against
|
||||
# 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.
|
||||
plugin.compile.version = 18590
|
||||
plugin.compile.version = 18724
|
||||
plugin.canloadatruntime = true
|
||||
plugin.author = Taylor Smock
|
||||
plugin.class = org.openstreetmap.josm.plugins.mapwithai.MapWithAIPlugin
|
||||
|
|
|
@ -3,9 +3,6 @@ package org.openstreetmap.josm.plugins.mapwithai.backend;
|
|||
|
||||
import static org.openstreetmap.josm.tools.I18n.tr;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonValue;
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
@ -52,6 +49,10 @@ import org.openstreetmap.josm.tools.HttpClient;
|
|||
import org.openstreetmap.josm.tools.JosmRuntimeException;
|
||||
import org.openstreetmap.josm.tools.Logging;
|
||||
|
||||
import jakarta.json.Json;
|
||||
import jakarta.json.JsonValue;
|
||||
import jakarta.json.stream.JsonParser;
|
||||
|
||||
/**
|
||||
* A bounding box downloader for MapWithAI
|
||||
*
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
// License: GPL. For details, see LICENSE file.
|
||||
package org.openstreetmap.josm.plugins.mapwithai.backend;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonException;
|
||||
import javax.json.JsonObject;
|
||||
import javax.json.JsonValue;
|
||||
import javax.json.stream.JsonParser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
|
@ -29,6 +23,11 @@ import org.openstreetmap.josm.tools.Logging;
|
|||
import org.openstreetmap.josm.tools.Territories;
|
||||
import org.openstreetmap.josm.tools.Utils;
|
||||
|
||||
import jakarta.json.Json;
|
||||
import jakarta.json.JsonException;
|
||||
import jakarta.json.JsonObject;
|
||||
import jakarta.json.JsonValue;
|
||||
|
||||
/**
|
||||
* Check for data availability in an area
|
||||
*/
|
||||
|
@ -69,16 +68,16 @@ public class DataAvailability {
|
|||
* Initialize the class
|
||||
*/
|
||||
private static void initialize() {
|
||||
try (CachedFile jsonFile = new CachedFile(MapWithAIConfig.getUrls().getMapWithAISourcesJson());
|
||||
JsonParser jsonParser = Json.createParser(jsonFile.getContentReader())) {
|
||||
try (var jsonFile = new CachedFile(MapWithAIConfig.getUrls().getMapWithAISourcesJson());
|
||||
var jsonParser = Json.createParser(jsonFile.getContentReader())) {
|
||||
jsonFile.setMaxAge(SEVEN_DAYS_IN_SECONDS);
|
||||
jsonParser.next();
|
||||
JsonObject jsonObject = jsonParser.getObject();
|
||||
for (Map.Entry<String, JsonValue> entry : jsonObject.entrySet()) {
|
||||
final var jsonObject = jsonParser.getObject();
|
||||
for (var entry : jsonObject.entrySet()) {
|
||||
Logging.debug("{0}: {1}", entry.getKey(), entry.getValue());
|
||||
if (JsonValue.ValueType.OBJECT == entry.getValue().getValueType()
|
||||
&& entry.getValue().asJsonObject().containsKey("countries")) {
|
||||
JsonValue countries = entry.getValue().asJsonObject().get("countries");
|
||||
final var countries = entry.getValue().asJsonObject().get("countries");
|
||||
parseCountries(COUNTRIES, countries, entry.getValue());
|
||||
}
|
||||
}
|
||||
|
@ -127,7 +126,7 @@ public class DataAvailability {
|
|||
if (JsonValue.ValueType.ARRAY == entry.getValue().getValueType()) {
|
||||
for (String provide : entry.getValue().asJsonArray().stream()
|
||||
.filter(c -> JsonValue.ValueType.STRING == c.getValueType()).map(JsonValue::toString)
|
||||
.map(DataAvailability::stripQuotes).collect(Collectors.toList())) {
|
||||
.map(DataAvailability::stripQuotes).toList()) {
|
||||
providesMap.put(provide, true);
|
||||
}
|
||||
}
|
||||
|
@ -136,7 +135,7 @@ public class DataAvailability {
|
|||
&& JsonValue.ValueType.ARRAY == information.asJsonObject().get(PROVIDES).getValueType()) {
|
||||
for (String provide : information.asJsonObject().getJsonArray(PROVIDES).stream()
|
||||
.filter(val -> JsonValue.ValueType.STRING == val.getValueType()).map(JsonValue::toString)
|
||||
.map(DataAvailability::stripQuotes).collect(Collectors.toList())) {
|
||||
.map(DataAvailability::stripQuotes).toList()) {
|
||||
providesMap.put(provide, Boolean.TRUE);
|
||||
}
|
||||
}
|
||||
|
@ -190,15 +189,13 @@ public class DataAvailability {
|
|||
* @return true if it is in an ares with data from MapWithAI
|
||||
*/
|
||||
public boolean hasData(LatLon latLon) {
|
||||
boolean returnBoolean = false;
|
||||
for (final Map.Entry<String, Map<String, Boolean>> entry : COUNTRIES.entrySet()) {
|
||||
Logging.debug(entry.getKey());
|
||||
if (Territories.isIso3166Code(entry.getKey(), latLon)) {
|
||||
returnBoolean = entry.getValue().entrySet().stream().anyMatch(Map.Entry::getValue);
|
||||
break;
|
||||
return entry.getValue().entrySet().stream().anyMatch(Map.Entry::getValue);
|
||||
}
|
||||
}
|
||||
return returnBoolean;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,12 +3,6 @@ package org.openstreetmap.josm.plugins.mapwithai.data.mapwithai;
|
|||
|
||||
import static org.openstreetmap.josm.tools.I18n.tr;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonArray;
|
||||
import javax.json.JsonObject;
|
||||
import javax.json.JsonValue;
|
||||
import javax.json.stream.JsonParser;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.io.StringReader;
|
||||
|
@ -36,6 +30,12 @@ import org.openstreetmap.josm.tools.CheckParameterUtil;
|
|||
import org.openstreetmap.josm.tools.Logging;
|
||||
import org.openstreetmap.josm.tools.Utils;
|
||||
|
||||
import jakarta.json.Json;
|
||||
import jakarta.json.JsonArray;
|
||||
import jakarta.json.JsonObject;
|
||||
import jakarta.json.JsonValue;
|
||||
import jakarta.json.stream.JsonParser;
|
||||
|
||||
/**
|
||||
* The information needed to download external data
|
||||
*/
|
||||
|
|
|
@ -3,10 +3,6 @@ package org.openstreetmap.josm.plugins.mapwithai.gui.preferences.mapwithai;
|
|||
|
||||
import static org.openstreetmap.josm.tools.I18n.tr;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonArray;
|
||||
import javax.json.JsonArrayBuilder;
|
||||
import javax.json.JsonObjectBuilder;
|
||||
import javax.swing.AbstractButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
|
@ -22,6 +18,7 @@ import java.awt.GridBagConstraints;
|
|||
import java.awt.GridBagLayout;
|
||||
import java.awt.LayoutManager;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.io.Serial;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
@ -42,10 +39,16 @@ import org.openstreetmap.josm.tools.GBC;
|
|||
import org.openstreetmap.josm.tools.Logging;
|
||||
import org.openstreetmap.josm.tools.Pair;
|
||||
|
||||
import jakarta.json.Json;
|
||||
import jakarta.json.JsonArray;
|
||||
import jakarta.json.JsonArrayBuilder;
|
||||
import jakarta.json.JsonObjectBuilder;
|
||||
|
||||
/**
|
||||
* An panel used to add MapWithAI sources.
|
||||
* A panel used to add MapWithAI sources.
|
||||
*/
|
||||
class AddMapWithAIPanel extends JPanel {
|
||||
@Serial
|
||||
private static final long serialVersionUID = -2838267045934203122L;
|
||||
private final transient JPanel layerPanel = new JPanel(new GridBagLayout());
|
||||
|
||||
|
@ -77,9 +80,9 @@ class AddMapWithAIPanel extends JPanel {
|
|||
this(new GridBagLayout());
|
||||
headersTable = new HeadersTable();
|
||||
parametersTable = new MapWithAIParametersPanel();
|
||||
minimumCacheExpiry = new JSpinner(new SpinnerNumberModel(
|
||||
(Number) TimeUnit.MILLISECONDS.toSeconds(TMSCachedTileLoaderJob.MINIMUM_EXPIRES.get()), 0L,
|
||||
Long.valueOf(Integer.MAX_VALUE), 1));
|
||||
minimumCacheExpiry = new JSpinner(
|
||||
new SpinnerNumberModel(TimeUnit.MILLISECONDS.toSeconds(TMSCachedTileLoaderJob.MINIMUM_EXPIRES.get()),
|
||||
0L, Integer.MAX_VALUE, 1));
|
||||
List<String> units = Arrays.asList(tr("seconds"), tr("minutes"), tr("hours"), tr("days"));
|
||||
minimumCacheExpiryUnit = new JComboBox<>(units.toArray(new String[] {}));
|
||||
currentUnit = TimeUnit.SECONDS;
|
||||
|
@ -87,24 +90,23 @@ class AddMapWithAIPanel extends JPanel {
|
|||
if (e.getStateChange() == ItemEvent.SELECTED) {
|
||||
long newValue = 0;
|
||||
switch (units.indexOf(e.getItem())) {
|
||||
case 0:
|
||||
case 0 -> {
|
||||
newValue = currentUnit.toSeconds((long) minimumCacheExpiry.getValue());
|
||||
currentUnit = TimeUnit.SECONDS;
|
||||
break;
|
||||
case 1:
|
||||
}
|
||||
case 1 -> {
|
||||
newValue = currentUnit.toMinutes((long) minimumCacheExpiry.getValue());
|
||||
currentUnit = TimeUnit.MINUTES;
|
||||
break;
|
||||
case 2:
|
||||
}
|
||||
case 2 -> {
|
||||
newValue = currentUnit.toHours((long) minimumCacheExpiry.getValue());
|
||||
currentUnit = TimeUnit.HOURS;
|
||||
break;
|
||||
case 3:
|
||||
}
|
||||
case 3 -> {
|
||||
newValue = currentUnit.toDays((long) minimumCacheExpiry.getValue());
|
||||
currentUnit = TimeUnit.DAYS;
|
||||
break;
|
||||
default:
|
||||
Logging.warn("Unknown unit: " + units.indexOf(e.getItem()));
|
||||
}
|
||||
default -> Logging.warn("Unknown unit: " + units.indexOf(e.getItem()));
|
||||
}
|
||||
minimumCacheExpiry.setValue(newValue);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,14 @@ package org.openstreetmap.josm.plugins.mapwithai.gui.preferences.mapwithai;
|
|||
|
||||
import static org.openstreetmap.josm.tools.I18n.tr;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import javax.swing.event.TableModelListener;
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import javax.swing.table.TableModel;
|
||||
|
||||
import java.awt.GridBagLayout;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
@ -11,19 +19,12 @@ import java.util.Set;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.json.JsonArray;
|
||||
import javax.json.JsonObject;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import javax.swing.event.TableModelListener;
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import javax.swing.table.TableModel;
|
||||
|
||||
import org.openstreetmap.josm.tools.GBC;
|
||||
import org.openstreetmap.josm.tools.Pair;
|
||||
|
||||
import jakarta.json.JsonArray;
|
||||
import jakarta.json.JsonObject;
|
||||
|
||||
/**
|
||||
* Parameters panel for adding MapWithAI URLs
|
||||
*
|
||||
|
@ -37,26 +38,20 @@ class MapWithAIParametersPanel extends JPanel {
|
|||
|
||||
@Override
|
||||
public String getColumnName(int column) {
|
||||
switch (column) {
|
||||
case 0:
|
||||
return tr("Parameter name");
|
||||
case 1:
|
||||
return tr("Parameter value");
|
||||
case 2:
|
||||
return tr("Enabled");
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
return switch (column) {
|
||||
case 0 -> tr("Parameter name");
|
||||
case 1 -> tr("Parameter value");
|
||||
case 2 -> tr("Enabled");
|
||||
default -> "";
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getColumnClass(int column) {
|
||||
switch (column) {
|
||||
case 2:
|
||||
if (column == 2) {
|
||||
return Boolean.class;
|
||||
default:
|
||||
return String.class;
|
||||
}
|
||||
return String.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -134,7 +129,7 @@ class MapWithAIParametersPanel extends JPanel {
|
|||
super(new GridBagLayout());
|
||||
this.headers = getHeadersAsVector(headers);
|
||||
this.model = new ParametersTableModel();
|
||||
JTable table = new JTable(model);
|
||||
final var table = new JTable(model);
|
||||
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
table.setAutoCreateRowSorter(true);
|
||||
table.setRowSelectionAllowed(false);
|
||||
|
@ -143,7 +138,7 @@ class MapWithAIParametersPanel extends JPanel {
|
|||
}
|
||||
|
||||
private static List<Object[]> getHeadersAsVector(Map<String, Pair<String, Boolean>> headers) {
|
||||
return headers.entrySet().stream().sorted((e1, e2) -> e1.getKey().compareTo(e2.getKey()))
|
||||
return headers.entrySet().stream().sorted(Map.Entry.comparingByKey())
|
||||
.map(e -> new Object[] { e.getKey(), e.getValue().a, e.getValue().b }).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
@ -163,13 +158,13 @@ class MapWithAIParametersPanel extends JPanel {
|
|||
* @param parameters The initial parameters to show in the dialog
|
||||
*/
|
||||
public void setParameters(JsonArray parameters) {
|
||||
int i = 0;
|
||||
var i = 0;
|
||||
for (JsonObject obj : parameters.stream().filter(JsonObject.class::isInstance).map(JsonObject.class::cast)
|
||||
.collect(Collectors.toList())) {
|
||||
.toList()) {
|
||||
model.setValueAt(obj.getString("parameter"), i, 1);
|
||||
model.setValueAt(obj.getString("description", ""), i, 0);
|
||||
model.setValueAt(obj.getBoolean("enabled", false), i, 2);
|
||||
boolean permanent = obj.getBoolean("permanent", false);
|
||||
final var permanent = obj.getBoolean("permanent", false);
|
||||
if (permanent) {
|
||||
model.disableRowEdits(i);
|
||||
}
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
// License: GPL. For details, see LICENSE file.
|
||||
package org.openstreetmap.josm.plugins.mapwithai.io.mapwithai;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonObject;
|
||||
import javax.json.JsonReader;
|
||||
import javax.json.JsonStructure;
|
||||
import javax.json.JsonValue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
|
||||
|
@ -14,6 +8,12 @@ import org.openstreetmap.josm.io.CachedFile;
|
|||
import org.openstreetmap.josm.tools.HttpClient;
|
||||
import org.openstreetmap.josm.tools.Utils;
|
||||
|
||||
import jakarta.json.Json;
|
||||
import jakarta.json.JsonObject;
|
||||
import jakarta.json.JsonReader;
|
||||
import jakarta.json.JsonStructure;
|
||||
import jakarta.json.JsonValue;
|
||||
|
||||
/**
|
||||
* Read sources for MapWithAI
|
||||
*
|
||||
|
@ -46,7 +46,7 @@ public abstract class CommonSourceReader<T> implements AutoCloseable {
|
|||
.setCachingStrategy(CachedFile.CachingStrategy.IfModifiedSince).getContentReader())) {
|
||||
JsonStructure struct = reader.read();
|
||||
if (JsonValue.ValueType.OBJECT == struct.getValueType()) {
|
||||
JsonObject jsonObject = struct.asJsonObject();
|
||||
final var jsonObject = struct.asJsonObject();
|
||||
return Optional.ofNullable(this.parseJson(jsonObject));
|
||||
}
|
||||
return Optional.empty();
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
// License: GPL. For details, see LICENSE file.
|
||||
package org.openstreetmap.josm.plugins.mapwithai.io.mapwithai;
|
||||
|
||||
import javax.json.JsonObject;
|
||||
import javax.json.JsonString;
|
||||
import javax.json.JsonValue;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
@ -14,6 +10,10 @@ import java.util.stream.Collectors;
|
|||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAICategory;
|
||||
import org.openstreetmap.josm.tools.Pair;
|
||||
|
||||
import jakarta.json.JsonObject;
|
||||
import jakarta.json.JsonString;
|
||||
import jakarta.json.JsonValue;
|
||||
|
||||
/**
|
||||
* Read conflation entries from JSON
|
||||
*/
|
||||
|
@ -55,10 +55,10 @@ public class ConflationSourceReader extends CommonSourceReader<Map<MapWithAICate
|
|||
|
||||
private static List<Pair<MapWithAICategory, String>> parse(Map.Entry<String, JsonValue> entry) {
|
||||
if (JsonValue.ValueType.OBJECT == entry.getValue().getValueType()) {
|
||||
JsonObject object = entry.getValue().asJsonObject();
|
||||
String url = object.getString("url", null);
|
||||
final var object = entry.getValue().asJsonObject();
|
||||
final var url = object.getString("url", null);
|
||||
List<MapWithAICategory> categories = object.getJsonArray("categories").getValuesAs(JsonString.class)
|
||||
.stream().map(JsonString::toString).map(MapWithAICategory::fromString).collect(Collectors.toList());
|
||||
.stream().map(JsonString::toString).map(MapWithAICategory::fromString).toList();
|
||||
return categories.stream().map(c -> new Pair<>(c, url)).collect(Collectors.toList());
|
||||
}
|
||||
return Collections.emptyList();
|
||||
|
|
|
@ -3,14 +3,6 @@ package org.openstreetmap.josm.plugins.mapwithai.io.mapwithai;
|
|||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonArray;
|
||||
import javax.json.JsonNumber;
|
||||
import javax.json.JsonObject;
|
||||
import javax.json.JsonString;
|
||||
import javax.json.JsonValue;
|
||||
import javax.json.spi.JsonProvider;
|
||||
import javax.json.stream.JsonParsingException;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
|
@ -26,6 +18,8 @@ import java.util.concurrent.ExecutionException;
|
|||
import java.util.concurrent.ForkJoinTask;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -42,6 +36,16 @@ import org.openstreetmap.josm.spi.preferences.Config;
|
|||
import org.openstreetmap.josm.tools.HttpClient;
|
||||
import org.openstreetmap.josm.tools.Logging;
|
||||
|
||||
import jakarta.json.Json;
|
||||
import jakarta.json.JsonArray;
|
||||
import jakarta.json.JsonNumber;
|
||||
import jakarta.json.JsonObject;
|
||||
import jakarta.json.JsonString;
|
||||
import jakarta.json.JsonValue;
|
||||
import jakarta.json.spi.JsonProvider;
|
||||
import jakarta.json.stream.JsonParser;
|
||||
import jakarta.json.stream.JsonParsingException;
|
||||
|
||||
/**
|
||||
* Take a {@link MapWithAIType#ESRI} layer and convert it to a list of "true"
|
||||
* layers.
|
||||
|
@ -99,31 +103,35 @@ public class ESRISourceReader {
|
|||
|
||||
final var information = new ArrayList<ForkJoinTask<MapWithAIInfo>>();
|
||||
|
||||
var next = 1;
|
||||
var searchUrl = startReplace.matcher(search).replaceAll(Integer.toString(next));
|
||||
final var next = new AtomicInteger(1);
|
||||
final var searchUrl = new AtomicReference<>(
|
||||
startReplace.matcher(search).replaceAll(Integer.toString(next.get())));
|
||||
|
||||
while (next != -1) {
|
||||
final var finalUrl = url + "content/groups/" + group + searchUrl;
|
||||
while (next.get() != -1) {
|
||||
final var finalUrl = url + "content/groups/" + group + searchUrl.get();
|
||||
final var jsonString = getJsonString(finalUrl, TimeUnit.SECONDS.toMillis(MIRROR_MAXTIME.get()) / 7,
|
||||
this.fastFail);
|
||||
if (jsonString == null) {
|
||||
continue;
|
||||
}
|
||||
try (var reader = jsonProvider
|
||||
.createReader(new ByteArrayInputStream(jsonString.getBytes(StandardCharsets.UTF_8)))) {
|
||||
final var parser = reader.read();
|
||||
if (parser.getValueType() == JsonValue.ValueType.OBJECT) {
|
||||
final var obj = parser.asJsonObject();
|
||||
next = obj.getInt("nextStart", -1);
|
||||
searchUrl = startReplace.matcher(search).replaceAll(Integer.toString(next));
|
||||
final var features = obj.getJsonArray("results");
|
||||
for (var feature : features.getValuesAs(JsonObject.class)) {
|
||||
information.add(parse(feature));
|
||||
}
|
||||
try (var parser = jsonProvider
|
||||
.createParser(new ByteArrayInputStream(jsonString.getBytes(StandardCharsets.UTF_8)))) {
|
||||
/* Do nothing */
|
||||
if (parser.hasNext() && parser.next() == JsonParser.Event.START_OBJECT) {
|
||||
parser.getObjectStream().forEach(entry -> {
|
||||
if ("nextStart".equals(entry.getKey()) && entry.getValue() instanceof JsonNumber number) {
|
||||
next.set(number.intValue());
|
||||
searchUrl.set(startReplace.matcher(search).replaceAll(Integer.toString(next.get())));
|
||||
} else if ("results".equals(entry.getKey()) && entry.getValue() instanceof JsonArray features) {
|
||||
for (var feature : features.getValuesAs(JsonObject.class)) {
|
||||
information.add(parse(feature));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (ClassCastException e) {
|
||||
Logging.error(e);
|
||||
next = -1;
|
||||
next.set(-1);
|
||||
}
|
||||
}
|
||||
for (var future : information) {
|
||||
|
|
|
@ -1,16 +1,10 @@
|
|||
// License: GPL. For details, see LICENSE file.
|
||||
package org.openstreetmap.josm.plugins.mapwithai.io.mapwithai;
|
||||
|
||||
import javax.json.JsonArray;
|
||||
import javax.json.JsonObject;
|
||||
import javax.json.JsonString;
|
||||
import javax.json.JsonValue;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
@ -23,6 +17,10 @@ import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
|
|||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIType;
|
||||
import org.openstreetmap.josm.tools.Territories;
|
||||
|
||||
import jakarta.json.JsonObject;
|
||||
import jakarta.json.JsonString;
|
||||
import jakarta.json.JsonValue;
|
||||
|
||||
/**
|
||||
* Reader to parse the list of available MapWithAI servers from an JSON
|
||||
* definition file.
|
||||
|
@ -65,22 +63,22 @@ public class MapWithAISourceReader extends CommonSourceReader<List<MapWithAIInfo
|
|||
}
|
||||
|
||||
private static MapWithAIInfo parse(Map.Entry<String, JsonValue> entry) {
|
||||
String name = entry.getKey();
|
||||
final var name = entry.getKey();
|
||||
if (JsonValue.ValueType.OBJECT == entry.getValue().getValueType()) {
|
||||
JsonObject values = entry.getValue().asJsonObject();
|
||||
String url = values.getString("url", "");
|
||||
String type = values.getString("type", MapWithAIType.values()[0].getDefault().getTypeString());
|
||||
String[] categories = values
|
||||
final var values = entry.getValue().asJsonObject();
|
||||
final var url = values.getString("url", "");
|
||||
final var type = values.getString("type", MapWithAIType.values()[0].getDefault().getTypeString());
|
||||
final var categories = values
|
||||
.getString("category", MapWithAICategory.values()[0].getDefault().getCategoryString())
|
||||
.split(";", -1);
|
||||
String eula = values.getString("eula", "");
|
||||
boolean conflation = values.getBoolean("conflate", false);
|
||||
String conflationUrl = values.getString("conflationUrl", null);
|
||||
String id = values.getString("id", name.replace(" ", "_"));
|
||||
String alreadyConflatedKey = values.getString("conflated_key", null);
|
||||
JsonValue countries = values.getOrDefault("countries", JsonValue.EMPTY_JSON_OBJECT);
|
||||
List<ImageryBounds> bounds = getBounds(countries);
|
||||
MapWithAIInfo info = new MapWithAIInfo(name, url, type, eula, id);
|
||||
final var eula = values.getString("eula", "");
|
||||
final var conflation = values.getBoolean("conflate", false);
|
||||
final var conflationUrl = values.getString("conflationUrl", null);
|
||||
final var id = values.getString("id", name.replace(" ", "_"));
|
||||
final var alreadyConflatedKey = values.getString("conflated_key", null);
|
||||
final var countries = values.getOrDefault("countries", JsonValue.EMPTY_JSON_OBJECT);
|
||||
final var bounds = getBounds(countries);
|
||||
final var info = new MapWithAIInfo(name, url, type, eula, id);
|
||||
info.setDefaultEntry(values.getBoolean("default", false));
|
||||
info.setParameters(values.getJsonArray("parameters"));
|
||||
info.setConflationParameters(values.getJsonArray("conflationParameters"));
|
||||
|
@ -97,9 +95,9 @@ public class MapWithAISourceReader extends CommonSourceReader<List<MapWithAIInfo
|
|||
}
|
||||
}
|
||||
if (values.containsKey("conflation_ignore_categories")) {
|
||||
JsonArray ignore = values.getJsonArray("conflation_ignore_categories");
|
||||
final var ignore = values.getJsonArray("conflation_ignore_categories");
|
||||
for (MapWithAICategory cat : ignore.getValuesAs(JsonString.class).stream().map(JsonString::getString)
|
||||
.map(MapWithAICategory::fromString).filter(Objects::nonNull).collect(Collectors.toList())) {
|
||||
.map(MapWithAICategory::fromString).toList()) {
|
||||
info.addConflationIgnoreCategory(cat);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,6 @@
|
|||
// License: GPL. For details, see LICENSE file.
|
||||
package org.openstreetmap.josm.plugins.mapwithai.tools;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonArray;
|
||||
import javax.json.JsonException;
|
||||
import javax.json.JsonObject;
|
||||
import javax.json.JsonReader;
|
||||
import javax.json.JsonString;
|
||||
import javax.json.JsonStructure;
|
||||
import javax.json.JsonValue;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.openstreetmap.josm.io.CachedFile;
|
||||
|
@ -18,6 +8,13 @@ import org.openstreetmap.josm.io.NetworkManager;
|
|||
import org.openstreetmap.josm.plugins.mapwithai.MapWithAIPlugin;
|
||||
import org.openstreetmap.josm.tools.Logging;
|
||||
|
||||
import jakarta.json.Json;
|
||||
import jakarta.json.JsonArray;
|
||||
import jakarta.json.JsonException;
|
||||
import jakarta.json.JsonObject;
|
||||
import jakarta.json.JsonString;
|
||||
import jakarta.json.JsonValue;
|
||||
|
||||
/**
|
||||
* Check if this version has been blacklisted (i.e., bad data is uploaded)
|
||||
*
|
||||
|
@ -39,18 +36,15 @@ public final class BlacklistUtils {
|
|||
* {@code true}.
|
||||
*/
|
||||
public static boolean isBlacklisted() {
|
||||
String version = MapWithAIPlugin.getVersionInfo();
|
||||
CachedFile blacklist = new CachedFile(blacklistUrl);
|
||||
try (BufferedReader bufferedReader = blacklist.getContentReader();
|
||||
JsonReader reader = Json.createReader(bufferedReader)) {
|
||||
JsonStructure structure = reader.read();
|
||||
if (structure.getValueType() == JsonValue.ValueType.ARRAY) {
|
||||
JsonArray array = (JsonArray) structure;
|
||||
final var version = MapWithAIPlugin.getVersionInfo();
|
||||
final var blacklist = new CachedFile(blacklistUrl);
|
||||
try (var bufferedReader = blacklist.getContentReader(); var reader = Json.createReader(bufferedReader)) {
|
||||
final var structure = reader.read();
|
||||
if (structure instanceof JsonArray array) {
|
||||
return array.stream().filter(v -> v.getValueType() == JsonValue.ValueType.STRING)
|
||||
.map(v -> ((JsonString) v).getString()).anyMatch(version::equals);
|
||||
} else if (structure.getValueType() == JsonValue.ValueType.OBJECT) {
|
||||
JsonObject object = (JsonObject) structure;
|
||||
return object.keySet().contains(version);
|
||||
} else if (structure instanceof JsonObject object) {
|
||||
return object.containsKey(version);
|
||||
}
|
||||
} catch (IOException | JsonException e) {
|
||||
try {
|
||||
|
|
|
@ -9,6 +9,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.openstreetmap.josm.data.Bounds;
|
||||
import org.openstreetmap.josm.data.coor.ILatLon;
|
||||
import org.openstreetmap.josm.data.coor.LatLon;
|
||||
import org.openstreetmap.josm.data.gpx.GpxData;
|
||||
import org.openstreetmap.josm.data.gpx.WayPoint;
|
||||
|
@ -61,8 +62,9 @@ class DetectTaskingManagerUtilsTest {
|
|||
layer.data.addWaypoint(new WayPoint(new LatLon(1, 1)));
|
||||
final BBox bbox = DetectTaskingManagerUtils.getTaskingManagerBounds().toBBox();
|
||||
assertTrue(bbox.isInWorld(), "A TM layer exists");
|
||||
assertTrue(bbox.getBottomRight().equalsEpsilon(new LatLon(0, 1)), "The bottom right should be at (0, 1)");
|
||||
assertTrue(bbox.getTopLeft().equalsEpsilon(new LatLon(1, 0)), "The top left should be at (1, 0)");
|
||||
assertTrue(bbox.getBottomRight().equalsEpsilon((ILatLon) new LatLon(0, 1)),
|
||||
"The bottom right should be at (0, 1)");
|
||||
assertTrue(bbox.getTopLeft().equalsEpsilon((ILatLon) new LatLon(1, 0)), "The top left should be at (1, 0)");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -20,6 +20,7 @@ import org.junit.jupiter.api.Test;
|
|||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.openstreetmap.josm.TestUtils;
|
||||
import org.openstreetmap.josm.data.Bounds;
|
||||
import org.openstreetmap.josm.data.coor.ILatLon;
|
||||
import org.openstreetmap.josm.data.coor.LatLon;
|
||||
import org.openstreetmap.josm.data.gpx.GpxData;
|
||||
import org.openstreetmap.josm.data.gpx.WayPoint;
|
||||
|
@ -232,8 +233,8 @@ public class MapWithAIDataUtilsTest {
|
|||
|
||||
private static boolean bboxCheckConnections(BBox bbox1, BBox bbox2) {
|
||||
int shared = 0;
|
||||
for (final LatLon bbox1Corner : getBBoxCorners(bbox1)) {
|
||||
for (final LatLon bbox2Corner : getBBoxCorners(bbox2)) {
|
||||
for (final ILatLon bbox1Corner : getBBoxCorners(bbox1)) {
|
||||
for (final ILatLon bbox2Corner : getBBoxCorners(bbox2)) {
|
||||
if (bbox1Corner.equalsEpsilon(bbox2Corner)) {
|
||||
shared++;
|
||||
}
|
||||
|
|
|
@ -7,9 +7,6 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
|||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonArray;
|
||||
|
||||
import java.awt.Polygon;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
@ -33,6 +30,8 @@ import org.openstreetmap.josm.gui.util.GuiHelper;
|
|||
import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
|
||||
import org.openstreetmap.josm.tools.Logging;
|
||||
|
||||
import jakarta.json.Json;
|
||||
import jakarta.json.JsonArray;
|
||||
import mockit.Mock;
|
||||
import mockit.MockUp;
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
|
|
|
@ -4,11 +4,7 @@ package org.openstreetmap.josm.plugins.mapwithai.io.mapwithai;
|
|||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonArrayBuilder;
|
||||
import javax.json.JsonObjectBuilder;
|
||||
import javax.json.JsonValue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -20,21 +16,28 @@ import org.openstreetmap.josm.testutils.annotations.Territories;
|
|||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import jakarta.json.Json;
|
||||
import jakarta.json.JsonArrayBuilder;
|
||||
import jakarta.json.JsonObjectBuilder;
|
||||
import jakarta.json.JsonValue;
|
||||
|
||||
@BasicPreferences
|
||||
@Territories
|
||||
@Projection
|
||||
class MapWithAISourceReaderTest {
|
||||
@Test
|
||||
void testParseSimple() {
|
||||
void testParseSimple() throws IOException {
|
||||
JsonObjectBuilder builder = Json.createObjectBuilder();
|
||||
builder.add("nowhere", JsonValue.NULL);
|
||||
List<MapWithAIInfo> infoList = new MapWithAISourceReader("").parseJson(builder.build());
|
||||
assertEquals(1, infoList.size());
|
||||
assertEquals("nowhere", infoList.get(0).getName());
|
||||
try (var reader = new MapWithAISourceReader("")) {
|
||||
List<MapWithAIInfo> infoList = reader.parseJson(builder.build());
|
||||
assertEquals(1, infoList.size());
|
||||
assertEquals("nowhere", infoList.get(0).getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testParseComplex() {
|
||||
void testParseComplex() throws IOException {
|
||||
JsonObjectBuilder builder = Json.createObjectBuilder();
|
||||
JsonObjectBuilder co = Json.createObjectBuilder(
|
||||
ImmutableMap.of("url", "test", "license", "pd", "permission_url", "https://permission.url"));
|
||||
|
@ -43,11 +46,13 @@ class MapWithAISourceReaderTest {
|
|||
coCountries.add("US-CO", coCountriesArray.build());
|
||||
co.add("countries", coCountries.build());
|
||||
builder.add("Colorado", co);
|
||||
List<MapWithAIInfo> infoList = new MapWithAISourceReader("").parseJson(builder.build());
|
||||
assertEquals(1, infoList.size());
|
||||
MapWithAIInfo info = infoList.stream().filter(i -> "Colorado".equals(i.getName())).findFirst().orElse(null);
|
||||
assertNotNull(info);
|
||||
assertEquals("Colorado", info.getName());
|
||||
assertEquals("test", info.getUrl());
|
||||
try (var reader = new MapWithAISourceReader("")) {
|
||||
List<MapWithAIInfo> infoList = reader.parseJson(builder.build());
|
||||
assertEquals(1, infoList.size());
|
||||
MapWithAIInfo info = infoList.stream().filter(i -> "Colorado".equals(i.getName())).findFirst().orElse(null);
|
||||
assertNotNull(info);
|
||||
assertEquals("Colorado", info.getName());
|
||||
assertEquals("test", info.getUrl());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue