aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2015-06-09 11:11:05 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2015-06-10 11:26:30 +0200
commit9a2b65ef12ccccda5d4d0bfdd0afad6538252fdc (patch)
treec94a032b7a7063bb96867281c1444fde51684bf7 /sonar-core
parente326e4e042accf475341aec6a6cb6d4576d07f85 (diff)
downloadsonarqube-9a2b65ef12ccccda5d4d0bfdd0afad6538252fdc.tar.gz
sonarqube-9a2b65ef12ccccda5d4d0bfdd0afad6538252fdc.zip
SONAR-6567 send notifications on QGate failures
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/properties/PropertiesDao.java8
-rw-r--r--sonar-core/src/main/java/org/sonar/core/properties/PropertiesMapper.java2
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/properties/PropertiesMapper.xml10
-rw-r--r--sonar-core/src/test/java/org/sonar/core/properties/PropertiesDaoTest.java8
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/shouldFindUsersForNotification.xml3
5 files changed, 17 insertions, 14 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/properties/PropertiesDao.java b/sonar-core/src/main/java/org/sonar/core/properties/PropertiesDao.java
index 4f37b6405d7..91c34a12741 100644
--- a/sonar-core/src/main/java/org/sonar/core/properties/PropertiesDao.java
+++ b/sonar-core/src/main/java/org/sonar/core/properties/PropertiesDao.java
@@ -58,16 +58,14 @@ public class PropertiesDao implements DaoComponent {
* Returns the logins of users who have subscribed to the given notification dispatcher with the given notification channel.
* If a resource ID is passed, the search is made on users who have specifically subscribed for the given resource.
*
- * @param notificationDispatcherKey the key of the notification dispatcher
- * @param notificationChannelKey the key of the notification channel
- * @param resourceId the resource id
* @return the list of logins (maybe be empty - obviously)
*/
- public List<String> findUsersForNotification(String notificationDispatcherKey, String notificationChannelKey, @Nullable Long resourceId) {
+ public List<String> findUsersForNotification(String notificationDispatcherKey, String notificationChannelKey,
+ @Nullable String projectUuid) {
SqlSession session = mybatis.openSession(false);
PropertiesMapper mapper = session.getMapper(PropertiesMapper.class);
try {
- return mapper.findUsersForNotification(NOTIFICATION_PREFIX + notificationDispatcherKey + "." + notificationChannelKey, resourceId);
+ return mapper.findUsersForNotification(NOTIFICATION_PREFIX + notificationDispatcherKey + "." + notificationChannelKey, projectUuid);
} finally {
MyBatis.closeQuietly(session);
}
diff --git a/sonar-core/src/main/java/org/sonar/core/properties/PropertiesMapper.java b/sonar-core/src/main/java/org/sonar/core/properties/PropertiesMapper.java
index b2368e69f98..9b75aa5d6a6 100644
--- a/sonar-core/src/main/java/org/sonar/core/properties/PropertiesMapper.java
+++ b/sonar-core/src/main/java/org/sonar/core/properties/PropertiesMapper.java
@@ -28,7 +28,7 @@ import java.util.List;
public interface PropertiesMapper {
- List<String> findUsersForNotification(@Param("notifKey") String notificationKey, @Nullable @Param("rId") Long resourceId);
+ List<String> findUsersForNotification(@Param("notifKey") String notificationKey, @Nullable @Param("projectUuid") String projectUuid);
List<String> findNotificationSubscribers(@Param("propKey") String propertyKey, @Nullable @Param("componentKey") String componentKey);
diff --git a/sonar-core/src/main/resources/org/sonar/core/properties/PropertiesMapper.xml b/sonar-core/src/main/resources/org/sonar/core/properties/PropertiesMapper.xml
index fb4e703d33e..1a15db272d4 100644
--- a/sonar-core/src/main/resources/org/sonar/core/properties/PropertiesMapper.xml
+++ b/sonar-core/src/main/resources/org/sonar/core/properties/PropertiesMapper.xml
@@ -6,12 +6,14 @@
<select id="findUsersForNotification" parameterType="map" resultType="String">
SELECT U.login
FROM properties P, users U
- WHERE P.user_id = U.id AND P.prop_key = #{notifKey} AND P.text_value LIKE 'true'
- <if test="rId == null">
+ <if test="projectUuid == null">
+ WHERE P.user_id = U.id AND P.prop_key = #{notifKey} AND P.text_value LIKE 'true'
AND P.resource_id is null
</if>
- <if test="rId != null">
- AND P.resource_id = #{rId}
+ <if test="projectUuid != null">
+ inner join projects c on c.id=P.resource_id
+ WHERE P.user_id = U.id AND P.prop_key = #{notifKey} AND P.text_value LIKE 'true'
+ AND c.uuid = #{projectUuid}
</if>
</select>
diff --git a/sonar-core/src/test/java/org/sonar/core/properties/PropertiesDaoTest.java b/sonar-core/src/test/java/org/sonar/core/properties/PropertiesDaoTest.java
index 7095646484d..15182fc4719 100644
--- a/sonar-core/src/test/java/org/sonar/core/properties/PropertiesDaoTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/properties/PropertiesDaoTest.java
@@ -62,10 +62,10 @@ public class PropertiesDaoTest extends AbstractDaoTestCase {
List<String> users = dao.findUsersForNotification("NewViolations", "Email", null);
assertThat(users).isEmpty();
- users = dao.findUsersForNotification("NewViolations", "Email", 78L);
+ users = dao.findUsersForNotification("NewViolations", "Email", "uuid_78");
assertThat(users).isEmpty();
- users = dao.findUsersForNotification("NewViolations", "Email", 45L);
+ users = dao.findUsersForNotification("NewViolations", "Email", "uuid_45");
assertThat(users).hasSize(1);
assertThat(users).containsOnly("user2");
@@ -73,10 +73,10 @@ public class PropertiesDaoTest extends AbstractDaoTestCase {
assertThat(users).hasSize(1);
assertThat(users).containsOnly("user3");
- users = dao.findUsersForNotification("NewViolations", "Twitter", 78L);
+ users = dao.findUsersForNotification("NewViolations", "Twitter", "uuid_78");
assertThat(users).isEmpty();
- users = dao.findUsersForNotification("NewViolations", "Twitter", 56L);
+ users = dao.findUsersForNotification("NewViolations", "Twitter", "uuid_56");
assertThat(users).hasSize(2);
assertThat(users).containsOnly("user1", "user3");
}
diff --git a/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/shouldFindUsersForNotification.xml b/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/shouldFindUsersForNotification.xml
index e941d29dfca..18c4d691284 100644
--- a/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/shouldFindUsersForNotification.xml
+++ b/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/shouldFindUsersForNotification.xml
@@ -1,5 +1,8 @@
<dataset>
+ <projects id="45" uuid="uuid_45"/>
+ <projects id="56" uuid="uuid_56"/>
+
<properties
id="1"
prop_key="notification.NewViolations.Email"