source: osm/applications/editors/josm/plugins/reverter/src/reverter/ReverterUploadHook.java@ 35972

Last change on this file since 35972 was 35972, checked in by taylor.smock, 2 years ago

ReverterUploadHook: Use modifyChangesetTags instead of checkUpload

This also fixes an issue where any reverter change on any OSM layer
would cause the changeset created_by tag to be changed, even if
the reverter plugin was not used on that OSM layer.

See #20025 for more information.

File size: 1.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package reverter;
3
4import java.util.Map;
5import java.util.Objects;
6
7import org.openstreetmap.josm.actions.upload.UploadHook;
8import org.openstreetmap.josm.command.Command;
9import org.openstreetmap.josm.command.SequenceCommand;
10import org.openstreetmap.josm.data.UndoRedoHandler;
11import org.openstreetmap.josm.gui.MainApplication;
12import org.openstreetmap.josm.plugins.PluginInformation;
13
14/**
15 * Upload hook to add tag to new changeset.
16 *
17 */
18public class ReverterUploadHook implements UploadHook {
19 final String pluginString;
20
21 /**
22 * Create new {@link ReverterUploadHook}
23 * @param info plugin information
24 */
25 public ReverterUploadHook(PluginInformation info) {
26 pluginString = "reverter_plugin/" + info.version;
27 }
28
29 @Override
30 public void modifyChangesetTags(Map<String, String> tags) {
31 if (ReverterPlugin.reverterUsed.get()) {
32 for (Command cmd : UndoRedoHandler.getInstance().getUndoCommands()) {
33 if (Objects.equals(MainApplication.getLayerManager().getEditDataSet(), cmd.getAffectedDataSet()) && isReverterCmd(cmd)) {
34 tags.put("created_by", pluginString);
35 break;
36 }
37 }
38 }
39 }
40
41 private static boolean isReverterCmd(Command cmd) {
42 if (cmd instanceof RevertChangesetCommand)
43 return true;
44 if (cmd instanceof SequenceCommand) {
45 return ((SequenceCommand) cmd).getLastCommand() instanceof RevertChangesetCommand;
46 }
47 return false;
48 }
49}
Note: See TracBrowser for help on using the repository browser.