Changeset 34953 in osm


Ignore:
Timestamp:
2019-03-30T09:39:01+01:00 (6 years ago)
Author:
gerdp
Message:

fix #17535:

  • don't create new progress monitor in RevertChangesetTask.checkAndDownloadMissing() , instead use setTicks(0) in existing one
  • add changeset id to progress bar (where possible)
  • add changeset id to IllegalStateException "Missing merge target" created in ChangesetReverter
  • react on Cancel button in method fixNodesWithoutCoordinates()
  • fix / improve several I18N strings
  • fix some javadoc/sonarLint issues
  • improve code in RevertChangesetCommand (no functional change)
Location:
applications/editors/josm/plugins/reverter/src/reverter
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/reverter/src/reverter/ChangesetReverter.java

    r34930 r34953  
    33
    44import static org.openstreetmap.josm.tools.I18n.tr;
     5import static org.openstreetmap.josm.tools.I18n.trn;
    56
    67import java.net.HttpURLConnection;
     
    6162
    6263    public static final Collection<Long> MODERATOR_REDACTION_ACCOUNTS = Collections.unmodifiableCollection(Arrays.asList(
    63             722137L, // OSMF Redaction Account
    64             760215L  // pnorman redaction revert
     64            722_137L, // OSMF Redaction Account
     65            760_215L  // pnorman redaction revert
    6566            ));
    6667
     
    193194                    throw e;
    194195                }
    195                 String message = "Version "+version+" of "+id+" is unauthorized";
    196                 if (version > 1) {
    197                     message += ", requesting previous one";
    198                 }
    199                 Logging.info(message);
     196                String message = "Version " + version + " of " + id + " is unauthorized";
     197                Logging.info(version <= 1 ? message : message + ", requesting previous one");
    200198                version--;
    201199            }
     
    214212        final OsmServerMultiObjectReader rdr = new OsmServerMultiObjectReader();
    215213
    216         progressMonitor.beginTask(tr("Downloading objects history"), updated.size()+deleted.size()+1);
     214        int num = updated.size() + deleted.size();
     215        progressMonitor.beginTask(
     216                addChangesetIdPrefix(
     217                        trn("Downloading history for {0} object", "Downloading history for {0} objects", num, num)), num + 1);
    217218        try {
    218219            for (HashSet<HistoryOsmPrimitive> collection : Arrays.asList(updated, deleted)) {
     
    377378            HistoryOsmPrimitive hp = entry.getPrimitive();
    378379            OsmPrimitive dp = ds.getPrimitiveById(hp.getPrimitiveId());
    379             if (dp == null || dp.isIncomplete())
    380                 throw new IllegalStateException(tr("Missing merge target for {0} with id {1}",
    381                         hp.getType(), hp.getId()));
     380            if (dp == null || dp.isIncomplete()) {
     381                throw new IllegalStateException(addChangesetIdPrefix(tr("Missing merge target for {0}", hp.getPrimitiveId())));
     382            }
    382383
    383384            if (hp.getVersion() != dp.getVersion()
     
    434435
    435436    public void fixNodesWithoutCoordinates(ProgressMonitor progressMonitor) throws OsmTransferException {
    436         for (Node n : nds.getNodes()) {
    437             if (!n.isDeleted() && n.getCoor() == null) {
    438                 PrimitiveId id = n.getPrimitiveId();
    439                 OsmPrimitive p = ds.getPrimitiveById(id);
    440                 if (p instanceof Node && !((Node) p).isLatLonKnown()) {
    441                     int version = p.getVersion();
    442                     while (version > 1) {
    443                         // find the version that was in use when the current changeset was closed
    444                         --version;
    445                         final OsmServerMultiObjectReader rdr = new OsmServerMultiObjectReader();
    446                         readObjectVersion(rdr, id, version, progressMonitor);
    447                         DataSet history = rdr.parseOsm(progressMonitor.createSubTaskMonitor(1, true));
    448                         if (!history.isEmpty()) {
    449                             Node historyNode = (Node) history.allPrimitives().iterator().next();
    450                             if (historyNode.isLatLonKnown() && changeset.getClosedAt().after(historyNode.getTimestamp())) {
    451                                 n.load(historyNode.save());
    452                                 break;
     437        Collection<Node> nodes = nds.getNodes();
     438        int num = nodes.size();
     439        progressMonitor.beginTask(addChangesetIdPrefix(
     440                trn("Checking coordinates of {0} node", "Checking coordinates of {0} nodes", num, num)), num);
     441
     442        try {
     443            for (Node n : nodes) {
     444                if (!n.isDeleted() && n.getCoor() == null) {
     445                    PrimitiveId id = n.getPrimitiveId();
     446                    OsmPrimitive p = ds.getPrimitiveById(id);
     447                    if (p instanceof Node && !((Node) p).isLatLonKnown()) {
     448                        int version = p.getVersion();
     449                        while (version > 1) {
     450                            // find the version that was in use when the current changeset was closed
     451                            --version;
     452                            final OsmServerMultiObjectReader rdr = new OsmServerMultiObjectReader();
     453                            readObjectVersion(rdr, id, version, progressMonitor);
     454                            DataSet history = rdr.parseOsm(progressMonitor.createSubTaskMonitor(1, true));
     455                            if (!history.isEmpty()) {
     456                                Node historyNode = (Node) history.allPrimitives().iterator().next();
     457                                if (historyNode.isLatLonKnown() && changeset.getClosedAt().after(historyNode.getTimestamp())) {
     458                                    n.load(historyNode.save());
     459                                    break;
     460                                }
    453461                            }
    454462                        }
    455463                    }
    456464                }
    457             }
    458         }
     465                if (progressMonitor.isCanceled())
     466                    return;
     467                progressMonitor.worked(1);
     468            }
     469        } finally {
     470            progressMonitor.finishTask();
     471        }
     472    }
     473
     474    /**
     475     * Add prefix with properly formatted changeset id to a message.
     476     * @param msg the message string
     477     * @return prefixed message
     478     */
     479    String addChangesetIdPrefix(String msg) {
     480        return tr("Changeset {0}: {1}", Long.toString(changesetId), msg);
    459481    }
    460482}
  • applications/editors/josm/plugins/reverter/src/reverter/DataSetCommandMerger.java

    r34946 r34953  
    6262        OsmPrimitive p = targetDataSet.getPrimitiveById(mergeSource.getId(), mergeSource.getType());
    6363        if (p == null)
    64             throw new IllegalStateException(tr("Missing merge target of type {0} with id {1}",
    65                     mergeSource.getType(), mergeSource.getUniqueId()));
     64            throw new IllegalStateException(tr("Missing merge target for {0}", mergeSource.getPrimitiveId()));
    6665        return p;
    6766    }
  • applications/editors/josm/plugins/reverter/src/reverter/RevertChangesetCommand.java

    r32905 r34953  
    1010import org.openstreetmap.josm.tools.ImageProvider;
    1111
     12/**
     13 * Commands to revert a changeset.
     14 *
     15 */
    1216public class RevertChangesetCommand extends SequenceCommand {
    13     protected String name;
    1417
     18    /**
     19     * Create the command by specifying the list of commands to execute.
     20     * @param name The description text
     21     * @param sequenz The sequence that should be executed.
     22     */
    1523    public RevertChangesetCommand(String name, Collection<Command> sequenz) {
    1624        super(name, sequenz);
    17         this.name = name;
    1825        ReverterPlugin.reverterUsed = true;
    1926    }
     
    2128    @Override
    2229    public String getDescriptionText() {
    23         return name;
     30        return getName();
    2431    }
    2532
  • applications/editors/josm/plugins/reverter/src/reverter/RevertChangesetTask.java

    r34552 r34953  
    2222import org.openstreetmap.josm.gui.PleaseWaitRunnable;
    2323import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    24 import org.openstreetmap.josm.gui.progress.swing.PleaseWaitProgressMonitor;
    2524import org.openstreetmap.josm.gui.util.GuiHelper;
    2625import org.openstreetmap.josm.io.OsmTransferException;
     
    7473            if (!downloadConfirmed) return false;
    7574        }
    76         final PleaseWaitProgressMonitor monitor =
    77             new PleaseWaitProgressMonitor(tr("Fetching missing primitives"));
    78         try {
    79             rev.downloadMissingPrimitives(monitor);
    80         } finally {
    81             monitor.close();
    82         }
    83         return !monitor.isCanceled();
     75        progressMonitor.setTicks(0);
     76        rev.downloadMissingPrimitives(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false));
     77        return !progressMonitor.isCanceled();
    8478    }
    8579
     
    109103        }
    110104        if (!allcmds.isEmpty()) {
    111             Command cmd = allcmds.size() == 1 ? allcmds.get(0) : new SequenceCommand(tr("Revert changeset"), allcmds);
     105            Command cmd = allcmds.size() == 1 ? allcmds.get(0) : new SequenceCommand(tr("Revert changesets"), allcmds);
    112106            GuiHelper.runInEDT(() -> {
    113107                UndoRedoHandler.getInstance().add(cmd);
     
    120114
    121115    private RevertChangesetCommand revertChangeset(int changesetId) throws OsmTransferException, UserCancelException {
    122         progressMonitor.indeterminateSubTask(tr("Downloading changeset"));
     116        progressMonitor.indeterminateSubTask(tr("Reverting changeset {0}", Long.toString(changesetId)));
    123117        try {
    124118            rev = new ChangesetReverter(changesetId, revertType, newLayer, progressMonitor.createSubTaskMonitor(0, true));
     
    146140            // Don't ask user to download primitives going to be undeleted
    147141            rev.checkMissingDeleted();
    148             rev.downloadMissingPrimitives(progressMonitor.createSubTaskMonitor(0, false));
     142            rev.downloadMissingPrimitives(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false));
    149143        }
    150144
    151145        if (progressMonitor.isCanceled())
    152146            throw new UserCancelException();
     147        progressMonitor.setTicks(0);
    153148        rev.downloadObjectsHistory(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false));
    154149        if (progressMonitor.isCanceled())
     
    156151        if (!checkAndDownloadMissing())
    157152            throw new UserCancelException();
    158         rev.fixNodesWithoutCoordinates(progressMonitor);
     153        progressMonitor.setTicks(0);
     154        rev.fixNodesWithoutCoordinates(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false));
     155        if (progressMonitor.isCanceled())
     156            throw new UserCancelException();
    159157        List<Command> cmds = rev.getCommands();
    160158        if (cmds.isEmpty()) {
     
    167165            }
    168166        }
    169         return new RevertChangesetCommand(tr(revertType == RevertType.FULL ? "Revert changeset #{0}" :
    170                 "Partially revert changeset #{0}", changesetId), cmds);
     167        final String desc;
     168        if (revertType == RevertType.FULL) {
     169            desc = tr("Revert changeset {0}", String.valueOf(changesetId));
     170        } else {
     171            desc = tr("Partially revert changeset {0}", String.valueOf(changesetId));
     172        }
     173        return new RevertChangesetCommand(desc, cmds);
    171174    }
    172175
    173176    @Override
    174177    protected void cancel() {
     178        // nothing to do
    175179    }
    176180
    177181    @Override
    178182    protected void finish() {
     183        // nothing to do
     184
    179185    }
    180186
     187    /**
     188     * @return number of conflicts for this changeset
     189     */
    181190    public final int getNumberOfConflicts() {
    182191        return numberOfConflicts;
Note: See TracChangeset for help on using the changeset viewer.