From f96693e05a3917ceac4ff9c6b199368bb4ae2132 Mon Sep 17 00:00:00 2001 From: Taylor Smock Date: Tue, 24 Dec 2019 17:14:01 -0700 Subject: [PATCH] Add a cap on the number of objects can be added with MapWithAI before an upload is required (message is shown) Signed-off-by: Taylor Smock --- .../mapwithai/backend/DataAvailability.java | 2 +- .../mapwithai/backend/MapWithAIMoveAction.java | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/DataAvailability.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/DataAvailability.java index 8342278..b1bb322 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/DataAvailability.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/DataAvailability.java @@ -79,7 +79,7 @@ public class DataAvailability { false, entry.getValue().asJsonObject().getJsonArray("parameters").toString()); MapWithAIPreferenceHelper.setMapWithAIUrl(url, false, true); } - Logging.error("{0}: {1}", entry.getKey(), entry.getValue()); + Logging.debug("{0}: {1}", entry.getKey(), entry.getValue()); if (JsonValue.ValueType.OBJECT.equals(entry.getValue().getValueType()) && entry.getValue().asJsonObject().containsKey("countries")) { JsonValue countries = entry.getValue().asJsonObject().get("countries"); diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIMoveAction.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIMoveAction.java index cf03e61..888e77c 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIMoveAction.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIMoveAction.java @@ -32,6 +32,9 @@ public class MapWithAIMoveAction extends JosmAction { private static final long serialVersionUID = 319374598; private transient Notification lastNotification; + /** The maximum number of objects is this times the maximum add */ + public static final int MAX_ADD_MULTIPLIER = 10; + public MapWithAIMoveAction() { super(tr("{0}: Add selected data", MapWithAIPlugin.NAME), "mapwithai", tr("Add data from {0}", MapWithAIPlugin.NAME), obtainShortcut(), true); @@ -71,16 +74,29 @@ public class MapWithAIMoveAction extends JosmAction { } final Collection selected = limitCollection(ds, maxAddition); final OsmDataLayer editLayer = getOsmDataLayer(); - if (editLayer != null && !selected.isEmpty()) { + if (editLayer != null && !selected.isEmpty() + && MapWithAIDataUtils.getAddedObjects() < maxAddition * MAX_ADD_MULTIPLIER) { final MapWithAIAddCommand command = new MapWithAIAddCommand(mapWithAI, editLayer, selected); UndoRedoHandler.getInstance().add(command); if (MapWithAIPreferenceHelper.isSwitchLayers()) { MainApplication.getLayerManager().setActiveLayer(editLayer); } + } else if (MapWithAIDataUtils.getAddedObjects() >= maxAddition * MAX_ADD_MULTIPLIER) { + createTooManyAdditionsNotification(maxAddition); } } } + private void createTooManyAdditionsNotification(int maxAddition) { + Notification tooMany = new Notification(); + tooMany.setIcon(JOptionPane.WARNING_MESSAGE); + tooMany.setDuration(Notification.TIME_DEFAULT); + tooMany.setContent( + tr("There is a soft cap of {0} objects before uploading. Please verify everything before uploading.", + maxAddition * MAX_ADD_MULTIPLIER)); + tooMany.show(); + } + private static Collection limitCollection(DataSet ds, int maxSize) { return (maxSize > 0 || !ExpertToggleAction.isExpert()) ? ds.getSelected().stream().limit(maxSize).collect(Collectors.toList())