Changeset 17429 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2020-12-30T11:52:34+01:00 (4 years ago)
Author:
GerdP
Message:

fix #20325: Update Multipolygon removes tags instead of moving them to relation

  • rewrite handling of update multipolygon cases
  • let removeTagsFromWaysIfNeeded() check if getDataset() returns null instead of checking isNew(). I assume it was always meant to work like this. JoinAreasAction works fine with that and I hope no plugin relies on the old behaviour.
  • add regression unit test and more unit tests to improve coverage
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/CreateMultipolygonAction.java

    r17408 r17429  
    341341        boolean changedMembers = rr.a != rr.b;
    342342        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;
    344344
    345345        final List<Command> list = removeTagsFromWaysIfNeeded(relation);
     
    349349            commandName = getName(false);
    350350        } 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                }
    358357            }
    359358            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;
    367364                }
    368365
     
    404401     * This method removes tags/value pairs from inner and outer ways and put them on relation if necessary.
    405402     * 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 be
     403     * @param relation the multipolygon style relation to process. If it not linked to a dataset, the tags might be
    407404     * modified, else the list of commands will contain a command to modify its tags
    408405     * @return a list of commands to execute
     
    488485        if (moveTags && !values.isEmpty()) {
    489486            // add those tag values to the relation
    490             boolean fixed = false;
    491487            Map<String, String> tagsToAdd = new HashMap<>();
    492488            for (Entry<String, String> entry : values.entrySet()) {
    493489                String key = entry.getKey();
    494490                if (!relation.hasKey(key)) {
    495                     if (relation.isNew())
     491                    if (relation.getDataSet() == null)
    496492                        relation.put(key, entry.getValue());
    497493                    else
    498494                        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));
    508499            }
    509500        }
Note: See TracChangeset for help on using the changeset viewer.