kopia lustrzana https://github.com/JOSM/MapWithAI
Extract ESRI server reader to separate file
* Also add source provider information * Update pjson -> json (the latter is slightly more efficient) Signed-off-by: Taylor Smock <taylor.smock@kaart.com>pull/1/head
rodzic
2fe054e3ad
commit
60b99acef9
|
@ -3,13 +3,11 @@ package org.openstreetmap.josm.plugins.mapwithai.data.mapwithai;
|
|||
|
||||
import static org.openstreetmap.josm.tools.I18n.tr;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
@ -18,28 +16,16 @@ import java.util.Objects;
|
|||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonArray;
|
||||
import javax.json.JsonNumber;
|
||||
import javax.json.JsonObject;
|
||||
import javax.json.JsonReader;
|
||||
import javax.json.JsonString;
|
||||
import javax.json.JsonStructure;
|
||||
import javax.json.JsonValue;
|
||||
|
||||
import org.openstreetmap.josm.data.StructUtils;
|
||||
import org.openstreetmap.josm.data.imagery.ImageryInfo;
|
||||
import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryBounds;
|
||||
import org.openstreetmap.josm.gui.PleaseWaitRunnable;
|
||||
import org.openstreetmap.josm.gui.util.GuiHelper;
|
||||
import org.openstreetmap.josm.io.CachedFile;
|
||||
import org.openstreetmap.josm.io.NetworkManager;
|
||||
import org.openstreetmap.josm.io.imagery.ImageryReader;
|
||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo.MapWithAICategory;
|
||||
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.MapWithAISourceReader;
|
||||
import org.openstreetmap.josm.spi.preferences.Config;
|
||||
import org.openstreetmap.josm.tools.Logging;
|
||||
|
@ -213,7 +199,11 @@ public class MapWithAILayerInfo {
|
|||
defaultLayers.addAll(newLayers);
|
||||
for (MapWithAIInfo layer : newLayers) {
|
||||
if (MapWithAIInfo.MapWithAIType.ESRI.equals(layer.getSourceType())) {
|
||||
allDefaultLayers.addAll(addEsriLayer(layer));
|
||||
try (ESRISourceReader reader = new ESRISourceReader(layer)) {
|
||||
allDefaultLayers.addAll(reader.parse());
|
||||
} catch (IOException e) {
|
||||
Logging.error(e);
|
||||
}
|
||||
} else {
|
||||
allDefaultLayers.add(layer);
|
||||
}
|
||||
|
@ -234,115 +224,6 @@ public class MapWithAILayerInfo {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a {@link MapWithAIInfo.MapWithAIType#ESRI} layer and convert it to a
|
||||
* list of "true" layers.
|
||||
*
|
||||
* @param layer The ESRI layer (no checks performed here)
|
||||
* @return The layers to be added instead of the ESRI layer.
|
||||
*/
|
||||
public static Collection<MapWithAIInfo> addEsriLayer(MapWithAIInfo layer) {
|
||||
Pattern startReplace = Pattern.compile("\\{start\\}");
|
||||
String search = "/search?sortField=added&sortOrder=desc&num=12&start={start}&f=json";
|
||||
String url = layer.getUrl();
|
||||
String group = layer.getId();
|
||||
if (!url.endsWith("/")) {
|
||||
url = url.concat("/");
|
||||
}
|
||||
|
||||
Collection<MapWithAIInfo> information = new HashSet<>();
|
||||
|
||||
String next = "1";
|
||||
String searchUrl = startReplace.matcher(search).replaceAll(next);
|
||||
while (!next.equals("-1")) {
|
||||
try (CachedFile layers = new CachedFile(url + "content/groups/" + group + searchUrl);
|
||||
BufferedReader i = layers.getContentReader();
|
||||
JsonReader reader = Json.createReader(i)) {
|
||||
JsonStructure parser = reader.read();
|
||||
if (parser.getValueType().equals(JsonValue.ValueType.OBJECT)) {
|
||||
JsonObject obj = parser.asJsonObject();
|
||||
next = obj.getString("nextStart", "-1");
|
||||
searchUrl = startReplace.matcher(search).replaceAll(next);
|
||||
JsonArray features = obj.getJsonArray("results");
|
||||
for (JsonObject feature : features.getValuesAs(JsonObject.class)) {
|
||||
// Use the initial esri server information to keep conflation info
|
||||
MapWithAIInfo newInfo = new MapWithAIInfo(layer);
|
||||
newInfo.setId(feature.getString("id"));
|
||||
if (feature.getString("type", "").equals("Feature Service")) {
|
||||
newInfo.setUrl(featureService(newInfo, feature.getString("url")));
|
||||
} else {
|
||||
newInfo.setUrl(feature.getString("url"));
|
||||
}
|
||||
newInfo.setName(feature.getString("title", feature.getString("name")));
|
||||
String[] extent = feature.getJsonArray("extent").getValuesAs(JsonArray.class).stream()
|
||||
.flatMap(array -> array.getValuesAs(JsonNumber.class).stream())
|
||||
.map(JsonNumber::doubleValue).map(Object::toString).toArray(String[]::new);
|
||||
ImageryBounds imageryBounds = new ImageryBounds(
|
||||
String.join(",", extent[1], extent[0], extent[3], extent[2]), ",");
|
||||
newInfo.setBounds(imageryBounds);
|
||||
newInfo.setSourceType(MapWithAIInfo.MapWithAIType.ESRI_FEATURE_SERVER);
|
||||
newInfo.setTermsOfUseText(feature.getString("licenseInfo", null));
|
||||
if (feature.containsKey("thumbnail")) {
|
||||
newInfo.setAttributionImageURL(url + "content/items/" + newInfo.getId() + "/info/"
|
||||
+ feature.getString("thumbnail"));
|
||||
}
|
||||
if (feature.containsKey("groupCategories")) {
|
||||
MapWithAICategory category = feature.getJsonArray("groupCategories")
|
||||
.getValuesAs(JsonString.class).stream().map(JsonString::getString)
|
||||
.map(s -> s.replace("/Categories/", "")).map(MapWithAICategory::fromString)
|
||||
.filter(Objects::nonNull).findFirst().orElse(MapWithAICategory.OTHER);
|
||||
newInfo.setCategory(category);
|
||||
}
|
||||
newInfo.setDescription(feature.getString("snippet"));
|
||||
information.add(newInfo);
|
||||
}
|
||||
}
|
||||
} catch (ClassCastException | IOException e) {
|
||||
Logging.error(e);
|
||||
next = "-1";
|
||||
}
|
||||
}
|
||||
Comparator<MapWithAIInfo> comparator = (o1, o2) -> o1.getCategory().getDescription()
|
||||
.compareTo(o2.getCategory().getDescription());
|
||||
if (information != null) {
|
||||
information = information.stream().sorted(comparator).collect(Collectors.toSet());
|
||||
}
|
||||
return information;
|
||||
}
|
||||
|
||||
private static String featureService(MapWithAIInfo mapwithaiInfo, String url) {
|
||||
String toGet = url.endsWith("pjson") ? url : url.concat("?f=pjson");
|
||||
try (CachedFile featureServer = new CachedFile(toGet);
|
||||
BufferedReader br = featureServer.getContentReader();
|
||||
JsonReader reader = Json.createReader(br)) {
|
||||
JsonObject info = reader.readObject();
|
||||
JsonArray layers = info.getJsonArray("layers");
|
||||
// TODO use all the layers?
|
||||
JsonObject layer = layers.get(0).asJsonObject();
|
||||
String partialUrl = (url.endsWith("/") ? url : url + "/") + layer.getInt("id");
|
||||
mapwithaiInfo.setReplacementTags(getReplacementTags(partialUrl));
|
||||
|
||||
return partialUrl;
|
||||
} catch (IOException e) {
|
||||
Logging.error(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<String, String> getReplacementTags(String layerUrl) {
|
||||
String toGet = layerUrl.endsWith("?f=pjson") ? layerUrl : layerUrl.concat("?f=pjson");
|
||||
try (CachedFile featureServer = new CachedFile(toGet);
|
||||
BufferedReader br = featureServer.getContentReader();
|
||||
JsonReader reader = Json.createReader(br)) {
|
||||
|
||||
return reader.readObject().getJsonArray("fields").getValuesAs(JsonObject.class).stream()
|
||||
.collect(Collectors.toMap(o -> o.getString("name"), o -> o.getString("alias", null)));
|
||||
} catch (IOException e) {
|
||||
Logging.error(e);
|
||||
}
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the mapping of unique ids to {@link ImageryInfo}s.
|
||||
*
|
||||
|
|
|
@ -13,6 +13,7 @@ import java.awt.event.ActionEvent;
|
|||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
@ -63,6 +64,7 @@ import org.openstreetmap.josm.gui.widgets.HtmlPanel;
|
|||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
|
||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo.MapWithAICategory;
|
||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAILayerInfo;
|
||||
import org.openstreetmap.josm.plugins.mapwithai.io.mapwithai.ESRISourceReader;
|
||||
import org.openstreetmap.josm.tools.GBC;
|
||||
import org.openstreetmap.josm.tools.ImageProvider;
|
||||
import org.openstreetmap.josm.tools.ImageProvider.ImageSizes;
|
||||
|
@ -577,8 +579,12 @@ public class MapWithAIProvidersPanel extends JPanel {
|
|||
try {
|
||||
MapWithAIInfo info = p.getSourceInfo();
|
||||
if (MapWithAIInfo.MapWithAIType.ESRI.equals(info.getSourceType())) {
|
||||
for (MapWithAIInfo i : MapWithAILayerInfo.addEsriLayer(info)) {
|
||||
activeModel.addRow(i);
|
||||
try (ESRISourceReader reader = new ESRISourceReader(info)) {
|
||||
for (MapWithAIInfo i : reader.parse()) {
|
||||
activeModel.addRow(i);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Logging.error(e);
|
||||
}
|
||||
} else {
|
||||
activeModel.addRow(info);
|
||||
|
|
|
@ -0,0 +1,197 @@
|
|||
// License: GPL. For details, see LICENSE file.
|
||||
package org.openstreetmap.josm.plugins.mapwithai.io.mapwithai;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonArray;
|
||||
import javax.json.JsonNumber;
|
||||
import javax.json.JsonObject;
|
||||
import javax.json.JsonReader;
|
||||
import javax.json.JsonString;
|
||||
import javax.json.JsonStructure;
|
||||
import javax.json.JsonValue;
|
||||
|
||||
import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryBounds;
|
||||
import org.openstreetmap.josm.io.CachedFile;
|
||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
|
||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo.MapWithAICategory;
|
||||
import org.openstreetmap.josm.tools.HttpClient;
|
||||
import org.openstreetmap.josm.tools.Logging;
|
||||
import org.openstreetmap.josm.tools.Utils;
|
||||
|
||||
/**
|
||||
* Take a {@link MapWithAIInfo.MapWithAIType#ESRI} layer and convert it to a
|
||||
* list of "true" layers.
|
||||
*/
|
||||
public class ESRISourceReader implements Closeable {
|
||||
private final MapWithAIInfo source;
|
||||
private CachedFile cachedFile;
|
||||
private boolean fastFail;
|
||||
private static final String JSON_QUERY_PARAM = "?f=json";
|
||||
|
||||
/**
|
||||
* Constructs a {@code ImageryReader} from a given filename, URL or internal
|
||||
* resource.
|
||||
*
|
||||
* @param source can be:
|
||||
* <ul>
|
||||
* <li>relative or absolute file name</li>
|
||||
* <li>{@code file:///SOME/FILE} the same as above</li>
|
||||
* <li>{@code http://...} a URL. It will be cached on disk.</li>
|
||||
* <li>{@code resource://SOME/FILE} file from the classpath
|
||||
* (usually in the current *.jar)</li>
|
||||
* <li>{@code josmdir://SOME/FILE} file inside josm user data
|
||||
* directory (since r7058)</li>
|
||||
* <li>{@code josmplugindir://SOME/FILE} file inside josm plugin
|
||||
* directory (since r7834)</li>
|
||||
* </ul>
|
||||
*/
|
||||
public ESRISourceReader(MapWithAIInfo source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses MapWithAI source.
|
||||
*
|
||||
* @return list of source info
|
||||
* @throws IOException if any I/O error occurs
|
||||
*/
|
||||
public List<MapWithAIInfo> parse() throws IOException {
|
||||
Pattern startReplace = Pattern.compile("\\{start\\}");
|
||||
String search = "/search" + JSON_QUERY_PARAM + "&sortField=added&sortOrder=desc&num=12&start={start}";
|
||||
String url = source.getUrl();
|
||||
String group = source.getId();
|
||||
if (!url.endsWith("/")) {
|
||||
url = url.concat("/");
|
||||
}
|
||||
|
||||
List<MapWithAIInfo> information = new ArrayList<>();
|
||||
|
||||
String next = "1";
|
||||
String searchUrl = startReplace.matcher(search).replaceAll(next);
|
||||
while (!next.equals("-1")) {
|
||||
try (CachedFile layers = new CachedFile(url + "content/groups/" + group + searchUrl);
|
||||
BufferedReader i = layers.getContentReader();
|
||||
JsonReader reader = Json.createReader(i)) {
|
||||
layers.setFastFail(fastFail);
|
||||
JsonStructure parser = reader.read();
|
||||
if (parser.getValueType().equals(JsonValue.ValueType.OBJECT)) {
|
||||
JsonObject obj = parser.asJsonObject();
|
||||
next = obj.getString("nextStart", "-1");
|
||||
searchUrl = startReplace.matcher(search).replaceAll(next);
|
||||
JsonArray features = obj.getJsonArray("results");
|
||||
for (JsonObject feature : features.getValuesAs(JsonObject.class)) {
|
||||
information.add(parse(feature));
|
||||
}
|
||||
}
|
||||
} catch (ClassCastException | IOException e) {
|
||||
Logging.error(e);
|
||||
next = "-1";
|
||||
}
|
||||
}
|
||||
Comparator<MapWithAIInfo> comparator = (o1, o2) -> o1.getCategory().getDescription()
|
||||
.compareTo(o2.getCategory().getDescription());
|
||||
if (information != null) {
|
||||
information = information.stream().sorted(comparator).collect(Collectors.toList());
|
||||
}
|
||||
return information;
|
||||
}
|
||||
|
||||
private MapWithAIInfo parse(JsonObject feature) {
|
||||
// Use the initial esri server information to keep conflation info
|
||||
MapWithAIInfo newInfo = new MapWithAIInfo(source);
|
||||
newInfo.setId(feature.getString("id"));
|
||||
if (feature.getString("type", "").equals("Feature Service")) {
|
||||
newInfo.setUrl(featureService(newInfo, feature.getString("url")));
|
||||
} else {
|
||||
newInfo.setUrl(feature.getString("url"));
|
||||
}
|
||||
newInfo.setName(feature.getString("title", feature.getString("name")));
|
||||
String[] extent = feature.getJsonArray("extent").getValuesAs(JsonArray.class).stream()
|
||||
.flatMap(array -> array.getValuesAs(JsonNumber.class).stream()).map(JsonNumber::doubleValue)
|
||||
.map(Object::toString).toArray(String[]::new);
|
||||
ImageryBounds imageryBounds = new ImageryBounds(String.join(",", extent[1], extent[0], extent[3], extent[2]),
|
||||
",");
|
||||
newInfo.setBounds(imageryBounds);
|
||||
newInfo.setSourceType(MapWithAIInfo.MapWithAIType.ESRI_FEATURE_SERVER);
|
||||
newInfo.setTermsOfUseText(feature.getString("licenseInfo", null));
|
||||
if (feature.containsKey("thumbnail")) {
|
||||
newInfo.setAttributionImageURL(
|
||||
source.getUrl() + "content/items/" + newInfo.getId() + "/info/" + feature.getString("thumbnail"));
|
||||
}
|
||||
if (feature.containsKey("groupCategories")) {
|
||||
MapWithAICategory category = feature.getJsonArray("groupCategories").getValuesAs(JsonString.class).stream()
|
||||
.map(JsonString::getString).map(s -> s.replace("/Categories/", ""))
|
||||
.map(MapWithAICategory::fromString).filter(Objects::nonNull).findFirst()
|
||||
.orElse(MapWithAICategory.OTHER);
|
||||
newInfo.setCategory(category);
|
||||
}
|
||||
|
||||
if (feature.containsKey("accessInformation")) {
|
||||
newInfo.setAttributionText(feature.getString("accessInformation"));
|
||||
}
|
||||
newInfo.setDescription(feature.getString("snippet"));
|
||||
return (newInfo);
|
||||
}
|
||||
|
||||
private static String featureService(MapWithAIInfo mapwithaiInfo, String url) {
|
||||
String toGet = url.endsWith(JSON_QUERY_PARAM) ? url : url.concat(JSON_QUERY_PARAM);
|
||||
try (CachedFile featureServer = new CachedFile(toGet);
|
||||
BufferedReader br = featureServer.getContentReader();
|
||||
JsonReader reader = Json.createReader(br)) {
|
||||
JsonObject info = reader.readObject();
|
||||
JsonArray layers = info.getJsonArray("layers");
|
||||
// TODO use all the layers?
|
||||
JsonObject layer = layers.get(0).asJsonObject();
|
||||
String partialUrl = (url.endsWith("/") ? url : url + "/") + layer.getInt("id");
|
||||
mapwithaiInfo.setReplacementTags(getReplacementTags(partialUrl));
|
||||
|
||||
return partialUrl;
|
||||
} catch (IOException e) {
|
||||
Logging.error(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<String, String> getReplacementTags(String layerUrl) {
|
||||
String toGet = layerUrl.endsWith(JSON_QUERY_PARAM) ? layerUrl : layerUrl.concat(JSON_QUERY_PARAM);
|
||||
try (CachedFile featureServer = new CachedFile(toGet);
|
||||
BufferedReader br = featureServer.getContentReader();
|
||||
JsonReader reader = Json.createReader(br)) {
|
||||
|
||||
return reader.readObject().getJsonArray("fields").getValuesAs(JsonObject.class).stream()
|
||||
.collect(Collectors.toMap(o -> o.getString("name"), o -> o.getString("alias", null)));
|
||||
} catch (IOException e) {
|
||||
Logging.error(e);
|
||||
}
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether opening HTTP connections should fail fast, i.e., whether a
|
||||
* {@link HttpClient#setConnectTimeout(int) low connect timeout} should be used.
|
||||
*
|
||||
* @param fastFail whether opening HTTP connections should fail fast
|
||||
* @see CachedFile#setFastFail(boolean)
|
||||
*/
|
||||
public void setFastFail(boolean fastFail) {
|
||||
this.fastFail = fastFail;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
Utils.close(cachedFile);
|
||||
}
|
||||
|
||||
}
|
|
@ -23,7 +23,6 @@ import javax.json.JsonStructure;
|
|||
import javax.json.JsonValue;
|
||||
|
||||
import org.openstreetmap.josm.data.coor.LatLon;
|
||||
import org.openstreetmap.josm.data.imagery.ImageryInfo;
|
||||
import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryBounds;
|
||||
import org.openstreetmap.josm.data.imagery.Shape;
|
||||
import org.openstreetmap.josm.data.osm.BBox;
|
||||
|
@ -90,7 +89,6 @@ public class MapWithAISourceReader implements Closeable {
|
|||
public List<MapWithAIInfo> parse() throws IOException {
|
||||
List<MapWithAIInfo> entries = Collections.emptyList();
|
||||
cachedFile = new CachedFile(source);
|
||||
cachedFile.setParam(String.join(",", ImageryInfo.getActiveIds()));
|
||||
cachedFile.setFastFail(fastFail);
|
||||
try (JsonReader reader = Json.createReader(cachedFile.setMaxAge(CachedFile.DAYS)
|
||||
.setCachingStrategy(CachedFile.CachingStrategy.IfModifiedSince).getContentReader())) {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"id" : "ffce8d3a-c21a-410b-9303-2b59875b76aa",
|
||||
"name" : "do88dok2xjtucxd1_arcgis_rest_services_alexandria_va_addresses_featureserver",
|
||||
"request" : {
|
||||
"url" : "/Do88DoK2xjTUCXd1/arcgis/rest/services/Alexandria_VA_Addresses/FeatureServer?f=pjson",
|
||||
"url" : "/Do88DoK2xjTUCXd1/arcgis/rest/services/Alexandria_VA_Addresses/FeatureServer?f=json",
|
||||
"method" : "GET"
|
||||
},
|
||||
"response" : {
|
||||
|
@ -27,4 +27,4 @@
|
|||
"uuid" : "ffce8d3a-c21a-410b-9303-2b59875b76aa",
|
||||
"persistent" : true,
|
||||
"insertionIndex" : 33
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"id" : "ee34e070-0bf4-4a36-bfe5-4833a8f25ae5",
|
||||
"name" : "do88dok2xjtucxd1_arcgis_rest_services_alexandria_va_addresses_featureserver_0",
|
||||
"request" : {
|
||||
"url" : "/Do88DoK2xjTUCXd1/arcgis/rest/services/Alexandria_VA_Addresses/FeatureServer/0?f=pjson",
|
||||
"url" : "/Do88DoK2xjTUCXd1/arcgis/rest/services/Alexandria_VA_Addresses/FeatureServer/0?f=json",
|
||||
"method" : "GET"
|
||||
},
|
||||
"response" : {
|
||||
|
@ -27,4 +27,4 @@
|
|||
"uuid" : "ee34e070-0bf4-4a36-bfe5-4833a8f25ae5",
|
||||
"persistent" : true,
|
||||
"insertionIndex" : 35
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"id" : "f5b30af0-0177-459b-ac7a-b4fc0be7d99a",
|
||||
"name" : "do88dok2xjtucxd1_arcgis_rest_services_flagstaff_az_addresses_featureserver",
|
||||
"request" : {
|
||||
"url" : "/Do88DoK2xjTUCXd1/arcgis/rest/services/Flagstaff_AZ_Addresses/FeatureServer?f=pjson",
|
||||
"url" : "/Do88DoK2xjTUCXd1/arcgis/rest/services/Flagstaff_AZ_Addresses/FeatureServer?f=json",
|
||||
"method" : "GET"
|
||||
},
|
||||
"response" : {
|
||||
|
@ -27,4 +27,4 @@
|
|||
"uuid" : "f5b30af0-0177-459b-ac7a-b4fc0be7d99a",
|
||||
"persistent" : true,
|
||||
"insertionIndex" : 23
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"id" : "d0e9831e-6eff-4f7e-83ee-f09bad38c40d",
|
||||
"name" : "do88dok2xjtucxd1_arcgis_rest_services_flagstaff_az_addresses_featureserver_0",
|
||||
"request" : {
|
||||
"url" : "/Do88DoK2xjTUCXd1/arcgis/rest/services/Flagstaff_AZ_Addresses/FeatureServer/0?f=pjson",
|
||||
"url" : "/Do88DoK2xjTUCXd1/arcgis/rest/services/Flagstaff_AZ_Addresses/FeatureServer/0?f=json",
|
||||
"method" : "GET"
|
||||
},
|
||||
"response" : {
|
||||
|
@ -27,4 +27,4 @@
|
|||
"uuid" : "d0e9831e-6eff-4f7e-83ee-f09bad38c40d",
|
||||
"persistent" : true,
|
||||
"insertionIndex" : 40
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"id" : "4a594e6d-4b81-42ad-b547-39005f2a5f62",
|
||||
"name" : "do88dok2xjtucxd1_arcgis_rest_services_franklincounty_buildings_featureserver",
|
||||
"request" : {
|
||||
"url" : "/Do88DoK2xjTUCXd1/arcgis/rest/services/FranklinCounty_buildings/FeatureServer?f=pjson",
|
||||
"url" : "/Do88DoK2xjTUCXd1/arcgis/rest/services/FranklinCounty_buildings/FeatureServer?f=json",
|
||||
"method" : "GET"
|
||||
},
|
||||
"response" : {
|
||||
|
@ -27,4 +27,4 @@
|
|||
"uuid" : "4a594e6d-4b81-42ad-b547-39005f2a5f62",
|
||||
"persistent" : true,
|
||||
"insertionIndex" : 31
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"id" : "8cd10b04-891d-4d27-9282-82e7349f5bd3",
|
||||
"name" : "do88dok2xjtucxd1_arcgis_rest_services_franklincounty_buildings_featureserver_0",
|
||||
"request" : {
|
||||
"url" : "/Do88DoK2xjTUCXd1/arcgis/rest/services/FranklinCounty_buildings/FeatureServer/0?f=pjson",
|
||||
"url" : "/Do88DoK2xjTUCXd1/arcgis/rest/services/FranklinCounty_buildings/FeatureServer/0?f=json",
|
||||
"method" : "GET"
|
||||
},
|
||||
"response" : {
|
||||
|
@ -27,4 +27,4 @@
|
|||
"uuid" : "8cd10b04-891d-4d27-9282-82e7349f5bd3",
|
||||
"persistent" : true,
|
||||
"insertionIndex" : 36
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"id" : "757edf0f-0dc4-4b42-869e-1bc2cf3ecf31",
|
||||
"name" : "do88dok2xjtucxd1_arcgis_rest_services_orange_county_ca_buildings_featureserver",
|
||||
"request" : {
|
||||
"url" : "/Do88DoK2xjTUCXd1/arcgis/rest/services/Orange_County_CA_Buildings/FeatureServer?f=pjson",
|
||||
"url" : "/Do88DoK2xjTUCXd1/arcgis/rest/services/Orange_County_CA_Buildings/FeatureServer?f=json",
|
||||
"method" : "GET"
|
||||
},
|
||||
"response" : {
|
||||
|
@ -27,4 +27,4 @@
|
|||
"uuid" : "757edf0f-0dc4-4b42-869e-1bc2cf3ecf31",
|
||||
"persistent" : true,
|
||||
"insertionIndex" : 37
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"id" : "e759c7d0-92ff-4db5-9bd8-25c500797126",
|
||||
"name" : "do88dok2xjtucxd1_arcgis_rest_services_orange_county_ca_buildings_featureserver_0",
|
||||
"request" : {
|
||||
"url" : "/Do88DoK2xjTUCXd1/arcgis/rest/services/Orange_County_CA_Buildings/FeatureServer/0?f=pjson",
|
||||
"url" : "/Do88DoK2xjTUCXd1/arcgis/rest/services/Orange_County_CA_Buildings/FeatureServer/0?f=json",
|
||||
"method" : "GET"
|
||||
},
|
||||
"response" : {
|
||||
|
@ -27,4 +27,4 @@
|
|||
"uuid" : "e759c7d0-92ff-4db5-9bd8-25c500797126",
|
||||
"persistent" : true,
|
||||
"insertionIndex" : 33
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"id" : "1b8f292c-d3b0-4281-ad07-680b02579e6b",
|
||||
"name" : "do88dok2xjtucxd1_arcgis_rest_services_riverside_ca_buildings_featureserver",
|
||||
"request" : {
|
||||
"url" : "/Do88DoK2xjTUCXd1/arcgis/rest/services/Riverside_CA_Buildings/FeatureServer?f=pjson",
|
||||
"url" : "/Do88DoK2xjTUCXd1/arcgis/rest/services/Riverside_CA_Buildings/FeatureServer?f=json",
|
||||
"method" : "GET"
|
||||
},
|
||||
"response" : {
|
||||
|
@ -27,4 +27,4 @@
|
|||
"uuid" : "1b8f292c-d3b0-4281-ad07-680b02579e6b",
|
||||
"persistent" : true,
|
||||
"insertionIndex" : 25
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"id" : "50f13bcb-6c47-4133-acd6-2def98086289",
|
||||
"name" : "do88dok2xjtucxd1_arcgis_rest_services_riverside_ca_buildings_featureserver_0",
|
||||
"request" : {
|
||||
"url" : "/Do88DoK2xjTUCXd1/arcgis/rest/services/Riverside_CA_Buildings/FeatureServer/0?f=pjson",
|
||||
"url" : "/Do88DoK2xjTUCXd1/arcgis/rest/services/Riverside_CA_Buildings/FeatureServer/0?f=json",
|
||||
"method" : "GET"
|
||||
},
|
||||
"response" : {
|
||||
|
@ -29,4 +29,4 @@
|
|||
"scenarioName" : "scenario-2-Do88DoK2xjTUCXd1-arcgis-rest-services-Riverside_CA_Buildings-FeatureServer-0",
|
||||
"requiredScenarioState" : "scenario-2-Do88DoK2xjTUCXd1-arcgis-rest-services-Riverside_CA_Buildings-FeatureServer-0-2",
|
||||
"insertionIndex" : 42
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"id" : "9bba8228-60ea-4b25-b140-ea7b4aeb79ab",
|
||||
"name" : "do88dok2xjtucxd1_arcgis_rest_services_riverside_ca_buildings_featureserver_0",
|
||||
"request" : {
|
||||
"url" : "/Do88DoK2xjTUCXd1/arcgis/rest/services/Riverside_CA_Buildings/FeatureServer/0?f=pjson",
|
||||
"url" : "/Do88DoK2xjTUCXd1/arcgis/rest/services/Riverside_CA_Buildings/FeatureServer/0?f=json",
|
||||
"method" : "GET"
|
||||
},
|
||||
"response" : {
|
||||
|
@ -30,4 +30,4 @@
|
|||
"requiredScenarioState" : "Started",
|
||||
"newScenarioState" : "scenario-2-Do88DoK2xjTUCXd1-arcgis-rest-services-Riverside_CA_Buildings-FeatureServer-0-2",
|
||||
"insertionIndex" : 39
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"id" : "7950efe2-fcb1-4457-9b3a-fd281eb49684",
|
||||
"name" : "do88dok2xjtucxd1_arcgis_rest_services_sarpy_county_ne_addresses_featureserver",
|
||||
"request" : {
|
||||
"url" : "/Do88DoK2xjTUCXd1/arcgis/rest/services/Sarpy_County_NE_Addresses/FeatureServer?f=pjson",
|
||||
"url" : "/Do88DoK2xjTUCXd1/arcgis/rest/services/Sarpy_County_NE_Addresses/FeatureServer?f=json",
|
||||
"method" : "GET"
|
||||
},
|
||||
"response" : {
|
||||
|
@ -27,4 +27,4 @@
|
|||
"uuid" : "7950efe2-fcb1-4457-9b3a-fd281eb49684",
|
||||
"persistent" : true,
|
||||
"insertionIndex" : 29
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"id" : "89bb3fed-c485-401c-a9b9-9c5b367f81a0",
|
||||
"name" : "do88dok2xjtucxd1_arcgis_rest_services_sarpy_county_ne_addresses_featureserver_1",
|
||||
"request" : {
|
||||
"url" : "/Do88DoK2xjTUCXd1/arcgis/rest/services/Sarpy_County_NE_Addresses/FeatureServer/1?f=pjson",
|
||||
"url" : "/Do88DoK2xjTUCXd1/arcgis/rest/services/Sarpy_County_NE_Addresses/FeatureServer/1?f=json",
|
||||
"method" : "GET"
|
||||
},
|
||||
"response" : {
|
||||
|
@ -27,4 +27,4 @@
|
|||
"uuid" : "89bb3fed-c485-401c-a9b9-9c5b367f81a0",
|
||||
"persistent" : true,
|
||||
"insertionIndex" : 37
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"id" : "1ab90e03-6781-4f0b-97c0-9e66b728c81c",
|
||||
"name" : "do88dok2xjtucxd1_arcgis_rest_services_sarpy_county_ne_buildings_featureserver",
|
||||
"request" : {
|
||||
"url" : "/Do88DoK2xjTUCXd1/arcgis/rest/services/Sarpy_County_NE_Buildings/FeatureServer?f=pjson",
|
||||
"url" : "/Do88DoK2xjTUCXd1/arcgis/rest/services/Sarpy_County_NE_Buildings/FeatureServer?f=json",
|
||||
"method" : "GET"
|
||||
},
|
||||
"response" : {
|
||||
|
@ -27,4 +27,4 @@
|
|||
"uuid" : "1ab90e03-6781-4f0b-97c0-9e66b728c81c",
|
||||
"persistent" : true,
|
||||
"insertionIndex" : 27
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"id" : "1edea050-3368-40f5-80ae-099dba138e0d",
|
||||
"name" : "do88dok2xjtucxd1_arcgis_rest_services_sarpy_county_ne_buildings_featureserver_1",
|
||||
"request" : {
|
||||
"url" : "/Do88DoK2xjTUCXd1/arcgis/rest/services/Sarpy_County_NE_Buildings/FeatureServer/1?f=pjson",
|
||||
"url" : "/Do88DoK2xjTUCXd1/arcgis/rest/services/Sarpy_County_NE_Buildings/FeatureServer/1?f=json",
|
||||
"method" : "GET"
|
||||
},
|
||||
"response" : {
|
||||
|
@ -30,4 +30,4 @@
|
|||
"requiredScenarioState" : "Started",
|
||||
"newScenarioState" : "scenario-1-Do88DoK2xjTUCXd1-arcgis-rest-services-Sarpy_County_NE_Buildings-FeatureServer-1-2",
|
||||
"insertionIndex" : 38
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"id" : "fba7d31c-8e1c-42d7-ac61-99a0be815a3f",
|
||||
"name" : "do88dok2xjtucxd1_arcgis_rest_services_sarpy_county_ne_buildings_featureserver_1",
|
||||
"request" : {
|
||||
"url" : "/Do88DoK2xjTUCXd1/arcgis/rest/services/Sarpy_County_NE_Buildings/FeatureServer/1?f=pjson",
|
||||
"url" : "/Do88DoK2xjTUCXd1/arcgis/rest/services/Sarpy_County_NE_Buildings/FeatureServer/1?f=json",
|
||||
"method" : "GET"
|
||||
},
|
||||
"response" : {
|
||||
|
@ -29,4 +29,4 @@
|
|||
"scenarioName" : "scenario-1-Do88DoK2xjTUCXd1-arcgis-rest-services-Sarpy_County_NE_Buildings-FeatureServer-1",
|
||||
"requiredScenarioState" : "scenario-1-Do88DoK2xjTUCXd1-arcgis-rest-services-Sarpy_County_NE_Buildings-FeatureServer-1-2",
|
||||
"insertionIndex" : 41
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"id" : "66d2a4b2-09ce-46d3-b9c9-a0c7489fefab",
|
||||
"name" : "do88dok2xjtucxd1_arcgis_rest_services_wb_zanzibar_buildings_featureserver",
|
||||
"request" : {
|
||||
"url" : "/Do88DoK2xjTUCXd1/arcgis/rest/services/WB_Zanzibar_Buildings/FeatureServer?f=pjson",
|
||||
"url" : "/Do88DoK2xjTUCXd1/arcgis/rest/services/WB_Zanzibar_Buildings/FeatureServer?f=json",
|
||||
"method" : "GET"
|
||||
},
|
||||
"response" : {
|
||||
|
@ -27,4 +27,4 @@
|
|||
"uuid" : "66d2a4b2-09ce-46d3-b9c9-a0c7489fefab",
|
||||
"persistent" : true,
|
||||
"insertionIndex" : 35
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"id" : "d64a22d3-e6e0-4dc6-ae5c-f9a2ba8f8485",
|
||||
"name" : "do88dok2xjtucxd1_arcgis_rest_services_wb_zanzibar_buildings_featureserver_0",
|
||||
"request" : {
|
||||
"url" : "/Do88DoK2xjTUCXd1/arcgis/rest/services/WB_Zanzibar_Buildings/FeatureServer/0?f=pjson",
|
||||
"url" : "/Do88DoK2xjTUCXd1/arcgis/rest/services/WB_Zanzibar_Buildings/FeatureServer/0?f=json",
|
||||
"method" : "GET"
|
||||
},
|
||||
"response" : {
|
||||
|
@ -27,4 +27,4 @@
|
|||
"uuid" : "d64a22d3-e6e0-4dc6-ae5c-f9a2ba8f8485",
|
||||
"persistent" : true,
|
||||
"insertionIndex" : 34
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"id" : "ee758a6b-79d6-48a2-8af6-df2afe4ba8d8",
|
||||
"name" : "sharing_rest_content_groups_bdf6c800b3ae453b9db239e03d7c1727_search",
|
||||
"request" : {
|
||||
"url" : "/sharing/rest/content/groups/bdf6c800b3ae453b9db239e03d7c1727/search?sortField=added&sortOrder=desc&num=12&start=1&f=json",
|
||||
"url" : "/sharing/rest/content/groups/bdf6c800b3ae453b9db239e03d7c1727/search?f=json&sortField=added&sortOrder=desc&num=12&start=1",
|
||||
"method" : "GET"
|
||||
},
|
||||
"response" : {
|
||||
|
|
|
@ -1,33 +1,37 @@
|
|||
// License: GPL. For details, see LICENSE file.
|
||||
package org.openstreetmap.josm.plugins.mapwithai.data.mapwithai;
|
||||
package org.openstreetmap.josm.plugins.mapwithai.io.mapwithai;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
|
||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo.MapWithAIType;
|
||||
import org.openstreetmap.josm.plugins.mapwithai.testutils.MapWithAITestRules;
|
||||
|
||||
public class MapWithAILayerInfoTest {
|
||||
public class ESRISourceReaderTest {
|
||||
@Rule
|
||||
public MapWithAITestRules rule = (MapWithAITestRules) new MapWithAITestRules().wiremock().projection();
|
||||
|
||||
@Test
|
||||
public void testAddEsriLayer() {
|
||||
public void testAddEsriLayer() throws IOException {
|
||||
// TODO wiremock
|
||||
MapWithAIInfo info = new MapWithAIInfo("TEST", "test_url", "bdf6c800b3ae453b9db239e03d7c1727");
|
||||
info.setSourceType(MapWithAIType.ESRI);
|
||||
String tUrl = rule.getWireMock().baseUrl() + "/sharing/rest";
|
||||
for (String url : Arrays.asList(tUrl, tUrl + "/")) {
|
||||
info.setUrl(url);
|
||||
Collection<MapWithAIInfo> layers = MapWithAILayerInfo.addEsriLayer(info);
|
||||
assertFalse(layers.isEmpty());
|
||||
assertTrue(layers.stream().noneMatch(i -> info.getUrl().equals(i.getUrl())));
|
||||
assertTrue(layers.stream().allMatch(i -> MapWithAIType.ESRI_FEATURE_SERVER.equals(i.getSourceType())));
|
||||
try (ESRISourceReader reader = new ESRISourceReader(info)) {
|
||||
Collection<MapWithAIInfo> layers = reader.parse();
|
||||
assertFalse(layers.isEmpty());
|
||||
assertTrue(layers.stream().noneMatch(i -> info.getUrl().equals(i.getUrl())));
|
||||
assertTrue(layers.stream().allMatch(i -> MapWithAIType.ESRI_FEATURE_SERVER.equals(i.getSourceType())));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Ładowanie…
Reference in New Issue