import org.sonar.server.util.Validation;
import javax.annotation.CheckForNull;
+
import java.util.List;
import java.util.Map;
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");
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
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
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
<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? %>