]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5614 Do nothing when sonar.issues.use_es_backend is not set
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 19 Sep 2014 07:32:02 +0000 (09:32 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 19 Sep 2014 07:32:02 +0000 (09:32 +0200)
server/sonar-server/src/main/java/org/sonar/server/batch/UploadReportAction.java
server/sonar-server/src/test/java/org/sonar/server/batch/BatchWsTest.java
server/sonar-server/src/test/java/org/sonar/server/batch/UploadReportActionMediumTest.java

index ad50c942bd334dfa1ee6acf664b39f1a381a55d3..547accceb0380c26d45b33f05b759c0db2dff72e 100644 (file)
@@ -21,6 +21,7 @@
 package org.sonar.server.batch;
 
 import com.google.common.collect.ImmutableMap;
+import org.sonar.api.config.Settings;
 import org.sonar.api.server.ws.Request;
 import org.sonar.api.server.ws.RequestHandler;
 import org.sonar.api.server.ws.Response;
@@ -45,11 +46,13 @@ public class UploadReportAction implements RequestHandler {
   private final DbClient dbClient;
   private final IndexClient index;
   private final InternalPermissionService permissionService;
+  private final Settings settings;
 
-  public UploadReportAction(DbClient dbClient, IndexClient index, InternalPermissionService permissionService) {
+  public UploadReportAction(DbClient dbClient, IndexClient index, InternalPermissionService permissionService, Settings settings) {
     this.dbClient = dbClient;
     this.index = index;
     this.permissionService = permissionService;
+    this.settings = settings;
   }
 
   void define(WebService.NewController controller) {
@@ -75,28 +78,31 @@ public class UploadReportAction implements RequestHandler {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    DbSession session = dbClient.openSession(false);
-    try {
-      String projectKey = request.mandatoryParam(PARAM_PROJECT);
-      AuthorizedComponentDto project = dbClient.componentDao().getAuthorizedComponentByKey(projectKey, session);
-
-      // Synchronize project permission indexes
-      boolean isFirstAnalysis = request.mandatoryParamAsBoolean(PARAM_FIRST_ANALYSIS);
-      if (isFirstAnalysis) {
-        permissionService.synchronizePermissions(session, project.key());
+    UserSession.get().checkGlobalPermission(GlobalPermissions.SCAN_EXECUTION);
+
+    // Switch Issue search
+    if (settings.getString("sonar.issues.use_es_backend") != null) {
+      DbSession session = dbClient.openSession(false);
+      try {
+        String projectKey = request.mandatoryParam(PARAM_PROJECT);
+        AuthorizedComponentDto project = dbClient.componentDao().getAuthorizedComponentByKey(projectKey, session);
+
+        // Synchronize project permission indexes
+        boolean isFirstAnalysis = request.mandatoryParamAsBoolean(PARAM_FIRST_ANALYSIS);
+        if (isFirstAnalysis) {
+          permissionService.synchronizePermissions(session, project.key());
+          session.commit();
+        }
+
+        // Index project's issues
+        dbClient.issueDao().synchronizeAfter(session,
+          index.get(IssueIndex.class).getLastSynchronization(),
+          ImmutableMap.of("project", projectKey));
+
         session.commit();
+      } finally {
+        MyBatis.closeQuietly(session);
       }
-
-      UserSession.get().checkGlobalPermission(GlobalPermissions.SCAN_EXECUTION);
-
-      // Index project's issues
-      dbClient.issueDao().synchronizeAfter(session,
-        index.get(IssueIndex.class).getLastSynchronization(),
-        ImmutableMap.of("project", projectKey));
-
-      session.commit();
-    } finally {
-      MyBatis.closeQuietly(session);
     }
   }
 
index faecc1be4ee02f68c9c927b49e10ec9199c858ff..df007dfa4e377c5c4023eb03f7c9ec87c4292a93 100644 (file)
@@ -28,6 +28,7 @@ import org.junit.rules.TemporaryFolder;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
+import org.sonar.api.config.Settings;
 import org.sonar.api.resources.Languages;
 import org.sonar.core.properties.PropertiesDao;
 import org.sonar.server.db.DbClient;
@@ -65,7 +66,7 @@ public class BatchWsTest {
       new GlobalReferentialsAction(mock(DbClient.class), mock(PropertiesDao.class)),
       new ProjectReferentialsAction(mock(DbClient.class), mock(PropertiesDao.class), mock(QProfileFactory.class), mock(QProfileLoader.class), mock(RuleService.class),
         mock(Languages.class)),
-      new UploadReportAction(mock(DbClient.class), mock(IndexClient.class), mock(InternalPermissionService.class))));
+      new UploadReportAction(mock(DbClient.class), mock(IndexClient.class), mock(InternalPermissionService.class), new Settings())));
   }
 
   @Test
index 650a522efccb8e4ccebefde79df4db7d0d94b86a..2f2fb36c0242ea8b205c633b1b95260ea31ce5fc 100644 (file)
@@ -55,7 +55,8 @@ import static org.fest.assertions.Assertions.assertThat;
 public class UploadReportActionMediumTest {
 
   @ClassRule
-  public static ServerTester tester = new ServerTester();
+  public static ServerTester tester = new ServerTester()
+    .setProperty("sonar.issues.use_es_backend", "true");
 
   DbClient db;
   DbSession session;