Changeset 36122 in osm for applications/editors/josm/plugins/MicrosoftStreetside
- Timestamp:
- 2023-08-22T17:40:36+02:00 (18 months ago)
- Location:
- applications/editors/josm/plugins/MicrosoftStreetside
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/MicrosoftStreetside/gradle.properties
r36034 r36122 8 8 # Minimum required JOSM version to run this plugin, choose the lowest version possible that is compatible. 9 9 # You can check if the plugin compiles against this version by executing `./gradlew compileJava_minJosm`. 10 plugin.main.version=18 49410 plugin.main.version=18723 11 11 #plugin.version= 12 12 # Version of JOSM against which the plugin is compiled 13 13 # Please check, if the specified version is available for download from https://josm.openstreetmap.de/download/ . 14 14 # If not, choose the next higher number that is available, or the gradle build will break. 15 plugin.compile.version=18 49415 plugin.compile.version=18724 16 16 plugin.requires=apache-commons;apache-http;jackson;javafx;log4j;utilsplugin2 17 17 -
applications/editors/josm/plugins/MicrosoftStreetside/src/org/openstreetmap/josm/plugins/streetside/oauth/OAuthUtils.java
r34317 r36122 8 8 import java.net.URL; 9 9 10 import ja vax.json.Json;11 import ja vax.json.JsonException;12 import ja vax.json.JsonObject;13 import ja vax.json.JsonReader;10 import jakarta.json.Json; 11 import jakarta.json.JsonException; 12 import jakarta.json.JsonObject; 13 import jakarta.json.JsonReader; 14 14 15 15 import org.openstreetmap.josm.plugins.streetside.utils.StreetsideProperties; -
applications/editors/josm/plugins/MicrosoftStreetside/src/org/openstreetmap/josm/plugins/streetside/utils/api/JsonDecoder.java
r34428 r36122 9 9 import java.util.function.Function; 10 10 11 import ja vax.json.JsonArray;12 import ja vax.json.JsonNumber;13 import ja vax.json.JsonObject;14 import ja vax.json.JsonValue;11 import jakarta.json.JsonArray; 12 import jakarta.json.JsonNumber; 13 import jakarta.json.JsonObject; 14 import jakarta.json.JsonValue; 15 15 16 import org.apache.log4j.Logger;17 16 import org.openstreetmap.josm.data.coor.LatLon; 18 17 import org.openstreetmap.josm.tools.I18n; 18 import org.openstreetmap.josm.tools.Logging; 19 19 20 20 public final class JsonDecoder { 21 22 final static Logger logger = Logger.getLogger(JsonDecoder.class); 21 private static final double[] EMPTY_DOUBLE = new double[0]; 23 22 24 23 private JsonDecoder() { … … 65 64 static LatLon decodeLatLon(final JsonArray json) { 66 65 final double[] result = decodeDoublePair(json); 67 if (result != null) {66 if (result.length == 2) { 68 67 return new LatLon(result[1], result[0]); 69 68 } … … 77 76 * if the parameter was not a {@link JsonArray} of exactly size 2 containing two {@link JsonNumber}s 78 77 */ 79 @SuppressWarnings("PMD.ReturnEmptyArrayRatherThanNull")80 78 static double[] decodeDoublePair(final JsonArray json) { 81 79 if ( … … 87 85 return new double[]{json.getJsonNumber(0).doubleValue(), json.getJsonNumber(1).doubleValue()}; 88 86 } 89 return null;87 return EMPTY_DOUBLE; 90 88 } 91 89 … … 96 94 * @return the point in time as a {@link Long} value representing the UNIX epoch time, or <code>null</code> if the 97 95 * parameter does not match the required format (this also triggers a warning via 98 * {@link Logg er}, or the parameter is <code>null</code>).96 * {@link Logging}, or the parameter is <code>null</code>). 99 97 */ 100 98 static Long decodeTimestamp(final String timestamp) { … … 104 102 } catch (ParseException e) { 105 103 StackTraceElement calledBy = e.getStackTrace()[Math.min(e.getStackTrace().length - 1, 2)]; 106 logger.warn(I18n.tr(String.format(104 Logging.warn(I18n.tr(String.format( 107 105 "Could not decode time from the timestamp `%s` (called by %s.%s:%d)", 108 106 timestamp, calledBy.getClassName(), calledBy.getMethodName(), calledBy.getLineNumber() -
applications/editors/josm/plugins/MicrosoftStreetside/src/org/openstreetmap/josm/plugins/streetside/utils/api/JsonImageDetectionDecoder.java
r34399 r36122 5 5 import java.awt.geom.Path2D; 6 6 7 import ja vax.json.JsonArray;8 import ja vax.json.JsonNumber;9 import ja vax.json.JsonObject;10 import ja vax.json.JsonValue;7 import jakarta.json.JsonArray; 8 import jakarta.json.JsonNumber; 9 import jakarta.json.JsonObject; 10 import jakarta.json.JsonValue; 11 11 12 import org.apache.log4j.Logger;13 12 import org.openstreetmap.josm.plugins.streetside.model.ImageDetection; 14 13 import org.openstreetmap.josm.plugins.streetside.utils.StreetsideURL.APIv3; 14 import org.openstreetmap.josm.tools.Logging; 15 15 16 16 /** … … 19 19 */ 20 20 public final class JsonImageDetectionDecoder { 21 22 final static Logger logger = Logger.getLogger(JsonImageDetectionDecoder.class);23 21 24 22 private JsonImageDetectionDecoder() { … … 50 48 if (json instanceof JsonObject) { 51 49 if (!"Polygon".equals(((JsonObject) json).getString("type", null))) { 52 logger.warn(50 Logging.warn( 53 51 String.format("Image detections using shapes with type=%s are currently not supported!", 54 52 ((JsonObject) json).getString("type", "‹no type set›")) … … 93 91 json.forEach(val -> { 94 92 double[] coord = JsonDecoder.decodeDoublePair(val instanceof JsonArray ? (JsonArray) val : null); 95 if (shape.getCurrentPoint() == null && coord != null) {93 if (shape.getCurrentPoint() == null && coord.length == 2) { 96 94 shape.moveTo(coord[0], coord[1]); 97 } else if (coord != null) { 95 } else if (coord != null && coord.length == 2) { 98 96 shape.lineTo(coord[0], coord[1]); 99 97 } -
applications/editors/josm/plugins/MicrosoftStreetside/src/org/openstreetmap/josm/plugins/streetside/utils/api/JsonSequencesDecoder.java
r34325 r36122 5 5 import java.util.function.Function; 6 6 7 import ja vax.json.JsonArray;8 import ja vax.json.JsonNumber;9 import ja vax.json.JsonObject;10 import ja vax.json.JsonString;11 import ja vax.json.JsonValue;7 import jakarta.json.JsonArray; 8 import jakarta.json.JsonNumber; 9 import jakarta.json.JsonObject; 10 import jakarta.json.JsonString; 11 import jakarta.json.JsonValue; 12 12 13 13 import org.openstreetmap.josm.data.coor.LatLon; -
applications/editors/josm/plugins/MicrosoftStreetside/src/org/openstreetmap/josm/plugins/streetside/utils/api/JsonStreetsideDecoder.java
r34428 r36122 2 2 package org.openstreetmap.josm.plugins.streetside.utils.api; 3 3 4 import java.text.ParseException;5 import java.text.SimpleDateFormat;6 4 import java.util.Collection; 7 5 import java.util.HashSet; 8 import java.util.Locale;9 6 import java.util.function.Function; 10 7 11 import javax.json.JsonArray; 12 import javax.json.JsonNumber; 13 import javax.json.JsonObject; 14 import javax.json.JsonValue; 8 import org.openstreetmap.josm.data.coor.LatLon; 9 import org.openstreetmap.josm.tools.Logging; 15 10 16 import org.apache.log4j.Logger;17 import org.openstreetmap.josm.data.coor.LatLon;18 import org.openstreetmap.josm.tools.I18n;11 import jakarta.json.JsonArray; 12 import jakarta.json.JsonNumber; 13 import jakarta.json.JsonObject; 19 14 20 15 public final class JsonStreetsideDecoder { 21 22 final static Logger logger = Logger.getLogger(JsonStreetsideDecoder.class);23 16 24 17 private JsonStreetsideDecoder() { … … 38 31 */ 39 32 public static <T> Collection<T> decodeFeatureCollection(final JsonObject json, Function<JsonObject, T> featureDecoder) { 40 final Collection<T> result = new HashSet<>(); 41 if ( 42 json != null && "FeatureCollection".equals(json.getString("type", null)) && json.containsKey("features") 43 ) { 44 final JsonValue features = json.get("features"); 45 for (int i = 0; features instanceof JsonArray && i < ((JsonArray) features).size(); i++) { 46 final JsonValue val = ((JsonArray) features).get(i); 47 if (val instanceof JsonObject) { 48 final T feature = featureDecoder.apply((JsonObject) val); 49 if (feature != null) { 50 result.add(feature); 51 } 52 } 53 } 54 } 55 return result; 33 return JsonDecoder.decodeFeatureCollection(json, featureDecoder); 56 34 } 57 35 … … 64 42 */ 65 43 static LatLon decodeLatLon(final JsonArray json) { 66 final double[] result = decodeDoublePair(json); 67 if (result != null) { 68 return new LatLon(result[1], result[0]); 69 } 70 return null; 71 } 72 73 /** 74 * Decodes a pair of double values, which are stored in a {@link JsonArray} of exactly size 2. 75 * @param json the {@link JsonArray} containing the two values 76 * @return a double array which contains the two values in the same order, or <code>null</code> 77 * if the parameter was not a {@link JsonArray} of exactly size 2 containing two {@link JsonNumber}s 78 */ 79 @SuppressWarnings("PMD.ReturnEmptyArrayRatherThanNull") 80 static double[] decodeDoublePair(final JsonArray json) { 81 if ( 82 json != null && 83 json.size() == 2 && 84 json.get(0) instanceof JsonNumber && 85 json.get(1) instanceof JsonNumber 86 ) { 87 return new double[]{json.getJsonNumber(0).doubleValue(), json.getJsonNumber(1).doubleValue()}; 88 } 89 return null; 44 return JsonDecoder.decodeLatLon(json); 90 45 } 91 46 … … 96 51 * @return the point in time as a {@link Long} value representing the UNIX epoch time, or <code>null</code> if the 97 52 * parameter does not match the required format (this also triggers a warning via 98 * {@link Logg er}, or the parameter is <code>null</code>).53 * {@link Logging}, or the parameter is <code>null</code>). 99 54 */ 100 55 static Long decodeTimestamp(final String timestamp) { 101 if (timestamp != null) { 102 try { 103 return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX", Locale.UK).parse(timestamp).getTime(); 104 } catch (ParseException e) { 105 StackTraceElement calledBy = e.getStackTrace()[Math.min(e.getStackTrace().length - 1, 2)]; 106 logger.warn(I18n.tr(String.format( 107 "Could not decode time from the timestamp `%s` (called by %s.%s:%d)", 108 timestamp, calledBy.getClassName(), calledBy.getMethodName(), calledBy.getLineNumber() 109 ), e)); 110 } 111 } 112 return null; 56 return JsonDecoder.decodeTimestamp(timestamp); 113 57 } 114 58 } -
applications/editors/josm/plugins/MicrosoftStreetside/src/org/openstreetmap/josm/plugins/streetside/utils/api/JsonStreetsideSequencesDecoder.java
r34429 r36122 5 5 import java.util.function.Function; 6 6 7 import ja vax.json.JsonArray;8 import ja vax.json.JsonNumber;9 import ja vax.json.JsonObject;10 import ja vax.json.JsonString;11 import ja vax.json.JsonValue;7 import jakarta.json.JsonArray; 8 import jakarta.json.JsonNumber; 9 import jakarta.json.JsonObject; 10 import jakarta.json.JsonString; 11 import jakarta.json.JsonValue; 12 12 13 13 import org.openstreetmap.josm.data.coor.LatLon; … … 113 113 114 114 if (json.getString("id", null) != null && json.getString("la", null) != null && json.getString("lo", null) != null) { 115 result = new StreetsideSequence(json.getString("id", null), json.getJsonNumber("la").doubleValue(), json.getJsonNumber("lo").doubleValue(), json.getJsonNumber("cd").longValue()); 115 result = new StreetsideSequence(json.getString("id", null), 116 json.getJsonNumber("la").doubleValue(), json.getJsonNumber("lo").doubleValue(), json.getJsonNumber("cd").longValue()); 116 117 } 117 118 -
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/utils/JsonUtil.java
r34386 r36122 5 5 import java.nio.charset.StandardCharsets; 6 6 7 import ja vax.json.Json;8 import ja vax.json.JsonObject;7 import jakarta.json.Json; 8 import jakarta.json.JsonObject; 9 9 10 10 public final class JsonUtil { -
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/utils/api/JsonDecoderTest.java
r36064 r36122 3 3 4 4 5 import static org.junit.jupiter.api.Assertions.assertArrayEquals; 5 6 import static org.junit.jupiter.api.Assertions.assertNull; 6 7 … … 9 10 import java.util.function.Function; 10 11 11 import ja vax.json.Json;12 import ja vax.json.JsonObject;12 import jakarta.json.Json; 13 import jakarta.json.JsonObject; 13 14 14 15 import org.junit.jupiter.api.Test; … … 24 25 @Test 25 26 void testDecodeDoublePair() { 26 assert Null(JsonDecoder.decodeDoublePair(null));27 assertArrayEquals(new double[0], JsonDecoder.decodeDoublePair(null)); 27 28 } 28 29 -
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/utils/api/JsonSequencesDecoderTest.java
r36064 r36122 13 13 import java.util.function.Function; 14 14 15 import ja vax.json.Json;16 import ja vax.json.JsonArray;17 import ja vax.json.JsonObject;18 import ja vax.json.JsonValue;15 import jakarta.json.Json; 16 import jakarta.json.JsonArray; 17 import jakarta.json.JsonObject; 18 import jakarta.json.JsonValue; 19 19 20 20 import org.junit.jupiter.api.Assertions;
Note:
See TracChangeset
for help on using the changeset viewer.