]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4535 Use new Java facade when loading rule template creation form
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 23 Dec 2013 16:49:25 +0000 (17:49 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 23 Dec 2013 16:49:25 +0000 (17:49 +0100)
sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileOperations.java
sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfiles.java
sonar-server/src/main/webapp/WEB-INF/app/controllers/new_rules_configuration_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/helpers/new_rules_configuration_helper.rb
sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/new.html.erb
sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileOperationsTest.java
sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfilesTest.java

index 580f97e153e9bef4e827e3360610196a4fd22dbe..e0db7f231745dc78caaed851eee9443792c570a4 100644 (file)
@@ -72,7 +72,6 @@ public class QProfileOperations implements ServerComponent {
   private final List<ProfileImporter> 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.<ProfileImporter>newArrayList(), dryRunCache, ruleRegistry,
-      profilesManager, profileRules, System2.INSTANCE);
+      profilesManager, System2.INSTANCE);
   }
 
   public QProfileOperations(MyBatis myBatis, QualityProfileDao dao, ActiveRuleDao activeRuleDao, RuleDao ruleDao, PropertiesDao propertiesDao,
                             List<ProfileImporter> importers, PreviewCache dryRunCache, RuleRegistry ruleRegistry,
                             ProfilesManager profilesManager, ProfileRules profileRules) {
     this(myBatis, dao, activeRuleDao, ruleDao, propertiesDao, Lists.<ProfileImporter>newArrayList(), dryRunCache, ruleRegistry,
-      profilesManager, profileRules, System2.INSTANCE);
+      profilesManager, System2.INSTANCE);
   }
 
   @VisibleForTesting
   QProfileOperations(MyBatis myBatis, QualityProfileDao dao, ActiveRuleDao activeRuleDao, RuleDao ruleDao, PropertiesDao propertiesDao,
                      List<ProfileImporter> 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;
   }
 
index b7e93b3ea50e933895c267ba00b23441977995a9..15c248838bef67e3e244185bc2a2e050e667a4cf 100644 (file)
@@ -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
index 3031eb2f1a5b14392ac450eb820f87d53f038850..4e5e312ca861e82e713b90b5dad9901e66a7b42a 100644 (file)
@@ -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
 
   #
index c88190b7fa91276bfab1d450728ad9802af6aaf8..448c873bf49431976967f5acc80b32bebacf7728 100644 (file)
@@ -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)
index c767c2059fd19a509e8fa339ace085d3c219f841..14d4f99aa39da95be42db12f3a5fdfe0b805f075 100644 (file)
       </select>
     </td>
   </tr>
-  <% @rule.parameters.sort{|x,y| x.name <=> y.name}.each do |parameter| %>
-    <tr>
-      <td width="1%" nowrap><%= parameter.name %>:</td>
-      <td class="sep"> </td>
-      <td>
-        <%= param_value_input(parameter, "", {:name => "rule_param[#{h parameter.name}]", :size => '80x10'}) -%>
-        <span class="small"><%= h parameter.description %></span>
-      </td>
-    </tr>
+  <% 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 %>
+      <tr>
+        <td width="1%" nowrap><%= parameter.key() %>:</td>
+        <td class="sep"> </td>
+        <td>
+          <%= param_value_input(@rule, parameter, "", {:name => "rule_param[#{h parameter.key()}]", :size => '80x10'}) -%>
+          <span class="small"><%= h parameter.description() %></span>
+        </td>
+      </tr>
+    <% end %>
   <% end %>
   <tr>
     <td width="1%" nowrap style="vertical-align: top"><%= message('description') -%>:</td>
index 8ee0f0bce0655476e3b38bdda0d3bc1936bcc167..c467845b7d2eefe1214710855749b7bda4852d7f 100644 (file)
@@ -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);
index 488f80635743506e0a05e76520af670584e5db88..186cee57e53dffcd3a683218e524b999994adee3 100644 (file)
@@ -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);
+  }
+
 }