aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Marion <steve.marion@sonarsource.com>2025-03-17 18:02:52 +0100
committersonartech <sonartech@sonarsource.com>2025-03-18 20:04:07 +0000
commitc59af7b9629fc284b5945d3f2eb8106db66a5ac9 (patch)
treeb4307b31f942ec9225eb2c8539559b5027c803a1
parent5f27a59fa2d104ef3712fa72c65eca049ad54c8c (diff)
downloadsonarqube-c59af7b9629fc284b5945d3f2eb8106db66a5ac9.tar.gz
sonarqube-c59af7b9629fc284b5945d3f2eb8106db66a5ac9.zip
SONAR-24602 Add Telemetry for architecture visualization usage.
-rw-r--r--server/sonar-db-dao/src/it/java/org/sonar/db/property/PropertiesDaoIT.java41
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java4
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesMapper.java2
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/property/PropertiesMapper.xml10
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"},
@@ -561,6 +562,26 @@ class PropertiesDaoIT {
}
@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<PropertyDto> 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
insertProperty("global.one", "one", null, null, null, null, null);
@@ -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<String, String> 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<PropertyDto> selectUserPropertiesByKey(DbSession session, String key) {
+ return getMapper(session).selectUserPropertiesByKey(key);
+ }
+
/**
* Saves the specified property and its value.
* <p>
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<PropertyDto> selectProjectPropertyByKey(@Param("key") String key);
+ List<PropertyDto> selectUserPropertiesByKey(@Param("key") String key);
+
List<PropertyDto> selectByEntityUuids(@Param("entityUuids") List<String> entityUuids);
List<PropertyDto> 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
</select>
+ <select id="selectUserPropertiesByKey" parameterType="map" resultType="ScrapProperty">
+ select
+ <include refid="columnsToScrapPropertyDto"/>
+ from properties p
+ inner join users u on u.uuid=p.user_uuid
+ where
+ p.prop_key = #{key, jdbcType=VARCHAR}
+ and p.entity_uuid is null
+ </select>
+
<select id="selectByQuery" parameterType="map" resultType="ScrapProperty">
select
<include refid="columnsToScrapPropertyDto"/>