aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2016-10-20 12:14:59 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2016-10-20 13:16:50 +0200
commit4bcc72d0042112612d1f94f90d2e16f6b9adc1fc (patch)
tree128834164f9707cb48852a472351f26fcc03e067 /server/sonar-server
parent1ab2d1cc43df5a9af5944e0b8c946c11d34ed41c (diff)
downloadsonarqube-4bcc72d0042112612d1f94f90d2e16f6b9adc1fc.tar.gz
sonarqube-4bcc72d0042112612d1f94f90d2e16f6b9adc1fc.zip
SONAR-8227 Add DbSession parameter in AuthorizationIndexer index methods
Diffstat (limited to 'server/sonar-server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/ApplyPermissionsStep.java4
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/permission/PermissionService.java8
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/permission/PermissionUpdater.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/permission/index/AuthorizationIndexer.java20
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/component/ComponentCleanerServiceTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/permission/index/AuthorizationIndexerTest.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java4
7 files changed, 21 insertions, 25 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/ApplyPermissionsStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/ApplyPermissionsStep.java
index f6c27656f65..b46059d147f 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/ApplyPermissionsStep.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/ApplyPermissionsStep.java
@@ -47,7 +47,7 @@ public class ApplyPermissionsStep implements ComputationStep {
private final TreeRootHolder treeRootHolder;
public ApplyPermissionsStep(DbClient dbClient, DbIdsRepository dbIdsRepository, AuthorizationIndexer indexer, PermissionRepository permissionRepository,
- TreeRootHolder treeRootHolder) {
+ TreeRootHolder treeRootHolder) {
this.dbClient = dbClient;
this.dbIdsRepository = dbIdsRepository;
this.indexer = indexer;
@@ -77,7 +77,7 @@ public class ApplyPermissionsStep implements ComputationStep {
if (hasNoPermissions(dbSession, projectId)) {
permissionRepository.applyDefaultPermissionTemplate(dbSession, projectId);
dbSession.commit();
- indexer.index(project.getUuid());
+ indexer.index(dbSession, project.getUuid());
}
}
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionService.java b/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionService.java
index fcda00f76a7..9f3c15d95ae 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionService.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionService.java
@@ -87,7 +87,7 @@ public class PermissionService {
Long userId = Qualifiers.PROJECT.equals(component.qualifier()) && currentUserId != null ? currentUserId.longValue() : null;
permissionRepository.applyDefaultPermissionTemplate(session, component, userId);
session.commit();
- indexProjectPermissions(asList(component.uuid()));
+ indexProjectPermissions(session, asList(component.uuid()));
}
public boolean wouldCurrentUserHavePermissionWithDefaultTemplate(DbSession dbSession, String permission, @Nullable String branch, String projectKey, String qualifier) {
@@ -110,10 +110,10 @@ public class PermissionService {
permissionRepository.apply(dbSession, template, project, null);
}
dbSession.commit();
- indexProjectPermissions(projects.stream().map(ComponentDto::uuid).collect(Collectors.toList()));
+ indexProjectPermissions(dbSession, projects.stream().map(ComponentDto::uuid).collect(Collectors.toList()));
}
- private void indexProjectPermissions(List<String> projectUuids) {
- authorizationIndexer.index(projectUuids);
+ private void indexProjectPermissions(DbSession dbSession, List<String> projectUuids) {
+ authorizationIndexer.index(dbSession, projectUuids);
}
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionUpdater.java b/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionUpdater.java
index 47a426a2736..07f5813776b 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionUpdater.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionUpdater.java
@@ -66,7 +66,7 @@ public class PermissionUpdater {
dbSession.commit();
if (!projectIds.isEmpty()) {
- authorizationIndexer.index(projectUuids);
+ authorizationIndexer.index(dbSession, projectUuids);
}
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/index/AuthorizationIndexer.java b/server/sonar-server/src/main/java/org/sonar/server/permission/index/AuthorizationIndexer.java
index d2ebc57d28e..502b254acd4 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/permission/index/AuthorizationIndexer.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/permission/index/AuthorizationIndexer.java
@@ -101,12 +101,10 @@ public class AuthorizationIndexer implements Startable {
BulkIndexer.delete(esClient, index, esClient.prepareSearch(index).setTypes(type).setQuery(matchAllQuery()));
}
- public void index(List<String> projectUuids) {
+ public void index(DbSession dbSession, List<String> projectUuids) {
checkArgument(!projectUuids.isEmpty(), "ProjectUuids cannot be empty");
- try (DbSession dbSession = dbClient.openSession(false)) {
- AuthorizationDao dao = new AuthorizationDao();
- index(dao.selectByProjects(dbClient, dbSession, projectUuids));
- }
+ AuthorizationDao dao = new AuthorizationDao();
+ index(dao.selectByProjects(dbClient, dbSession, projectUuids));
}
private void index(Collection<AuthorizationDao.Dto> authorizations) {
@@ -130,13 +128,11 @@ public class AuthorizationIndexer implements Startable {
esClient.prepareRefresh(ProjectMeasuresIndexDefinition.TYPE_PROJECT_MEASURES).get();
}
- public void index(String projectUuid) {
- try (DbSession dbSession = dbClient.openSession(false)) {
- AuthorizationDao dao = new AuthorizationDao();
- List<AuthorizationDao.Dto> dtos = dao.selectByProjects(dbClient, dbSession, singletonList(projectUuid));
- if (dtos.size() == 1) {
- index(dtos.get(0));
- }
+ public void index(DbSession dbSession, String projectUuid) {
+ AuthorizationDao dao = new AuthorizationDao();
+ List<AuthorizationDao.Dto> dtos = dao.selectByProjects(dbClient, dbSession, singletonList(projectUuid));
+ if (dtos.size() == 1) {
+ index(dtos.get(0));
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ComponentCleanerServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ComponentCleanerServiceTest.java
index ede7d441018..e2e0b138b51 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/component/ComponentCleanerServiceTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/component/ComponentCleanerServiceTest.java
@@ -225,7 +225,7 @@ public class ComponentCleanerServiceTest {
dbClient.componentDao().insert(dbSession, project);
dbSession.commit();
projectMeasuresIndexer.index();
- authorizationIndexer.index(project.uuid());
+ authorizationIndexer.index(dbSession, project.uuid());
String issueKey = "issue-key-" + suffix;
es.putDocuments(IssueIndexDefinition.INDEX, TYPE_ISSUE, IssueTesting.newDoc(issueKey, project));
diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/index/AuthorizationIndexerTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/index/AuthorizationIndexerTest.java
index 1e5fcae3e18..dd366beaf97 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/permission/index/AuthorizationIndexerTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/permission/index/AuthorizationIndexerTest.java
@@ -133,7 +133,7 @@ public class AuthorizationIndexerTest {
ComponentDto project2 = componentDbTester.insertProject();
userDbTester.insertProjectPermissionOnGroup(group, USER, project2);
- underTest.index(project1.uuid());
+ underTest.index(dbTester.getSession(), project1.uuid());
authorizationIndexerTester.verifyProjectExistsWithAuthorization(project1.uuid(), asList(group.getName(), ANYONE), emptyList());
authorizationIndexerTester.verifyProjectDoesNotExist(project2.uuid());
@@ -150,7 +150,7 @@ public class AuthorizationIndexerTest {
userDbTester.insertProjectPermissionOnGroup(group, USER, project3);
// Only index projects 1 and 2
- underTest.index(asList(project1.uuid(), project2.uuid()));
+ underTest.index(dbTester.getSession(), asList(project1.uuid(), project2.uuid()));
authorizationIndexerTester.verifyProjectExistsWithAuthorization(project1.uuid(), asList(group.getName(), ANYONE), emptyList());
authorizationIndexerTester.verifyProjectExistsWithAuthorization(project2.uuid(), asList(group.getName(), ANYONE), emptyList());
@@ -170,6 +170,6 @@ public class AuthorizationIndexerTest {
@Test
public void fail_when_trying_to_index_empty_project_uuids() throws Exception {
expectedException.expect(IllegalArgumentException.class);
- underTest.index(Collections.<String>emptyList());
+ underTest.index(dbTester.getSession(), Collections.emptyList());
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java b/server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java
index 4b145f94906..c9a3a254e69 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java
@@ -151,7 +151,7 @@ public class ViewIndexerTest {
dbClient.ruleDao().insert(dbSession, rule);
ComponentDto project1 = addProjectWithIssue(rule);
issueIndexer.indexAll();
- authorizationIndexer.index(project1.uuid());
+ authorizationIndexer.index(dbSession, project1.uuid());
ComponentDto view = ComponentTesting.newView("ABCD");
ComponentDto techProject1 = ComponentTesting.newProjectCopy("CDEF", project1, view);
@@ -168,7 +168,7 @@ public class ViewIndexerTest {
// Add a project to the view and index it again
ComponentDto project2 = addProjectWithIssue(rule);
issueIndexer.indexAll();
- authorizationIndexer.index(project2.uuid());
+ authorizationIndexer.index(dbSession, project2.uuid());
ComponentDto techProject2 = ComponentTesting.newProjectCopy("EFGH", project2, view);
dbClient.componentDao().insert(dbSession, techProject2);