From: Teryk Bellahsene Date: Tue, 29 Sep 2015 09:06:23 +0000 (+0200) Subject: SONAR-6821 WS qualityprofiles/search load project profiles when giving a module key X-Git-Tag: 5.2-RC1~159 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2793f3cc6d468ad930e3b77138b07a3e3b372a15;p=sonarqube.git SONAR-6821 WS qualityprofiles/search load project profiles when giving a module key --- diff --git a/it/it-tests/src/test/java/batch/suite/IssueJsonReportTest.java b/it/it-tests/src/test/java/batch/suite/IssueJsonReportTest.java index a6b8c6605af..8442467743c 100644 --- a/it/it-tests/src/test/java/batch/suite/IssueJsonReportTest.java +++ b/it/it-tests/src/test/java/batch/suite/IssueJsonReportTest.java @@ -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 { diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchDataLoader.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchDataLoader.java index e0de16f8746..844c2b31084 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchDataLoader.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchDataLoader.java @@ -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 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 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 findDefaultProfiles() { List profiles = new ArrayList<>(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java index d83aac49b21..18ec96c5006 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java @@ -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