source: josm/trunk/src/org/openstreetmap/josm/actions/relation/DownloadMembersAction.java@ 17341

Last change on this file since 17341 was 17341, checked in by GerdP, 3 years ago

fix #20091: Downloading incomplete, deleted members leads to data inconsitency

  • changes the logic of "download members" so that all non-new members of all selected relations are downloaded. It doesn't recurse down on child relations. The old code did a download of members using the relation id, so the server returned the members of the version as known by the server. Disadvantage: The new code is slower.
  • changes and simplifies DataSetMerger to fix the wrong handling of deleted objects in the source
  • additional unit tests to cover more branches in mergeById()
  • also fixes #19783
  • Property svn:eol-style set to native
File size: 2.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions.relation;
3
4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.awt.event.ActionEvent;
8import java.util.Collection;
9import java.util.List;
10import java.util.stream.Collectors;
11
12import org.openstreetmap.josm.data.osm.IPrimitive;
13import org.openstreetmap.josm.data.osm.PrimitiveId;
14import org.openstreetmap.josm.gui.MainApplication;
15import org.openstreetmap.josm.gui.io.DownloadPrimitivesTask;
16import org.openstreetmap.josm.tools.ImageProvider;
17
18/**
19 * The action for downloading members of relations
20 * @since 5793
21 */
22public class DownloadMembersAction extends AbstractRelationAction {
23
24 /**
25 * Constructs a new <code>DownloadMembersAction</code>.
26 */
27 public DownloadMembersAction() {
28 putValue(SHORT_DESCRIPTION, tr("Download all members of the selected relations"));
29 putValue(NAME, tr("Download members"));
30 new ImageProvider("dialogs", "downloadincomplete").getResource().attachImageIcon(this, true);
31 setHelpId(ht("/Dialog/RelationList#DownloadMembers"));
32 }
33
34 @Override
35 public void actionPerformed(ActionEvent e) {
36 if (!isEnabled() || relations.isEmpty() || !MainApplication.isDisplayingMapView()) return;
37 List<PrimitiveId> members = relations.stream()
38 .flatMap(r -> r.getMemberPrimitivesList().stream().filter(osm -> !osm.isNew()).map(IPrimitive::getOsmPrimitiveId))
39 .distinct()
40 .collect(Collectors.toList());
41
42 MainApplication.worker.submit(new DownloadPrimitivesTask(MainApplication.getLayerManager().getEditLayer(), members, false));
43 }
44
45 @Override
46 public void setPrimitives(Collection<? extends IPrimitive> primitives) {
47 this.relations = getRelations(primitives);
48 updateEnabledState();
49 }
50
51 @Override
52 protected void updateEnabledState() {
53 setEnabled(canDownload());
54 }
55}
Note: See TracBrowser for help on using the repository browser.