summaryrefslogtreecommitdiffstats
path: root/sonar-server/src/main
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-01-08 17:27:05 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-01-08 17:27:05 +0100
commitb8f14b0c67995f3372af529772d91ee9c1af8874 (patch)
treebc174bd0b61338ed830dfd76795d1faef0f1a924 /sonar-server/src/main
parentf309fc178aae760aee263bf19f2afe2f2fd25967 (diff)
downloadsonarqube-b8f14b0c67995f3372af529772d91ee9c1af8874.tar.gz
sonarqube-b8f14b0c67995f3372af529772d91ee9c1af8874.zip
SONAR-4923 List inheritance profiles now uses Java facade
Diffstat (limited to 'sonar-server/src/main')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileRule.java8
-rw-r--r--sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileSearch.java22
-rw-r--r--sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfiles.java14
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rule/ProfileRuleQuery.java17
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rule/ProfileRules.java12
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb11
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/helpers/profiles_helper.rb7
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/profiles/inheritance.html.erb14
8 files changed, 86 insertions, 19 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileRule.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileRule.java
index 837c52f1508..d7a6693e8c0 100644
--- a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileRule.java
+++ b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileRule.java
@@ -23,7 +23,6 @@ import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.elasticsearch.common.collect.Lists;
import org.elasticsearch.common.collect.Maps;
import org.elasticsearch.common.joda.time.format.ISODateTimeFormat;
-import org.sonar.api.rules.ActiveRule;
import org.sonar.check.Cardinality;
import org.sonar.server.rule.ActiveRuleDocument;
import org.sonar.server.rule.RuleDocument;
@@ -36,6 +35,9 @@ import java.util.Map;
public class QProfileRule {
+ public static final String INHERITED = "INHERITED";
+ public static final String OVERRIDES = "OVERRIDES";
+
private final Integer id;
private final Integer parentId;
private final String key;
@@ -200,11 +202,11 @@ public class QProfileRule {
}
public boolean isInherited() {
- return ActiveRule.INHERITED.equals(inheritance);
+ return INHERITED.equals(inheritance);
}
public boolean isOverrides() {
- return ActiveRule.OVERRIDES.equals(inheritance);
+ return OVERRIDES.equals(inheritance);
}
public boolean isTemplate() {
diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileSearch.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileSearch.java
index 27d9ad2abc9..60370762bc2 100644
--- a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileSearch.java
+++ b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileSearch.java
@@ -44,6 +44,10 @@ public class QProfileSearch implements ServerComponent {
return toQProfiles(dao.selectAll());
}
+ public List<QProfile> profiles(String language) {
+ return toQProfiles(dao.selectByLanguage(language));
+ }
+
@CheckForNull
public QProfile defaultProfile(String language) {
QualityProfileDto dto = dao.selectDefaultProfile(language, QProfileProjectService.PROPERTY_PREFIX + language);
@@ -57,6 +61,24 @@ public class QProfileSearch implements ServerComponent {
return toQProfiles(dao.selectChildren(profile.name(), profile.language()));
}
+ public List<QProfile> ancestors(QProfile profile) {
+ List<QProfile> ancestors = newArrayList();
+ incrementAncestors(profile, ancestors);
+ return ancestors;
+ }
+
+ private void incrementAncestors(QProfile profile, List<QProfile> ancestors){
+ if (profile.parent() != null) {
+ QualityProfileDto parentDto = dao.selectParent(profile.id());
+ if (parentDto == null) {
+ throw new IllegalStateException("Cannot find parent of profile : "+ profile.id());
+ }
+ QProfile parent = QProfile.from(parentDto);
+ ancestors.add(parent);
+ incrementAncestors(parent, ancestors);
+ }
+ }
+
public int countChildren(QProfile profile) {
return dao.countChildren(profile.name(), profile.language());
}
diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfiles.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfiles.java
index 9095be6bcc6..633b353f202 100644
--- a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfiles.java
+++ b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfiles.java
@@ -94,13 +94,17 @@ public class QProfiles implements ServerComponent {
// ACTIVE RULES
// bulk activate all
// bulk deactivate all
- // active rule parameter validation (only Integer types are checked)
+ // active rule parameter validation (only Integer and Boolean types are checked)
public List<QProfile> allProfiles() {
return search.allProfiles();
}
+ public List<QProfile> profilesByLanguage(String language) {
+ return search.profiles(language);
+ }
+
public QProfile profile(int id) {
return QProfile.from(findNotNull(id));
}
@@ -123,6 +127,10 @@ public class QProfiles implements ServerComponent {
return search.children(profile);
}
+ public List<QProfile> ancestors(QProfile profile) {
+ return search.ancestors(profile);
+ }
+
public int countChildren(QProfile profile) {
return search.countChildren(profile);
}
@@ -219,6 +227,10 @@ public class QProfiles implements ServerComponent {
return rules.countProfileRules(ProfileRuleQuery.create(profile.id()));
}
+ public long countOverridingProfileRules(QProfile profile) {
+ return rules.countProfileRules(ProfileRuleQuery.create(profile.id()).setInheritance(QProfileRule.OVERRIDES));
+ }
+
public ProfileRuleChanged activateRule(int profileId, int ruleId, String severity) {
QualityProfileDto qualityProfile = findNotNull(profileId);
RuleDto rule = findRuleNotNull(ruleId);
diff --git a/sonar-server/src/main/java/org/sonar/server/rule/ProfileRuleQuery.java b/sonar-server/src/main/java/org/sonar/server/rule/ProfileRuleQuery.java
index 397db375757..1ec3113831f 100644
--- a/sonar-server/src/main/java/org/sonar/server/rule/ProfileRuleQuery.java
+++ b/sonar-server/src/main/java/org/sonar/server/rule/ProfileRuleQuery.java
@@ -26,6 +26,7 @@ import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.util.RubyUtils;
import javax.annotation.CheckForNull;
+
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
@@ -44,6 +45,7 @@ public class ProfileRuleQuery {
private static final String PARAM_REPOSITORY_KEYS = "repositoryKeys";
private static final String PARAM_SEVERITIES = "severities";
private static final String PARAM_STATUSES = "statuses";
+ private static final String PARAM_INHERITANCE = "inheritance";
private int profileId;
private String language;
@@ -51,6 +53,7 @@ public class ProfileRuleQuery {
private List<String> repositoryKeys;
private List<String> severities;
private List<String> statuses;
+ private String inheritance;
private ProfileRuleQuery() {
repositoryKeys = Lists.newArrayList();
@@ -80,6 +83,9 @@ public class ProfileRuleQuery {
if (params.get(PARAM_STATUSES) != null) {
result.addStatuses(optionalVarargs(params.get(PARAM_STATUSES)));
}
+ if (params.containsKey(PARAM_INHERITANCE)) {
+ result.setInheritance((String) params.get(PARAM_INHERITANCE));
+ }
if (!errors.isEmpty()) {
throw BadRequestException.of("Incorrect rule search parameters", errors);
@@ -128,6 +134,12 @@ public class ProfileRuleQuery {
return this;
}
+ public ProfileRuleQuery setInheritance(String inheritance) {
+ this.inheritance = inheritance;
+ return this;
+ }
+
+
public int profileId() {
return profileId;
}
@@ -154,6 +166,11 @@ public class ProfileRuleQuery {
return ImmutableList.copyOf(statuses);
}
+ @CheckForNull
+ public String inheritance() {
+ return inheritance;
+ }
+
private static String[] optionalVarargs(Object jRubyArray) {
List<String> items = RubyUtils.toStrings(jRubyArray);
String[] empty = new String[0];
diff --git a/sonar-server/src/main/java/org/sonar/server/rule/ProfileRules.java b/sonar-server/src/main/java/org/sonar/server/rule/ProfileRules.java
index 0402d82a117..64bafb28dc9 100644
--- a/sonar-server/src/main/java/org/sonar/server/rule/ProfileRules.java
+++ b/sonar-server/src/main/java/org/sonar/server/rule/ProfileRules.java
@@ -158,12 +158,20 @@ public class ProfileRules implements ServerExtension {
hasParentFilter(TYPE_RULE, parentRuleFilter(query))
);
addMustTermOrTerms(filter, ActiveRuleDocument.FIELD_SEVERITY, query.severities());
+ String inheritance = query.inheritance();
+ if (inheritance != null) {
+ addMustTermOrTerms(filter, ActiveRuleDocument.FIELD_INHERITANCE, newArrayList(inheritance));
+ }
return filter;
}
public long countProfileRules(ProfileRuleQuery query) {
- return index.executeCount(index.client().prepareCount(INDEX_RULES).setTypes(TYPE_ACTIVE_RULE)
- .setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), activeRuleFilter(query))));
+ return index.executeCount(
+ index.client()
+ .prepareCount(INDEX_RULES)
+ .setTypes(TYPE_ACTIVE_RULE)
+ .setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), activeRuleFilter(query)))
+ );
}
public long countInactiveProfileRules(ProfileRuleQuery query) {
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb
index b4bce6d2c83..cab5e63475a 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb
@@ -180,10 +180,15 @@ class ProfilesController < ApplicationController
# GET /profiles/inheritance?id=<profile id>
def inheritance
require_parameters 'id'
- @profile = Profile.find(params[:id])
- profiles=Profile.all(:conditions => ['language=? and id<>? and (parent_name is null or parent_name<>?)', @profile.language, @profile.id, @profile.name], :order => 'name')
- @select_parent = [[message('none'), nil]] + profiles.collect { |profile| [profile.name, profile.name] }
+ call_backend do
+ @profile = Internal.quality_profiles.profile(params[:id].to_i)
+ @ancestors = Internal.quality_profiles.ancestors(@profile).to_a
+ @children = Internal.quality_profiles.children(@profile).to_a
+ profiles = Internal.quality_profiles.profilesByLanguage(@profile.language()).to_a.reject{|p| p.id == @profile.id() || p.parent() == @profile.name()}
+ profiles = Api::Utils.insensitive_sort(profiles) { |p| p.name()}
+ @select_parent = [[message('none'), nil]] + profiles.collect { |profile| [profile.name(), profile.name()] }
+ end
set_profile_breadcrumbs
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/profiles_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/profiles_helper.rb
index eb019e18398..71df4bfae66 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/profiles_helper.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/profiles_helper.rb
@@ -23,10 +23,11 @@ module ProfilesHelper
controller.java_facade.getLanguages()
end
- def label_for_rules_count(profile)
- label="#{profile.count_active_rules} #{message('rules').downcase}"
+ def label_for_rules_count(qProfile)
+ profile_rules_count = profile_rules_count(qProfile)
+ label = "#{profile_rules_count} #{message('rules').downcase}"
- count_overriding=profile.count_overriding_rules
+ count_overriding = Internal.quality_profiles.countOverridingProfileRules(qProfile).to_i
if count_overriding>0
label += message('quality_profiles.including_x_overriding.suffix', :params => count_overriding)
label += image_tag('overrides.png')
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/inheritance.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/inheritance.html.erb
index 06cb2996288..806111b245c 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/inheritance.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/inheritance.html.erb
@@ -7,19 +7,19 @@
<tr>
<td align="center" valign="top">
<div>
- <% @profile.ancestors.reverse.each do |parent| %>
- <a href="<%= url_for :action => 'inheritance', :id => parent.id -%>"><%= parent.name -%></a>
+ <% @ancestors.reverse.each do |parent| %>
+ <a href="<%= url_for :action => 'inheritance', :id => parent.id() -%>"><%= parent.name() -%></a>
<span class="note">(<%= label_for_rules_count(parent) -%>)</span><br/>
<%= image_tag 'blue-up.png' -%><br/>
<% end %>
<b><%= @profile.name -%></b> <span class="note">(<%= label_for_rules_count(@profile) -%>)</span><br/>
- <% if @profile.children.size>0 %>
+ <% if @children.size>0 %>
<%= image_tag 'blue-up.png' -%><br/>
- <% @profile.children.each_with_index do |child,index| %>
+ <% @children.each_with_index do |child,index| %>
<%= ', ' if index>0 -%>
- <a href="<%= url_for :action => 'inheritance', :id => child.id -%>"><%= child.name -%></a>
+ <a href="<%= url_for :action => 'inheritance', :id => child.id() -%>"><%= child.name() -%></a>
<span class="note">(<%= label_for_rules_count(child) -%>)</span>
<% end %>
<br/><%= image_tag 'blue-up.png' -%><br/>
@@ -33,8 +33,8 @@
<h3><%= message('quality_profiles.set_parent') -%>:</h3>
<p><%= message('quality_profiles.inherit_rules_from_profile') -%>:</p>
<% form_tag({:action => 'change_parent'}, {:method => 'post'}) do %>
- <%= hidden_field_tag "id", @profile.id %>
- <%= select_tag "parent_name", options_for_select(@select_parent, @profile.parent_name) %>
+ <%= hidden_field_tag "id", @profile.id() %>
+ <%= select_tag "parent_name", options_for_select(@select_parent, @profile.parent()) %>
<%= submit_tag message('change_verb'), :id => 'submit_parent'%>
<% end %>
</div>