]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5007 Fix display of active rules in Profile inheritance page
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 18 Jun 2014 16:20:21 +0000 (18:20 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 18 Jun 2014 16:20:21 +0000 (18:20 +0200)
sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfiles.java
sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/helpers/profiles_helper.rb
sonar-server/src/main/webapp/WEB-INF/app/views/profiles/inheritance.html.erb

index cd688a375110e58dfbfead4a8a8d3c27666ee72c..b6baa8f657fdf82e29072de339d1ebd6f7f3eacc 100644 (file)
@@ -28,6 +28,7 @@ import org.sonar.server.user.UserSession;
 import org.sonar.server.util.Validation;
 
 import javax.annotation.CheckForNull;
+
 import java.util.List;
 import java.util.Map;
 
@@ -132,19 +133,6 @@ public class QProfiles implements ServerComponent {
     projectOperations.removeAllProjects(profileId, UserSession.get());
   }
 
-
-  // PROFILE RULES
-  public long countProfileRules(QProfile profile) {
-    // TODO
-    return -1;
-  }
-
-  public long countOverridingProfileRules(QProfile profile) {
-    // TODO
-    return -1;
-    //return rules.countProfileRules(ProfileRuleQuery.create(profile.id()).setInheritance(QProfileRule.OVERRIDES));
-  }
-
   private void checkProfileNameParam(String name) {
     if (Strings.isNullOrEmpty(name)) {
       throw new BadRequestException("quality_profiles.please_type_profile_name");
index 0be0572ec01962fb594608c21e92bb83a62d2bd0..d309b1053583038eea97265ad498d1f6f7ad7cba 100644 (file)
@@ -222,6 +222,8 @@ class ProfilesController < ApplicationController
       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.id()] }
+
+      @all_profile_stats = Internal.component(Java::OrgSonarServerQualityprofile::QProfileService.java_class).getAllProfileStats()
     end
 
     set_profile_breadcrumbs
index 156f964835164f279de4556329a847c4aaf62d43..280eaf1331d6791a5ff71a3dea85e6032c9fc71e 100644 (file)
@@ -23,12 +23,13 @@ module ProfilesHelper
     controller.java_facade.getLanguages()
   end
 
-  def label_for_rules_count(qProfile)
-    profile_rules_count = profile_rules_count(qProfile)
+  def label_for_rules_count(qProfile, all_profile_stats)
+    profile_stat = all_profile_stats[qProfile.key()]
+    profile_rules_count = profile_rules_count(qProfile, profile_stat)
     label = "#{profile_rules_count} #{message('rules').downcase}"
 
-    count_overriding = Internal.quality_profiles.countOverridingProfileRules(qProfile).to_i
-    if count_overriding>0
+    count_overriding = overriding_rules_count(profile_stat)
+    if count_overriding && count_overriding>0
       label += message('quality_profiles.including_x_overriding.suffix', :params => count_overriding)
       label += image_tag('overrides.png')
     end
@@ -55,7 +56,14 @@ module ProfilesHelper
     Internal.quality_profiles.countProjects(qProfile).to_i
   end
 
-  def profile_rules_count(qProfile)
-    Internal.quality_profiles.countProfileRules(qProfile).to_i
+  def profile_rules_count(qProfile, profile_stat)
+    count = 0
+    count = profile_stat.get('countActiveRules').get(0).getValue() if profile_stat && profile_stat.get('countActiveRules')
+    count
+  end
+
+  def overriding_rules_count(profile_stat)
+    inheritance_stats = Hash[ *profile_stat.get('inheritance').collect { |v| [ v.getKey(), v ] }.flatten ] if profile_stat
+    inheritance_stats['OVERRIDES'].getValue().to_i if inheritance_stats['OVERRIDES']
   end
 end
index 8ec69c3fe3a9c1520c7b0916711a40a4968d8dba..eb6831e481bee9c28e96f7c3dcfa773da045de58 100644 (file)
@@ -7,24 +7,24 @@
     <tr>
       <td align="center"  valign="top">
         <div>
-            <% @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 %>
+          <% @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, @all_profile_stats) -%>)</span><br/>
+            <%= image_tag 'blue-up.png' -%><br/>
+          <% end %>
 
-            <b><%= @profile.name -%></b> <span class="note">(<%= label_for_rules_count(@profile) -%>)</span><br/>
+          <b><%= @profile.name -%></b> <span class="note">(<%= label_for_rules_count(@profile, @all_profile_stats) -%>)</span><br/>
 
-            <% if @children.size>0 %>
-              <%= image_tag 'blue-up.png' -%><br/>
-              <% @children.each_with_index do |child,index| %>
-                <%= ', ' if index>0 -%>
-                <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/>
-              ...
+          <% if @children.size>0 %>
+            <%= image_tag 'blue-up.png' -%><br/>
+            <% @children.each_with_index do |child,index| %>
+              <%= ', ' if index>0 -%>
+              <a href="<%= url_for :action => 'inheritance', :id => child.id() -%>"><%= child.name() -%></a>
+              <span class="note">(<%= label_for_rules_count(child, @all_profile_stats) -%>)</span>
             <% end %>
+            <br/><%= image_tag 'blue-up.png' -%><br/>
+            ...
+          <% end %>
           </div>
       </td>
      <% if profiles_administrator? %>