Changeset 13929 in josm


Ignore:
Timestamp:
2018-06-13T23:37:59+02:00 (5 weeks ago)
Author:
Don-vip
Message:

fix #11000 - add layer_locked, download_policy, upload_policy to download handlers (import, load_data, load_object and load_and_zoom). Bump remote control version to 1.8

Location:
trunk/src/org/openstreetmap/josm
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java

    r13928 r13929  
    267267                layerName = OsmDataLayer.createNewName();
    268268            }
     269            if (settings.getDownloadPolicy() != null) {
     270                dataSet.setDownloadPolicy(settings.getDownloadPolicy());
     271            }
     272            if (settings.getUploadPolicy() != null) {
     273                dataSet.setUploadPolicy(settings.getUploadPolicy());
     274            }
     275            if (dataSet.isLocked() && !settings.isLocked()) {
     276                dataSet.unlock();
     277            } else if (!dataSet.isLocked() && settings.isLocked()) {
     278                dataSet.lock();
     279            }
    269280            return new OsmDataLayer(dataSet, layerName, null);
    270281        }
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/RemoteControl.java

    r13649 r13929  
    4141     */
    4242    static final int protocolMajorVersion = 1;
    43     static final int protocolMinorVersion = 7;
     43    static final int protocolMinorVersion = 8;
    4444
    4545    /**
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/ImportHandler.java

    r13927 r13929  
    6464    @Override
    6565    public String[] getOptionalParams() {
    66         return new String[] {"new_layer", "layer_name"};
     66        return new String[] {"new_layer", "layer_name", "layer_locked", "download_policy", "upload_policy"};
    6767    }
    6868
     
    102102    @Override
    103103    protected void validateRequest() throws RequestHandlerBadRequestException {
     104        validateDownloadParams();
    104105        String urlString = args != null ? args.get("url") : null;
    105106        if (Config.getPref().getBoolean("remotecontrol.importhandler.fix_url_query", true)) {
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/LoadAndZoomHandler.java

    r13927 r13929  
    8383    public String[] getOptionalParams() {
    8484        return new String[] {"new_layer", "layer_name", "addtags", "select", "zoom_mode",
    85                 "changeset_comment", "changeset_source", "changeset_hashtags", "search"};
     85                "changeset_comment", "changeset_source", "changeset_hashtags", "search",
     86                "layer_locked", "download_policy", "upload_policy"};
    8687    }
    8788
     
    261262    @Override
    262263    protected void validateRequest() throws RequestHandlerBadRequestException {
     264        validateDownloadParams();
    263265        // Process mandatory arguments
    264266        minlat = 0;
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/LoadDataHandler.java

    r13927 r13929  
    5151    @Override
    5252    public String[] getOptionalParams() {
    53         return new String[] {"new_layer", "mime_type", "layer_name"};
     53        return new String[] {"new_layer", "mime_type", "layer_name", "layer_locked", "download_policy", "upload_policy"};
    5454    }
    5555
     
    8080    @Override
    8181    protected void validateRequest() throws RequestHandlerBadRequestException {
     82        validateDownloadParams();
    8283        this.data = args.get("data");
    8384        /**
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/LoadObjectHandler.java

    r13927 r13929  
    4141    @Override
    4242    public String[] getOptionalParams() {
    43         return new String[] {"new_layer", "layer_name", "addtags", "relation_members", "referrers"};
     43        return new String[] {"new_layer", "layer_name", "layer_locked", "download_policy", "upload_policy",
     44                "addtags", "relation_members", "referrers"};
    4445    }
    4546
     
    9798    @Override
    9899    protected void validateRequest() throws RequestHandlerBadRequestException {
     100        validateDownloadParams();
    99101        ps.clear();
    100102        for (String i : splitArg("objects", SPLITTER_COMMA)) {
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/RequestHandler.java

    r13927 r13929  
    1414import java.util.Map;
    1515import java.util.Set;
     16import java.util.function.Function;
     17import java.util.function.Supplier;
    1618import java.util.regex.Pattern;
    1719
     
    2123import org.openstreetmap.josm.Main;
    2224import org.openstreetmap.josm.actions.downloadtasks.DownloadParams;
     25import org.openstreetmap.josm.data.osm.DownloadPolicy;
     26import org.openstreetmap.josm.data.osm.UploadPolicy;
    2327import org.openstreetmap.josm.io.remotecontrol.PermissionPrefWithDefault;
    2428import org.openstreetmap.josm.spi.preferences.Config;
     
    299303    }
    300304
     305    private <T> T get(String key, Function<String, T> parser, Supplier<T> defaultSupplier) {
     306        String val = args.get(key);
     307        return val != null && !val.isEmpty() ? parser.apply(val) : defaultSupplier.get();
     308    }
     309
    301310    private boolean isLoadInNewLayer() {
    302         return args.get("new_layer") != null && !args.get("new_layer").isEmpty()
    303                 ? Boolean.parseBoolean(args.get("new_layer"))
    304                 : Config.getPref().getBoolean(loadInNewLayerKey, loadInNewLayerDefault);
     311        return get("new_layer", Boolean::parseBoolean, () -> Config.getPref().getBoolean(loadInNewLayerKey, loadInNewLayerDefault));
     312    }
     313
     314    private boolean is(String key) {
     315        return get(key, Boolean::parseBoolean, () -> false);
    305316    }
    306317
     
    308319        return new DownloadParams()
    309320                .withNewLayer(isLoadInNewLayer())
    310                 .withLayerName(args.get("layer_name"));
     321                .withLayerName(args.get("layer_name"))
     322                .withLocked(is("layer_locked"))
     323                .withDownloadPolicy(get("download_policy", DownloadPolicy::of, () -> DownloadPolicy.NORMAL))
     324                .withUploadPolicy(get("upload_policy", UploadPolicy::of, () -> UploadPolicy.NORMAL));
     325    }
     326
     327    protected void validateDownloadParams() throws RequestHandlerBadRequestException {
     328        try {
     329            getDownloadParams();
     330        } catch (IllegalArgumentException e) {
     331            throw new RequestHandlerBadRequestException(e);
     332        }
    311333    }
    312334
Note: See TracChangeset for help on using the changeset viewer.