kopia lustrzana https://github.com/JOSM/MapWithAI
Fix URL reset on JOSM restart
This was reported on Slack by drkludge. Signed-off-by: Taylor Smock <tsmock@fb.com>pull/1/head v1.9.5
rodzic
a3cd232117
commit
cf01febcf1
|
@ -18,7 +18,9 @@ import java.util.Map;
|
|||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -344,7 +346,16 @@ public class MapWithAILayerInfo {
|
|||
private void updateEsriLayers(@Nonnull final Collection<MapWithAIInfo> layers) {
|
||||
for (MapWithAIInfo layer : layers) {
|
||||
if (MapWithAIType.ESRI == layer.getSourceType()) {
|
||||
allDefaultLayers.addAll(parseEsri(layer));
|
||||
for (Future<MapWithAIInfo> future : parseEsri(layer)) {
|
||||
try {
|
||||
allDefaultLayers.add(future.get());
|
||||
} catch (InterruptedException e) {
|
||||
Logging.error(e);
|
||||
Thread.currentThread().interrupt();
|
||||
} catch (ExecutionException e) {
|
||||
Logging.error(e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
allDefaultLayers.add(layer);
|
||||
}
|
||||
|
@ -385,7 +396,7 @@ public class MapWithAILayerInfo {
|
|||
* @param layer The layer to parse
|
||||
* @return The Feature Servers for the ESRI layer
|
||||
*/
|
||||
private Collection<MapWithAIInfo> parseEsri(MapWithAIInfo layer) {
|
||||
private Collection<Future<MapWithAIInfo>> parseEsri(MapWithAIInfo layer) {
|
||||
try {
|
||||
return new ESRISourceReader(layer).parse();
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -36,6 +36,8 @@ import java.util.Collections;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
@ -658,8 +660,15 @@ public class MapWithAIProvidersPanel extends JPanel {
|
|||
if (MapWithAIType.ESRI == info.getSourceType()) {
|
||||
final ESRISourceReader reader = new ESRISourceReader(info);
|
||||
try {
|
||||
for (MapWithAIInfo i : reader.parse()) {
|
||||
ACTIVE_MODEL.addRow(i);
|
||||
for (Future<MapWithAIInfo> i : reader.parse()) {
|
||||
try {
|
||||
ACTIVE_MODEL.addRow(i.get());
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
Logging.error(e);
|
||||
} catch (ExecutionException e) {
|
||||
Logging.error(e);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Logging.error(e);
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
import java.util.concurrent.Future;
|
||||
|
@ -36,7 +37,6 @@ import org.apache.commons.jcs3.engine.behavior.IElementAttributes;
|
|||
import org.openstreetmap.josm.data.cache.JCSCacheManager;
|
||||
import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryBounds;
|
||||
import org.openstreetmap.josm.data.preferences.LongProperty;
|
||||
import org.openstreetmap.josm.gui.MainApplication;
|
||||
import org.openstreetmap.josm.io.CachedFile;
|
||||
import org.openstreetmap.josm.plugins.mapwithai.backend.MapWithAIDataUtils;
|
||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAICategory;
|
||||
|
@ -89,7 +89,7 @@ public class ESRISourceReader {
|
|||
* @return list of source info
|
||||
* @throws IOException if any I/O error occurs
|
||||
*/
|
||||
public List<MapWithAIInfo> parse() throws IOException {
|
||||
public List<Future<MapWithAIInfo>> parse() throws IOException {
|
||||
Pattern startReplace = Pattern.compile("\\{start}");
|
||||
String search = "/search" + JSON_QUERY_PARAM + "&sortField=added&sortOrder=desc&num=" + INITIAL_SEARCH
|
||||
+ "&start={start}";
|
||||
|
@ -99,7 +99,7 @@ public class ESRISourceReader {
|
|||
url = url.concat("/");
|
||||
}
|
||||
|
||||
final List<MapWithAIInfo> information = Collections.synchronizedList(new ArrayList<>());
|
||||
final List<Future<MapWithAIInfo>> information = Collections.synchronizedList(new ArrayList<>());
|
||||
|
||||
int next = 1;
|
||||
String searchUrl = startReplace.matcher(search).replaceAll(Integer.toString(next));
|
||||
|
@ -124,7 +124,7 @@ public class ESRISourceReader {
|
|||
JsonArray features = obj.getJsonArray("results");
|
||||
for (JsonObject feature : features.getValuesAs(JsonObject.class)) {
|
||||
futureList.add(forkJoinPool.submit(() -> {
|
||||
MapWithAIInfo info = parse(feature);
|
||||
Future<MapWithAIInfo> info = parse(feature);
|
||||
information.add(info);
|
||||
}));
|
||||
}
|
||||
|
@ -147,13 +147,16 @@ public class ESRISourceReader {
|
|||
return information;
|
||||
}
|
||||
|
||||
private MapWithAIInfo parse(JsonObject feature) {
|
||||
private Future<MapWithAIInfo> parse(JsonObject feature) {
|
||||
// Use the initial esri server information to keep conflation info
|
||||
MapWithAIInfo newInfo = new MapWithAIInfo(source);
|
||||
newInfo.setId(feature.getString("id"));
|
||||
Future<MapWithAIInfo> future;
|
||||
if (feature.getString("type", "").equals("Feature Service")) {
|
||||
MainApplication.worker.execute(() -> newInfo.setUrl(featureService(newInfo, feature.getString("url"))));
|
||||
future = MapWithAIDataUtils.getForkJoinPool()
|
||||
.submit(() -> newInfo.setUrl(featureService(newInfo, feature.getString("url"))), newInfo);
|
||||
} else {
|
||||
future = CompletableFuture.completedFuture(newInfo);
|
||||
newInfo.setUrl(feature.getString("url"));
|
||||
}
|
||||
newInfo.setName(feature.getString("title", feature.getString("name")));
|
||||
|
@ -197,7 +200,7 @@ public class ESRISourceReader {
|
|||
newInfo.setSource(sourceTag.toString());
|
||||
}
|
||||
newInfo.setTermsOfUseURL("https://wiki.openstreetmap.org/wiki/Esri/ArcGIS_Datasets#License");
|
||||
return newInfo;
|
||||
return future;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,11 +4,14 @@ package org.openstreetmap.josm.plugins.mapwithai.io.mapwithai;
|
|||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.awaitility.Awaitility;
|
||||
import org.awaitility.Durations;
|
||||
|
@ -60,7 +63,14 @@ class ESRISourceReaderTest {
|
|||
for (String url : Arrays.asList(tUrl, tUrl + "/")) {
|
||||
info.setUrl(url);
|
||||
final ESRISourceReader reader = new ESRISourceReader(info);
|
||||
Collection<MapWithAIInfo> layers = reader.parse();
|
||||
List<MapWithAIInfo> layers = reader.parse().stream().map(future -> {
|
||||
try {
|
||||
return future.get();
|
||||
} catch (ExecutionException | InterruptedException e) {
|
||||
fail(e);
|
||||
}
|
||||
return null;
|
||||
}).collect(Collectors.toList());
|
||||
Future<?> workerQueue = MainApplication.worker.submit(() -> {
|
||||
/* Sync threads */});
|
||||
Awaitility.await().atMost(Durations.FIVE_SECONDS).until(workerQueue::isDone);
|
||||
|
|
Ładowanie…
Reference in New Issue