kopia lustrzana https://github.com/JOSM/MapWithAI
Add upload hook to add changeset tags
* Also remove default keys from preferences Signed-off-by: Taylor Smock <taylor.smock@kaart.com>pull/1/head
rodzic
44de005f16
commit
93246042a9
|
@ -202,7 +202,8 @@ publish to / GitLab.com packages:
|
|||
name: GitLab.com / JOSM-MapWithAI packages
|
||||
url: https://gitlab.com/gokaart/JOSM_MapWithAI/-/packages
|
||||
script:
|
||||
- ./gradlew publishPluginPublicationToGitlabRepository publishAllPublicationsToGitlabRepository releaseToGitlab
|
||||
- ./gradlew publishAllPublicationsToGitlabRepository
|
||||
- ./gradlew releaseToGitlab
|
||||
dependencies:
|
||||
- build
|
||||
only:
|
||||
|
|
|
@ -14,6 +14,7 @@ import javax.swing.JMenu;
|
|||
import javax.swing.JMenuItem;
|
||||
|
||||
import org.openstreetmap.josm.actions.JosmAction;
|
||||
import org.openstreetmap.josm.actions.UploadAction;
|
||||
import org.openstreetmap.josm.gui.MainApplication;
|
||||
import org.openstreetmap.josm.gui.MainMenu;
|
||||
import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
|
||||
|
@ -26,6 +27,7 @@ import org.openstreetmap.josm.plugins.mapwithai.backend.MapWithAIDataUtils;
|
|||
import org.openstreetmap.josm.plugins.mapwithai.backend.MapWithAILayer;
|
||||
import org.openstreetmap.josm.plugins.mapwithai.backend.MapWithAIMoveAction;
|
||||
import org.openstreetmap.josm.plugins.mapwithai.backend.MapWithAIRemoteControl;
|
||||
import org.openstreetmap.josm.plugins.mapwithai.backend.MapWithAIUploadHook;
|
||||
import org.openstreetmap.josm.tools.Destroyable;
|
||||
import org.openstreetmap.josm.tools.Logging;
|
||||
|
||||
|
@ -34,6 +36,8 @@ public final class MapWithAIPlugin extends Plugin implements Destroyable {
|
|||
public static final String NAME = "MapWithAI";
|
||||
private static String versionInfo;
|
||||
|
||||
private final MapWithAIUploadHook uploadHook;
|
||||
|
||||
private final PreferenceSetting preferenceSetting;
|
||||
|
||||
private static final Map<Class<? extends JosmAction>, Boolean> MENU_ENTRIES = new LinkedHashMap<>();
|
||||
|
@ -47,6 +51,7 @@ public final class MapWithAIPlugin extends Plugin implements Destroyable {
|
|||
super(info);
|
||||
|
||||
preferenceSetting = new MapWithAIPreferences();
|
||||
uploadHook = new MapWithAIUploadHook(info);
|
||||
|
||||
final JMenu dataMenu = MainApplication.getMenu().dataMenu;
|
||||
for (final Entry<Class<? extends JosmAction>, Boolean> entry : MENU_ENTRIES.entrySet()) {
|
||||
|
@ -70,6 +75,8 @@ public final class MapWithAIPlugin extends Plugin implements Destroyable {
|
|||
|
||||
MapWithAIDataUtils.addMapWithAIPaintStyles();
|
||||
|
||||
UploadAction.registerUploadHook(uploadHook);
|
||||
|
||||
setVersionInfo(info.localversion);
|
||||
RequestProcessor.addRequestHandlerClass("mapwithai", MapWithAIRemoteControl.class);
|
||||
}
|
||||
|
@ -90,6 +97,11 @@ public final class MapWithAIPlugin extends Plugin implements Destroyable {
|
|||
versionInfo = newVersionInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is so that if JOSM ever decides to support updating plugins without
|
||||
* restarting, I don't have to do anything (hopefully -- I might have to change
|
||||
* the interface and method). Not currently used... (October 16, 2019)
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
final JMenu dataMenu = MainApplication.getMenu().dataMenu;
|
||||
|
@ -101,6 +113,7 @@ public final class MapWithAIPlugin extends Plugin implements Destroyable {
|
|||
dataMenu.remove(action.getValue());
|
||||
}
|
||||
}
|
||||
UploadAction.unregisterUploadHook(uploadHook);
|
||||
|
||||
MainApplication.getLayerManager().getLayersOfType(MapWithAILayer.class).stream()
|
||||
.forEach(layer -> MainApplication.getLayerManager().removeLayer(layer));
|
||||
|
|
|
@ -50,6 +50,7 @@ import org.openstreetmap.josm.tools.Logging;
|
|||
public final class MapWithAIDataUtils {
|
||||
public static final String DEFAULT_MAPWITHAI_API = "https://www.facebook.com/maps/ml_roads?conflate_with_osm=true&theme=ml_road_vector&collaborator=josm&token=ASb3N5o9HbX8QWn8G_NtHIRQaYv3nuG2r7_f3vnGld3KhZNCxg57IsaQyssIaEw5rfRNsPpMwg4TsnrSJtIJms5m&hash=ASawRla3rBcwEjY4HIY&result_type=road_building_vector_xml&bbox={bbox}";
|
||||
public static final int MAXIMUM_SIDE_DIMENSIONS = 1000; // 1 km
|
||||
private static final int DEFAULT_MAXIMUM_ADDITION = 5;
|
||||
|
||||
static final Object LAYER_LOCK = new Object();
|
||||
|
||||
|
@ -293,6 +294,9 @@ public final class MapWithAIDataUtils {
|
|||
urls.add(url);
|
||||
setMapWithAIURLs(urls);
|
||||
}
|
||||
if (DEFAULT_MAPWITHAI_API.equals(url)) {
|
||||
url = "";
|
||||
}
|
||||
Config.getPref().put(MapWithAIPlugin.NAME.concat(".current_api"), url);
|
||||
} else if (layer != null) {
|
||||
layer.setMapWithAIUrl(url);
|
||||
|
@ -345,7 +349,11 @@ public final class MapWithAIDataUtils {
|
|||
public static void setSwitchLayers(boolean selected, boolean permanent) {
|
||||
final MapWithAILayer layer = getLayer(false);
|
||||
if (permanent) {
|
||||
if (!selected) {
|
||||
Config.getPref().putBoolean(MapWithAIPlugin.NAME.concat(".autoswitchlayers"), selected);
|
||||
} else {
|
||||
Config.getPref().put(MapWithAIPlugin.NAME.concat(".autoswitchlayers"), null);
|
||||
}
|
||||
} else if (layer != null) {
|
||||
layer.setSwitchLayers(selected);
|
||||
}
|
||||
|
@ -370,13 +378,18 @@ public final class MapWithAIDataUtils {
|
|||
*/
|
||||
public static int getMaximumAddition() {
|
||||
final MapWithAILayer mapWithAILayer = MapWithAIDataUtils.getLayer(false);
|
||||
Integer defaultReturn = Config.getPref().getInt(MapWithAIPlugin.NAME.concat(".maximumselection"), 5);
|
||||
Integer defaultReturn = Config.getPref().getInt(MapWithAIPlugin.NAME.concat(".maximumselection"),
|
||||
getDefaultMaximumAddition());
|
||||
if (mapWithAILayer != null && mapWithAILayer.getMaximumAddition() != null) {
|
||||
defaultReturn = mapWithAILayer.getMaximumAddition();
|
||||
}
|
||||
return defaultReturn;
|
||||
}
|
||||
|
||||
public static int getDefaultMaximumAddition() {
|
||||
return DEFAULT_MAXIMUM_ADDITION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the maximum number of objects that can be added at one time.
|
||||
*
|
||||
|
@ -388,7 +401,11 @@ public final class MapWithAIDataUtils {
|
|||
public static void setMaximumAddition(int max, boolean permanent) {
|
||||
final MapWithAILayer mapWithAILayer = getLayer(false);
|
||||
if (permanent) {
|
||||
if (getDefaultMaximumAddition() != max) {
|
||||
Config.getPref().putInt(MapWithAIPlugin.NAME.concat(".maximumselection"), max);
|
||||
} else {
|
||||
Config.getPref().put(MapWithAIPlugin.NAME.concat(".maximumselection"), null);
|
||||
}
|
||||
} else if (mapWithAILayer != null) {
|
||||
mapWithAILayer.setMaximumAddition(max);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
// License: GPL. For details, see LICENSE file.
|
||||
package org.openstreetmap.josm.plugins.mapwithai.backend;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.openstreetmap.josm.actions.upload.UploadHook;
|
||||
import org.openstreetmap.josm.data.UndoRedoHandler;
|
||||
import org.openstreetmap.josm.plugins.PluginInformation;
|
||||
import org.openstreetmap.josm.plugins.mapwithai.commands.MapWithAIAddCommand;
|
||||
|
||||
/**
|
||||
* @author Taylor Smock
|
||||
*
|
||||
*/
|
||||
public class MapWithAIUploadHook implements UploadHook {
|
||||
private final String version;
|
||||
|
||||
public MapWithAIUploadHook(PluginInformation info) {
|
||||
version = info.localversion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void modifyChangesetTags(Map<String, String> tags) {
|
||||
final Integer addedObjects = getAddedObjects();
|
||||
if (addedObjects != 0) {
|
||||
tags.put("mapwithai", addedObjects.toString());
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append("version=").append(version);
|
||||
if (MapWithAIDataUtils.getMaximumAddition() != MapWithAIDataUtils.getDefaultMaximumAddition()) {
|
||||
sb.append(";maxadd=").append(MapWithAIDataUtils.getMaximumAddition());
|
||||
}
|
||||
if (!MapWithAIDataUtils.getMapWithAIUrl().equalsIgnoreCase(MapWithAIDataUtils.DEFAULT_MAPWITHAI_API)) {
|
||||
sb.append(";url=").append(MapWithAIDataUtils.getMapWithAIUrl());
|
||||
}
|
||||
if (DetectTaskingManagerUtils.hasTaskingManagerLayer()) {
|
||||
sb.append(";task=").append(DetectTaskingManagerUtils.getTaskingManagerBBox().toStringCSV(","));
|
||||
}
|
||||
tags.put("mapwithai:options", sb.toString());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static int getAddedObjects() {
|
||||
return UndoRedoHandler.getInstance().getUndoCommands().parallelStream()
|
||||
.filter(object -> object instanceof MapWithAIAddCommand).map(object -> (MapWithAIAddCommand) object)
|
||||
.mapToInt(MapWithAIAddCommand::getAddedObjects).sum();
|
||||
}
|
||||
}
|
|
@ -131,4 +131,8 @@ public class MapWithAIAddCommand extends Command implements Runnable {
|
|||
Collection<OsmPrimitive> added) {
|
||||
modified.addAll(primitives);
|
||||
}
|
||||
|
||||
public int getAddedObjects() {
|
||||
return primitives.size();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ public class MapWithAIAvailabilityTest {
|
|||
|
||||
@Rule
|
||||
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
||||
public JOSMTestRules test = new JOSMTestRules();
|
||||
public JOSMTestRules test = new JOSMTestRules().projection();
|
||||
|
||||
@Rule
|
||||
public WireMockRule wireMockRule = new WireMockRule(options().usingFilesUnderDirectory("test/resources/wiremock"));
|
||||
|
|
Ładowanie…
Reference in New Issue