From c59af7b9629fc284b5945d3f2eb8106db66a5ac9 Mon Sep 17 00:00:00 2001 From: Steve Marion Date: Mon, 17 Mar 2025 18:02:52 +0100 Subject: SONAR-24602 Add Telemetry for architecture visualization usage. --- .../org/sonar/db/property/PropertiesDaoIT.java | 41 ++++++++++++++++------ .../java/org/sonar/db/property/PropertiesDao.java | 4 +++ .../org/sonar/db/property/PropertiesMapper.java | 2 ++ .../org/sonar/db/property/PropertiesMapper.xml | 10 ++++++ 4 files changed, 47 insertions(+), 10 deletions(-) diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/property/PropertiesDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/property/PropertiesDaoIT.java index 8cc5c95e032..05283591dbe 100644 --- a/server/sonar-db-dao/src/it/java/org/sonar/db/property/PropertiesDaoIT.java +++ b/server/sonar-db-dao/src/it/java/org/sonar/db/property/PropertiesDaoIT.java @@ -30,6 +30,7 @@ import java.util.Set; import java.util.function.Consumer; import javax.annotation.CheckForNull; import javax.annotation.Nullable; +import org.assertj.core.groups.Tuple; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -125,10 +126,10 @@ class PropertiesDaoIT { // Global + Project subscribers assertThat(underTest.hasProjectNotificationSubscribersForDispatchers(projectUuid, singletonList( "DispatcherWithGlobalAndProjectSubscribers"))) - .isTrue(); + .isTrue(); assertThat(underTest.hasProjectNotificationSubscribersForDispatchers("PROJECT_B", singletonList( "DispatcherWithGlobalAndProjectSubscribers"))) - .isTrue(); + .isTrue(); } @Test @@ -536,7 +537,7 @@ class PropertiesDaoIT { } private static Object[][] allValuesForSelect() { - return new Object[][] { + return new Object[][]{ {null, ""}, {"", ""}, {"some value", "some value"}, @@ -560,6 +561,26 @@ class PropertiesDaoIT { .contains(property); } + @Test + void selectUserProperty() { + final String propertyKey = "user.property.one"; + + UserDto userDto1 = db.users().insertUser(); + UserDto userDto2 = db.users().insertUser(); + + insertProperty(propertyKey, "one", null, userDto1.getUuid(), null, null, null); + insertProperty(propertyKey, "two", null, userDto2.getUuid(), null, null, null); + + List property = underTest.selectUserPropertiesByKey(db.getSession(), propertyKey); + + assertThat(property) + .extracting(PropertyDto::getKey, PropertyDto::getEntityUuid, PropertyDto::getUserUuid, PropertyDto::getValue) + .containsExactlyInAnyOrderElementsOf(Set.of( + Tuple.tuple(propertyKey, null, userDto1.getUuid(), "one"), + Tuple.tuple(propertyKey, null, userDto2.getUuid(), "two") + )); + } + @Test void select_by_query() { // global @@ -641,10 +662,10 @@ class PropertiesDaoIT { tuple(key, project2.getUuid())); assertThat(underTest.selectPropertiesByKeysAndEntityUuids(session, newHashSet(key, anotherKey), newHashSet(project.getUuid(), project2.getUuid()))) - .extracting(PropertyDto::getKey, PropertyDto::getEntityUuid).containsOnly( - tuple(key, project.getUuid()), - tuple(key, project2.getUuid()), - tuple(anotherKey, project2.getUuid())); + .extracting(PropertyDto::getKey, PropertyDto::getEntityUuid).containsOnly( + tuple(key, project.getUuid()), + tuple(key, project2.getUuid()), + tuple(anotherKey, project2.getUuid())); assertThat(underTest.selectPropertiesByKeysAndEntityUuids(session, newHashSet("unknown"), newHashSet(project.getUuid()))).isEmpty(); assertThat(underTest.selectPropertiesByKeysAndEntityUuids(session, newHashSet("key"), newHashSet("uuid123456789"))).isEmpty(); @@ -849,7 +870,7 @@ class PropertiesDaoIT { } static Object[][] valueUpdatesDataProvider() { - return new Object[][] { + return new Object[][]{ {null, null}, {null, ""}, {null, "some value"}, @@ -934,8 +955,8 @@ class PropertiesDaoIT { assertThat(db.select("select prop_key as \"key\", text_value as \"value\", entity_uuid as \"projectUuid\", user_uuid as \"userUuid\" " + "from properties")) - .extracting((row) -> row.get("key"), (row) -> row.get("value"), (row) -> row.get("projectUuid"), (row) -> row.get("userUuid")) - .containsOnly(tuple("KEY", "ANOTHER_VALUE", null, null), tuple("ANOTHER_KEY", "VALUE", project.uuid(), "100")); + .extracting((row) -> row.get("key"), (row) -> row.get("value"), (row) -> row.get("projectUuid"), (row) -> row.get("userUuid")) + .containsOnly(tuple("KEY", "ANOTHER_VALUE", null, null), tuple("ANOTHER_KEY", "VALUE", project.uuid(), "100")); } private static Map mapOf(String... values) { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java index 97d5ee872e4..824ea54b14e 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java @@ -179,6 +179,10 @@ public class PropertiesDao implements Dao { return getMapper(session).selectProjectPropertyByKey(key); } + public List selectUserPropertiesByKey(DbSession session, String key) { + return getMapper(session).selectUserPropertiesByKey(key); + } + /** * Saves the specified property and its value. *

diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesMapper.java index c1685ad9a59..8fb96f382a2 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesMapper.java @@ -42,6 +42,8 @@ public interface PropertiesMapper { List selectProjectPropertyByKey(@Param("key") String key); + List selectUserPropertiesByKey(@Param("key") String key); + List selectByEntityUuids(@Param("entityUuids") List entityUuids); List selectByQuery(@Param("query") PropertyQuery query); diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/property/PropertiesMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/property/PropertiesMapper.xml index b186e885986..a6c5ca9e2e0 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/property/PropertiesMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/property/PropertiesMapper.xml @@ -163,6 +163,16 @@ and p.user_uuid is null + +