Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow filtering by users (since Mapillary added the data back to the … #230

Merged
merged 3 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 11 additions & 17 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import kotlin.reflect.full.starProjectedType

plugins {
id("application")
id("com.diffplug.spotless") version "6.20.0"
id("com.github.ben-manes.versions") version "0.47.0"
id("com.github.spotbugs") version "5.0.14"
id("com.diffplug.spotless") version "6.25.0"
id("com.github.ben-manes.versions") version "0.51.0"
id("com.github.spotbugs") version "6.0.12"
id("net.ltgt.errorprone") version "3.1.0"
id("org.openstreetmap.josm") version "0.8.2"
id("org.sonarqube") version "4.3.0.3225"
Expand Down Expand Up @@ -56,21 +56,17 @@ java.sourceCompatibility = JavaVersion.VERSION_17
java.targetCompatibility = JavaVersion.VERSION_17

val versions = mapOf(
"awaitility" to "4.2.0",
// Errorprone 2.11 requires Java 11+
"errorprone" to if (JavaVersion.current() >= JavaVersion.VERSION_11) "2.20.0" else "2.10.0",
"awaitility" to "4.2.1",
"errorprone" to "2.26.1",
"jdatepicker" to "1.3.4",
"jmockit" to "1.49",
"junit" to "5.9.3",
"junit" to "5.10.2",
"pmd" to "6.42.0",
"spotbugs" to "4.7.3",
"wiremock" to "2.35.0"
"spotbugs" to "4.8.4",
"wiremock" to "2.35.1"
)

dependencies {
if (!JavaVersion.current().isJava9Compatible) {
errorproneJavac("com.google.errorprone:javac:9+181-r4173-1")
}
errorprone("com.google.errorprone:error_prone_core:${versions["errorprone"]}")
testImplementation ("org.openstreetmap.josm:josm-unittest:SNAPSHOT"){ isChanging = true }
testImplementation("com.github.tomakehurst:wiremock-jre8:${versions["wiremock"]}")
Expand Down Expand Up @@ -255,23 +251,21 @@ project.afterEvaluate {

// Spotbugs config
spotbugs {
toolVersion.set("4.0.6")
ignoreFailures.set(true)
effort.set(Effort.MAX)
reportLevel.set(Confidence.LOW)
reportsDir.set(File(buildDir, "reports/spotbugs"))
reportsDir = file("$buildDir/reports/spotbugs")
}
tasks.withType(SpotBugsTask::class) {
reports.create("html") {
outputLocation.set(File(spotbugs.reportsDir.get().asFile, "$baseName.html"))
setStylesheet("color.xsl")
setStylesheet("fancy-hist.xsl")
}
}


// JaCoCo config
jacoco {
toolVersion = "0.8.10"
toolVersion = "0.8.12"
}

tasks.jacocoTestReport {
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ plugin.icon=images/mapillary-logo.svg
plugin.link=https://wiki.openstreetmap.org/wiki/JOSM/Plugins/Mapillary
# Minimum required JOSM version to run this plugin, choose the lowest version possible that is compatible.
# You can check if the plugin compiles against this version by executing `./gradlew compileJava_minJosm`.
plugin.main.version=18877
plugin.main.version=18940
# Version of JOSM against which the plugin is compiled
# Please check, if the specified version is available for download from https://josm.openstreetmap.de/download/ .
# If not, choose the next higher number that is available, or the gradle build will break.
plugin.compile.version=18877
plugin.compile.version=18940
# The datepicker plugin is currently in the source tree. TODO fix
plugin.requires=apache-commons

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 4 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=03ec176d388f2aa99defcadc3ac6adf8dd2bce5145a129659537c0874dea5ad1
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
distributionSha256Sum=544c35d6bd849ae8a5ed0bcea39ba677dc40f49df7d1835561582da2009b961d
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
24 changes: 16 additions & 8 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,13 +80,10 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -133,22 +130,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -193,6 +197,10 @@ if "$cygwin" || "$msys" ; then
done
fi


# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
Expand Down
1 change: 1 addition & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -17,8 +18,8 @@
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Stream;

import javax.swing.JOptionPane;
Expand All @@ -38,6 +39,8 @@
import org.openstreetmap.josm.gui.Notification;
import org.openstreetmap.josm.gui.util.GuiHelper;
import org.openstreetmap.josm.plugins.mapillary.model.UserProfile;
import org.openstreetmap.josm.plugins.mapillary.oauth.OAuthUtils;
import org.openstreetmap.josm.plugins.mapillary.utils.api.JsonUserProfileDecoder;
import org.openstreetmap.josm.spi.preferences.Config;
import org.openstreetmap.josm.tools.JosmRuntimeException;
import org.openstreetmap.josm.tools.Logging;
Expand Down Expand Up @@ -103,6 +106,16 @@ public final class Caches {
final IElementAttributes fullImageElementCacheAttributes = FULL_IMAGE_CACHE.getDefaultElementAttributes();
fullImageElementCacheAttributes.setMaxLife(maxTime);
FULL_IMAGE_CACHE.setDefaultElementAttributes(fullImageElementCacheAttributes);

USER_PROFILE_CACHE.setDefaultSupplier(url -> {
try {
final var data = OAuthUtils.getWithHeader(URI.create(url));
return JsonUserProfileDecoder.decodeUserProfile(data);
} catch (IOException e) {
Logging.error(e);
return null;
}
});
}

public static File getCacheDirectory() {
Expand Down Expand Up @@ -131,7 +144,7 @@ public static class MapillaryCacheAccess<V> {
@Nonnull
private final List<Predicate<V>> validators;
@Nullable
private Supplier<V> defaultSupplier;
private Function<String, V> defaultSupplier;

private boolean rateLimited;

Expand All @@ -150,7 +163,7 @@ public MapillaryCacheAccess(@Nonnull CacheAccess<String, V> cacheAccess, @Nullab
*
* @param defaultSupplier The default supplier
*/
public void setDefaultSupplier(@Nullable Supplier<V> defaultSupplier) {
public void setDefaultSupplier(@Nullable Function<String, V> defaultSupplier) {
this.defaultSupplier = defaultSupplier;
}

Expand Down Expand Up @@ -185,7 +198,7 @@ public V get(@Nonnull String url) {
if (this.defaultSupplier != null) {
return this.get(url, this.defaultSupplier);
} else {
return this.get(url, () -> null);
return this.get(url, (u) -> null);
}
}

Expand All @@ -202,7 +215,7 @@ public Future<V> get(@Nonnull String url, @Nonnull ForkJoinPool pool) {
if (this.defaultSupplier != null) {
return this.get(url, pool, this.defaultSupplier);
} else {
return this.get(url, pool, () -> null);
return this.get(url, pool, (u) -> null);
}
}

Expand All @@ -214,7 +227,7 @@ public Future<V> get(@Nonnull String url, @Nonnull ForkJoinPool pool) {
* @return The type the supplier returns
*/
@Nullable
public V get(@Nonnull String url, @Nonnull Supplier<V> supplier) {
public V get(@Nonnull String url, @Nonnull Function<String, V> supplier) {
if (this.cacheAccess.get(url) != null) {
return this.cacheAccess.get(url);
}
Expand All @@ -228,7 +241,7 @@ public V get(@Nonnull String url, @Nonnull Supplier<V> supplier) {
}
final V newReturnObject;
synchronized (this) {
newReturnObject = this.cacheAccess.get(url) == null ? supplier.get() : this.cacheAccess.get(url);
newReturnObject = this.cacheAccess.get(url) == null ? supplier.apply(url) : this.cacheAccess.get(url);
if (newReturnObject != null && this.validators.stream().allMatch(p -> p.test(newReturnObject))) {
this.cacheAccess.put(url, newReturnObject);
} else if (newReturnObject != null) {
Expand All @@ -253,7 +266,7 @@ public V get(@Nonnull String url, @Nonnull Supplier<V> supplier) {
* @param supplier The supplier to get the object with
* @return A future with the object, when it completes.
*/
public Future<V> get(@Nonnull String url, @Nonnull ForkJoinPool pool, @Nonnull Supplier<V> supplier) {
public Future<V> get(@Nonnull String url, @Nonnull ForkJoinPool pool, @Nonnull Function<String, V> supplier) {
if (this.cacheAccess.get(url) != null) {
return CompletableFuture.completedFuture(this.cacheAccess.get(url));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public static Map<String, List<MapillaryNode>> downloadImages(final long... imag
}
final Caches.MapillaryCacheAccess<String> metaDataCache = Caches.META_DATA_CACHE;
String url = MapillaryConfig.getUrls().getImageInformation(images);
String stringJson = metaDataCache.get(url, () -> {
final JsonObject jsonObject = getUrlResponse(url);
String stringJson = metaDataCache.get(url, (u) -> {
final JsonObject jsonObject = getUrlResponse(u);
return jsonObject != null ? jsonObject.toString() : null;
});
if (stringJson == null) {
Expand Down Expand Up @@ -118,8 +118,8 @@ public static long[] downloadSequence(@Nonnull String sequence) {
}
}
final String url = MapillaryConfig.getUrls().getImagesBySequences(sequence);
final String response = Caches.META_DATA_CACHE.get(url, () -> {
final JsonObject urlResponse = getUrlResponse(url);
final String response = Caches.META_DATA_CACHE.get(url, (u) -> {
final JsonObject urlResponse = getUrlResponse(u);
return urlResponse == null ? null : urlResponse.toString();
});
if (response != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
package org.openstreetmap.josm.plugins.mapillary.data.mapillary;

import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.Serializable;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
Expand All @@ -16,6 +18,7 @@

import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
import jakarta.json.Json;
import jakarta.json.JsonObject;
import org.openstreetmap.josm.data.imagery.vectortile.mapbox.MVTTile;
import org.openstreetmap.josm.data.osm.INode;
Expand Down Expand Up @@ -63,7 +66,7 @@ public record OrganizationRecord(long id, String name, String niceName, String d
@Nonnull
private static ImageIcon createAvatarIcon(@Nullable String avatar) {
if (avatar != null && !avatar.isEmpty()) {
final BufferedImage avatarImage = Caches.META_IMAGES.get(avatar, () -> fetchAvatarIcon(avatar));
final BufferedImage avatarImage = Caches.META_IMAGES.get(avatar, OrganizationRecord::fetchAvatarIcon);
return avatarImage != null ? new ImageIcon(avatarImage) : ImageProvider.createBlankIcon(ImageSizes.DEFAULT);
}
return ImageProvider.getEmpty(ImageSizes.DEFAULT);
Expand Down Expand Up @@ -106,7 +109,13 @@ public static OrganizationRecord getOrganization(long id) {
* @return The organization
*/
public static OrganizationRecord getOrganization(String id) {
return getOrganization(Long.parseLong(id));
if (id.matches("^\\d+$")) {
return getOrganization(Long.parseLong(id));
} else { // Assume json
try (var reader = Json.createReader(new ByteArrayInputStream(id.getBytes(StandardCharsets.UTF_8)))) {
return getOrganization(Long.parseLong(reader.readObject().getString("id")));
}
}
}

/**
Expand Down
Loading