Changeset 35398 in osm for applications


Ignore:
Timestamp:
2020-03-27T15:42:18+01:00 (5 years ago)
Author:
gerdp
Message:

see #josm10873: Loses everything already downloaded when encountering an error
Collect missing primitives and show dialog with a list of them similar to the download objects dialog
Requires JOSM r16205 or later.

Location:
applications/editors/josm/plugins/undelete
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/undelete/build.xml

    r34881 r35398  
    44    <property name="commit.message" value="adapt to core changes (backwards compatible)"/>
    55    <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
    6     <property name="plugin.main.version" value="14763"/>
     6    <property name="plugin.main.version" value="16205"/>
    77
    88    <property name="plugin.author" value="Nakor"/>
  • applications/editors/josm/plugins/undelete/src/org/openstreetmap/josm/plugins/undelete/UndeleteAction.java

    r35396 r35398  
    33
    44import static org.openstreetmap.josm.tools.I18n.tr;
     5import static org.openstreetmap.josm.tools.I18n.trn;
    56
    67import java.awt.event.ActionEvent;
     
    3536import org.openstreetmap.josm.data.osm.history.HistoryWay;
    3637import org.openstreetmap.josm.gui.MainApplication;
    37 import org.openstreetmap.josm.gui.Notification;
    3838import org.openstreetmap.josm.gui.history.HistoryLoadTask;
    3939import org.openstreetmap.josm.gui.io.DownloadPrimitivesTask;
     40import org.openstreetmap.josm.gui.io.DownloadPrimitivesWithReferrersTask;
    4041import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    4142import org.openstreetmap.josm.gui.util.GuiHelper;
     
    5859        private Set<OsmPrimitive> restored;
    5960
    60         private Worker(OsmPrimitive parent, OsmDataLayer layer, List<PrimitiveId> ids, Set<OsmPrimitive> restored) {
    61             this.parent = parent;
    62             this.layer = layer;
    63             this.ids = ids;
    64             this.restored = restored != null ? restored : new LinkedHashSet<>();
    65         }
     61                private Set<PrimitiveId> missingPrimitives;
     62
     63                private Worker(OsmPrimitive parent, OsmDataLayer layer, List<PrimitiveId> ids, Set<OsmPrimitive> restored,
     64                                HistoryLoadTask task) {
     65                        this.parent = parent;
     66                        this.layer = layer;
     67                        this.ids = ids;
     68                        this.restored = restored;
     69                        this.missingPrimitives = task.getMissingPrimitives();
     70                }
    6671
    6772        @Override
     
    6974            List<Node> nodes = new ArrayList<>();
    7075            for (PrimitiveId pid : ids) {
     76                                if (missingPrimitives == null || missingPrimitives.contains(pid)) {
     77                                        continue;
     78                                }
     79
    7180                OsmPrimitive primitive = layer.data.getPrimitiveById(pid);
    7281                if (primitive == null) {
     
    7786                        History h = HistoryDataSet.getInstance().getHistory(id, type);
    7887
    79                         if (h == null) {
    80                             Logging.warn("Cannot find history for " + type + " " + id);
    81                             return;
    82                         }
     88                                                if (h == null) {
     89                                                        Logging.warn("Cannot find history for " + type + " " + id);
     90                                                        return;
     91                                                }
    8392
    8493                        HistoryOsmPrimitive hPrimitive1 = h.getLatest();
     
    186195                                layer.data.addPrimitive(primitive);
    187196                                restored.add(primitive);
    188                             } else {
    189                               final String msg = OsmPrimitiveType.NODE == type
    190                                   ? tr("Unable to undelete node {0}. Object has likely been redacted", id)
    191                                   : OsmPrimitiveType.WAY == type
    192                                   ? tr("Unable to undelete way {0}. Object has likely been redacted", id)
    193                                   : OsmPrimitiveType.RELATION == type
    194                                   ? tr("Unable to undelete relation {0}. Object has likely been redacted", id)
    195                                   : null;
    196                                 GuiHelper.runInEDT(() -> new Notification(msg).setIcon(JOptionPane.WARNING_MESSAGE).show());
    197                                 Logging.warn(msg);
    198197                            }
    199198                        }
     
    215214                });
    216215            }
     216            if (missingPrimitives != null && !missingPrimitives.isEmpty()) {
     217                GuiHelper.runInEDTAndWait(() -> DownloadPrimitivesWithReferrersTask.reportProblemDialog(missingPrimitives,
     218                        trn("Object could not be undeleted", "Some objects could not be undeleted", missingPrimitives.size()),
     219                        trn("One object could not be undeleted.<br>",
     220                                "{0} objects could not be undeleted.<br>",
     221                                missingPrimitives.size(),
     222                                missingPrimitives.size())
     223                                + tr("The server replied with response code 404.<br>"
     224                                     + "This usually means, the server does not know an object with the requested id. Maybe it was redacted."),
     225                        tr("missing objects:"),
     226                        JOptionPane.ERROR_MESSAGE
     227                        ).showDialog());
     228
     229            }
    217230        }
     231
    218232    }
    219233
     
    255269        HistoryLoadTask task = new HistoryLoadTask();
    256270        task.setChangesetDataNeeded(false);
     271        task.setCollectMissing(true);
    257272        for (PrimitiveId id : ids) {
    258273            task.add(id);
     
    260275
    261276        MainApplication.worker.execute(task);
    262         MainApplication.worker.submit(new Worker(parent, layer, ids, restored));
     277        MainApplication.worker.submit(new Worker(parent, layer, ids, restored, task));
    263278    }
    264279}
Note: See TracChangeset for help on using the changeset viewer.