summaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2019-03-13 09:11:58 +0100
committerSonarTech <sonartech@sonarsource.com>2019-03-18 20:20:59 +0100
commit3ed96a6b902132626d4f6f4a76139613d7cbb81d (patch)
tree03a52f112331996709691f12d9f2b8aaafe838a2 /server/sonar-db-dao
parentc5ad29eb81b2d31916ba89188d6e4deed29c46a8 (diff)
downloadsonarqube-3ed96a6b902132626d4f6f4a76139613d7cbb81d.tar.gz
sonarqube-3ed96a6b902132626d4f6f4a76139613d7cbb81d.zip
SONAR-10277 Prevent user to have more than 100 projects as favorite
Diffstat (limited to 'server/sonar-db-dao')
-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.xml11
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java35
4 files changed, 46 insertions, 6 deletions
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 04ac22cb459..619e45f2931 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
@@ -160,6 +160,10 @@ public class PropertiesDao implements Dao {
return getMapper(session).selectByKeyAndMatchingValue(key, value);
}
+ public List<PropertyDto> selectByKeyAndUserIdAndComponentQualifier(DbSession session, String key, int userId, String qualifier) {
+ return getMapper(session).selectByKeyAndUserIdAndComponentQualifier(key, userId, qualifier);
+ }
+
/**
* 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 7221069be0e..1dd88c185cc 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
@@ -38,6 +38,8 @@ public interface PropertiesMapper {
List<PropertyDto> selectByKeysAndComponentIds(@Param("keys") List<String> keys, @Param("componentIds") List<Long> componentIds);
+ List<PropertyDto> selectByKeyAndUserIdAndComponentQualifier(@Param("key") String key, @Param("userId") int userId, @Param("qualifier") String qualifier);
+
List<PropertyDto> selectByComponentIds(@Param("componentIds") List<Long> componentIds);
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 f1d4344765e..06fc8ddd4b1 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
@@ -128,6 +128,17 @@
and p.user_id is null
</select>
+ <select id="selectByKeyAndUserIdAndComponentQualifier" parameterType="map" resultType="ScrapProperty">
+ select
+ <include refid="columnsToScrapPropertyDto"/>
+ from
+ properties p
+ inner join projects prj on prj.id=p.resource_id and prj.qualifier = #{qualifier, jdbcType=VARCHAR}
+ where
+ p.prop_key = #{key, jdbcType=VARCHAR}
+ and p.user_id = #{userId, jdbcType=INTEGER}
+ </select>
+
<select id="selectByQuery" parameterType="map" resultType="ScrapProperty">
select
<include refid="columnsToScrapPropertyDto"/>
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java
index 0f508819563..ec70637034e 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java
@@ -40,6 +40,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.user.UserDto;
@@ -52,6 +53,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.sonar.db.property.PropertyTesting.newComponentPropertyDto;
import static org.sonar.db.property.PropertyTesting.newGlobalPropertyDto;
+import static org.sonar.db.property.PropertyTesting.newPropertyDto;
import static org.sonar.db.property.PropertyTesting.newUserPropertyDto;
@RunWith(DataProviderRunner.class)
@@ -401,12 +403,33 @@ public class PropertiesDaoTest {
newComponentPropertyDto("another key", "value", project1));
assertThat(underTest.selectByKeyAndMatchingValue(db.getSession(), "key", "value"))
- .extracting(PropertyDto::getValue, PropertyDto::getResourceId)
- .containsExactlyInAnyOrder(
- tuple("value", project1.getId()),
- tuple("value", project2.getId()),
- tuple("value", null)
- );
+ .extracting(PropertyDto::getValue, PropertyDto::getResourceId)
+ .containsExactlyInAnyOrder(
+ tuple("value", project1.getId()),
+ tuple("value", project2.getId()),
+ tuple("value", null));
+ }
+
+ @Test
+ public void selectByKeyAndUserIdAndComponentQualifier() {
+ UserDto user1 = db.users().insertUser();
+ UserDto user2 = db.users().insertUser();
+ ComponentDto project1 = db.components().insertPrivateProject();
+ ComponentDto file1 = db.components().insertComponent(ComponentTesting.newFileDto(project1));
+ ComponentDto project2 = db.components().insertPrivateProject();
+ db.properties().insertProperties(
+ newPropertyDto("key", "1", project1, user1),
+ newPropertyDto("key", "2", project2, user1),
+ newPropertyDto("key", "3", file1, user1),
+ newPropertyDto("another key", "4", project1, user1),
+ newPropertyDto("key", "5", project1, user2),
+ newGlobalPropertyDto("key", "global"));
+
+ assertThat(underTest.selectByKeyAndUserIdAndComponentQualifier(db.getSession(), "key", user1.getId(), "TRK"))
+ .extracting(PropertyDto::getValue).containsExactlyInAnyOrder("1", "2");
+ assertThat(underTest.selectByKeyAndUserIdAndComponentQualifier(db.getSession(), "key", user1.getId(), "FIL"))
+ .extracting(PropertyDto::getValue).containsExactlyInAnyOrder("3");
+ assertThat(underTest.selectByKeyAndUserIdAndComponentQualifier(db.getSession(), "key", user2.getId(), "FIL")).isEmpty();
}
@Test