aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/notification/email/EmailNotificationChannel.java8
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java4
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java4
-rw-r--r--sonar-core/src/main/java/org/sonar/core/user/DeprecatedUserFinder.java (renamed from sonar-core/src/main/java/org/sonar/core/user/HibernateUserFinder.java)26
-rw-r--r--sonar-core/src/main/resources/META-INF/persistence.xml1
-rw-r--r--sonar-core/src/test/java/org/sonar/core/user/DeprecatedUserFinderTest.java (renamed from sonar-core/src/test/java/org/sonar/core/user/HibernateUserFinderTest.java)37
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/user/DeprecatedUserFinderTest/fixture.xml (renamed from sonar-core/src/test/resources/org/sonar/core/user/HibernateUserFinderTest/fixture.xml)0
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/database/model/User.java11
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/security/UserFinder.java4
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/user/UserFinder.java8
11 files changed, 47 insertions, 58 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/notification/email/EmailNotificationChannel.java b/server/sonar-server/src/main/java/org/sonar/server/notification/email/EmailNotificationChannel.java
index de7dc0f81ea..5e004e69b2b 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/notification/email/EmailNotificationChannel.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/notification/email/EmailNotificationChannel.java
@@ -25,10 +25,10 @@ import org.apache.commons.lang.StringUtils;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;
import org.sonar.api.config.EmailSettings;
-import org.sonar.api.database.model.User;
import org.sonar.api.notifications.Notification;
import org.sonar.api.notifications.NotificationChannel;
-import org.sonar.api.security.UserFinder;
+import org.sonar.api.user.User;
+import org.sonar.api.user.UserFinder;
import org.sonar.api.utils.SonarException;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
@@ -95,13 +95,13 @@ public class EmailNotificationChannel extends NotificationChannel {
@Override
public void deliver(Notification notification, String username) {
User user = userFinder.findByLogin(username);
- if (StringUtils.isBlank(user.getEmail())) {
+ if (StringUtils.isBlank(user.email())) {
LOG.debug("Email not defined for user: " + username);
return;
}
EmailMessage emailMessage = format(notification);
if (emailMessage != null) {
- emailMessage.setTo(user.getEmail());
+ emailMessage.setTo(user.email());
deliver(emailMessage);
}
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
index c12c780a810..65815e09dae 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
@@ -45,7 +45,7 @@ import org.sonar.core.qualitygate.db.QualityGateDao;
import org.sonar.core.resource.DefaultResourceTypes;
import org.sonar.core.timemachine.Periods;
import org.sonar.core.user.DefaultUserFinder;
-import org.sonar.core.user.HibernateUserFinder;
+import org.sonar.core.user.DeprecatedUserFinder;
import org.sonar.jpa.dao.MeasuresDao;
import org.sonar.server.activity.ActivityService;
import org.sonar.server.activity.RubyQProfileActivityService;
@@ -533,7 +533,7 @@ public class PlatformLevel4 extends PlatformLevel {
// users
SecurityRealmFactory.class,
- HibernateUserFinder.class,
+ DeprecatedUserFinder.class,
NewUserNotifier.class,
DefaultUserFinder.class,
DefaultUserService.class,
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java
index b2280f7bcb8..9c50b4d76ae 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java
@@ -60,7 +60,6 @@ import org.sonar.core.platform.PluginLoader;
import org.sonar.core.platform.PluginRepository;
import org.sonar.core.purge.PurgeProfiler;
import org.sonar.core.rule.CacheRuleFinder;
-import org.sonar.core.user.HibernateUserFinder;
import org.sonar.core.util.DefaultHttpDownloader;
import org.sonar.jpa.dao.MeasuresDao;
import org.sonar.jpa.session.DefaultDatabaseConnector;
@@ -148,7 +147,6 @@ public class GlobalContainer extends ComponentContainer {
EmailSettings.class,
RuleI18nManager.class,
MeasuresDao.class,
- HibernateUserFinder.class,
PastSnapshotFinderByDate.class,
PastSnapshotFinderByDays.class,
PastSnapshotFinderByPreviousAnalysis.class,
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
index 0cb92aa0994..017b4b67b91 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
@@ -81,7 +81,6 @@ import org.sonar.core.issue.workflow.IssueWorkflow;
import org.sonar.core.permission.PermissionFacade;
import org.sonar.core.platform.ComponentContainer;
import org.sonar.core.technicaldebt.DefaultTechnicalDebtModel;
-import org.sonar.core.user.DefaultUserFinder;
public class ProjectScanContainer extends ComponentContainer {
@@ -208,9 +207,6 @@ public class ProjectScanContainer extends ComponentContainer {
add(
PastMeasuresLoader.class,
- // Users
- DefaultUserFinder.class,
-
// Rules
new RulesProvider(),
new DebtModelProvider(),
diff --git a/sonar-core/src/main/java/org/sonar/core/user/HibernateUserFinder.java b/sonar-core/src/main/java/org/sonar/core/user/DeprecatedUserFinder.java
index 4cc42aacccc..7a180bb7d54 100644
--- a/sonar-core/src/main/java/org/sonar/core/user/HibernateUserFinder.java
+++ b/sonar-core/src/main/java/org/sonar/core/user/DeprecatedUserFinder.java
@@ -19,32 +19,38 @@
*/
package org.sonar.core.user;
-import org.sonar.api.database.DatabaseSession;
+import javax.annotation.Nullable;
import org.sonar.api.database.model.User;
import org.sonar.api.security.UserFinder;
-import org.sonar.jpa.session.DatabaseSessionFactory;
/**
* @since 2.10
*/
-public class HibernateUserFinder implements UserFinder {
+public class DeprecatedUserFinder implements UserFinder {
- private DatabaseSessionFactory sessionFactory;
+ private final UserDao userDao;
- public HibernateUserFinder(DatabaseSessionFactory sessionFactory) {
- this.sessionFactory = sessionFactory;
+ public DeprecatedUserFinder(UserDao userDao) {
+ this.userDao = userDao;
}
@Override
public User findById(int id) {
- DatabaseSession session = sessionFactory.getSession();
- return session.getSingleResult(User.class, "id", id);
+ return copy(userDao.getUser(id));
}
@Override
public User findByLogin(String login) {
- DatabaseSession session = sessionFactory.getSession();
- return session.getSingleResult(User.class, "login", login);
+ return copy(userDao.selectActiveUserByLogin(login));
+ }
+
+ private User copy(@Nullable UserDto dto) {
+ if (dto != null) {
+ User user = new User().setEmail(dto.getEmail()).setLogin(dto.getLogin()).setName(dto.getName());
+ user.setId(dto.getId().intValue());
+ return user;
+ }
+ return null;
}
}
diff --git a/sonar-core/src/main/resources/META-INF/persistence.xml b/sonar-core/src/main/resources/META-INF/persistence.xml
index d8b0e5613fd..543cc5e66c4 100644
--- a/sonar-core/src/main/resources/META-INF/persistence.xml
+++ b/sonar-core/src/main/resources/META-INF/persistence.xml
@@ -6,7 +6,6 @@
<persistence-unit name="sonar" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
- <class>org.sonar.api.database.model.User</class>
<class>org.sonar.api.database.model.Snapshot</class>
<class>org.sonar.api.measures.Metric</class>
<class>org.sonar.api.database.model.ResourceModel</class>
diff --git a/sonar-core/src/test/java/org/sonar/core/user/HibernateUserFinderTest.java b/sonar-core/src/test/java/org/sonar/core/user/DeprecatedUserFinderTest.java
index f685c4ccecf..b0fa938476d 100644
--- a/sonar-core/src/test/java/org/sonar/core/user/HibernateUserFinderTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/user/DeprecatedUserFinderTest.java
@@ -19,59 +19,66 @@
*/
package org.sonar.core.user;
-import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
import org.junit.Test;
+import org.junit.experimental.categories.Category;
import org.sonar.api.database.model.User;
-import org.sonar.api.security.UserFinder;
-import org.sonar.jpa.test.AbstractDbUnitTestCase;
+import org.sonar.api.utils.System2;
+import org.sonar.core.persistence.DbTester;
+import org.sonar.test.DbTests;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
-public class HibernateUserFinderTest extends AbstractDbUnitTestCase {
+@Category(DbTests.class)
+public class DeprecatedUserFinderTest {
- private UserFinder userFinder;
+ @ClassRule
+ public static final DbTester dbTester = new DbTester();
- @Before
- public void setUp() {
- setupData("fixture");
- userFinder = new HibernateUserFinder(getSessionFactory());
+ @BeforeClass
+ public static void init() {
+ dbTester.prepareDbUnit(DeprecatedUserFinderTest.class, "fixture.xml");
}
@Test
public void shouldFindUserByLogin() {
- User user = userFinder.findByLogin("simon");
+ DeprecatedUserFinder finder = new DeprecatedUserFinder(new UserDao(dbTester.myBatis(), mock(System2.class)));
+ User user = finder.findByLogin("simon");
assertThat(user.getId(), is(1));
assertThat(user.getLogin(), is("simon"));
assertThat(user.getName(), is("Simon Brandhof"));
assertThat(user.getEmail(), is("simon.brandhof@sonarsource.com"));
- user = userFinder.findByLogin("godin");
+ user = finder.findByLogin("godin");
assertThat(user.getId(), is(2));
assertThat(user.getLogin(), is("godin"));
assertThat(user.getName(), is("Evgeny Mandrikov"));
assertThat(user.getEmail(), is("evgeny.mandrikov@sonarsource.com"));
- user = userFinder.findByLogin("user");
+ user = finder.findByLogin("user");
assertThat(user, nullValue());
}
@Test
public void shouldFindUserById() {
- User user = userFinder.findById(1);
+ DeprecatedUserFinder finder = new DeprecatedUserFinder(new UserDao(dbTester.myBatis(), mock(System2.class)));
+ User user = finder.findById(1);
assertThat(user.getId(), is(1));
assertThat(user.getLogin(), is("simon"));
assertThat(user.getName(), is("Simon Brandhof"));
assertThat(user.getEmail(), is("simon.brandhof@sonarsource.com"));
- user = userFinder.findById(2);
+ user = finder.findById(2);
assertThat(user.getId(), is(2));
assertThat(user.getLogin(), is("godin"));
assertThat(user.getName(), is("Evgeny Mandrikov"));
assertThat(user.getEmail(), is("evgeny.mandrikov@sonarsource.com"));
- user = userFinder.findById(3);
+ user = finder.findById(3);
assertThat(user, nullValue());
}
diff --git a/sonar-core/src/test/resources/org/sonar/core/user/HibernateUserFinderTest/fixture.xml b/sonar-core/src/test/resources/org/sonar/core/user/DeprecatedUserFinderTest/fixture.xml
index 456f9305802..456f9305802 100644
--- a/sonar-core/src/test/resources/org/sonar/core/user/HibernateUserFinderTest/fixture.xml
+++ b/sonar-core/src/test/resources/org/sonar/core/user/DeprecatedUserFinderTest/fixture.xml
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/User.java b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/User.java
index 15fce83fd9c..d5049fcfb15 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/User.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/User.java
@@ -23,24 +23,13 @@ import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.sonar.api.database.BaseIdentifiable;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.Table;
-
/**
* @since 2.2
*/
-@Entity
-@Table(name = "users")
public class User extends BaseIdentifiable {
- @Column(name = "login", updatable = true, nullable = true, length = 255)
private String login;
-
- @Column(name = "name", updatable = true, nullable = true, length = 200)
private String name;
-
- @Column(name = "email", updatable = true, nullable = true, length = 100)
private String email;
public String getLogin() {
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/security/UserFinder.java b/sonar-plugin-api/src/main/java/org/sonar/api/security/UserFinder.java
index 94c78120fb6..8e07887f421 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/security/UserFinder.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/security/UserFinder.java
@@ -19,16 +19,14 @@
*/
package org.sonar.api.security;
-import org.sonar.api.batch.BatchSide;
-import org.sonar.api.server.ServerSide;
import org.sonar.api.database.model.User;
+import org.sonar.api.server.ServerSide;
/**
* @since 2.10
* @deprecated since 5.1 DB access will soon be removed from batch side
*/
@Deprecated
-@BatchSide
@ServerSide
public interface UserFinder {
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/user/UserFinder.java b/sonar-plugin-api/src/main/java/org/sonar/api/user/UserFinder.java
index a73ff532466..8eed4f8da38 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/user/UserFinder.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/user/UserFinder.java
@@ -19,19 +19,15 @@
*/
package org.sonar.api.user;
-import org.sonar.api.batch.BatchSide;
-import org.sonar.api.server.ServerSide;
-
-import javax.annotation.CheckForNull;
-
import java.util.List;
+import javax.annotation.CheckForNull;
+import org.sonar.api.server.ServerSide;
/**
* @since 3.6
* @deprecated since 5.1 DB access will soon be removed from batch side
*/
@Deprecated
-@BatchSide
@ServerSide
public interface UserFinder {