Changeset 18007 in josm
- Timestamp:
- 2021-07-12T16:25:33+02:00 (4 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/conflict/tags/TagConflictResolverModel.java
r17333 r18007 10 10 import java.util.Map; 11 11 import java.util.Set; 12 import java.util.function.BiConsumer; 12 13 13 14 import javax.swing.table.DefaultTableModel; … … 299 300 return new HashSet<>(keysWithConflicts); 300 301 } 302 303 /** 304 * Perform an action on all decisions, useful to perform a global decision (keep all, keep none, etc.) 305 * @param action action to perform on decision 306 * @since 18007 307 */ 308 public final void actOnDecisions(BiConsumer<String, MultiValueResolutionDecision> action) { 309 decisions.forEach(action::accept); 310 } 301 311 } -
trunk/src/org/openstreetmap/josm/io/GeoJSONReader.java
r17646 r18007 12 12 import java.nio.charset.StandardCharsets; 13 13 import java.util.ArrayList; 14 import java.util.Arrays; 14 15 import java.util.List; 15 16 import java.util.Map; 16 17 import java.util.Objects; 17 18 import java.util.Optional; 18 import java.util.TreeMap;19 19 import java.util.stream.Collectors; 20 20 … … 37 37 import org.openstreetmap.josm.data.osm.Relation; 38 38 import org.openstreetmap.josm.data.osm.RelationMember; 39 import org.openstreetmap.josm.data.osm.Tag; 40 import org.openstreetmap.josm.data.osm.TagCollection; 41 import org.openstreetmap.josm.data.osm.TagMap; 39 42 import org.openstreetmap.josm.data.osm.UploadPolicy; 40 43 import org.openstreetmap.josm.data.osm.Way; … … 43 46 import org.openstreetmap.josm.data.validation.TestError; 44 47 import org.openstreetmap.josm.data.validation.tests.DuplicateWay; 48 import org.openstreetmap.josm.gui.conflict.tags.TagConflictResolutionUtil; 49 import org.openstreetmap.josm.gui.conflict.tags.TagConflictResolverModel; 45 50 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 46 51 import org.openstreetmap.josm.gui.progress.ProgressMonitor; … … 329 334 330 335 /** 331 * Replace allexisting tags in primitivebythe values given in the GeoJSON feature.336 * Merge existing tags in primitive (if any) with the values given in the GeoJSON feature. 332 337 * @param feature the GeoJSON feature 333 338 * @param primitive the OSM primitive … … 335 340 private static void fillTagsFromFeature(final JsonObject feature, final OsmPrimitive primitive) { 336 341 if (feature != null) { 337 primitive.setKeys(getTags(feature)); 338 } 342 TagCollection featureTags = getTags(feature); 343 primitive.setKeys(new TagMap(primitive.isTagged() ? mergeAllTagValues(primitive, featureTags) : featureTags)); 344 } 345 } 346 347 private static TagCollection mergeAllTagValues(final OsmPrimitive primitive, TagCollection featureTags) { 348 TagCollection tags = TagCollection.from(primitive).union(featureTags); 349 TagConflictResolutionUtil.applyAutomaticTagConflictResolution(tags); 350 TagConflictResolutionUtil.normalizeTagCollectionBeforeEditing(tags, Arrays.asList(primitive)); 351 TagConflictResolverModel tagModel = new TagConflictResolverModel(); 352 tagModel.populate(new TagCollection(tags), tags.getKeysWithMultipleValues()); 353 tagModel.actOnDecisions((k, d) -> d.keepAll()); 354 return tagModel.getAllResolutions(); 339 355 } 340 356 … … 347 363 } 348 364 349 private static Map<String, String>getTags(final JsonObject feature) {350 final Map<String, String>tags = new TreeMap<>();365 private static TagCollection getTags(final JsonObject feature) { 366 final TagCollection tags = new TagCollection(); 351 367 352 368 if (feature.containsKey(PROPERTIES) && !feature.isNull(PROPERTIES)) { … … 357 373 358 374 if (value instanceof JsonString) { 359 tags. put(stringJsonValueEntry.getKey(), ((JsonString) value).getString());375 tags.add(new Tag(stringJsonValueEntry.getKey(), ((JsonString) value).getString())); 360 376 } else if (value instanceof JsonObject) { 361 377 Logging.warn( … … 365 381 ); 366 382 } else if (value.getValueType() != JsonValue.ValueType.NULL) { 367 tags. put(stringJsonValueEntry.getKey(), value.toString());383 tags.add(new Tag(stringJsonValueEntry.getKey(), value.toString())); 368 384 } 369 385 } -
trunk/test/unit/org/openstreetmap/josm/io/GeoJSONReaderTest.java
r17661 r18007 217 217 218 218 /** 219 * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/21044">Bug #21044</a>. 220 * @throws Exception in case of error 221 */ 222 @Test 223 void testTicket21044Duplicates() throws Exception { 224 try (InputStream in = TestUtils.getRegressionDataStream(21044, "test.geojson")) { 225 final List<OsmPrimitive> primitives = new ArrayList<>( 226 new GeoJSONReader().doParseDataSet(in, null).getPrimitives(it -> true)); 227 assertEquals(1, primitives.size()); 228 OsmPrimitive primitive = primitives.get(0); 229 assertTrue(primitive instanceof Node); 230 Node n = (Node) primitive; 231 assertNull(n.get("addr:building")); 232 assertEquals("06883", n.get("addr:postcode")); 233 assertEquals("22;26", n.get("addr:housenumber")); 234 } 235 } 236 237 /** 219 238 * Tests error reporting for an invalid FeatureCollection 220 239 * @throws Exception in case of error … … 229 248 } 230 249 } 231 232 250 }
Note:
See TracChangeset
for help on using the changeset viewer.