﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
15464	[PATCH] Allow plugins to modify the changeset tags before upload	rorym	team	"This is a patch that allows plugins to modify the tags of a changeset before upload. I previous suggested a patch for changeset tags (in issue #14864), but this is a more general and better way to do that.

This patch gives a new method to `UploadHook`: `modifyChangesetTags`. Implementor can choose to implement this and modify the tags in place. The default implementation is to not change anything.

I also changed the `checkUpload` method to return true by default, in case you wanted to implement a hook which only changes the changeset tags. I also improved the javadoc for `UploadHook`.

{{{
#!diff
Index: src/org/openstreetmap/josm/actions/UploadAction.java
===================================================================
--- src/org/openstreetmap/josm/actions/UploadAction.java	(revision 13027)
+++ src/org/openstreetmap/josm/actions/UploadAction.java	(working copy)
@@ -8,6 +8,7 @@
 import java.awt.event.KeyEvent;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Map;
 
 import javax.swing.JOptionPane;
 
@@ -20,6 +21,7 @@
 import org.openstreetmap.josm.actions.upload.ValidateUploadHook;
 import org.openstreetmap.josm.data.APIDataSet;
 import org.openstreetmap.josm.data.conflict.ConflictCollection;
+import org.openstreetmap.josm.data.osm.Changeset;
 import org.openstreetmap.josm.gui.HelpAwareOptionPane;
 import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.io.UploadDialog;
@@ -245,12 +247,22 @@
                 return;
         }
 
+        // Any hooks want to change the changeset tags?
+        Changeset cs = UploadDialog.getUploadDialog().getChangeset();
+        Map<String, String> changeset_tags = cs.getKeys();
+        for (UploadHook hook : UPLOAD_HOOKS) {
+            hook.modifyChangesetTags(changeset_tags);
+        }
+        for (UploadHook hook : LATE_UPLOAD_HOOKS) {
+            hook.modifyChangesetTags(changeset_tags);
+        }
+
         MainApplication.worker.execute(
                 new UploadPrimitivesTask(
                         UploadDialog.getUploadDialog().getUploadStrategySpecification(),
                         layer,
                         apiData,
-                        UploadDialog.getUploadDialog().getChangeset()
+                        cs
                 )
         );
     }
Index: src/org/openstreetmap/josm/actions/upload/UploadHook.java
===================================================================
--- src/org/openstreetmap/josm/actions/upload/UploadHook.java	(revision 13027)
+++ src/org/openstreetmap/josm/actions/upload/UploadHook.java	(working copy)
@@ -1,20 +1,36 @@
 // License: GPL. For details, see LICENSE file.
 package org.openstreetmap.josm.actions.upload;
 
+import java.util.Map;
+
 import org.openstreetmap.josm.data.APIDataSet;
 
 /**
- * A check right before the upload. The UploadHook may modify the uploaded data
- * silently, it may display a warning message to the user or prevent the upload
- * altogether.
+ * Change, or block, the upload.
+ * 
+ * The UploadHook may modify the uploaded data silently, it may display a
+ * warning message to the user or prevent the upload altogether.
+ *
+ * The tags of the changeset can also be changed with modifyChangesetTags
+ * method.
  */
-@FunctionalInterface
 public interface UploadHook {
 
     /**
-     * Checks the upload.
-     * @param apiDataSet the data to upload
-     * @return {@code true} if upload is possible
+     * Check, and/or change, the data to be uploaded.
+     * Default implementation is to approve the upload.
+     * @param apiDataSet the data to upload, modify this to change the data.
+     * @return {@code true} if upload is possible, {@code false} to block the upload.
      */
-    boolean checkUpload(APIDataSet apiDataSet);
+    default boolean checkUpload(APIDataSet apiDataSet) {
+        return true;
+    }
+
+    /**
+     * Modify the changeset tags (in place) before upload.
+     * Default implementation is to do no changes.
+     * @param tags The current tags to change
+     */
+    default void modifyChangesetTags(Map<String, String> tags) {
+    }
 }
}}}"	enhancement	closed	normal	17.10	Core		fixed	tags, changeset, upload	
