Modify

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#15464 closed enhancement (fixed)

[PATCH] Allow plugins to modify the changeset tags before upload

Reported by: rorym Owned by: team
Priority: normal Milestone: 17.10
Component: Core Version:
Keywords: tags, changeset, upload Cc:

Description

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.

  • src/org/openstreetmap/josm/actions/UploadAction.java

     
    88import java.awt.event.KeyEvent;
    99import java.util.LinkedList;
    1010import java.util.List;
     11import java.util.Map;
    1112
    1213import javax.swing.JOptionPane;
    1314
     
    2021import org.openstreetmap.josm.actions.upload.ValidateUploadHook;
    2122import org.openstreetmap.josm.data.APIDataSet;
    2223import org.openstreetmap.josm.data.conflict.ConflictCollection;
     24import org.openstreetmap.josm.data.osm.Changeset;
    2325import org.openstreetmap.josm.gui.HelpAwareOptionPane;
    2426import org.openstreetmap.josm.gui.MainApplication;
    2527import org.openstreetmap.josm.gui.io.UploadDialog;
     
    245247                return;
    246248        }
    247249
     250        // Any hooks want to change the changeset tags?
     251        Changeset cs = UploadDialog.getUploadDialog().getChangeset();
     252        Map<String, String> changeset_tags = cs.getKeys();
     253        for (UploadHook hook : UPLOAD_HOOKS) {
     254            hook.modifyChangesetTags(changeset_tags);
     255        }
     256        for (UploadHook hook : LATE_UPLOAD_HOOKS) {
     257            hook.modifyChangesetTags(changeset_tags);
     258        }
     259
    248260        MainApplication.worker.execute(
    249261                new UploadPrimitivesTask(
    250262                        UploadDialog.getUploadDialog().getUploadStrategySpecification(),
    251263                        layer,
    252264                        apiData,
    253                         UploadDialog.getUploadDialog().getChangeset()
     265                        cs
    254266                )
    255267        );
    256268    }
  • src/org/openstreetmap/josm/actions/upload/UploadHook.java

     
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.actions.upload;
    33
     4import java.util.Map;
     5
    46import org.openstreetmap.josm.data.APIDataSet;
    57
    68/**
    7  * A check right before the upload. The UploadHook may modify the uploaded data
    8  * silently, it may display a warning message to the user or prevent the upload
    9  * altogether.
     9 * Change, or block, the upload.
     10 *
     11 * The UploadHook may modify the uploaded data silently, it may display a
     12 * warning message to the user or prevent the upload altogether.
     13 *
     14 * The tags of the changeset can also be changed with modifyChangesetTags
     15 * method.
    1016 */
    11 @FunctionalInterface
    1217public interface UploadHook {
    1318
    1419    /**
    15      * Checks the upload.
    16      * @param apiDataSet the data to upload
    17      * @return {@code true} if upload is possible
     20     * Check, and/or change, the data to be uploaded.
     21     * Default implementation is to approve the upload.
     22     * @param apiDataSet the data to upload, modify this to change the data.
     23     * @return {@code true} if upload is possible, {@code false} to block the upload.
    1824     */
    19     boolean checkUpload(APIDataSet apiDataSet);
     25    default boolean checkUpload(APIDataSet apiDataSet) {
     26        return true;
     27    }
     28
     29    /**
     30     * Modify the changeset tags (in place) before upload.
     31     * Default implementation is to do no changes.
     32     * @param tags The current tags to change
     33     */
     34    default void modifyChangesetTags(Map<String, String> tags) {
     35    }
    2036}

Attachments (0)

Change History (4)

comment:1 by rorym, 7 years ago

The purpose of this patch is to add the clacks_overhead=GNU Terry Pratchett tag to changesets. I have a plugin which uses this functionality to do this: https://github.com/rory/josm-pTerry

comment:2 by Don-vip, 7 years ago

Resolution: fixed
Status: newclosed

In 13028/josm:

fix #15464 - Allow plugins to modify the changeset tags before upload (patch by rorym)

comment:3 by Don-vip, 7 years ago

Milestone: 17.10

comment:4 by Don-vip, 7 years ago

Thanks! :)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain team.
as The resolution will be set.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.