Changeset 34953 in osm for applications/editors/josm/plugins
- Timestamp:
- 2019-03-30T09:39:01+01:00 (5 years ago)
- 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 3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 import static org.openstreetmap.josm.tools.I18n.trn; 5 6 6 7 import java.net.HttpURLConnection; … … 61 62 62 63 public static final Collection<Long> MODERATOR_REDACTION_ACCOUNTS = Collections.unmodifiableCollection(Arrays.asList( 63 722 137L, // OSMF Redaction Account64 760 215L // pnorman redaction revert64 722_137L, // OSMF Redaction Account 65 760_215L // pnorman redaction revert 65 66 )); 66 67 … … 193 194 throw e; 194 195 } 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"); 200 198 version--; 201 199 } … … 214 212 final OsmServerMultiObjectReader rdr = new OsmServerMultiObjectReader(); 215 213 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); 217 218 try { 218 219 for (HashSet<HistoryOsmPrimitive> collection : Arrays.asList(updated, deleted)) { … … 377 378 HistoryOsmPrimitive hp = entry.getPrimitive(); 378 379 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 } 382 383 383 384 if (hp.getVersion() != dp.getVersion() … … 434 435 435 436 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 } 453 461 } 454 462 } 455 463 } 456 464 } 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); 459 481 } 460 482 } -
applications/editors/josm/plugins/reverter/src/reverter/DataSetCommandMerger.java
r34946 r34953 62 62 OsmPrimitive p = targetDataSet.getPrimitiveById(mergeSource.getId(), mergeSource.getType()); 63 63 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())); 66 65 return p; 67 66 } -
applications/editors/josm/plugins/reverter/src/reverter/RevertChangesetCommand.java
r32905 r34953 10 10 import org.openstreetmap.josm.tools.ImageProvider; 11 11 12 /** 13 * Commands to revert a changeset. 14 * 15 */ 12 16 public class RevertChangesetCommand extends SequenceCommand { 13 protected String name;14 17 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 */ 15 23 public RevertChangesetCommand(String name, Collection<Command> sequenz) { 16 24 super(name, sequenz); 17 this.name = name;18 25 ReverterPlugin.reverterUsed = true; 19 26 } … … 21 28 @Override 22 29 public String getDescriptionText() { 23 return name;30 return getName(); 24 31 } 25 32 -
applications/editors/josm/plugins/reverter/src/reverter/RevertChangesetTask.java
r34552 r34953 22 22 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 23 23 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 24 import org.openstreetmap.josm.gui.progress.swing.PleaseWaitProgressMonitor;25 24 import org.openstreetmap.josm.gui.util.GuiHelper; 26 25 import org.openstreetmap.josm.io.OsmTransferException; … … 74 73 if (!downloadConfirmed) return false; 75 74 } 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(); 84 78 } 85 79 … … 109 103 } 110 104 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); 112 106 GuiHelper.runInEDT(() -> { 113 107 UndoRedoHandler.getInstance().add(cmd); … … 120 114 121 115 private RevertChangesetCommand revertChangeset(int changesetId) throws OsmTransferException, UserCancelException { 122 progressMonitor.indeterminateSubTask(tr(" Downloading changeset"));116 progressMonitor.indeterminateSubTask(tr("Reverting changeset {0}", Long.toString(changesetId))); 123 117 try { 124 118 rev = new ChangesetReverter(changesetId, revertType, newLayer, progressMonitor.createSubTaskMonitor(0, true)); … … 146 140 // Don't ask user to download primitives going to be undeleted 147 141 rev.checkMissingDeleted(); 148 rev.downloadMissingPrimitives(progressMonitor.createSubTaskMonitor( 0, false));142 rev.downloadMissingPrimitives(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 149 143 } 150 144 151 145 if (progressMonitor.isCanceled()) 152 146 throw new UserCancelException(); 147 progressMonitor.setTicks(0); 153 148 rev.downloadObjectsHistory(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 154 149 if (progressMonitor.isCanceled()) … … 156 151 if (!checkAndDownloadMissing()) 157 152 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(); 159 157 List<Command> cmds = rev.getCommands(); 160 158 if (cmds.isEmpty()) { … … 167 165 } 168 166 } 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); 171 174 } 172 175 173 176 @Override 174 177 protected void cancel() { 178 // nothing to do 175 179 } 176 180 177 181 @Override 178 182 protected void finish() { 183 // nothing to do 184 179 185 } 180 186 187 /** 188 * @return number of conflicts for this changeset 189 */ 181 190 public final int getNumberOfConflicts() { 182 191 return numberOfConflicts;
Note:
See TracChangeset
for help on using the changeset viewer.