From 69d69e8df3fd7b9ebd12f4cbb1ec95e2a6bc9989 Mon Sep 17 00:00:00 2001 From: Taylor Smock Date: Mon, 22 Jun 2020 11:12:23 -0600 Subject: [PATCH] Add a wiremock response transformer This ensures that any URL's in the response are also mocked (or fails the test). I also fixed a listener bug for MapWithAILayerInfo. Signed-off-by: Taylor Smock --- .../conflation/MergeBuildingNodeCommand.java | 60 +++++++++++++++++++ .../data/mapwithai/MapWithAILayerInfo.java | 2 +- ...-ee758a6b-79d6-48a2-8af6-df2afe4ba8d8.json | 11 +++- .../testutils/MapWithAITestRules.java | 39 ++++++++++-- 4 files changed, 104 insertions(+), 8 deletions(-) create mode 100644 src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/commands/conflation/MergeBuildingNodeCommand.java diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/commands/conflation/MergeBuildingNodeCommand.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/commands/conflation/MergeBuildingNodeCommand.java new file mode 100644 index 0000000..a558112 --- /dev/null +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/commands/conflation/MergeBuildingNodeCommand.java @@ -0,0 +1,60 @@ +// License: GPL. For details, see LICENSE file. +package org.openstreetmap.josm.plugins.mapwithai.backend.commands.conflation; + +import static org.openstreetmap.josm.tools.I18n.tr; + +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.openstreetmap.josm.command.Command; +import org.openstreetmap.josm.data.osm.Node; +import org.openstreetmap.josm.data.osm.OsmPrimitive; +import org.openstreetmap.josm.data.osm.Relation; +import org.openstreetmap.josm.data.osm.Way; + +/** + * This is similar to the ReplaceGeometryUtils.buildUpgradeNodeCommand method + * + * @author Taylor Smock + * + */ +public class MergeBuildingNodeCommand { + /** + * Upgrade a node to a way or multipolygon + * + * @param subjectNode node to be replaced + * @param referenceObject object with greater spatial quality + */ + public static Command buildUpgradeNodeCommand(Node subjectNode, OsmPrimitive referenceObject) { + boolean keepNode = !subjectNode.isNew(); + if (keepNode) { + getNewOrNoTagNode(referenceObject); + } + return null; + } + + private static Node getNewOrNoTagNode(OsmPrimitive referenceObject) { + List nodes; + if (referenceObject instanceof Way) { + nodes = ((Way) referenceObject).getNodes(); + } else if (referenceObject instanceof Relation) { + nodes = ((Relation) referenceObject).getMemberPrimitives().stream().flatMap(o -> { + if (o instanceof Way) { + return ((Way) o).getNodes().stream(); + } else if (o instanceof Node) { + return Stream.of((Node) o); + } + return null; + }).filter(Objects::nonNull).collect(Collectors.toList()); + } else if (referenceObject instanceof Node) { + nodes = Collections.singletonList((Node) referenceObject); + } else { + throw new IllegalArgumentException(tr("Unknown OsmPrimitive type")); + } + return nodes.stream().filter(OsmPrimitive::isNew).findAny() + .orElse(nodes.stream().filter(p -> !p.isTagged()).findAny().orElse(nodes.get(0))); + } +} diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAILayerInfo.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAILayerInfo.java index 944a8f5..615c51d 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAILayerInfo.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAILayerInfo.java @@ -142,7 +142,7 @@ public class MapWithAILayerInfo { } Collections.sort(layers); } - loadDefaults(false, MainApplication.worker, fastFail, null); + loadDefaults(false, MainApplication.worker, fastFail, listener); } /** diff --git a/test/resources/wiremock/mappings/sharing_rest_content_groups_bdf6c800b3ae453b9db239e03d7c1727_search-ee758a6b-79d6-48a2-8af6-df2afe4ba8d8.json b/test/resources/wiremock/mappings/sharing_rest_content_groups_bdf6c800b3ae453b9db239e03d7c1727_search-ee758a6b-79d6-48a2-8af6-df2afe4ba8d8.json index fbbf573..61fe8f0 100644 --- a/test/resources/wiremock/mappings/sharing_rest_content_groups_bdf6c800b3ae453b9db239e03d7c1727_search-ee758a6b-79d6-48a2-8af6-df2afe4ba8d8.json +++ b/test/resources/wiremock/mappings/sharing_rest_content_groups_bdf6c800b3ae453b9db239e03d7c1727_search-ee758a6b-79d6-48a2-8af6-df2afe4ba8d8.json @@ -2,12 +2,19 @@ "id" : "ee758a6b-79d6-48a2-8af6-df2afe4ba8d8", "name" : "sharing_rest_content_groups_bdf6c800b3ae453b9db239e03d7c1727_search", "request" : { - "url" : "/sharing/rest/content/groups/bdf6c800b3ae453b9db239e03d7c1727/search?f=json&sortField=added&sortOrder=desc&num=12&start=1", + "urlPath" : "/sharing/rest/content/groups/bdf6c800b3ae453b9db239e03d7c1727/search", + "queryParameters": { + "f": { "equalTo": "json" }, + "sortField": { "equalTo": "added" }, + "sortOrder": { "equalTo": "desc" }, + "num": { "equalTo": "12"}, + "start": { "equalTo": "1"} + }, "method" : "GET" }, "response" : { "status" : 200, - "body" : "{\"query\":null,\"total\":8,\"start\":1,\"num\":12,\"nextStart\":-1,\"results\":[{\"id\":\"9ba701980ab94d8db87524ac6911f862\",\"owner\":\"dkensok_osm\",\"created\":1590633199000,\"modified\":1590634525000,\"guid\":null,\"name\":\"Orange_County_CA_Buildings\",\"title\":\"Orange County, CA Buildings\",\"type\":\"Feature Service\",\"typeKeywords\":[\"ArcGIS Server\",\"Data\",\"Feature Access\",\"Feature Service\",\"Service\",\"Singlelayer\",\"Hosted Service\",\"View Service\"],\"description\":\"This layer contains pre-processed building footprints with addresses for Orange County, California to be added to OpenStreetMap.<\\/span>

<\\/span><\\/div>
Data Source<\\/b><\\/span><\\/font><\\/div>
The building footprints were downloaded in May 2020 from the <\\/font>ArcGIS Hub Open Data site<\\/a>.<\\/font><\\/div>

<\\/font><\\/div>
This layer contains 754,811 buildings for Orange County. Of the total building features, 666,911 buildings<\\/b> do not intersect an existing building in OSM and<\\/span> can be added.<\\/div>

<\\/div>
Features with an Import_2_OSM value of 1 <\\/span>(i.e. <\\/span>Import <\\/b><\\/font>features, shown in <\\/span>Green<\\/b><\\/font>)<\\/span> have no conflict and can be added<\\/span>.  Features with an Import_2_OSM value of 0 <\\/span>(i.e. <\\/span>No Import<\\/font><\\/b> features, shown in <\\/span>Red<\\/b><\\/font>) <\\/span>conflict with existing buildings and should not be added.<\\/span>
<\\/div><\\/div>\",\"tags\":[\"buildings\",\"orange county\",\"california\",\"OSM\"],\"snippet\":\"This layer contains pre-processed building footprints with addresses for Orange County, California to be added to OpenStreetMap.\",\"thumbnail\":\"thumbnail/thumbnail1590634116077.jpeg\",\"documentation\":null,\"extent\":[[-118.12928314353422,33.38194281716835],[-117.39614201190716,33.9621048644816]],\"categories\":[],\"spatialReference\":\"4326\",\"accessInformation\":\"Orange County, CA\",\"licenseInfo\":\"
CC0 1.0<\\/a> <\\/span>Public Domain Dedication<\\/span>\",\"culture\":\"en-us\",\"properties\":null,\"url\":\"http://localhost:8080/Do88DoK2xjTUCXd1/arcgis/rest/services/Orange_County_CA_Buildings/FeatureServer\",\"proxyFilter\":null,\"access\":\"public\",\"size\":-1,\"appCategories\":[],\"industries\":[],\"languages\":[],\"largeThumbnail\":null,\"banner\":null,\"screenshots\":[],\"listed\":false,\"numComments\":0,\"numRatings\":0,\"avgRating\":0,\"numViews\":10,\"groupCategories\":[\"/Categories/Buildings\"],\"scoreCompleteness\":100,\"groupDesignations\":null},{\"id\":\"a4aa6891126544fd8f80d72f5cd88c19\",\"owner\":\"dkensok_osm\",\"created\":1590001784000,\"modified\":1590071515000,\"guid\":null,\"name\":\"WB_Zanzibar_Buildings\",\"title\":\"Zanzibar Buildings (Sample)\",\"type\":\"Feature Service\",\"typeKeywords\":[\"ArcGIS Server\",\"Data\",\"Feature Access\",\"Feature Service\",\"Service\",\"Singlelayer\",\"Hosted Service\",\"View Service\"],\"description\":\"This layer includes sample building footprint data for Zanzibar provided by the World Bank for the purpose of adding to OpenStreetMap.<\\/span>\",\"tags\":[\"World Bank\",\"Zanzibar\",\"buildings\",\"OpenStreetMap\",\"OSM\"],\"snippet\":\"This layer includes sample building footprint data for Zanzibar provided by the World Bank for the purpose of adding to OpenStreetMap.\",\"thumbnail\":\"thumbnail/thumbnail1590002827057.jpeg\",\"documentation\":null,\"extent\":[[39.289190614176775,-5.743137731401959],[39.31303218139561,-5.7222076213435695]],\"categories\":[],\"spatialReference\":\"4326\",\"accessInformation\":\"World Bank\",\"licenseInfo\":\"Data is provided under an ODbL license.\",\"culture\":\"en-us\",\"properties\":null,\"url\":\"http://localhost:8080/Do88DoK2xjTUCXd1/arcgis/rest/services/WB_Zanzibar_Buildings/FeatureServer\",\"proxyFilter\":null,\"access\":\"public\",\"size\":-1,\"appCategories\":[],\"industries\":[],\"languages\":[],\"largeThumbnail\":null,\"banner\":null,\"screenshots\":[],\"listed\":false,\"numComments\":0,\"numRatings\":0,\"avgRating\":0,\"numViews\":19,\"groupCategories\":[\"/Categories/Buildings\"],\"scoreCompleteness\":95,\"groupDesignations\":null},{\"id\":\"1bd0c546d5cd42ddb21b67a8770f1ab6\",\"owner\":\"dkensok_osm\",\"created\":1589920924000,\"modified\":1590634975000,\"guid\":null,\"name\":\"Alexandria_VA_Addresses\",\"title\":\"City of Alexandria, VA Addresses\",\"type\":\"Feature Service\",\"typeKeywords\":[\"ArcGIS Server\",\"Data\",\"Feature Access\",\"Feature Service\",\"Service\",\"Singlelayer\",\"Hosted Service\",\"View Service\"],\"description\":\"This layer contains pre-processed address points for the City of Alexandria, Virginia to update OpenStreetMap (OSM).

<\\/div>
Data Source<\\/b><\\/span><\\/font><\\/div>
The address points were downloaded in May 2020 from the ArcGIS Hub Open Data site<\\/a>.<\\/font><\\/div>

<\\/div>
There are 35,567 total address points in this layer.  Of these, 34,927 addresses are not already represented as points in OSM and can be added to OSM. Features with an Import_2_OSM value of 1 (i.e. <\\/span>Import <\\/b><\\/font>features, shown in <\\/span>Green<\\/b><\\/font>) have no conflict and can be added to OSM.  Features with an Import_2_OSM value of 2 (i.e. <\\/span>No Import<\\/font><\\/b> features, shown in <\\/span>Red<\\/b><\\/font>) conflict with existing addresses and should not be added.<\\/span><\\/div><\\/div><\\/div>\",\"tags\":[\"alexandria\",\"addresses\",\"virginia\",\"OpenStreetMap\",\"OSM\"],\"snippet\":\"This layer contains pre-processed address points for the City of Alexandria, Virginia to update OpenStreetMap.\",\"thumbnail\":\"thumbnail/thumbnail1589928545221.jpeg\",\"documentation\":null,\"extent\":[[-77.14352792634458,38.79039235642301],[-77.03774476086892,38.84457147058765]],\"categories\":[],\"spatialReference\":\"4326\",\"accessInformation\":\"City of Alexandria\",\"licenseInfo\":\"CC0 1.0<\\/a> <\\/span>Public Domain Dedication<\\/span>\",\"culture\":\"en-us\",\"properties\":null,\"url\":\"http://localhost:8080/Do88DoK2xjTUCXd1/arcgis/rest/services/Alexandria_VA_Addresses/FeatureServer\",\"proxyFilter\":null,\"access\":\"public\",\"size\":-1,\"appCategories\":[],\"industries\":[],\"languages\":[],\"largeThumbnail\":null,\"banner\":null,\"screenshots\":[],\"listed\":false,\"numComments\":0,\"numRatings\":0,\"avgRating\":0,\"numViews\":11,\"groupCategories\":[\"/Categories/Featured\",\"/Categories/Addresses\"],\"scoreCompleteness\":100,\"groupDesignations\":null},{\"id\":\"27796b2f1f10470d87c036d2b40c8d64\",\"owner\":\"dkensok_osm\",\"created\":1589920734000,\"modified\":1590634657000,\"guid\":null,\"name\":\"FranklinCounty_buildings\",\"title\":\"Franklin County, OH Buildings\",\"type\":\"Feature Service\",\"typeKeywords\":[\"ArcGIS Server\",\"Data\",\"Feature Access\",\"Feature Service\",\"Metadata\",\"Service\",\"Singlelayer\",\"Hosted Service\"],\"description\":\"

This layer contains pre-processed building footprints for Franklin County, Ohio to be added to OpenStreetMap (OSM). <\\/span>The building polygons have the OSM attribute fields for building (feature type), name and leisure.<\\/span><\\/p>

Data Source<\\/b><\\/span><\\/font><\\/div>
The building footprints were downloaded in May 2020 from the <\\/font>ArcGIS Hub Open Data site<\\/a>.<\\/font><\\/div>

<\\/font><\\/div>
This layer contains 660,866 buildings for Franklin <\\/span>County. Of the total building features, 561,195 buildings<\\/b> do not intersect an existing building in OSM and can be added.<\\/div>

<\\/div>
Features with an Import_2_OSM value of 1 (i.e. <\\/span>Import <\\/b><\\/font>features, shown in <\\/span>Green<\\/b><\\/font>)<\\/span> have no conflict and can be added<\\/span>.  Features with an Import_2_OSM value of 0 <\\/span>(i.e. <\\/span>No Import<\\/font><\\/b> features, shown in <\\/span>Red<\\/b><\\/font>) <\\/span>conflict with existing buildings and should not be added.<\\/span><\\/div><\\/div>\",\"tags\":[\"Franklin County\",\"buildings\",\"OpenStreetMap\",\"OSM\"],\"snippet\":\"This layer contains pre-processed building footprints for Franklin County, Ohio to be added to OpenStreetMap.\",\"thumbnail\":\"thumbnail/thumbnail1589927520496.jpeg\",\"documentation\":null,\"extent\":[[-83.25729090156125,39.794679562712304],[-82.76097354968617,40.14287287724949]],\"categories\":[],\"spatialReference\":\"4326\",\"accessInformation\":\"Franklin County\",\"licenseInfo\":\"

CC0 1.0<\\/a> Public Domain Dedication<\\/span><\\/p><\\/div>\",\"culture\":\"en-us\",\"properties\":null,\"url\":\"http://localhost:8080/Do88DoK2xjTUCXd1/arcgis/rest/services/FranklinCounty_buildings/FeatureServer\",\"proxyFilter\":null,\"access\":\"public\",\"size\":-1,\"appCategories\":[],\"industries\":[],\"languages\":[],\"largeThumbnail\":null,\"banner\":null,\"screenshots\":[],\"listed\":false,\"numComments\":0,\"numRatings\":0,\"avgRating\":0,\"numViews\":15,\"groupCategories\":[\"/Categories/Buildings\",\"/Categories/Featured\"],\"scoreCompleteness\":100,\"groupDesignations\":null},{\"id\":\"9a0a7e1a462b44f0ad043e92fc72ddd3\",\"owner\":\"dkensok_osm\",\"created\":1589747580000,\"modified\":1589927073000,\"guid\":null,\"name\":\"Sarpy_County_NE_Addresses\",\"title\":\"Sarpy County, NE Addresses\",\"type\":\"Feature Service\",\"typeKeywords\":[\"ArcGIS Server\",\"Data\",\"Feature Access\",\"Feature Service\",\"Service\",\"Singlelayer\",\"Hosted Service\",\"View Service\"],\"description\":\"This layer contains pre-processed address points for Sarpy County, Nebraska that can be used to update OpenStreetMap (OSM).<\\/span>


<\\/span><\\/div>
Data Source<\\/b><\\/span><\\/font><\\/div>
The address points were downloaded in May 2020 from the <\\/font>Sarpy County GIS portal<\\/a>.<\\/font><\\/div><\\/div>

<\\/div>
There are 87,872 total address points.  33,980 of the addresses are not already represented by buildings or points in OSM and can be added.  <\\/span>Features where Import_2_OSM = 1 can be added to OpenStreetMap.<\\/span><\\/div>