diff options
author | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-07-28 05:33:33 +0400 |
---|---|---|
committer | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-07-28 11:17:54 +0400 |
commit | b56b994e0e67043be18cf5803474ed01ffed100f (patch) | |
tree | 43fdc8cf8f3517c9262b54098b84ac2f8fbbb4bb /sonar-core/src | |
parent | b0e768ada85207c3ac6424b069e0dbc4e162c9db (diff) | |
download | sonarqube-b56b994e0e67043be18cf5803474ed01ffed100f.tar.gz sonarqube-b56b994e0e67043be18cf5803474ed01ffed100f.zip |
SONAR-2596 Reduce number of arguments for NotificationService constructor
Diffstat (limited to 'sonar-core/src')
3 files changed, 28 insertions, 3 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/notifications/DefaultNotificationManager.java b/sonar-core/src/main/java/org/sonar/core/notifications/DefaultNotificationManager.java index 4f8b604726a..f9e2107743f 100644 --- a/sonar-core/src/main/java/org/sonar/core/notifications/DefaultNotificationManager.java +++ b/sonar-core/src/main/java/org/sonar/core/notifications/DefaultNotificationManager.java @@ -19,15 +19,17 @@ */ package org.sonar.core.notifications; +import java.util.Date; +import java.util.List; + import org.sonar.api.database.DatabaseSession; +import org.sonar.api.database.configuration.Property; +import org.sonar.api.database.model.User; import org.sonar.api.notifications.Notification; import org.sonar.api.notifications.NotificationManager; import org.sonar.jpa.entity.NotificationQueueElement; import org.sonar.jpa.session.DatabaseSessionFactory; -import java.util.Date; -import java.util.List; - /** * @since 2.10 */ @@ -61,4 +63,12 @@ public class DefaultNotificationManager implements NotificationManager { return notification; } + public boolean isEnabled(String username, String channelKey, String dispatcherKey) { + DatabaseSession session = sessionFactory.getSession(); + User user = session.getSingleResult(User.class, "login", username); + String notificationKey = "notification." + dispatcherKey + "." + channelKey; + Property property = session.getSingleResult(Property.class, "userId", user.getId(), "key", notificationKey); + return property != null && "true".equals(property.getValue()); + } + } diff --git a/sonar-core/src/test/java/org/sonar/core/notifications/DefaultNotificationManagerTest.java b/sonar-core/src/test/java/org/sonar/core/notifications/DefaultNotificationManagerTest.java index 70587fa8493..ae661ae43cc 100644 --- a/sonar-core/src/test/java/org/sonar/core/notifications/DefaultNotificationManagerTest.java +++ b/sonar-core/src/test/java/org/sonar/core/notifications/DefaultNotificationManagerTest.java @@ -49,4 +49,11 @@ public class DefaultNotificationManagerTest extends AbstractDbUnitTestCase { assertThat(manager.getFromQueue(), nullValue()); } + @Test + public void shouldCheckEnablement() { + setupData("fixture"); + assertThat(manager.isEnabled("simon", "email", "CommentOnReviewAssignedToMe"), is(true)); + assertThat(manager.isEnabled("godin", "email", "CommentOnReviewAssignedToMe"), is(false)); + } + } diff --git a/sonar-core/src/test/resources/org/sonar/core/notifications/DefaultNotificationManagerTest/fixture.xml b/sonar-core/src/test/resources/org/sonar/core/notifications/DefaultNotificationManagerTest/fixture.xml new file mode 100644 index 00000000000..7933d24446d --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/notifications/DefaultNotificationManagerTest/fixture.xml @@ -0,0 +1,8 @@ +<dataset> + + <users id="1" login="simon" /> + <users id="2" login="godin" /> + + <properties user_id="1" prop_key="notification.CommentOnReviewAssignedToMe.email" text_value="true"/> + +</dataset>
\ No newline at end of file |