From: Julien Lancelot Date: Mon, 23 Dec 2013 16:49:25 +0000 (+0100) Subject: SONAR-4535 Use new Java facade when loading rule template creation form X-Git-Tag: 4.2~857 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f637ca8550225ba9e1c46799f4dbead18d90bf8f;p=sonarqube.git SONAR-4535 Use new Java facade when loading rule template creation form --- diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileOperations.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileOperations.java index 580f97e153e..e0db7f23174 100644 --- a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileOperations.java +++ b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileOperations.java @@ -72,7 +72,6 @@ public class QProfileOperations implements ServerComponent { private final List importers; private final PreviewCache dryRunCache; private final RuleRegistry ruleRegistry; - private final ProfileRules profileRules; private final ProfilesManager profilesManager; private final System2 system; @@ -83,20 +82,20 @@ public class QProfileOperations implements ServerComponent { public QProfileOperations(MyBatis myBatis, QualityProfileDao dao, ActiveRuleDao activeRuleDao, RuleDao ruleDao, PropertiesDao propertiesDao, PreviewCache dryRunCache, RuleRegistry ruleRegistry, ProfilesManager profilesManager, ProfileRules profileRules) { this(myBatis, dao, activeRuleDao, ruleDao, propertiesDao, Lists.newArrayList(), dryRunCache, ruleRegistry, - profilesManager, profileRules, System2.INSTANCE); + profilesManager, System2.INSTANCE); } public QProfileOperations(MyBatis myBatis, QualityProfileDao dao, ActiveRuleDao activeRuleDao, RuleDao ruleDao, PropertiesDao propertiesDao, List importers, PreviewCache dryRunCache, RuleRegistry ruleRegistry, ProfilesManager profilesManager, ProfileRules profileRules) { this(myBatis, dao, activeRuleDao, ruleDao, propertiesDao, Lists.newArrayList(), dryRunCache, ruleRegistry, - profilesManager, profileRules, System2.INSTANCE); + profilesManager, System2.INSTANCE); } @VisibleForTesting QProfileOperations(MyBatis myBatis, QualityProfileDao dao, ActiveRuleDao activeRuleDao, RuleDao ruleDao, PropertiesDao propertiesDao, List importers, PreviewCache dryRunCache, RuleRegistry ruleRegistry, - ProfilesManager profilesManager, ProfileRules profileRules, System2 system) { + ProfilesManager profilesManager, System2 system) { this.myBatis = myBatis; this.dao = dao; this.activeRuleDao = activeRuleDao; @@ -106,7 +105,6 @@ public class QProfileOperations implements ServerComponent { this.dryRunCache = dryRunCache; this.ruleRegistry = ruleRegistry; this.profilesManager = profilesManager; - this.profileRules = profileRules; this.system = system; } 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 b7e93b3ea50..15c248838be 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 @@ -86,8 +86,6 @@ public class QProfiles implements ServerComponent { // ACTIVE RULES // bulk activate all // bulk deactivate all - // update note on an active rule (only E/S indexing) - // delete note on an active rule (only E/S indexing) // extends extension of a rule (only E/S indexing) // revert modification on active rule with inheritance // active rule parameter validation (only Integer types are checked) @@ -280,6 +278,8 @@ public class QProfiles implements ServerComponent { return rules.getFromActiveRuleId(activeRule.getId()); } + // RULES + public QProfileRule updateRuleNote(int activeRuleId, int ruleId, String note) { RuleDto rule = findRuleNotNull(ruleId); String sanitizedNote = Strings.emptyToNull(note); @@ -292,6 +292,12 @@ public class QProfiles implements ServerComponent { return rules.getFromActiveRuleId(activeRule.getId()); } + @CheckForNull + public QProfileRule rule(int ruleId) { +// "".indexOf(); + return rules.getFromRuleId(ruleId); + } + // // Quality profile validation diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/new_rules_configuration_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/new_rules_configuration_controller.rb index 3031eb2f1a5..4e5e312ca86 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/new_rules_configuration_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/new_rules_configuration_controller.rb @@ -143,12 +143,12 @@ class NewRulesConfigurationController < ApplicationController # def new # form to duplicate a rule - access_denied unless has_role?(:profileadmin) require_parameters :id, :rule_id - @profile = Profile.find(params[:id].to_i) - add_breadcrumbs ProfilesController::root_breadcrumb, Api::Utils.language_name(@profile.language), {:name => @profile.name, :url => {:controller => 'new_rules_configuration', :action => 'index', :id => @profile.id}} + @profile = Internal.quality_profiles.profile(params[:id].to_i) + add_breadcrumbs ProfilesController::root_breadcrumb, Api::Utils.language_name(@profile.language), + {:name => @profile.name, :url => {:controller => 'new_rules_configuration', :action => 'index', :id => @profile.id}} - @rule = Rule.find(params[:rule_id]) + @rule = Internal.quality_profiles.rule(params[:rule_id].to_i) end # diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/new_rules_configuration_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/new_rules_configuration_helper.rb index c88190b7fa9..448c873bf49 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/new_rules_configuration_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/new_rules_configuration_helper.rb @@ -48,9 +48,9 @@ module NewRulesConfigurationHelper end def param_value_input(rule, parameter, value, options = {}) - type=type_with_compatibility(parameter.type) + type = type_with_compatibility(parameter.type().to_s) name = options[:name] || 'value' - property_input_field name, type, value, 'WIDGET', {:id => "#{rule.id}#{parameter.key}", :size => options[:size] }.update(options) + property_input_field name, type, value, 'WIDGET', {:id => "#{rule.id().to_s}#{parameter.key().to_s}", :size => options[:size] }.update(options) end def is_set(type) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/new.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/new.html.erb index c767c2059fd..14d4f99aa39 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/new.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/new.html.erb @@ -24,15 +24,18 @@ - <% @rule.parameters.sort{|x,y| x.name <=> y.name}.each do |parameter| %> - - <%= parameter.name %>: - - - <%= param_value_input(parameter, "", {:name => "rule_param[#{h parameter.name}]", :size => '80x10'}) -%> - <%= h parameter.description %> - - + <% if @rule.params && @rule.params.to_a.size > 0 %> + <% @rule.params.to_a.sort{|x,y| x.key() <=> y.key()}.each do |parameter| %> + <% puts "### parameter : " + parameter.inspect %> + + <%= parameter.key() %>: + + + <%= param_value_input(@rule, parameter, "", {:name => "rule_param[#{h parameter.key()}]", :size => '80x10'}) -%> + <%= h parameter.description() %> + + + <% end %> <% end %> <%= message('description') -%>: diff --git a/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileOperationsTest.java b/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileOperationsTest.java index 8ee0f0bce06..c467845b7d2 100644 --- a/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileOperationsTest.java +++ b/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileOperationsTest.java @@ -54,7 +54,6 @@ import org.sonar.core.rule.RuleParamDto; import org.sonar.server.configuration.ProfilesManager; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.ForbiddenException; -import org.sonar.server.rule.ProfileRules; import org.sonar.server.rule.RuleRegistry; import org.sonar.server.user.MockUserSession; import org.sonar.server.user.UserSession; @@ -103,9 +102,6 @@ public class QProfileOperationsTest { @Mock RuleRegistry ruleRegistry; - @Mock - ProfileRules profileRules; - @Mock ProfilesManager profilesManager; @@ -136,7 +132,7 @@ public class QProfileOperationsTest { }).when(activeRuleDao).insert(any(ActiveRuleDto.class), any(SqlSession.class)); operations = new QProfileOperations(myBatis, qualityProfileDao, activeRuleDao, ruleDao, propertiesDao, importers, dryRunCache, ruleRegistry, profilesManager, - profileRules, system); + system); } @Test @@ -259,7 +255,6 @@ public class QProfileOperationsTest { QualityProfileDto qualityProfile = new QualityProfileDto().setId(1).setName("My profile").setLanguage("java"); RuleDto rule = new RuleDto().setId(10).setRepositoryKey("squid").setRuleKey("AvoidCycle"); when(ruleDao.selectParameters(eq(10), eq(session))).thenReturn(newArrayList(new RuleParamDto().setId(20).setName("max").setDefaultValue("10"))); - when(profileRules.getFromActiveRuleId(anyInt())).thenReturn(mock(QProfileRule.class)); final int idActiveRuleToUpdate = 42; final int idActiveRuleToDelete = 24; RuleInheritanceActions inheritanceActions = new RuleInheritanceActions() @@ -293,7 +288,6 @@ public class QProfileOperationsTest { Rule rule = Rule.create().setRepositoryKey("squid").setKey("AvoidCycle"); rule.setId(10); ActiveRuleDto activeRule = new ActiveRuleDto().setId(5).setProfileId(1).setRuleId(10).setSeverity(1); - when(profileRules.getFromActiveRuleId(anyInt())).thenReturn(mock(QProfileRule.class)); when(profilesManager.ruleSeverityChanged(eq(1), eq(5), eq(RulePriority.MINOR), eq(RulePriority.MAJOR), eq("Nicolas"))).thenReturn(new RuleInheritanceActions()); operations.updateSeverity(qualityProfile, activeRule, Severity.MAJOR, authorizedUserSession); @@ -325,7 +319,6 @@ public class QProfileOperationsTest { public void deactivate_rule() throws Exception { ActiveRuleDto activeRule = new ActiveRuleDto().setId(5).setProfileId(1).setRuleId(10).setSeverity(1); when(activeRuleDao.selectByProfileAndRule(1, 10)).thenReturn(activeRule); - when(profileRules.getFromRuleId(anyInt())).thenReturn(mock(QProfileRule.class)); when(profilesManager.deactivated(eq(1), anyInt(), eq("Nicolas"))).thenReturn(new RuleInheritanceActions()); operations.deactivateRule(activeRule, authorizedUserSession); diff --git a/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfilesTest.java b/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfilesTest.java index 488f8063574..186cee57e53 100644 --- a/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfilesTest.java +++ b/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfilesTest.java @@ -332,7 +332,6 @@ public class QProfilesTest { when(qualityProfileDao.selectById(1)).thenReturn(qualityProfile); QProfileRule rule = mock(QProfileRule.class); when(rule.id()).thenReturn(10); - when(rules.getFromRuleId(10)).thenReturn(null); try { qProfiles.activateRule(1, 10, Severity.BLOCKER); @@ -529,4 +528,11 @@ public class QProfilesTest { verify(service).deleteRuleNote(eq(rule), any(UserSession.class)); } + @Test + public void get_rule_from_id() throws Exception { + qProfiles.rule(10); + + verify(rules).getFromRuleId(10); + } + }