aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2015-10-01 10:44:48 +0200
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2015-10-01 10:46:19 +0200
commit9cd17b26616cd146c8954e1e38ee7c9589280842 (patch)
tree4c6bf4bfcf14c258b4b152d0993327cf23a49da7
parent11e165afac83810f7f366aac8c719624574279fd (diff)
downloadsonarqube-9cd17b26616cd146c8954e1e38ee7c9589280842.tar.gz
sonarqube-9cd17b26616cd146c8954e1e38ee7c9589280842.zip
SONAR-6821 WS qualityprofiles/search handle profile name when asking for default profiles
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java6
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchDataLoader.java22
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java9
3 files changed, 21 insertions, 16 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java
index 552f6b07971..beedca2c6cf 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java
@@ -74,13 +74,13 @@ public class SearchAction implements QProfileWsAction {
action
.createParam(PARAM_DEFAULTS)
.setDescription(format("Return the quality profile marked as default for each language. " +
- "If provided, then the parameters '%s', '%s' and '%s' must not be set.",
- PARAM_LANGUAGE, PARAM_PROJECT_KEY, PARAM_PROFILE_NAME))
+ "If provided, then the parameters '%s', '%s' must not be set.",
+ PARAM_LANGUAGE, PARAM_PROJECT_KEY))
.setDefaultValue(false)
.setBooleanPossibleValues();
action.createParam(PARAM_PROFILE_NAME)
- .setDescription(format("Profile name. It should be always used with the '%s' parameter.", PARAM_PROJECT_KEY))
+ .setDescription(format("Profile name. It should be always used with the '%s' or '%s' parameter.", PARAM_PROJECT_KEY, PARAM_DEFAULTS))
.setExampleValue("SonarQube Way");
}
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 844c2b31084..0814a84e21e 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
@@ -56,7 +56,8 @@ public class SearchDataLoader {
private final DbClient dbClient;
private final ComponentFinder componentFinder;
- public SearchDataLoader(Languages languages, QProfileLookup profileLookup, QProfileLoader profileLoader, QProfileFactory profileFactory, DbClient dbClient, ComponentFinder componentFinder) {
+ public SearchDataLoader(Languages languages, QProfileLookup profileLookup, QProfileLoader profileLoader, QProfileFactory profileFactory, DbClient dbClient,
+ ComponentFinder componentFinder) {
this.languages = languages;
this.profileLookup = profileLookup;
this.profileLoader = profileLoader;
@@ -77,7 +78,7 @@ public class SearchDataLoader {
private List<QProfile> findProfiles(Request request) {
List<QProfile> profiles;
if (askDefaultProfiles(request)) {
- profiles = findDefaultProfiles();
+ profiles = findDefaultProfiles(request);
} else if (hasComponentKey(request)) {
profiles = findProjectProfiles(request);
} else {
@@ -95,8 +96,7 @@ public class SearchDataLoader {
private List<QProfile> findAllProfiles(Request request) {
String language = request.param(PARAM_LANGUAGE);
- List<QProfile> profiles = language != null ?
- profileLookup.profiles(language)
+ List<QProfile> profiles = language != null ? profileLookup.profiles(language)
: profileLookup.allProfiles();
return from(profiles)
@@ -133,13 +133,14 @@ public class SearchDataLoader {
}
}
- private List<QProfile> findDefaultProfiles() {
+ private List<QProfile> findDefaultProfiles(Request request) {
+ String profileName = request.param(PARAM_PROFILE_NAME);
List<QProfile> profiles = new ArrayList<>();
DbSession dbSession = dbClient.openSession(false);
try {
for (Language language : languages.all()) {
- profiles.add(getDefaultProfile(dbSession, language.getKey()));
+ profiles.add(getDefaultProfile(dbSession, language.getKey(), profileName));
}
} finally {
dbClient.closeSession(dbSession);
@@ -175,8 +176,11 @@ public class SearchDataLoader {
return profileDtoToQProfile(profileDto);
}
- private QProfile getDefaultProfile(DbSession dbSession, String languageKey) {
- QualityProfileDto profile = profileFactory.getDefault(dbSession, languageKey);
+ private QProfile getDefaultProfile(DbSession dbSession, String languageKey, @Nullable String profileName) {
+ QualityProfileDto profile = profileName != null ? profileFactory.getByNameAndLanguage(dbSession, profileName, languageKey) : null;
+ if (profile == null) {
+ profile = profileFactory.getDefault(dbSession, languageKey);
+ }
checkState(profile != null, format("No quality profile can been found on language '%s'", languageKey));
return profileDtoToQProfile(profile);
@@ -190,7 +194,7 @@ public class SearchDataLoader {
checkRequest(!hasLanguage || (!hasComponentKey && !hasProfileName && !isDefault),
"The language parameter cannot be provided at the same time than the component key or profile name.");
- checkRequest(!isDefault || (!hasComponentKey && !hasProfileName), "The default parameter cannot be provided at the same time than the component key or profile name");
+ checkRequest(!isDefault || !hasComponentKey, "The default parameter cannot be provided at the same time than the component key");
}
private static boolean hasProfileName(Request request) {
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 18ec96c5006..a0ae237b1bd 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
@@ -170,24 +170,25 @@ public class SearchActionTest {
}
@Test
- public void search_for_default_qp() {
+ public void search_for_default_qp_with_profile_name() {
QualityProfileDto qualityProfileOnXoo1 = QualityProfileDto.createFor("sonar-way-xoo1-12345")
.setLanguage(xoo1.getKey())
.setName("Sonar way")
- .setDefault(true);
+ .setDefault(false);
QualityProfileDto qualityProfileOnXoo2 = QualityProfileDto.createFor("sonar-way-xoo2-12345")
.setLanguage(xoo2.getKey())
.setName("Sonar way")
.setDefault(true);
QualityProfileDto anotherQualityProfileOnXoo1 = QualityProfileDto.createFor("sonar-way-xoo1-45678")
.setLanguage(xoo1.getKey())
- .setName("Sonar way")
- .setDefault(false);
+ .setName("Another way")
+ .setDefault(true);
qualityProfileDb.insertQualityProfiles(qualityProfileOnXoo1, qualityProfileOnXoo2, anotherQualityProfileOnXoo1);
commit();
String result = ws.newRequest()
.setParam(PARAM_DEFAULTS, Boolean.TRUE.toString())
+ .setParam(PARAM_PROFILE_NAME, "Sonar way")
.execute().getInput();
assertThat(result)