]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6821 WS qualityprofiles/search load project profiles when giving a module key
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Tue, 29 Sep 2015 09:06:23 +0000 (11:06 +0200)
committerDuarte Meneses <duarte.meneses@sonarsource.com>
Wed, 30 Sep 2015 14:28:08 +0000 (16:28 +0200)
it/it-tests/src/test/java/batch/suite/IssueJsonReportTest.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchDataLoader.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java

index a6b8c6605af768ab3d76189a047be7db81c4fb21..8442467743ce7adde06613bf252a121e49da8099 100644 (file)
@@ -5,25 +5,24 @@
  */
 package batch.suite;
 
-import com.sonar.orchestrator.locator.ResourceLocation;
-import util.ItUtils;
-import org.junit.Rule;
-import org.junit.rules.TemporaryFolder;
 import com.sonar.orchestrator.Orchestrator;
 import com.sonar.orchestrator.build.SonarRunner;
 import com.sonar.orchestrator.locator.FileLocation;
-
+import com.sonar.orchestrator.locator.ResourceLocation;
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.InputStream;
-
-import static org.assertj.core.api.Assertions.assertThat;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.junit.Before;
 import org.junit.ClassRule;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
 import org.skyscreamer.jsonassert.JSONAssert;
+import util.ItUtils;
+
+import static org.assertj.core.api.Assertions.assertThat;
 
 public class IssueJsonReportTest {
 
index e0de16f8746bcf26830b8b2a89ebb3e0d675d5e4..844c2b3108444eeaf64731920eb91b7e24d18537 100644 (file)
@@ -31,7 +31,9 @@ import org.sonar.api.resources.Languages;
 import org.sonar.api.server.ws.Request;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
+import org.sonar.db.component.ComponentDto;
 import org.sonar.db.qualityprofile.QualityProfileDto;
+import org.sonar.server.component.ComponentFinder;
 import org.sonar.server.qualityprofile.QProfile;
 import org.sonar.server.qualityprofile.QProfileFactory;
 import org.sonar.server.qualityprofile.QProfileLoader;
@@ -52,13 +54,15 @@ public class SearchDataLoader {
   private final QProfileLoader profileLoader;
   private final QProfileFactory profileFactory;
   private final DbClient dbClient;
+  private final ComponentFinder componentFinder;
 
-  public SearchDataLoader(Languages languages, QProfileLookup profileLookup, QProfileLoader profileLoader, QProfileFactory profileFactory, DbClient dbClient) {
+  public SearchDataLoader(Languages languages, QProfileLookup profileLookup, QProfileLoader profileLoader, QProfileFactory profileFactory, DbClient dbClient, ComponentFinder componentFinder) {
     this.languages = languages;
     this.profileLookup = profileLookup;
     this.profileLoader = profileLoader;
     this.profileFactory = profileFactory;
     this.dbClient = dbClient;
+    this.componentFinder = componentFinder;
   }
 
   SearchData load(Request request) {
@@ -101,7 +105,7 @@ public class SearchDataLoader {
   }
 
   private List<QProfile> findProjectProfiles(Request request) {
-    String projectKey = request.param(PARAM_PROJECT_KEY);
+    String moduleKey = request.param(PARAM_PROJECT_KEY);
     String profileName = request.param(PARAM_PROFILE_NAME);
 
     List<QProfile> profiles = new ArrayList<>();
@@ -110,7 +114,8 @@ public class SearchDataLoader {
     try {
       for (Language language : languages.all()) {
         String languageKey = language.getKey();
-        profiles.add(getProfile(dbSession, languageKey, projectKey, profileName));
+        ComponentDto project = getProject(moduleKey, dbSession);
+        profiles.add(getProfile(dbSession, languageKey, project.key(), profileName));
       }
     } finally {
       dbClient.closeSession(dbSession);
@@ -119,6 +124,15 @@ public class SearchDataLoader {
     return profiles;
   }
 
+  private ComponentDto getProject(String moduleKey, DbSession session) {
+    ComponentDto module = componentFinder.getByKey(session, moduleKey);
+    if (!module.isRootProject()) {
+      return dbClient.componentDao().selectOrFailByUuid(session, module.projectUuid());
+    } else {
+      return module;
+    }
+  }
+
   private List<QProfile> findDefaultProfiles() {
     List<QProfile> profiles = new ArrayList<>();
 
index d83aac49b21481e23dfb559590f24ae02d7fdcc1..18ec96c500602cab4c2e3d11e2c7d2399ff31e9e 100644 (file)
@@ -37,6 +37,7 @@ import org.sonar.db.component.ComponentDto;
 import org.sonar.db.qualityprofile.QualityProfileDao;
 import org.sonar.db.qualityprofile.QualityProfileDbTester;
 import org.sonar.db.qualityprofile.QualityProfileDto;
+import org.sonar.server.component.ComponentFinder;
 import org.sonar.server.language.LanguageTesting;
 import org.sonar.server.qualityprofile.QProfileFactory;
 import org.sonar.server.qualityprofile.QProfileLoader;
@@ -93,7 +94,14 @@ public class SearchActionTest {
         new RuleDao(System2.INSTANCE),
         System2.INSTANCE));
     ws = new WsActionTester(new SearchAction(
-      new SearchDataLoader(languages, new QProfileLookup(dbClient), profileLoader, new QProfileFactory(oldDbClient), dbClient), languages));
+      new SearchDataLoader(
+        languages,
+        new QProfileLookup(dbClient),
+        profileLoader,
+        new QProfileFactory(oldDbClient),
+        dbClient,
+        new ComponentFinder(dbClient)),
+      languages));
   }
 
   @Test