From 957e62ce77e23d31d59f9369657e91a9dd616c84 Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov Date: Thu, 21 Jul 2011 11:45:41 +0400 Subject: SONAR-2607 Provide email notifications on review changes * Add email templates. * Add server component - UserFinder. --- .../sonar/core/components/DefaultUserFinder.java | 43 ++++++++++++++++++++++ .../sonar/jpa/entity/NotificationQueueElement.java | 7 ++-- 2 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 sonar-core/src/main/java/org/sonar/core/components/DefaultUserFinder.java (limited to 'sonar-core') diff --git a/sonar-core/src/main/java/org/sonar/core/components/DefaultUserFinder.java b/sonar-core/src/main/java/org/sonar/core/components/DefaultUserFinder.java new file mode 100644 index 00000000000..648aa104fb5 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/components/DefaultUserFinder.java @@ -0,0 +1,43 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.core.components; + +import org.sonar.api.database.DatabaseSession; +import org.sonar.api.database.model.User; +import org.sonar.api.security.UserFinder; +import org.sonar.jpa.session.DatabaseSessionFactory; + +/** + * @since 2.10 + */ +public class DefaultUserFinder implements UserFinder { + + private DatabaseSessionFactory sessionFactory; + + public DefaultUserFinder(DatabaseSessionFactory sessionFactory) { + this.sessionFactory = sessionFactory; + } + + public User findByLogin(String login) { + DatabaseSession session = sessionFactory.getSession(); + return session.getSingleResult(User.class, "login", login); + } + +} diff --git a/sonar-core/src/main/java/org/sonar/jpa/entity/NotificationQueueElement.java b/sonar-core/src/main/java/org/sonar/jpa/entity/NotificationQueueElement.java index 198cd0871ce..ac80cec95e6 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/entity/NotificationQueueElement.java +++ b/sonar-core/src/main/java/org/sonar/jpa/entity/NotificationQueueElement.java @@ -20,6 +20,7 @@ package org.sonar.jpa.entity; import org.sonar.api.notifications.Notification; +import org.sonar.api.utils.SonarException; import java.io.*; import java.util.Date; @@ -65,7 +66,7 @@ public class NotificationQueueElement { objectOutputStream.close(); this.data = byteArrayOutputStream.toByteArray(); } catch (IOException e) { - throw new RuntimeException(e); + throw new SonarException(e); } } @@ -80,9 +81,9 @@ public class NotificationQueueElement { objectInputStream.close(); return (Notification) result; } catch (IOException e) { - throw new RuntimeException(e); + throw new SonarException(e); } catch (ClassNotFoundException e) { - throw new RuntimeException(e); + throw new SonarException(e); } } -- cgit v1.2.3