Changeset 17655 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/ImageryHandler.java
r16735 r17655 5 5 6 6 import java.util.Arrays; 7 import java.util.LinkedHashSet; 8 import java.util.Map; 9 import java.util.Objects; 10 import java.util.Optional; 11 import java.util.Set; 7 12 8 13 import org.openstreetmap.josm.data.StructUtils; … … 10 15 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryPreferenceEntry; 11 16 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType; 17 import org.openstreetmap.josm.data.imagery.ImageryLayerInfo; 12 18 import org.openstreetmap.josm.gui.MainApplication; 13 19 import org.openstreetmap.josm.gui.layer.ImageryLayer; … … 32 38 public String getPermissionMessage() { 33 39 return tr("Remote Control has been asked to load an imagery layer from the following URL:") 34 + "<br>" + args.get ("url");40 + "<br>" + args.getOrDefault("url", args.get("id")); 35 41 } 36 42 37 43 @Override 38 44 public String[] getMandatoryParams() { 39 return new String[ ]{"url"};45 return new String[0]; 40 46 } 41 47 42 48 @Override 43 49 public String[] getOptionalParams() { 44 return StructUtils.serializeStruct(new ImageryPreferenceEntry(), ImageryPreferenceEntry.class, 45 StructUtils.SerializeOptions.INCLUDE_NULL, StructUtils.SerializeOptions.INCLUDE_DEFAULT 46 ).keySet().toArray(new String[0]); 50 Set<String> params = new LinkedHashSet<>(); 51 params.add("url"); 52 params.add("id"); 53 Map<String, String> struct = StructUtils.serializeStruct(new ImageryPreferenceEntry(), ImageryPreferenceEntry.class, 54 StructUtils.SerializeOptions.INCLUDE_NULL, StructUtils.SerializeOptions.INCLUDE_DEFAULT); 55 params.addAll(struct.keySet()); 56 return params.toArray(new String[0]); 47 57 } 48 58 … … 53 63 54 64 protected ImageryInfo buildImageryInfo() { 65 String id = args.get("id"); 66 if (id != null) { 67 Optional<ImageryInfo> byId = ImageryLayerInfo.instance.getLayers().stream() 68 .filter(l -> Objects.equals(l.getId(), id)) 69 .findFirst(); 70 if (byId.isPresent()) { 71 return byId.get(); 72 } 73 } 55 74 args.computeIfAbsent("type", ignore -> ImageryType.WMS.getDefault().getTypeString()); 56 75 args.computeIfAbsent("name", ignore -> args.getOrDefault("title", tr("Remote imagery"))); … … 83 102 try { 84 103 CheckParameterUtil.ensureParameterNotNull(args); 85 CheckParameterUtil.ensureParameterNotNull(args.get("url")); 104 CheckParameterUtil.ensureThat(args.containsKey("url") || args.containsKey("id"), 105 tr("The following keys are mandatory, but have not been provided: {0}", "url/id")); 86 106 ImageryLayer.create(buildImageryInfo()); 87 107 } catch (IllegalArgumentException e) { … … 100 120 ImageryType::getTypeString)); 101 121 return new String[] { 122 "/imagery?id=Bing", 102 123 "/imagery?title=osm&type=tms&url=https://a.tile.openstreetmap.org/%7Bzoom%7D/%7Bx%7D/%7By%7D.png", 103 124 "/imagery?title=landsat&type=wms&url=http://irs.gis-lab.info/?" + -
trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/ImageryHandlerTest.java
r17275 r17655 53 53 void testBadRequestInvalidUrl() { 54 54 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("invalid_url").handle()); 55 assertEquals("The following keys are mandatory, but have not been provided: url ", e.getMessage());55 assertEquals("The following keys are mandatory, but have not been provided: url/id", e.getMessage()); 56 56 } 57 57 … … 62 62 void testBadRequestIncompleteUrl() { 63 63 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("https://localhost").handle()); 64 assertEquals("The following keys are mandatory, but have not been provided: url ", e.getMessage());64 assertEquals("The following keys are mandatory, but have not been provided: url/id", e.getMessage()); 65 65 } 66 66
Note:
See TracChangeset
for help on using the changeset viewer.