Changeset 36233 in osm for applications
- Timestamp:
- 2024-03-28T15:04:04+01:00 (8 months ago)
- Location:
- applications/editors/josm/plugins/reverter
- Files:
-
- 12 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/reverter/src/reverter/ChangesetReverter.java
r36230 r36233 504 504 505 505 public void fixNodesWithoutCoordinates(ProgressMonitor progressMonitor) throws OsmTransferException { 506 Collection<Node> nodes = n ds.getNodes();506 Collection<Node> nodes = new ArrayList<>(nds.getNodes()); 507 507 int num = nodes.size(); 508 508 progressMonitor.beginTask(addChangesetIdPrefix( … … 510 510 // downloads == num ticks, then we get the downloaded data (1 tick), then we process the nodes (num ticks) 511 511 2 * num + 1); 512 513 // Remove primitives where we already know the LatLon. 514 nodes.removeIf(n -> { 515 PrimitiveId id = n.getPrimitiveId(); 516 OsmPrimitive p = ds.getPrimitiveById(id); 517 return !(p instanceof Node) || ((Node) p).isLatLonKnown(); 518 }); 519 progressMonitor.worked(num - nodes.size()); 512 520 513 521 // Do bulk version fetches first … … 526 534 versionMap.replaceAll((key, value) -> value - 1); 527 535 versionMap.values().removeIf(i -> i <= 0); 528 ds.update(() -> { 529 for (Node n : nodes) { 530 if (!n.isDeleted() && !n.isLatLonKnown()) { 531 final Node historyNode = (Node) history.getPrimitiveById(n); 532 if (historyNode != null && historyNode.isLatLonKnown() 533 && changeset.getClosedAt().isAfter(historyNode.getInstant())) { 534 n.load(historyNode.save()); 535 versionMap.remove(n.getUniqueId()); 536 progressMonitor.worked(1); 537 } 538 } 539 if (progressMonitor.isCanceled()) { 540 break; 541 } 542 } 543 }); 536 ds.update(() -> updateNodes(progressMonitor, nodes, versionMap, history)); 544 537 if (progressMonitor.isCanceled()) { 545 538 break; … … 548 541 } finally { 549 542 progressMonitor.finishTask(); 543 } 544 } 545 546 /** 547 * Update nodes lacking a lat/lon 548 * @param progressMonitor The monitor to update 549 * @param nodes The nodes to update 550 * @param versionMap The version map to update for the next round 551 * @param history The history dataset 552 */ 553 private void updateNodes(ProgressMonitor progressMonitor, Collection<Node> nodes, Map<Long, Integer> versionMap, DataSet history) { 554 for (Node n : nodes) { 555 if (!n.isDeleted() && !n.isLatLonKnown()) { 556 final Node historyNode = (Node) history.getPrimitiveById(n); 557 if (historyNode != null && historyNode.isLatLonKnown() 558 && changeset.getClosedAt().isAfter(historyNode.getInstant())) { 559 n.load(historyNode.save()); 560 versionMap.remove(n.getUniqueId()); 561 progressMonitor.worked(1); 562 } 563 } 564 if (progressMonitor.isCanceled()) { 565 break; 566 } 550 567 } 551 568 } -
applications/editors/josm/plugins/reverter/test/unit/reverter/ChangesetReverterTest.java
r36122 r36233 4 4 import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; 5 5 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; 6 import static org.junit.jupiter.api.Assertions.assertEquals; 7 import static org.junit.jupiter.api.Assertions.assertInstanceOf; 6 8 import static org.junit.jupiter.api.Assertions.assertNotNull; 7 9 import static org.junit.jupiter.api.Assertions.assertTrue; … … 21 23 import java.util.stream.Collectors; 22 24 23 import jakarta.json.Json; 24 import jakarta.json.JsonArray; 25 import jakarta.json.JsonNumber; 26 import jakarta.json.JsonObject; 27 import jakarta.json.JsonReader; 28 import jakarta.json.JsonString; 29 import jakarta.json.JsonValue; 25 import org.junit.jupiter.api.Test; 26 import org.junit.jupiter.api.extension.RegisterExtension; 27 import org.openstreetmap.josm.TestUtils; 28 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask; 29 import org.openstreetmap.josm.actions.downloadtasks.DownloadParams; 30 import org.openstreetmap.josm.data.UndoRedoHandler; 31 import org.openstreetmap.josm.data.osm.DataSet; 32 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 33 import org.openstreetmap.josm.data.osm.PrimitiveId; 34 import org.openstreetmap.josm.data.osm.SimplePrimitiveId; 35 import org.openstreetmap.josm.data.osm.Way; 36 import org.openstreetmap.josm.gui.MainApplication; 37 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 38 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 39 import org.openstreetmap.josm.gui.util.GuiHelper; 40 import org.openstreetmap.josm.spi.preferences.Config; 41 import org.openstreetmap.josm.testutils.annotations.BasicPreferences; 42 import org.openstreetmap.josm.testutils.annotations.HTTP; 43 import org.openstreetmap.josm.testutils.annotations.Main; 44 import org.openstreetmap.josm.testutils.annotations.Projection; 45 import org.openstreetmap.josm.tools.JosmRuntimeException; 46 import org.openstreetmap.josm.tools.Logging; 30 47 31 48 import com.github.tomakehurst.wiremock.client.WireMock; … … 38 55 import com.github.tomakehurst.wiremock.junit5.WireMockExtension; 39 56 import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; 40 import org.junit.jupiter.api.Test; 41 import org.junit.jupiter.api.extension.RegisterExtension; 42 import org.openstreetmap.josm.TestUtils; 43 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask; 44 import org.openstreetmap.josm.actions.downloadtasks.DownloadParams; 45 import org.openstreetmap.josm.data.UndoRedoHandler; 46 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 47 import org.openstreetmap.josm.data.osm.PrimitiveId; 48 import org.openstreetmap.josm.data.osm.SimplePrimitiveId; 49 import org.openstreetmap.josm.gui.MainApplication; 50 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 51 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 52 import org.openstreetmap.josm.gui.util.GuiHelper; 53 import org.openstreetmap.josm.spi.preferences.Config; 54 import org.openstreetmap.josm.testutils.annotations.BasicPreferences; 55 import org.openstreetmap.josm.testutils.annotations.HTTP; 56 import org.openstreetmap.josm.tools.JosmRuntimeException; 57 import org.openstreetmap.josm.tools.Logging; 57 import jakarta.json.Json; 58 import jakarta.json.JsonArray; 59 import jakarta.json.JsonNumber; 60 import jakarta.json.JsonObject; 61 import jakarta.json.JsonReader; 62 import jakarta.json.JsonString; 63 import jakarta.json.JsonValue; 58 64 59 65 /** … … 62 68 @BasicPreferences 63 69 @HTTP 70 @Main 71 @Projection 64 72 class ChangesetReverterTest { 65 73 @RegisterExtension … … 74 82 void testTicket22520(WireMockRuntimeInfo wireMockRuntimeInfo) throws ExecutionException, InterruptedException { 75 83 wireMockRuntimeInfo.getWireMock().loadMappingsFrom(TestUtils.getRegressionDataDir(22520)); 76 wireMockRuntimeInfo.getWireMock().register(WireMock.get(WireMock.urlPathMatching("/0.6/nodes")).willReturn(WireMock.aResponse().withTransformer s("MultiplePrimitiveTransformer")));77 wireMockRuntimeInfo.getWireMock().register(WireMock.get(WireMock.urlPathMatching("/0.6/relations")).willReturn(WireMock.aResponse().withTransformer s("MultiplePrimitiveTransformer")));78 wireMockRuntimeInfo.getWireMock().register(WireMock.get(WireMock.urlPathMatching("/0.6/ways")).willReturn(WireMock.aResponse().withTransformer s("MultiplePrimitiveTransformer")));84 wireMockRuntimeInfo.getWireMock().register(WireMock.get(WireMock.urlPathMatching("/0.6/nodes")).willReturn(WireMock.aResponse().withTransformer("MultiplePrimitiveTransformer", "ticket", 22520))); 85 wireMockRuntimeInfo.getWireMock().register(WireMock.get(WireMock.urlPathMatching("/0.6/relations")).willReturn(WireMock.aResponse().withTransformer("MultiplePrimitiveTransformer", "ticket", 22520))); 86 wireMockRuntimeInfo.getWireMock().register(WireMock.get(WireMock.urlPathMatching("/0.6/ways")).willReturn(WireMock.aResponse().withTransformer("MultiplePrimitiveTransformer", "ticket", 22520))); 79 87 Config.getPref().put("osm-server.url", wireMockRuntimeInfo.getHttpBaseUrl()); 80 88 PrimitiveId building = new SimplePrimitiveId(233056719, OsmPrimitiveType.WAY); … … 90 98 91 99 /** 100 * Non-regression test for #23582: Nodes that were not modified by a changeset should not be reverted. 101 * Note: This might not be the intended behavior, but it was the behavior prior to r36230. 102 */ 103 @Test 104 void testTicket23582(WireMockRuntimeInfo wireMockRuntimeInfo) { 105 wireMockRuntimeInfo.getWireMock().loadMappingsFrom(TestUtils.getRegressionDataDir(23582)); 106 wireMockRuntimeInfo.getWireMock().register(WireMock.get(WireMock.urlPathMatching("/0.6/nodes")).willReturn(WireMock.aResponse().withTransformer("MultiplePrimitiveTransformer", "ticket", 23582))); 107 wireMockRuntimeInfo.getWireMock().register(WireMock.get(WireMock.urlPathMatching("/0.6/relations")).willReturn(WireMock.aResponse().withTransformer("MultiplePrimitiveTransformer", "ticket", 23582))); 108 wireMockRuntimeInfo.getWireMock().register(WireMock.get(WireMock.urlPathMatching("/0.6/ways")).willReturn(WireMock.aResponse().withTransformer("MultiplePrimitiveTransformer", "ticket", 23582))); 109 Config.getPref().put("osm-server.url", wireMockRuntimeInfo.getHttpBaseUrl()); 110 final RevertChangesetTask task = new RevertChangesetTask(149181932, ChangesetReverter.RevertType.FULL, true, true); 111 task.run(); 112 GuiHelper.runInEDTAndWait(() -> { /* Sync UI thread (some actions are taken on this thread which modify primitives) */ }); 113 final DataSet reverted = MainApplication.getLayerManager().getEditDataSet(); 114 assertEquals(1, reverted.allModifiedPrimitives().size()); 115 final Way oldWay = assertInstanceOf(Way.class, reverted.allModifiedPrimitives().iterator().next()); 116 assertEquals(8, oldWay.getNodesCount()); 117 } 118 119 /** 92 120 * A transformer for the /nodes?node, /ways?ways, and /relations?relations endpoints. This is needed since we don't always do the requests in the same order. 93 121 */ … … 100 128 @Override 101 129 public Response transform(Request request, Response response, FileSource files, Parameters parameters) { 130 final int ticket = parameters.getInt("ticket"); 102 131 final QueryParameter wayParam = request.queryParameter("ways"); 103 132 final QueryParameter nodeParam = request.queryParameter("nodes"); 104 133 final QueryParameter relParam = request.queryParameter("relations"); 105 134 if (wayParam.isPresent()) { 106 return Response.Builder.like(response).but().body(getReturnXml( OsmPrimitiveType.WAY, wayParam)).build();135 return Response.Builder.like(response).but().body(getReturnXml(ticket, OsmPrimitiveType.WAY, wayParam)).build(); 107 136 } else if (nodeParam.isPresent()) { 108 return Response.Builder.like(response).but().body(getReturnXml( OsmPrimitiveType.NODE, nodeParam)).build();137 return Response.Builder.like(response).but().body(getReturnXml(ticket, OsmPrimitiveType.NODE, nodeParam)).build(); 109 138 } else if (relParam.isPresent()) { 110 return Response.Builder.like(response).but().body(getReturnXml( OsmPrimitiveType.RELATION, relParam)).build();139 return Response.Builder.like(response).but().body(getReturnXml(ticket, OsmPrimitiveType.RELATION, relParam)).build(); 111 140 } else { 112 141 IllegalArgumentException e = new IllegalArgumentException("No query parameter present"); … … 121 150 } 122 151 123 private static String getReturnXml( OsmPrimitiveType type, QueryParameter parameter) {152 private static String getReturnXml(int ticket, OsmPrimitiveType type, QueryParameter parameter) { 124 153 final String file; 125 154 switch (type) { … … 140 169 : parameter.values()) 141 170 .stream().map(s -> new OsmParameterInformation(type, s)).collect(Collectors.toSet()); 142 try (InputStream fis = Files.newInputStream(Paths.get(TestUtils.getRegressionDataDir( 22520), file));171 try (InputStream fis = Files.newInputStream(Paths.get(TestUtils.getRegressionDataDir(ticket), file)); 143 172 JsonReader reader = Json.createReader(fis)) { 144 173 String version = "0.6";
Note:
See TracChangeset
for help on using the changeset viewer.