Changeset 17429 in josm
- Timestamp:
- 2020-12-30T11:52:34+01:00 (4 years ago)
- Location:
- trunk
- Files:
-
- 7 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/CreateMultipolygonAction.java
r17408 r17429 341 341 boolean changedMembers = rr.a != rr.b; 342 342 final Relation existingRelation = rr.a; 343 final Relation relation = changedMembers ? rr.b : new Relation(rr.a);343 final Relation relation = changedMembers ? rr.b : rr.a; 344 344 345 345 final List<Command> list = removeTagsFromWaysIfNeeded(relation); … … 349 349 commandName = getName(false); 350 350 } else { 351 boolean changedKeys = !relation.getKeys().equals(existingRelation.getKeys()); 352 if (changedKeys && changedMembers) 353 list.add(new ChangeCommand(existingRelation, relation)); 354 else if (changedMembers) { 355 list.add(new ChangeMembersCommand(existingRelation, new ArrayList<>(relation.getMembers()))); 356 } else if (changedKeys) { 357 list.add(ChangePropertyCommand.build(existingRelation, relation)); 351 if (changedMembers) { 352 if (!relation.getKeys().equals(existingRelation.getKeys())) { 353 list.add(new ChangeCommand(existingRelation, relation)); 354 } else { 355 list.add(new ChangeMembersCommand(existingRelation, new ArrayList<>(relation.getMembers()))); 356 } 358 357 } 359 358 if (list.isEmpty()) { 360 if (!changedMembers) { 361 MultipolygonTest mpTest = new MultipolygonTest(); 362 mpTest.visit(existingRelation); 363 if (!mpTest.getErrors().isEmpty()) { 364 showErrors(mpTest.getErrors()); 365 return null; 366 } 359 MultipolygonTest mpTest = new MultipolygonTest(); 360 mpTest.visit(existingRelation); 361 if (!mpTest.getErrors().isEmpty()) { 362 showErrors(mpTest.getErrors()); 363 return null; 367 364 } 368 365 … … 404 401 * This method removes tags/value pairs from inner and outer ways and put them on relation if necessary. 405 402 * Function was extended in reltoolbox plugin by Zverikk and copied back to the core 406 * @param relation the multipolygon style relation to process. If it is new, the tags might be403 * @param relation the multipolygon style relation to process. If it not linked to a dataset, the tags might be 407 404 * modified, else the list of commands will contain a command to modify its tags 408 405 * @return a list of commands to execute … … 488 485 if (moveTags && !values.isEmpty()) { 489 486 // add those tag values to the relation 490 boolean fixed = false;491 487 Map<String, String> tagsToAdd = new HashMap<>(); 492 488 for (Entry<String, String> entry : values.entrySet()) { 493 489 String key = entry.getKey(); 494 490 if (!relation.hasKey(key)) { 495 if (relation. isNew())491 if (relation.getDataSet() == null) 496 492 relation.put(key, entry.getValue()); 497 493 else 498 494 tagsToAdd.put(key, entry.getValue()); 499 fixed = true; 500 } 501 } 502 if (fixed && !relation.isNew()) { 503 DataSet ds = relation.getDataSet(); 504 if (ds == null) { 505 ds = MainApplication.getLayerManager().getEditDataSet(); 506 } 507 commands.add(new ChangePropertyCommand(ds, Collections.singleton(relation), tagsToAdd)); 495 } 496 } 497 if (!tagsToAdd.isEmpty()) { 498 commands.add(new ChangePropertyCommand(Collections.singleton(relation), tagsToAdd)); 508 499 } 509 500 } -
trunk/test/unit/org/openstreetmap/josm/actions/CreateMultipolygonActionTest.java
r17408 r17429 5 5 import static org.junit.jupiter.api.Assertions.assertFalse; 6 6 import static org.junit.jupiter.api.Assertions.assertNotNull; 7 import static org.junit.jupiter.api.Assertions.assertNull; 7 8 import static org.junit.jupiter.api.Assertions.assertTrue; 8 9 … … 45 46 @RegisterExtension 46 47 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 47 public JOSMTestRules test = new JOSMTestRules().projection().main().preferences() ;48 public JOSMTestRules test = new JOSMTestRules().projection().main().preferences().mapStyles(); 48 49 49 50 private static Map<String, String> getRefToRoleMap(Relation relation) { … … 214 215 assertEquals(1, ds.getWays().stream().filter(w -> w.hasTag("building", "yes")).count()); 215 216 } 217 218 /** 219 * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/20325">Bug #20325</a>. 220 * @throws Exception if an error occurs 221 */ 222 @Test 223 void testTicket20325() throws Exception { 224 DataSet ds = OsmReader.parseDataSet(TestUtils.getRegressionDataStream(20325, "data.osm"), null); 225 assertEquals(1, ds.getRelations().size()); 226 Relation mp = ds.getRelations().iterator().next(); 227 assertFalse(ds.getRelations().iterator().next().hasTag("landuse", "farmland")); 228 assertEquals(1, ds.getWays().stream().filter(w -> w.hasTag("landuse", "farmland")).count()); 229 Pair<SequenceCommand, Relation> cmd = CreateMultipolygonAction.createMultipolygonCommand(ds.getWays(), mp); 230 assertNotNull(cmd); 231 cmd.a.executeCommand(); 232 assertEquals(1, ds.getRelations().size()); 233 assertTrue(ds.getRelations().iterator().next().hasTag("landuse", "farmland")); 234 assertEquals(0, ds.getWays().stream().filter(w -> w.hasTag("landuse", "farmland")).count()); 235 cmd.a.undoCommand(); 236 assertEquals(1, ds.getRelations().size()); 237 assertFalse(ds.getRelations().iterator().next().hasTag("landuse", "farmland")); 238 assertEquals(1, ds.getWays().stream().filter(w -> w.hasTag("landuse", "farmland")).count()); 239 } 240 241 /** 242 * Coverage test for <a href="https://josm.openstreetmap.de/ticket/20325">Bug #20325</a>. 243 * New relation, no update needed, no command should be produced. 244 * @throws Exception if an error occurs 245 */ 246 @Test 247 void testTicket20325New() throws Exception { 248 DataSet ds = OsmReader.parseDataSet(TestUtils.getRegressionDataStream(20325, "no-change-new.osm"), null); 249 assertEquals(1, ds.getRelations().size()); 250 Relation mp = ds.getRelations().iterator().next(); 251 Pair<SequenceCommand, Relation> cmd = CreateMultipolygonAction.createMultipolygonCommand(ds.getWays(), mp); 252 assertNull(cmd); 253 } 254 255 /** 256 * Coverage test for <a href="https://josm.openstreetmap.de/ticket/20325">Bug #20325</a>. 257 * Old relation, no update needed, no command should be produced. 258 * @throws Exception if an error occurs 259 */ 260 @Test 261 void testTicket20325Old() throws Exception { 262 DataSet ds = OsmReader.parseDataSet(TestUtils.getRegressionDataStream(20325, "no-change-old.osm"), null); 263 assertEquals(1, ds.getRelations().size()); 264 Relation mp = ds.getRelations().iterator().next(); 265 Pair<SequenceCommand, Relation> cmd = CreateMultipolygonAction.createMultipolygonCommand(ds.getWays(), mp); 266 assertNull(cmd); 267 } 268 269 /** 270 * Coverage test for <a href="https://josm.openstreetmap.de/ticket/20325">Bug #20325</a>. 271 * Relation cannot be updated but produces warnings. Doesn't test that a popup was shown. 272 * @throws Exception if an error occurs 273 */ 274 @Test 275 void testTicket20325Invalid() throws Exception { 276 DataSet ds = OsmReader.parseDataSet(TestUtils.getRegressionDataStream(20325, "invalid-new-upldate.osm"), null); 277 assertEquals(1, ds.getRelations().size()); 278 Relation mp = ds.getRelations().iterator().next(); 279 Pair<SequenceCommand, Relation> cmd = CreateMultipolygonAction.createMultipolygonCommand(ds.getWays(), mp); 280 assertNull(cmd); 281 } 282 283 /** 284 * Coverage test for <a href="https://josm.openstreetmap.de/ticket/20325">Bug #20325</a>. 285 * Relation needs no updates but produces warnings. Doesn't test that a popup was shown. 286 * @throws Exception if an error occurs 287 */ 288 @Test 289 void testTicket20325NoUpdateWarning() throws Exception { 290 DataSet ds = OsmReader.parseDataSet(TestUtils.getRegressionDataStream(20325, "update-no-command-warning.osm"), null); 291 assertEquals(1, ds.getRelations().size()); 292 Relation mp = ds.getRelations().iterator().next(); 293 Pair<SequenceCommand, Relation> cmd = CreateMultipolygonAction.createMultipolygonCommand(ds.getWays(), mp); 294 assertNull(cmd); 295 } 296 216 297 }
Note:
See TracChangeset
for help on using the changeset viewer.