]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4923 Switch "Coding Rules reloaded" with "Coding Rules" (and previous "Coding...
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 15 Jan 2014 18:04:35 +0000 (19:04 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 15 Jan 2014 18:04:35 +0000 (19:04 +0100)
35 files changed:
sonar-server/src/main/java/org/sonar/server/platform/Platform.java
sonar-server/src/main/java/org/sonar/server/util/StringTypeValidation.java [new file with mode: 0644]
sonar-server/src/main/java/org/sonar/server/util/TextTypeValidation.java [new file with mode: 0644]
sonar-server/src/main/java/org/sonar/server/util/TypeValidations.java
sonar-server/src/main/webapp/WEB-INF/app/controllers/new_rules_configuration_controller.rb [deleted file]
sonar-server/src/main/webapp/WEB-INF/app/controllers/old_rules_configuration_controller.rb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/controllers/rules_configuration_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/helpers/new_rules_configuration_helper.rb [deleted file]
sonar-server/src/main/webapp/WEB-INF/app/helpers/old_rules_configuration_helper.rb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/helpers/rules_configuration_helper.rb
sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/_active_rule_note.html.erb [deleted file]
sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/_rule.html.erb [deleted file]
sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/_rule_note.html.erb [deleted file]
sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/_rule_param.html.erb [deleted file]
sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/edit.html.erb [deleted file]
sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/index.html.erb [deleted file]
sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/new.html.erb [deleted file]
sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/_active_rule_note.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/_rule.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/_rule_note.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/_rule_param.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/edit.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/index.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/new.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_tabs.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_active_rule_note.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule_note.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule_param.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/edit.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/index.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/new.html.erb
sonar-server/src/test/java/org/sonar/server/util/StringTypeValidationTest.java [new file with mode: 0644]
sonar-server/src/test/java/org/sonar/server/util/TextTypeValidationTest.java [new file with mode: 0644]
sonar-server/src/test/java/org/sonar/server/util/TypeValidationsTest.java

index 7c01ff6da0ce4677cab498399957c4484616d8d3..97e0e29544c2e9e9b4786f29b57c725d257f0094 100644 (file)
@@ -362,6 +362,8 @@ public final class Platform {
     servicesContainer.addSingleton(IntegerTypeValidation.class);
     servicesContainer.addSingleton(FloatTypeValidation.class);
     servicesContainer.addSingleton(BooleanTypeValidation.class);
+    servicesContainer.addSingleton(TextTypeValidation.class);
+    servicesContainer.addSingleton(StringTypeValidation.class);
     servicesContainer.addSingleton(StringListTypeValidation.class);
 
     ServerExtensionInstaller extensionRegistrar = servicesContainer.getComponentByType(ServerExtensionInstaller.class);
diff --git a/sonar-server/src/main/java/org/sonar/server/util/StringTypeValidation.java b/sonar-server/src/main/java/org/sonar/server/util/StringTypeValidation.java
new file mode 100644 (file)
index 0000000..ac33ffd
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+package org.sonar.server.util;
+
+import org.sonar.api.PropertyType;
+
+import java.util.List;
+
+public class StringTypeValidation implements TypeValidation {
+
+  @Override
+  public String key() {
+    return PropertyType.STRING.name();
+  }
+
+  @Override
+  public void validate(String value, List<String> options) {
+    // Nothing to do
+  }
+
+}
diff --git a/sonar-server/src/main/java/org/sonar/server/util/TextTypeValidation.java b/sonar-server/src/main/java/org/sonar/server/util/TextTypeValidation.java
new file mode 100644 (file)
index 0000000..c4e9df5
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+package org.sonar.server.util;
+
+import org.sonar.api.PropertyType;
+
+import java.util.List;
+
+public class TextTypeValidation implements TypeValidation {
+
+  @Override
+  public String key() {
+    return PropertyType.TEXT.name();
+  }
+
+  @Override
+  public void validate(String value, List<String> options) {
+    // Nothing to do
+  }
+
+}
index 5c28b425714bfb96db7f3187b493086e8ef2200c..e3b9e84b080923e5b5bdeff99379d031acb665cc 100644 (file)
@@ -23,6 +23,7 @@ package org.sonar.server.util;
 import com.google.common.base.Predicate;
 import com.google.common.collect.Iterables;
 import org.sonar.api.ServerComponent;
+import org.sonar.server.exceptions.BadRequestException;
 
 import java.util.List;
 
@@ -40,11 +41,15 @@ public class TypeValidations implements ServerComponent {
   }
 
   private TypeValidation findByKey(final String key) {
-    return Iterables.find(typeValidationList, new Predicate<TypeValidation>() {
+    TypeValidation typeValidation = Iterables.find(typeValidationList, new Predicate<TypeValidation>() {
       @Override
       public boolean apply(TypeValidation input) {
         return input.key().equals(key);
       }
-    });
+    }, null);
+    if (typeValidation == null) {
+      throw new BadRequestException(String.format("Type '%s' is not valid.", key));
+    }
+    return typeValidation;
   }
 }
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
deleted file mode 100644 (file)
index 13a808a..0000000
+++ /dev/null
@@ -1,372 +0,0 @@
-#
-# SonarQube, open source software quality management tool.
-# Copyright (C) 2008-2013 SonarSource
-# mailto:contact AT sonarsource DOT com
-#
-# SonarQube is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 3 of the License, or (at your option) any later version.
-#
-# SonarQube is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this program; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-#
-require 'cgi'
-require 'java'
-
-class NewRulesConfigurationController < ApplicationController
-
-  SECTION=Navigation::SECTION_QUALITY_PROFILES
-
-  STATUS_ACTIVE = "ACTIVE"
-  STATUS_INACTIVE = "INACTIVE"
-
-  ANY_SELECTION = []
-  RULE_PRIORITIES = Sonar::RulePriority.as_options.reverse
-
-  def index
-    require_parameters :id
-
-    call_backend do
-      @profile = Internal.quality_profiles.profile(params[:id].to_i)
-      @parent_profile = Internal.quality_profiles.parent(@profile) if @profile.parent()
-
-      add_breadcrumbs ProfilesController::root_breadcrumb, Api::Utils.language_name(@profile.language),
-                      {:name => @profile.name, :url => {:controller => 'new_rules_configuration', :action => 'index', :id => @profile.id}}
-
-      init_params
-      @criteria_params = criteria_params
-      stop_watch = Internal.profiling.start("rules", "BASIC")
-
-      @pagination = Api::Pagination.new(params)
-      paging = Java::OrgSonarServerQualityprofile::Paging.create(@pagination.per_page.to_i, @pagination.page.to_i)
-
-      criteria = init_criteria
-      query = Java::OrgSonarServerRule::ProfileRuleQuery::parse(criteria.to_java)
-      if @activation==STATUS_ACTIVE
-        result = Internal.quality_profiles.searchProfileRules(query, paging)
-      else
-        result = Internal.quality_profiles.searchInactiveProfileRules(query, paging)
-      end
-
-      @pagination.count = result.paging.total
-      unless @searchtext.blank?
-        if @activation==STATUS_ACTIVE
-          @hidden_inactives = Internal.quality_profiles.countProfileRules(query)
-        else
-          @hidden_actives = Internal.quality_profiles.countInactiveProfileRules(query)
-        end
-      end
-      stop_watch.stop("found #{@pagination.count} rules with criteria #{criteria.to_json}, displaying #{@pagination.per_page} items")
-
-      @current_rules = result.rules
-
-      @select_repositories = ANY_SELECTION + java_facade.getRuleRepositoriesByLanguage(@profile.language).collect { |repo| [repo.name(), repo.key()] }
-      @select_priority = ANY_SELECTION + RULE_PRIORITIES
-      @select_activation = [[message('active'), STATUS_ACTIVE], [message('inactive'), STATUS_INACTIVE]]
-      @select_inheritance = [[message('any'), 'any'], [message('rules_configuration.not_inherited'), 'NOT'], [message('rules_configuration.inherited'), 'INHERITED'],
-                             [message('rules_configuration.overrides'), 'OVERRIDES']]
-      @select_status = ANY_SELECTION + [[message('rules.status.beta'), Rule::STATUS_BETA],
-                                        [message('rules.status.deprecated'), Rule::STATUS_DEPRECATED],
-                                        [message('rules.status.ready'), Rule::STATUS_READY]]
-      @select_sort_by = [[message('rules_configuration.rule_name'), Rule::SORT_BY_RULE_NAME], [message('rules_configuration.creation_date'), Rule::SORT_BY_CREATION_DATE]]
-    end
-  end
-
-
-  #
-  #
-  # POST /rules_configuration/revert_rule?id=<profile id>&active_rule_id=<active rule id>
-  #
-  #
-  def revert_rule
-    verify_post_request
-    require_parameters :id, :active_rule_id
-
-    active_rule_id = params[:active_rule_id].to_i
-    call_backend do
-      Internal.quality_profiles.revertActiveRule(active_rule_id)
-    end
-
-    redirect_to request.query_parameters.merge({:action => 'index', :id => params[:id].to_i, :commit => nil})
-  end
-
-
-  #
-  #
-  # POST /rules_configuration/activate_rule?id=<profile id>&rule_id=<rule id>&level=<priority>
-  #
-  # If the parameter "level" is blank or null, then the rule is removed from the profile.
-  #
-  #
-  def activate_rule
-    verify_post_request
-    require_parameters :id, :rule_id
-
-    rule = nil
-    profile_id = params[:id].to_i
-    rule_id = params[:rule_id].to_i
-    call_backend do
-      severity = params[:level]
-      if severity.blank?
-        # deactivate the rule
-        Internal.quality_profiles.deactivateRule(profile_id, rule_id)
-        rule = Internal.quality_profiles.findByRule(rule_id)
-      else
-        # activate the rule
-        Internal.quality_profiles.activateRule(profile_id, rule_id, severity)
-        rule = Internal.quality_profiles.findByProfileAndRule(profile_id, rule_id)
-      end
-    end
-
-    profile = Internal.quality_profiles.profile(profile_id)
-    parent_profile = Internal.quality_profiles.parent(profile)
-
-    render :update do |page|
-      page.replace_html("rule_#{rule.id}", :partial => 'rule', :object => rule, :locals => {:rule => rule, :profile => profile, :parent_profile => parent_profile})
-      page.assign('localModifications', true)
-    end
-  end
-
-
-  #
-  #
-  # GET /rules_configuration/new/<profile id>?rule_id=<rule id>
-  #
-  #
-  def new
-    # form to duplicate a rule
-    require_parameters :id, :rule_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 = Internal.quality_profiles.rule(params[:rule_id].to_i)
-  end
-
-  #
-  #
-  # POST /rules_configuration/create/<profile id>?rule_id=<rule id>&rule[name]=<new name>&...
-  #
-  #
-  def create
-    verify_post_request
-    require_parameters :id, :rule_id
-
-    profile_id = params[:id].to_i
-    rule_id = params[:rule_id].to_i
-    new_rule = nil
-    call_backend do
-      new_rule = Internal.quality_profiles.createRule(rule_id, params[:rule][:name], params[:rule][:priority], params[:rule][:description], params[:rule_param])
-    end
-
-    if new_rule
-      redirect_to :action => 'index', :id => profile_id, :searchtext => "\"#{new_rule.name()}\"", :rule_activation => 'INACTIVE', "plugins[]" => new_rule.repositoryKey()
-    else
-      redirect_to :action => 'new', :id => profile_id, :rule_id => rule_id
-    end
-  end
-
-
-  # deprecated since 2.3
-  def export
-    redirect_to request.query_parameters.merge({:controller => 'profiles', :action => 'export'})
-  end
-
-  #
-  #
-  # GET /rules_configuration/new/<profile id>?rule_id=<rule id>
-  #
-  #
-  def edit
-    # form to edit a rule
-    require_parameters :id, :rule_id
-
-    call_backend do
-      @profile = Internal.quality_profiles.profile(params[:id].to_i)
-      @rule = Internal.quality_profiles.rule(params[:rule_id].to_i)
-      if @rule.ruleId().nil?
-        redirect_to :action => 'index', :id => params[:id]
-      else
-        @parent_rule = Internal.quality_profiles.rule(@rule.ruleId())
-        @active_rules = Internal.quality_profiles.countActiveRules(@rule)
-      end
-    end
-  end
-
-  #
-  #
-  # POST /rules_configuration/update/<profile id>?rule_id=<rule id>&rule[name]=<new name>&...
-  #
-  #
-  def update
-    verify_post_request
-    require_parameters :id, :rule_id
-
-    profile_id = params[:id].to_i
-    rule_id = params[:rule_id].to_i
-    rule = nil
-    call_backend do
-      rule = Internal.quality_profiles.updateRule(rule_id, params[:rule][:name], params[:rule][:priority], params[:rule][:description], params[:rule_param])
-    end
-
-    if rule
-      redirect_to :action => 'index', :id => profile_id, :searchtext => "\"#{rule.name()}\"", :rule_activation => '', "plugins[]" => rule.repositoryKey()
-    else
-      redirect_to :action => 'new', :id => profile_id, :rule_id => rule_id
-    end
-  end
-
-
-  #
-  #
-  # POST /rules_configuration/delete/<profile id>?rule_id=<rule id>
-  #
-  #
-  def delete
-    verify_post_request
-    require_parameters :id, :rule_id
-
-    call_backend do
-      Internal.quality_profiles.deleteRule(params[:rule_id].to_i)
-      flash[:notice]=message('rules_configuration.rule_deleted')
-    end
-    redirect_to :action => 'index', :id => params[:id]
-  end
-
-  #
-  #
-  # POST /rules_configuration/bulk_edit?id=<profile id>&&bulk_action=<action>
-  #
-  # Values of the parameter 'bulk_action' :
-  #   - 'activate' : activate all the selected rules with their default priority
-  #   - 'deactivate' : deactivate all the selected rules
-  #
-  #
-  def bulk_edit
-    verify_post_request
-    access_denied unless has_role?(:profileadmin)
-    require_parameters :id, :bulk_action
-
-    stop_watch = Internal.profiling.start("rules", "BASIC")
-    @profile = Internal.quality_profiles.profile(params[:id].to_i)
-    init_params
-    criteria = init_criteria
-    query = Java::OrgSonarServerRule::ProfileRuleQuery::parse(criteria.to_java)
-    activation = params[:rule_activation] || STATUS_ACTIVE
-    case params[:bulk_action]
-      when 'activate'
-        count = Internal.quality_profiles.bulkActivateRule(query)
-        stop_watch.stop("Activate #{count} rules with criteria #{criteria.to_json}")
-
-        flash[:notice]=message('rules_configuration.x_rules_have_been_activated', :params => count)
-        activation=STATUS_ACTIVE if activation==STATUS_INACTIVE
-
-      when 'deactivate'
-        count = Internal.quality_profiles.bulkDeactivateRule(query)
-        stop_watch.stop("Deactivate #{count} rules with criteria #{criteria.to_json}")
-
-        flash[:notice]=message('rules_configuration.x_rules_have_been_deactivated', :params => count)
-        activation=STATUS_INACTIVE if activation==STATUS_ACTIVE
-    end
-
-    url_parameters=request.query_parameters.merge({:action => 'index', :bulk_action => nil, :id => @profile.id, :rule_activation => activation})
-    redirect_to url_parameters
-  end
-
-
-  def update_param
-    verify_post_request
-
-    access_denied unless has_role?(:profileadmin)
-    require_parameters :param_id, :active_rule_id, :profile_id
-
-    rule = nil
-    profile_id = params[:profile_id].to_i
-    active_rule_id = params[:active_rule_id].to_i
-    call_backend do
-      Internal.quality_profiles.updateActiveRuleParam(active_rule_id, params[:param_id], params[:value])
-      rule = Internal.quality_profiles.findByActiveRuleId(active_rule_id)
-    end
-
-    profile = Internal.quality_profiles.profile(profile_id)
-    parent_profile = Internal.quality_profiles.parent(profile)
-    render :partial => 'rule', :locals => {:rule => rule, :profile => profile, :parent_profile => parent_profile}
-  end
-
-
-  def update_rule_note
-    verify_post_request
-    require_parameters :rule_id, :active_rule_id
-
-    rule = nil
-    call_backend do
-      rule = Internal.quality_profiles.updateRuleNote(params[:active_rule_id].to_i, params[:rule_id].to_i, params[:text])
-    end
-    render :partial => 'rule_note', :locals => {:rule => rule}
-  end
-
-
-  def update_active_rule_note
-    verify_post_request
-    require_parameters :active_rule_id, :note
-
-    rule = nil
-    call_backend do
-      rule = Internal.quality_profiles.updateActiveRuleNote(params[:active_rule_id].to_i, params[:note])
-    end
-    render :partial => 'active_rule_note', :locals => {:rule => rule}
-  end
-
-
-  def delete_active_rule_note
-    verify_post_request
-    require_parameters :active_rule_id
-
-    rule = nil
-    call_backend do
-      rule = Internal.quality_profiles.deleteActiveRuleNote(params[:active_rule_id].to_i)
-    end
-    render :partial => 'active_rule_note', :locals => {:rule => rule}
-  end
-
-
-  private
-
-  def init_params
-    @id = params[:id]
-    @priorities = filter_any(params[:priorities]) || ['']
-    @repositories = filter_any(params[:repositories]) || ['']
-    @activation = params[:rule_activation] || STATUS_ACTIVE
-    @inheritance = params[:inheritance] || 'any'
-    @status = params[:status]
-    @sort_by = !params[:sort_by].blank? ? params[:sort_by] : Rule::SORT_BY_RULE_NAME
-    @searchtext = params[:searchtext]
-  end
-
-  def filter_any(array)
-    if array && array.size>1 && array.include?('')
-      array=[''] #keep only 'any'
-    end
-    array
-  end
-
-  def init_criteria()
-    {"profileId" => @profile.id.to_i, "activation" => @activation, "severities" => @priorities, "inheritance" => @inheritance, "statuses" => @status,
-     "repositoryKeys" => @repositories, "nameOrKey" => @searchtext, "include_parameters_and_notes" => true, "language" => @profile.language, "sort_by" => @sort_by}
-  end
-
-  def criteria_params
-    new_params = params.clone
-    new_params.delete('controller')
-    new_params.delete('action')
-    new_params
-  end
-
-end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/old_rules_configuration_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/old_rules_configuration_controller.rb
new file mode 100644 (file)
index 0000000..ee3faeb
--- /dev/null
@@ -0,0 +1,446 @@
+#
+# SonarQube, open source software quality management tool.
+# Copyright (C) 2008-2013 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# SonarQube is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 3 of the License, or (at your option) any later version.
+#
+# SonarQube is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+#
+require 'cgi'
+
+class OldRulesConfigurationController < ApplicationController
+
+  SECTION=Navigation::SECTION_QUALITY_PROFILES
+
+  STATUS_ACTIVE = "ACTIVE"
+  STATUS_INACTIVE = "INACTIVE"
+
+  ANY_SELECTION = []
+  RULE_PRIORITIES = Sonar::RulePriority.as_options.reverse
+
+  def index
+    require_parameters :id
+
+    @profile = Profile.find(params[:id])
+    add_breadcrumbs ProfilesController::root_breadcrumb, Api::Utils.language_name(@profile.language),
+                    {:name => @profile.name, :url => {:controller => 'old_rules_configuration', :action => 'index', :id => @profile.id}}
+
+    init_params()
+
+    @select_repositories = ANY_SELECTION + java_facade.getRuleRepositoriesByLanguage(@profile.language).collect { |repo| [repo.name(), repo.key()] }.sort
+    @select_priority = ANY_SELECTION + RULE_PRIORITIES
+    @select_activation = [[message('any'), 'any'], [message('active'), STATUS_ACTIVE], [message('inactive'), STATUS_INACTIVE]]
+    @select_inheritance = [[message('any'), 'any'], [message('rules_configuration.not_inherited'), 'NOT'], [message('rules_configuration.inherited'), 'INHERITED'],
+                           [message('rules_configuration.overrides'), 'OVERRIDES']]
+    @select_status = ANY_SELECTION + [[message('rules.status.beta'), Rule::STATUS_BETA],
+                      [message('rules.status.deprecated'), Rule::STATUS_DEPRECATED],
+                      [message('rules.status.ready'), Rule::STATUS_READY]]
+    @select_sort_by = [[message('rules_configuration.rule_name'), Rule::SORT_BY_RULE_NAME], [message('rules_configuration.creation_date'), Rule::SORT_BY_CREATION_DATE]]
+
+    begin
+      stop_watch = Internal.profiling.start("rules", "BASIC")
+
+      criteria = {
+      :profile => @profile, :activation => @activation, :priorities => @priorities, :inheritance => @inheritance, :status => @status,
+      :repositories => @repositories, :searchtext => @searchtext, :include_parameters_and_notes => true, :language => @profile.language, :sort_by => @sort_by}
+      @rules = Rule.search(java_facade, criteria)
+
+      unless @searchtext.blank?
+        if @activation==STATUS_ACTIVE
+          @hidden_inactives = Rule.search(java_facade, {
+              :profile => @profile, :activation => STATUS_INACTIVE, :priorities => @priorities, :status => @status,
+              :repositories => @repositories, :language => @profile.language, :searchtext => @searchtext, :include_parameters_and_notes => false}).size
+
+        elsif @activation==STATUS_INACTIVE
+          @hidden_actives = Rule.search(java_facade, {
+              :profile => @profile, :activation => STATUS_ACTIVE, :priorities => @priorities, :status => @status,
+              :repositories => @repositories, :language => @profile.language, :searchtext => @searchtext, :include_parameters_and_notes => false}).size
+        end
+      end
+
+      stop_watch.stop("found #{@rules.size} rules with criteria #{criteria.to_json}")
+    rescue
+      @rules = []
+    end
+      @pagination = Api::Pagination.new(params)
+      @pagination.count = @rules.size
+      @current_rules = @rules[@pagination.offset, @pagination.limit]
+  end
+
+
+  #
+  #
+  # POST /old_rules_configuration/revert_rule?id=<profile id>&active_rule_id=<active rule id>
+  #
+  #
+  def revert_rule
+    verify_post_request
+    access_denied unless has_role?(:profileadmin)
+    require_parameters :id, :active_rule_id
+    id = params[:id].to_i
+    rule_id = params[:active_rule_id].to_i
+    java_facade.revertRule(id, rule_id, current_user.name)
+    redirect_to request.query_parameters.merge({:action => 'index', :id => params[:id], :commit => nil})
+  end
+
+
+  #
+  #
+  # POST /old_rules_configuration/activate_rule?id=<profile id>&rule_id=<rule id>&level=<priority>
+  #
+  # If the parameter "level" is blank or null, then the rule is removed from the profile.
+  #
+  #
+  def activate_rule
+    verify_post_request
+    access_denied unless has_role?(:profileadmin)
+    require_parameters :id, :rule_id
+    profile = Profile.find(params[:id].to_i)
+    if profile
+      rule=Rule.first(:conditions => ["id = ? and status <> ?", params[:rule_id].to_i, Rule::STATUS_REMOVED])
+      priority=params[:level]
+
+      active_rule=profile.active_by_rule_id(rule.id)
+      if priority.blank?
+        # deactivate the rule
+        if active_rule
+          java_facade.ruleDeactivated(profile.id, active_rule.id, current_user.name)
+          active_rule.destroy
+          active_rule=nil
+        end
+      else
+        # activate the rule
+        activated = false
+        if active_rule.nil?
+          active_rule = ActiveRule.new(:profile_id => profile.id, :rule => rule)
+          rule.parameters.select { |p| p.default_value.present? }.each do |p|
+            active_rule.active_rule_parameters.build(:rules_parameter => p, :value => p.default_value, :rules_parameter_key => p.name)
+          end
+          activated = true
+        end
+        old_severity = active_rule.failure_level
+        active_rule.failure_level=Sonar::RulePriority.id(priority)
+        active_rule.save!
+        if activated
+          java_facade.ruleActivated(profile.id, active_rule.id, current_user.name)
+        else
+          java_facade.ruleSeverityChanged(profile.id, active_rule.id, old_severity, active_rule.failure_level, current_user.name)
+        end
+      end
+      if active_rule
+        active_rule.reload
+      end
+
+      render :update do |page|
+        page.replace_html("rule_#{rule.id}", :partial => 'rule', :object => rule, :locals => {:profile => profile, :rule => rule, :active_rule => active_rule})
+        page.assign('localModifications', true)
+      end
+    end
+  end
+
+
+  #
+  #
+  # GET /old_rules_configuration/new/<profile id>?rule_id=<rule id>
+  #
+  #
+  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 => 'rules_configuration', :action => 'index', :id => @profile.id}}
+
+    @rule = Rule.find(params[:rule_id])
+  end
+
+  #
+  #
+  # POST /old_rules_configuration/create/<profile id>?rule_id=<rule id>&rule[name]=<new name>&...
+  #
+  #
+  def create
+    verify_post_request
+    access_denied unless has_role?(:profileadmin)
+    require_parameters :id, :rule_id
+    profile = Profile.find(params[:id].to_i)
+    template=Rule.find(params[:rule_id])
+    # TODO Call Internal.rule.create(...) ?
+    rule=Rule.create(params[:rule].merge(
+                         {
+                             :priority => Sonar::RulePriority.id(params[:rule][:priority]),
+                             :parent_id => template.id,
+                             :plugin_name => template.plugin_name,
+                             :cardinality => 'SINGLE',
+                             :plugin_rule_key => "#{template.plugin_rule_key}_#{Time.now.to_i}",
+                             :plugin_config_key => template.plugin_config_key,
+                             :status => Rule::STATUS_READY,
+                             :language => profile.language
+                         }
+                     ))
+
+    template.parameters.each do |template_parameter|
+      rule.rules_parameters.build(:name => template_parameter.name, :param_type => template_parameter.param_type, :description => template_parameter.description,
+                                  :default_value => params[:rule_param][template_parameter.name])
+    end
+
+    if rule.save
+      Internal.rules.saveOrUpdate(rule.id)
+      redirect_to :action => 'index', :id => profile.id, :searchtext => "\"#{rule.name}\"", :rule_activation => 'INACTIVE', "plugins[]" => rule.plugin_name
+
+    else
+      flash[:error]=message('rules_configuration.rule_not_valid_message_x', :params => rule.errors.full_messages.join('<br/>'))
+      redirect_to :action => 'new', :id => profile.id, :rule_id => params[:rule_id]
+    end
+  end
+
+
+  # deprecated since 2.3
+  def export
+    redirect_to request.query_parameters.merge({:controller => 'profiles', :action => 'export'})
+  end
+
+  #
+  #
+  # GET /old_rules_configuration/new/<profile id>?rule_id=<rule id>
+  #
+  #
+  def edit
+    # form to edit a rule
+    access_denied unless has_role?(:profileadmin)
+    require_parameters :id, :rule_id
+    @profile = Profile.find(params[:id])
+    @rule = Rule.find(params[:rule_id])
+    if !@rule.editable?
+      redirect_to :action => 'index', :id => params[:id]
+    end
+  end
+
+  #
+  #
+  # POST /old_rules_configuration/update/<profile id>?rule_id=<rule id>&rule[name]=<new name>&...
+  #
+  #
+  def update
+    verify_post_request
+    access_denied unless has_role?(:profileadmin)
+    require_parameters :id, :rule_id
+    rule=Rule.find(params[:rule_id])
+    if rule.editable?
+      rule.name=params[:rule][:name]
+      rule.description=params[:rule][:description]
+      rule.priority=Sonar::RulePriority.id(params[:rule][:priority])
+      rule.parameters.each do |parameter|
+        parameter.default_value=params[:rule_param][parameter.name]
+        parameter.save
+      end
+      if rule.save
+        Internal.rules.saveOrUpdate(rule.id)
+        redirect_to :action => 'index', :id => params[:id], :searchtext => "\"#{rule.name}\"", :rule_activation => '', "plugins[]" => rule.plugin_name
+      else
+        flash[:error]=message('rules_configuration.rule_not_valid_message_x', :params => rule.errors.full_messages.join('<br/>'))
+        redirect_to :action => 'new', :id => params[:id], :rule_id => params[:rule_id]
+      end
+    else
+      flash[:error]='Unknown rule'
+      redirect_to :action => 'index', :id => params[:id]
+    end
+  end
+
+
+  #
+  #
+  # POST /old_rules_configuration/delete/<profile id>?rule_id=<rule id>
+  #
+  #
+  def delete
+    verify_post_request
+    access_denied unless has_role?(:profileadmin)
+    require_parameters :id, :rule_id
+    rule=Rule.find(params[:rule_id])
+    if rule.editable?
+      rule.status=Rule::STATUS_REMOVED
+      rule.save
+      Internal.rules.saveOrUpdate(rule.id)
+
+      # it's mandatory to execute 'destroy_all' but not 'delete_all' because active_rule_parameters must
+      # also be destroyed in cascade.
+      ActiveRule.destroy_all("rule_id=#{rule.id}")
+      flash[:notice]=message('rules_configuration.rule_deleted')
+    else
+      flash[:error]=message('rules_configuration.unknown_rule')
+    end
+    redirect_to :action => 'index', :id => params[:id]
+  end
+
+  #
+  #
+  # POST /old_rules_configuration/bulk_edit?id=<profile id>&bulk_rule_ids=<list of rule ids>&bulk_action=<action>
+  #
+  # Values of the parameter 'bulk_action' :
+  #   - 'activate' : activate all the selected rules with their default priority
+  #   - 'deactivate' : deactivate all the selected rules
+  #
+  #
+  def bulk_edit
+    verify_post_request
+    access_denied unless has_role?(:profileadmin)
+    require_parameters :id, :bulk_rule_ids, :bulk_action
+    profile = Profile.find(params[:id].to_i)
+    rule_ids = params[:bulk_rule_ids].split(',').map { |id| id.to_i }
+    activation=params[:rule_activation] || STATUS_ACTIVE
+
+    case params[:bulk_action]
+      when 'activate'
+        count=activate_rules(profile, rule_ids)
+        flash[:notice]=message('rules_configuration.x_rules_have_been_activated', :params => count)
+        activation=STATUS_ACTIVE if activation==STATUS_INACTIVE
+
+      when 'deactivate'
+        count=deactivate_rules(profile, rule_ids)
+        flash[:notice]=message('rules_configuration.x_rules_have_been_deactivated', :params => count)
+        activation=STATUS_INACTIVE if activation==STATUS_ACTIVE
+    end
+
+    url_parameters=request.query_parameters.merge({:action => 'index', :bulk_action => nil, :bulk_rule_ids => nil, :id => profile.id, :rule_activation => activation})
+    redirect_to url_parameters
+  end
+
+
+  def update_param
+    verify_post_request
+    #access_denied unless has_role?(:profileadmin)
+    require_parameters :profile_id, :param_id, :active_rule_id
+
+    profile = Profile.find(params[:profile_id].to_i)
+    rule_param = RulesParameter.find(params[:param_id].to_i)
+    active_rule = ActiveRule.find(params[:active_rule_id].to_i)
+    # As the active param can be null, we should not raise a RecordNotFound exception when it's not found (as it would be done when using find(:id) function)
+    active_param = ActiveRuleParameter.find_by_id(params[:id].to_i) if params[:id].to_i > 0
+
+    value = params[:value]
+    if value != ""
+      active_param = ActiveRuleParameter.new(:rules_parameter => rule_param, :active_rule => active_rule, :rules_parameter_key => rule_param.name) if active_param.nil?
+      old_value = active_param.value
+      active_param.value = value
+      if active_param.save! && active_param.valid?
+        active_param.reload
+        java_facade.ruleParamChanged(profile.id, active_rule.id, rule_param.name, old_value, value, current_user.name)
+      end
+    elsif !active_param.nil?
+      old_value = active_param.value
+      active_param.destroy
+      java_facade.ruleParamChanged(profile.id, active_rule.id, rule_param.name, old_value, nil, current_user.name)
+    end
+    # let's reload the active rule
+    active_rule = ActiveRule.find(params[:active_rule_id].to_i)
+    render :partial => 'rule', :locals => {:profile => profile, :rule => active_rule.rule, :active_rule => active_rule}
+  end
+
+
+  def update_rule_note
+    verify_post_request
+    access_denied unless has_role?(:profileadmin)
+    require_parameters :rule_id
+    rule = Rule.find(params[:rule_id])
+    note = rule.note
+    unless note
+      note = RuleNote.new({:rule => rule})
+      # set the note on the rule to avoid reloading the rule
+      rule.note = note
+    end
+    note.text = params[:text]
+    note.user_login = current_user.login
+    note.save!
+    render :partial => 'rule_note', :locals => {:rule => rule}
+  end
+
+
+  def update_active_rule_note
+    verify_post_request
+    access_denied unless has_role?(:profileadmin)
+    require_parameters :active_rule_id, :note
+    active_rule = ActiveRule.find(params[:active_rule_id])
+    note = active_rule.note
+    unless note
+      note = ActiveRuleNote.new({:active_rule => active_rule})
+      # set the note on the rule to avoid reloading the rule
+      active_rule.note = note
+    end
+    note.text = params[:note]
+    note.user_login = current_user.login
+    note.save!
+    render :partial => 'active_rule_note', :locals => {:active_rule => active_rule, :profile => active_rule.rules_profile}
+  end
+
+
+  def delete_active_rule_note
+    verify_post_request
+    access_denied unless has_role?(:profileadmin)
+    require_parameters :active_rule_id
+    active_rule = ActiveRule.find(params[:active_rule_id])
+    active_rule.note.destroy if active_rule.note
+    active_rule.note = nil
+    render :partial => 'active_rule_note', :locals => {:active_rule => active_rule, :profile => active_rule.rules_profile}
+  end
+
+
+  private
+
+  # return the number of newly activated rules
+  def activate_rules(profile, rule_ids)
+    count=0
+    rule_ids_to_activate=(rule_ids - profile.active_rules.map { |ar| ar.rule_id })
+    unless rule_ids_to_activate.empty?
+      rules_to_activate=Rule.all(:conditions => ["status <> ? AND id IN (?)", Rule::STATUS_REMOVED, rule_ids_to_activate])
+      count = rules_to_activate.size
+      rules_to_activate.each do |rule|
+        active_rule = profile.active_rules.create(:rule => rule, :failure_level => rule.priority)
+        java_facade.ruleActivated(profile.id, active_rule.id, current_user.name)
+      end
+    end
+    count
+  end
+
+  def deactivate_rules(profile, rule_ids)
+    count=0
+    profile.active_rules.each do |ar|
+      if rule_ids.include?(ar.rule_id) && !ar.inheritance.present?
+        java_facade.ruleDeactivated(profile.id, ar.id, current_user.name)
+        ar.destroy
+        count+=1
+      end
+    end
+    count
+  end
+
+  def init_params
+    @id = params[:id]
+    @priorities = filter_any(params[:priorities]) || ['']
+    @repositories = filter_any(params[:repositories]) || ['']
+    @activation = params[:rule_activation] || STATUS_ACTIVE
+    @inheritance = params[:inheritance] || 'any'
+    @status = params[:status]
+    @sort_by = !params[:sort_by].blank? ? params[:sort_by] : Rule::SORT_BY_RULE_NAME
+    @searchtext = params[:searchtext]
+  end
+
+  def filter_any(array)
+    if array && array.size>1 && array.include?('')
+      array=[''] #keep only 'any'
+    end
+    array
+  end
+
+end
index 5c5a24dcdf3d1074fdac30e228bafa5a1edfb138..74ab0442349c922d0e5d9c4f5d491df47acd8412 100644 (file)
@@ -18,6 +18,7 @@
 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 require 'cgi'
+require 'java'
 
 class RulesConfigurationController < ApplicationController
 
@@ -32,50 +33,50 @@ class RulesConfigurationController < ApplicationController
   def index
     require_parameters :id
 
-    @profile = Profile.find(params[:id])
-    add_breadcrumbs ProfilesController::root_breadcrumb, Api::Utils.language_name(@profile.language),
-                    {:name => @profile.name, :url => {:controller => 'rules_configuration', :action => 'index', :id => @profile.id}}
-
-    init_params()
+    call_backend do
+      @profile = Internal.quality_profiles.profile(params[:id].to_i)
+      @parent_profile = Internal.quality_profiles.parent(@profile) if @profile.parent()
 
-    @select_repositories = ANY_SELECTION + java_facade.getRuleRepositoriesByLanguage(@profile.language).collect { |repo| [repo.name(), repo.key()] }.sort
-    @select_priority = ANY_SELECTION + RULE_PRIORITIES
-    @select_activation = [[message('any'), 'any'], [message('active'), STATUS_ACTIVE], [message('inactive'), STATUS_INACTIVE]]
-    @select_inheritance = [[message('any'), 'any'], [message('rules_configuration.not_inherited'), 'NOT'], [message('rules_configuration.inherited'), 'INHERITED'],
-                           [message('rules_configuration.overrides'), 'OVERRIDES']]
-    @select_status = ANY_SELECTION + [[message('rules.status.beta'), Rule::STATUS_BETA],
-                      [message('rules.status.deprecated'), Rule::STATUS_DEPRECATED],
-                      [message('rules.status.ready'), Rule::STATUS_READY]]
-    @select_sort_by = [[message('rules_configuration.rule_name'), Rule::SORT_BY_RULE_NAME], [message('rules_configuration.creation_date'), Rule::SORT_BY_CREATION_DATE]]
+      add_breadcrumbs ProfilesController::root_breadcrumb, Api::Utils.language_name(@profile.language),
+                      {:name => @profile.name, :url => {:controller => 'rules_configuration', :action => 'index', :id => @profile.id}}
 
-    begin
+      init_params
+      @criteria_params = criteria_params
       stop_watch = Internal.profiling.start("rules", "BASIC")
 
-      criteria = {
-      :profile => @profile, :activation => @activation, :priorities => @priorities, :inheritance => @inheritance, :status => @status,
-      :repositories => @repositories, :searchtext => @searchtext, :include_parameters_and_notes => true, :language => @profile.language, :sort_by => @sort_by}
-      @rules = Rule.search(java_facade, criteria)
+      @pagination = Api::Pagination.new(params)
+      paging = Java::OrgSonarServerQualityprofile::Paging.create(@pagination.per_page.to_i, @pagination.page.to_i)
 
+      criteria = init_criteria
+      query = Java::OrgSonarServerRule::ProfileRuleQuery::parse(criteria.to_java)
+      if @activation==STATUS_ACTIVE
+        result = Internal.quality_profiles.searchProfileRules(query, paging)
+      else
+        result = Internal.quality_profiles.searchInactiveProfileRules(query, paging)
+      end
+
+      @pagination.count = result.paging.total
       unless @searchtext.blank?
-        if @activation==STATUS_ACTIVE
-          @hidden_inactives = Rule.search(java_facade, {
-              :profile => @profile, :activation => STATUS_INACTIVE, :priorities => @priorities, :status => @status,
-              :repositories => @repositories, :language => @profile.language, :searchtext => @searchtext, :include_parameters_and_notes => false}).size
-
-        elsif @activation==STATUS_INACTIVE
-          @hidden_actives = Rule.search(java_facade, {
-              :profile => @profile, :activation => STATUS_ACTIVE, :priorities => @priorities, :status => @status,
-              :repositories => @repositories, :language => @profile.language, :searchtext => @searchtext, :include_parameters_and_notes => false}).size
+        if @activation == STATUS_ACTIVE
+          @hidden_inactives = Internal.quality_profiles.countInactiveProfileRules(query)
+        else
+          @hidden_actives = Internal.quality_profiles.countProfileRules(query)
         end
       end
-
-      stop_watch.stop("found #{@rules.size} rules with criteria #{criteria.to_json}")
-    rescue
-      @rules = []
+      stop_watch.stop("found #{@pagination.count} rules with criteria #{criteria.to_json}, displaying #{@pagination.per_page} items")
+
+      @current_rules = result.rules
+
+      @select_repositories = ANY_SELECTION + java_facade.getRuleRepositoriesByLanguage(@profile.language).collect { |repo| [repo.name(), repo.key()] }.sort
+      @select_priority = ANY_SELECTION + RULE_PRIORITIES
+      @select_activation = [[message('active'), STATUS_ACTIVE], [message('inactive'), STATUS_INACTIVE]]
+      @select_inheritance = [[message('any'), 'any'], [message('rules_configuration.not_inherited'), 'NOT'], [message('rules_configuration.inherited'), 'INHERITED'],
+                             [message('rules_configuration.overrides'), 'OVERRIDES']]
+      @select_status = ANY_SELECTION + [[message('rules.status.beta'), Rule::STATUS_BETA],
+                                        [message('rules.status.deprecated'), Rule::STATUS_DEPRECATED],
+                                        [message('rules.status.ready'), Rule::STATUS_READY]]
+      @select_sort_by = [[message('rules_configuration.rule_name'), Rule::SORT_BY_RULE_NAME], [message('rules_configuration.creation_date'), Rule::SORT_BY_CREATION_DATE]]
     end
-      @pagination = Api::Pagination.new(params)
-      @pagination.count = @rules.size
-      @current_rules = @rules[@pagination.offset, @pagination.limit]
   end
 
 
@@ -86,12 +87,14 @@ class RulesConfigurationController < ApplicationController
   #
   def revert_rule
     verify_post_request
-    access_denied unless has_role?(:profileadmin)
     require_parameters :id, :active_rule_id
-    id = params[:id].to_i
-    rule_id = params[:active_rule_id].to_i
-    java_facade.revertRule(id, rule_id, current_user.name)
-    redirect_to request.query_parameters.merge({:action => 'index', :id => params[:id], :commit => nil})
+
+    active_rule_id = params[:active_rule_id].to_i
+    call_backend do
+      Internal.quality_profiles.revertActiveRule(active_rule_id)
+    end
+
+    redirect_to request.query_parameters.merge({:action => 'index', :id => params[:id].to_i, :commit => nil})
   end
 
 
@@ -104,48 +107,30 @@ class RulesConfigurationController < ApplicationController
   #
   def activate_rule
     verify_post_request
-    access_denied unless has_role?(:profileadmin)
     require_parameters :id, :rule_id
-    profile = Profile.find(params[:id].to_i)
-    if profile
-      rule=Rule.first(:conditions => ["id = ? and status <> ?", params[:rule_id].to_i, Rule::STATUS_REMOVED])
-      priority=params[:level]
 
-      active_rule=profile.active_by_rule_id(rule.id)
-      if priority.blank?
+    rule = nil
+    profile_id = params[:id].to_i
+    rule_id = params[:rule_id].to_i
+    call_backend do
+      severity = params[:level]
+      if severity.blank?
         # deactivate the rule
-        if active_rule
-          java_facade.ruleDeactivated(profile.id, active_rule.id, current_user.name)
-          active_rule.destroy
-          active_rule=nil
-        end
+        Internal.quality_profiles.deactivateRule(profile_id, rule_id)
+        rule = Internal.quality_profiles.findByRule(rule_id)
       else
         # activate the rule
-        activated = false
-        if active_rule.nil?
-          active_rule = ActiveRule.new(:profile_id => profile.id, :rule => rule)
-          rule.parameters.select { |p| p.default_value.present? }.each do |p|
-            active_rule.active_rule_parameters.build(:rules_parameter => p, :value => p.default_value, :rules_parameter_key => p.name)
-          end
-          activated = true
-        end
-        old_severity = active_rule.failure_level
-        active_rule.failure_level=Sonar::RulePriority.id(priority)
-        active_rule.save!
-        if activated
-          java_facade.ruleActivated(profile.id, active_rule.id, current_user.name)
-        else
-          java_facade.ruleSeverityChanged(profile.id, active_rule.id, old_severity, active_rule.failure_level, current_user.name)
-        end
-      end
-      if active_rule
-        active_rule.reload
+        Internal.quality_profiles.activateRule(profile_id, rule_id, severity)
+        rule = Internal.quality_profiles.findByProfileAndRule(profile_id, rule_id)
       end
+    end
 
-      render :update do |page|
-        page.replace_html("rule_#{rule.id}", :partial => 'rule', :object => rule, :locals => {:profile => profile, :rule => rule, :active_rule => active_rule})
-        page.assign('localModifications', true)
-      end
+    profile = Internal.quality_profiles.profile(profile_id)
+    parent_profile = Internal.quality_profiles.parent(profile)
+
+    render :update do |page|
+      page.replace_html("rule_#{rule.id}", :partial => 'rule', :object => rule, :locals => {:rule => rule, :profile => profile, :parent_profile => parent_profile})
+      page.assign('localModifications', true)
     end
   end
 
@@ -157,12 +142,12 @@ class RulesConfigurationController < 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 => '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 => 'rules_configuration', :action => 'index', :id => @profile.id}}
 
-    @rule = Rule.find(params[:rule_id])
+    @rule = Internal.quality_profiles.rule(params[:rule_id].to_i)
   end
 
   #
@@ -172,36 +157,19 @@ class RulesConfigurationController < ApplicationController
   #
   def create
     verify_post_request
-    access_denied unless has_role?(:profileadmin)
     require_parameters :id, :rule_id
-    profile = Profile.find(params[:id].to_i)
-    template=Rule.find(params[:rule_id])
-    # TODO Call Internal.rule.create(...) ?
-    rule=Rule.create(params[:rule].merge(
-                         {
-                             :priority => Sonar::RulePriority.id(params[:rule][:priority]),
-                             :parent_id => template.id,
-                             :plugin_name => template.plugin_name,
-                             :cardinality => 'SINGLE',
-                             :plugin_rule_key => "#{template.plugin_rule_key}_#{Time.now.to_i}",
-                             :plugin_config_key => template.plugin_config_key,
-                             :status => Rule::STATUS_READY,
-                             :language => profile.language
-                         }
-                     ))
-
-    template.parameters.each do |template_parameter|
-      rule.rules_parameters.build(:name => template_parameter.name, :param_type => template_parameter.param_type, :description => template_parameter.description,
-                                  :default_value => params[:rule_param][template_parameter.name])
-    end
 
-    if rule.save
-      Internal.rules.saveOrUpdate(rule.id)
-      redirect_to :action => 'index', :id => profile.id, :searchtext => "\"#{rule.name}\"", :rule_activation => 'INACTIVE', "plugins[]" => rule.plugin_name
+    profile_id = params[:id].to_i
+    rule_id = params[:rule_id].to_i
+    new_rule = nil
+    call_backend do
+      new_rule = Internal.quality_profiles.createRule(rule_id, params[:rule][:name], params[:rule][:priority], params[:rule][:description], params[:rule_param])
+    end
 
+    if new_rule
+      redirect_to :action => 'index', :id => profile_id, :searchtext => "\"#{new_rule.name()}\"", :rule_activation => 'INACTIVE', "plugins[]" => new_rule.repositoryKey()
     else
-      flash[:error]=message('rules_configuration.rule_not_valid_message_x', :params => rule.errors.full_messages.join('<br/>'))
-      redirect_to :action => 'new', :id => profile.id, :rule_id => params[:rule_id]
+      redirect_to :action => 'new', :id => profile_id, :rule_id => rule_id
     end
   end
 
@@ -218,12 +186,17 @@ class RulesConfigurationController < ApplicationController
   #
   def edit
     # form to edit a rule
-    access_denied unless has_role?(:profileadmin)
     require_parameters :id, :rule_id
-    @profile = Profile.find(params[:id])
-    @rule = Rule.find(params[:rule_id])
-    if !@rule.editable?
-      redirect_to :action => 'index', :id => params[:id]
+
+    call_backend do
+      @profile = Internal.quality_profiles.profile(params[:id].to_i)
+      @rule = Internal.quality_profiles.rule(params[:rule_id].to_i)
+      if @rule.ruleId().nil?
+        redirect_to :action => 'index', :id => params[:id]
+      else
+        @parent_rule = Internal.quality_profiles.rule(@rule.ruleId())
+        @active_rules = Internal.quality_profiles.countActiveRules(@rule)
+      end
     end
   end
 
@@ -234,27 +207,19 @@ class RulesConfigurationController < ApplicationController
   #
   def update
     verify_post_request
-    access_denied unless has_role?(:profileadmin)
     require_parameters :id, :rule_id
-    rule=Rule.find(params[:rule_id])
-    if rule.editable?
-      rule.name=params[:rule][:name]
-      rule.description=params[:rule][:description]
-      rule.priority=Sonar::RulePriority.id(params[:rule][:priority])
-      rule.parameters.each do |parameter|
-        parameter.default_value=params[:rule_param][parameter.name]
-        parameter.save
-      end
-      if rule.save
-        Internal.rules.saveOrUpdate(rule.id)
-        redirect_to :action => 'index', :id => params[:id], :searchtext => "\"#{rule.name}\"", :rule_activation => '', "plugins[]" => rule.plugin_name
-      else
-        flash[:error]=message('rules_configuration.rule_not_valid_message_x', :params => rule.errors.full_messages.join('<br/>'))
-        redirect_to :action => 'new', :id => params[:id], :rule_id => params[:rule_id]
-      end
+
+    profile_id = params[:id].to_i
+    rule_id = params[:rule_id].to_i
+    rule = nil
+    call_backend do
+      rule = Internal.quality_profiles.updateRule(rule_id, params[:rule][:name], params[:rule][:priority], params[:rule][:description], params[:rule_param])
+    end
+
+    if rule
+      redirect_to :action => 'index', :id => profile_id, :searchtext => "\"#{rule.name()}\"", :rule_activation => '', "plugins[]" => rule.repositoryKey()
     else
-      flash[:error]='Unknown rule'
-      redirect_to :action => 'index', :id => params[:id]
+      redirect_to :action => 'new', :id => profile_id, :rule_id => rule_id
     end
   end
 
@@ -266,27 +231,18 @@ class RulesConfigurationController < ApplicationController
   #
   def delete
     verify_post_request
-    access_denied unless has_role?(:profileadmin)
     require_parameters :id, :rule_id
-    rule=Rule.find(params[:rule_id])
-    if rule.editable?
-      rule.status=Rule::STATUS_REMOVED
-      rule.save
-      Internal.rules.saveOrUpdate(rule.id)
-
-      # it's mandatory to execute 'destroy_all' but not 'delete_all' because active_rule_parameters must
-      # also be destroyed in cascade.
-      ActiveRule.destroy_all("rule_id=#{rule.id}")
+
+    call_backend do
+      Internal.quality_profiles.deleteRule(params[:rule_id].to_i)
       flash[:notice]=message('rules_configuration.rule_deleted')
-    else
-      flash[:error]=message('rules_configuration.unknown_rule')
     end
     redirect_to :action => 'index', :id => params[:id]
   end
 
   #
   #
-  # POST /rules_configuration/bulk_edit?id=<profile id>&bulk_rule_ids=<list of rule ids>&bulk_action=<action>
+  # POST /rules_configuration/bulk_edit?id=<profile id>&&bulk_action=<action>
   #
   # Values of the parameter 'bulk_action' :
   #   - 'activate' : activate all the selected rules with their default priority
@@ -296,134 +252,92 @@ class RulesConfigurationController < ApplicationController
   def bulk_edit
     verify_post_request
     access_denied unless has_role?(:profileadmin)
-    require_parameters :id, :bulk_rule_ids, :bulk_action
-    profile = Profile.find(params[:id].to_i)
-    rule_ids = params[:bulk_rule_ids].split(',').map { |id| id.to_i }
-    activation=params[:rule_activation] || STATUS_ACTIVE
-
+    require_parameters :id, :bulk_action
+
+    stop_watch = Internal.profiling.start("rules", "BASIC")
+    @profile = Internal.quality_profiles.profile(params[:id].to_i)
+    init_params
+    criteria = init_criteria
+    query = Java::OrgSonarServerRule::ProfileRuleQuery::parse(criteria.to_java)
+    activation = params[:rule_activation] || STATUS_ACTIVE
     case params[:bulk_action]
       when 'activate'
-        count=activate_rules(profile, rule_ids)
+        count = Internal.quality_profiles.bulkActivateRule(query)
+        stop_watch.stop("Activate #{count} rules with criteria #{criteria.to_json}")
+
         flash[:notice]=message('rules_configuration.x_rules_have_been_activated', :params => count)
         activation=STATUS_ACTIVE if activation==STATUS_INACTIVE
 
       when 'deactivate'
-        count=deactivate_rules(profile, rule_ids)
+        count = Internal.quality_profiles.bulkDeactivateRule(query)
+        stop_watch.stop("Deactivate #{count} rules with criteria #{criteria.to_json}")
+
         flash[:notice]=message('rules_configuration.x_rules_have_been_deactivated', :params => count)
         activation=STATUS_INACTIVE if activation==STATUS_ACTIVE
     end
 
-    url_parameters=request.query_parameters.merge({:action => 'index', :bulk_action => nil, :bulk_rule_ids => nil, :id => profile.id, :rule_activation => activation})
+    url_parameters=request.query_parameters.merge({:action => 'index', :bulk_action => nil, :id => @profile.id, :rule_activation => activation})
     redirect_to url_parameters
   end
 
 
   def update_param
     verify_post_request
-    #access_denied unless has_role?(:profileadmin)
-    require_parameters :profile_id, :param_id, :active_rule_id
-
-    profile = Profile.find(params[:profile_id].to_i)
-    rule_param = RulesParameter.find(params[:param_id].to_i)
-    active_rule = ActiveRule.find(params[:active_rule_id].to_i)
-    # As the active param can be null, we should not raise a RecordNotFound exception when it's not found (as it would be done when using find(:id) function)
-    active_param = ActiveRuleParameter.find_by_id(params[:id].to_i) if params[:id].to_i > 0
-
-    value = params[:value]
-    if value != ""
-      active_param = ActiveRuleParameter.new(:rules_parameter => rule_param, :active_rule => active_rule, :rules_parameter_key => rule_param.name) if active_param.nil?
-      old_value = active_param.value
-      active_param.value = value
-      if active_param.save! && active_param.valid?
-        active_param.reload
-        java_facade.ruleParamChanged(profile.id, active_rule.id, rule_param.name, old_value, value, current_user.name)
-      end
-    elsif !active_param.nil?
-      old_value = active_param.value
-      active_param.destroy
-      java_facade.ruleParamChanged(profile.id, active_rule.id, rule_param.name, old_value, nil, current_user.name)
+
+    access_denied unless has_role?(:profileadmin)
+    require_parameters :param_id, :active_rule_id, :profile_id
+
+    rule = nil
+    profile_id = params[:profile_id].to_i
+    active_rule_id = params[:active_rule_id].to_i
+    call_backend do
+      Internal.quality_profiles.updateActiveRuleParam(active_rule_id, params[:param_id], params[:value])
+      rule = Internal.quality_profiles.findByActiveRuleId(active_rule_id)
     end
-    # let's reload the active rule
-    active_rule = ActiveRule.find(params[:active_rule_id].to_i)
-    render :partial => 'rule', :locals => {:profile => profile, :rule => active_rule.rule, :active_rule => active_rule}
+
+    profile = Internal.quality_profiles.profile(profile_id)
+    parent_profile = Internal.quality_profiles.parent(profile)
+    render :partial => 'rule', :locals => {:rule => rule, :profile => profile, :parent_profile => parent_profile}
   end
 
 
   def update_rule_note
     verify_post_request
-    access_denied unless has_role?(:profileadmin)
-    require_parameters :rule_id
-    rule = Rule.find(params[:rule_id])
-    note = rule.note
-    unless note
-      note = RuleNote.new({:rule => rule})
-      # set the note on the rule to avoid reloading the rule
-      rule.note = note
+    require_parameters :rule_id, :active_rule_id
+
+    rule = nil
+    call_backend do
+      rule = Internal.quality_profiles.updateRuleNote(params[:active_rule_id].to_i, params[:rule_id].to_i, params[:text])
     end
-    note.text = params[:text]
-    note.user_login = current_user.login
-    note.save!
     render :partial => 'rule_note', :locals => {:rule => rule}
   end
 
 
   def update_active_rule_note
     verify_post_request
-    access_denied unless has_role?(:profileadmin)
     require_parameters :active_rule_id, :note
-    active_rule = ActiveRule.find(params[:active_rule_id])
-    note = active_rule.note
-    unless note
-      note = ActiveRuleNote.new({:active_rule => active_rule})
-      # set the note on the rule to avoid reloading the rule
-      active_rule.note = note
+
+    rule = nil
+    call_backend do
+      rule = Internal.quality_profiles.updateActiveRuleNote(params[:active_rule_id].to_i, params[:note])
     end
-    note.text = params[:note]
-    note.user_login = current_user.login
-    note.save!
-    render :partial => 'active_rule_note', :locals => {:active_rule => active_rule, :profile => active_rule.rules_profile}
+    render :partial => 'active_rule_note', :locals => {:rule => rule}
   end
 
 
   def delete_active_rule_note
     verify_post_request
-    access_denied unless has_role?(:profileadmin)
     require_parameters :active_rule_id
-    active_rule = ActiveRule.find(params[:active_rule_id])
-    active_rule.note.destroy if active_rule.note
-    active_rule.note = nil
-    render :partial => 'active_rule_note', :locals => {:active_rule => active_rule, :profile => active_rule.rules_profile}
-  end
-
 
-  private
-
-  # return the number of newly activated rules
-  def activate_rules(profile, rule_ids)
-    count=0
-    rule_ids_to_activate=(rule_ids - profile.active_rules.map { |ar| ar.rule_id })
-    unless rule_ids_to_activate.empty?
-      rules_to_activate=Rule.all(:conditions => ["status <> ? AND id IN (?)", Rule::STATUS_REMOVED, rule_ids_to_activate])
-      count = rules_to_activate.size
-      rules_to_activate.each do |rule|
-        active_rule = profile.active_rules.create(:rule => rule, :failure_level => rule.priority)
-        java_facade.ruleActivated(profile.id, active_rule.id, current_user.name)
-      end
+    rule = nil
+    call_backend do
+      rule = Internal.quality_profiles.deleteActiveRuleNote(params[:active_rule_id].to_i)
     end
-    count
+    render :partial => 'active_rule_note', :locals => {:rule => rule}
   end
 
-  def deactivate_rules(profile, rule_ids)
-    count=0
-    profile.active_rules.each do |ar|
-      if rule_ids.include?(ar.rule_id) && !ar.inheritance.present?
-        java_facade.ruleDeactivated(profile.id, ar.id, current_user.name)
-        ar.destroy
-        count+=1
-      end
-    end
-    count
-  end
+
+  private
 
   def init_params
     @id = params[:id]
@@ -443,4 +357,16 @@ class RulesConfigurationController < ApplicationController
     array
   end
 
+  def init_criteria()
+    {"profileId" => @profile.id.to_i, "activation" => @activation, "severities" => @priorities, "inheritance" => @inheritance, "statuses" => @status,
+     "repositoryKeys" => @repositories, "nameOrKey" => @searchtext, "include_parameters_and_notes" => true, "language" => @profile.language, "sort_by" => @sort_by}
+  end
+
+  def criteria_params
+    new_params = params.clone
+    new_params.delete('controller')
+    new_params.delete('action')
+    new_params
+  end
+
 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
deleted file mode 100644 (file)
index 448c873..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-#
-# SonarQube, open source software quality management tool.
-# Copyright (C) 2008-2013 SonarSource
-# mailto:contact AT sonarsource DOT com
-#
-# SonarQube is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 3 of the License, or (at your option) any later version.
-#
-# SonarQube is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this program; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-#
-module NewRulesConfigurationHelper
-  include PropertiesHelper
-
-  PARAM_TYPE_STRING_LIST = "s{}"
-  PARAM_TYPE_INTEGER_LIST = "i{}"
-
-  # Kept for compatibility with old rule param type
-  def type_with_compatibility(type)
-    return PropertyType::TYPE_STRING if type == 's'
-    return PropertyType::TYPE_STRING if type == PARAM_TYPE_STRING_LIST
-    return PropertyType::TYPE_INTEGER if type == 'i'
-    return PropertyType::TYPE_INTEGER if type == PARAM_TYPE_INTEGER_LIST
-    return PropertyType::TYPE_BOOLEAN if type == 'b'
-    return PropertyType::TYPE_REGULAR_EXPRESSION if type == 'r'
-    return PropertyType::TYPE_STRING if is_set(type)
-
-    type
-  end
-
-  def readable_type(param_type)
-    type=type_with_compatibility(param_type)
-
-    return "Set of comma delimited strings" if param_type == PARAM_TYPE_STRING_LIST
-    return "Number" if type == PropertyType::TYPE_INTEGER
-    return "Set of comma delimited numbers" if param_type == PARAM_TYPE_INTEGER_LIST
-    return "Regular expression" if type == PropertyType::TYPE_REGULAR_EXPRESSION
-    return "Set of comma delimited values" if is_set(param_type)
-    ""
-  end
-
-  def param_value_input(rule, parameter, value, options = {})
-    type = type_with_compatibility(parameter.type().to_s)
-    name = options[:name] || 'value'
-    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)
-    type.at(1) == "[" && type.ends_with?("]")
-  end
-
-  def validate_rule_param(attribute, param_type, errors, value)
-    return if attribute.nil? or attribute.length == 0
-
-    type=type_with_compatibility(param_type)
-
-    if is_set_type
-      attribute.split(',').each do |v|
-        if !get_allowed_tokens.include?(v)
-          errors.add("#{value}", "'#{v}' must be one of : " + get_allowed_tokens.join(', '))
-        end
-      end
-    elsif param_type == RulesConfigurationHelper::PARAM_TYPE_INTEGER_LIST
-      attribute.split(',').each do |n|
-        if !Api::Utils.is_integer?(n)
-          errors.add("#{value}", "'#{n}' must be an integer.")
-        end
-      end
-    elsif type == PropertyType::TYPE_REGULAR_EXPRESSION
-      errors.add("#{value}", "'#{attribute}' must be a regular expression") unless Api::Utils.is_regexp?(attribute)
-    elsif type == PropertyType::TYPE_INTEGER
-      errors.add("#{value}", "'#{attribute}' must be an integer.") unless Api::Utils.is_integer?(attribute)
-    elsif type == PropertyType::TYPE_BOOLEAN
-      errors.add("#{value}", "'#{attribute}' must be one of : true,false") unless Api::Utils.is_boolean?(attribute)
-    end
-  end
-end
-
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/old_rules_configuration_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/old_rules_configuration_helper.rb
new file mode 100644 (file)
index 0000000..e66d9fe
--- /dev/null
@@ -0,0 +1,86 @@
+#
+# SonarQube, open source software quality management tool.
+# Copyright (C) 2008-2013 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# SonarQube is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 3 of the License, or (at your option) any later version.
+#
+# SonarQube is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+#
+module OldRulesConfigurationHelper
+  include PropertiesHelper
+
+  PARAM_TYPE_STRING_LIST = "s{}"
+  PARAM_TYPE_INTEGER_LIST = "i{}"
+
+  # Kept for compatibility with old rule param type
+  def type_with_compatibility(type)
+    return PropertyType::TYPE_STRING if type == 's'
+    return PropertyType::TYPE_STRING if type == PARAM_TYPE_STRING_LIST
+    return PropertyType::TYPE_INTEGER if type == 'i'
+    return PropertyType::TYPE_INTEGER if type == PARAM_TYPE_INTEGER_LIST
+    return PropertyType::TYPE_BOOLEAN if type == 'b'
+    return PropertyType::TYPE_REGULAR_EXPRESSION if type == 'r'
+    return PropertyType::TYPE_STRING if is_set(type)
+
+    type
+  end
+
+  def readable_type(param_type)
+    type=type_with_compatibility(param_type)
+
+    return "Set of comma delimited strings" if param_type == PARAM_TYPE_STRING_LIST
+    return "Number" if type == PropertyType::TYPE_INTEGER
+    return "Set of comma delimited numbers" if param_type == PARAM_TYPE_INTEGER_LIST
+    return "Regular expression" if type == PropertyType::TYPE_REGULAR_EXPRESSION
+    return "Set of comma delimited values" if is_set(param_type)
+    ""
+  end
+
+  def param_value_input(parameter, value, options = {})
+    type=type_with_compatibility(parameter.param_type)
+    name = options[:name] || 'value'
+    property_input_field name, type, value, 'WIDGET', {:id => parameter.id, :size => options[:size] }.update(options)
+  end
+
+  def is_set(type)
+    type.at(1) == "[" && type.ends_with?("]")
+  end
+
+  def validate_rule_param(attribute, param_type, errors, value)
+    return if attribute.nil? or attribute.length == 0
+
+    type=type_with_compatibility(param_type)
+
+    if is_set_type
+      attribute.split(',').each do |v|
+        if !get_allowed_tokens.include?(v)
+          errors.add("#{value}", "'#{v}' must be one of : " + get_allowed_tokens.join(', '))
+        end
+      end
+    elsif param_type == RulesConfigurationHelper::PARAM_TYPE_INTEGER_LIST
+      attribute.split(',').each do |n|
+        if !Api::Utils.is_integer?(n)
+          errors.add("#{value}", "'#{n}' must be an integer.")
+        end
+      end
+    elsif type == PropertyType::TYPE_REGULAR_EXPRESSION
+      errors.add("#{value}", "'#{attribute}' must be a regular expression") unless Api::Utils.is_regexp?(attribute)
+    elsif type == PropertyType::TYPE_INTEGER
+      errors.add("#{value}", "'#{attribute}' must be an integer.") unless Api::Utils.is_integer?(attribute)
+    elsif type == PropertyType::TYPE_BOOLEAN
+      errors.add("#{value}", "'#{attribute}' must be one of : true,false") unless Api::Utils.is_boolean?(attribute)
+    end
+  end
+end
+
index f93ce912fc175be9a8b9b0809fc29bc882c23f58..2a1c0dd930112b98655bd856666a4ab58c033d7a 100644 (file)
@@ -47,10 +47,10 @@ module RulesConfigurationHelper
     ""
   end
 
-  def param_value_input(parameter, value, options = {})
-    type=type_with_compatibility(parameter.param_type)
+  def param_value_input(rule, parameter, value, options = {})
+    type = type_with_compatibility(parameter.type().to_s)
     name = options[:name] || 'value'
-    property_input_field name, type, value, 'WIDGET', {:id => parameter.id, :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)
@@ -82,5 +82,10 @@ module RulesConfigurationHelper
       errors.add("#{value}", "'#{attribute}' must be one of : true,false") unless Api::Utils.is_boolean?(attribute)
     end
   end
+
+  def rule_key(qProfileRule)
+    "#{qProfileRule.repositoryKey().to_s}:#{qProfileRule.key().to_s}"
+  end
+
 end
 
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/_active_rule_note.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/_active_rule_note.html.erb
deleted file mode 100644 (file)
index a053e5a..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-<% #locals = rule, profile
-  note = rule.activeRuleNote
-  active_note_detail_div_id = "and_" + rule.activeRuleId.to_s
-  add_active_note_button_id = "aanb_" + rule.activeRuleId.to_s
-  edit_active_note_link_id = "eanl_" + rule.activeRuleId.to_s
-  delete_active_note_link_id = "danl_" + rule.activeRuleId.to_s
-  active_note_form_div_id = "anf_" + rule.activeRuleId.to_s
-  active_note_textarea_id = "ant_" + rule.activeRuleId.to_s
-  submit_active_note_update_button_id = "sanub_" + rule.activeRuleId.to_s
-%>
-
-<div id="<%= active_note_detail_div_id -%>">
-  <% if !note.nil? %>
-    <blockquote class="spacer-bottom">
-      <cite>
-        <b><%= User.find_active_by_login(note.userLogin).name -%></b> (<%= distance_of_time_in_words_to_now(Time.at(note.updatedAt.time/1000)) -%>)&nbsp;
-        <% if profiles_administrator? %>
-          | &nbsp;
-          <a href="#" id="<%= edit_active_note_link_id -%>" class="link-action"
-             onclick="$j('#<%= active_note_detail_div_id -%>').hide();$j('#<%= active_note_form_div_id -%>').show();$j('#<%= active_note_textarea_id -%>').focus();return false;"><%= message('edit') %></a>
-          &nbsp;
-          <a class="link-action"
-             onclick="if(confirm('<%= escape_javascript(message('rules_configuration.confirm_delete_note')) -%>')){
-                             $j.ajax({
-                                       url: '<%=ApplicationController.root_context-%>/new_rules_configuration/delete_active_rule_note?active_rule_id=<%=rule.activeRuleId-%>',
-                                       type: 'post',
-                                       success:function(response){$j('#active_rule_note_<%= rule.activeRuleId -%>').html(response);}
-                                     });};return false;"
-             href="#!"><%=message('delete')-%></a>
-        <% end %>
-      </cite>
-      <p><%= note.data -%></p>
-    </blockquote>
-  <% elsif profiles_administrator? %>
-    <a href="#" onclick="$j('#<%= active_note_form_div_id -%>').show();$j('#<%= active_note_detail_div_id -%>').hide();$j('#<%= active_note_textarea_id -%>').focus(); return false;"
-       class="link-action spacer-right" id="<%= add_active_note_button_id -%>"><%= message('rules_configuration.add_note') -%></a>
-  <% end %>
-</div>
-
-<% if profiles_administrator? %>
-  <form onsubmit="$j.ajax({
-                            url:'<%= ApplicationController.root_context -%>/new_rules_configuration/update_active_rule_note?active_rule_id=<%=rule.activeRuleId-%>',
-                            data: $j(this).serialize(),
-                            type:'post',
-                            success:function(response){$j('#active_rule_note_<%= rule.activeRuleId -%>').html(response);}
-                          });
-                  return false;"
-          method="post"
-          action="<%= ApplicationController.root_context -%>/new_rules_configuration//update_active_rule_note?active_rule_id=<%=rule.activeRuleId-%>">
-  <table id="<%= active_note_form_div_id -%>" style="display: none" class="admin table width100">
-    <tbody>
-      <tr>
-        <td class="width100" colspan="2">
-          <textarea name="note" id="<%= active_note_textarea_id -%>" rows="10" style="width:100%"
-                    onkeyup="if (this.value=='') $j('#<%= submit_active_note_update_button_id -%>').prop('disabled', true); else $j('#<%= submit_active_note_update_button_id -%>').prop('disabled', false);"><%= h(note.data) unless note.nil? -%></textarea>
-        </td>
-      </tr>
-    <tr>
-      <td>
-        <input type="submit" value="<%= note ? message('update_verb') : message('rules_configuration.add_note') -%>" name="submit-active-note" id="<%= submit_active_note_update_button_id -%>" disabled="disabled"/>
-        <a href="#" onclick="$j('#<%= active_note_detail_div_id -%>').show();$j('#<%= active_note_form_div_id -%>').hide();return false;"><%= message('cancel') %></a>
-      </td>
-      <td align="right">
-        <%= render :partial => 'markdown/tips' -%>
-      </td>
-    </tr>
-    </tbody>
-  </table>
-  </form>
-<% end %>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/_rule.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/_rule.html.erb
deleted file mode 100644 (file)
index b652528..0000000
+++ /dev/null
@@ -1,124 +0,0 @@
-<% #locals = rule, profile, parent_profile -%>
-
-<td nowrap valign="top" class="left" x="<%= rule.severity -%>" width="1%">
-  <form id="levels_<%= rule.id -%>" action="" class="rule-levels-form">
-    <% enable_modification = profiles_administrator?
-       select_box_id = "levels_select_#{rule.id}"
-       check_box_id = "levels_check_#{rule.id}"
-       activate_rule = "$j.ajax({url:'#{ApplicationController.root_context}/new_rules_configuration/activate_rule/#{profile.id}?rule_id=#{rule.id}',type: 'POST',
-                                 beforeSend: function(request){$j('#levels_#{rule.id}').replaceWith('<img src=\"#{ApplicationController.root_context}/images/loading.gif\"/>');},
-                                 data: 'level='+ get_level_for_rule($j('#levels_select_#{rule.id} :selected'),$j('#levels_check_#{rule.id}'))});"
-       changel_level = "if($j('#levels_check_#{rule.id}').prop('checked'))
-                        {$j.ajax({url:'#{ApplicationController.root_context}/new_rules_configuration/activate_rule/#{profile.id}?rule_id=#{rule.id}',type:'POST',
-                                  beforeSend:function(request){$j('#levels_#{rule.id}').replaceWith('<img src=\"#{ApplicationController.root_context}/images/loading.gif\"/>');},
-                                  data:'level='+$j('#levels_select_#{rule.id} :selected').val()})}"
-    %>
-
-    <%= check_box_tag(check_box_id, 'yes', !rule.activeRuleId.nil?, :onclick => activate_rule, :disabled => !enable_modification || rule.inherited? || rule.overrides?) %>
-    <%= select_tag(select_box_id, options_for_select(RulesConfigurationController::RULE_PRIORITIES, rule.severity),
-                   {:onchange => changel_level, :disabled => (!(enable_modification))}) %>
-
-    <% if rule.inherited? %>
-      <img src="<%= ApplicationController.root_context -%>/images/inherited.png" alt="Inherited from parent" title="<%= message('rules_configuration.inherited_from_parent') -%>"/>
-    <% elsif rule.overrides? %>
-      <img src="<%= ApplicationController.root_context -%>/images/overrides.png" alt="Overrides parent definition" title="<%= message('rules_configuration.overrides_parent_definition') -%>"/>
-    <% end %>
-  </form>
-</td>
-
-<td class="left" colspan="2">
-  <% unless rule.status != "READY" %>
-    <div class="rule-status">
-      <% if rule.status == "BETA" %>
-        <span><%= message('rules.status.beta') %></span>
-      <% elsif rule.status == "DEPRECATED" %>
-        <span><%= message('rules.status.deprecated') %></span>
-      <% end %>
-    </div>
-  <% end %>
-
-  <div class="h3 rule-title"><%= link_to_function("#{h rule.name}", nil, :class => "") do |page|
-    page.toggle "desc_#{rule.id}"
-  end
-  %></div>
-
-  <div id="desc_<%= rule.id -%>" class="rule-desc" style="<%= 'display:none' -%>">
-    <a name="rule<%= rule.id -%>"></a>
-
-    <div id="rule_note_<%= rule.id -%>" class="marginbottom10">
-      <%= render :partial => 'rule_note', :locals => {:rule => rule} %>
-    </div>
-
-    <%
-       parent_active_rule = Internal.quality_profiles.parentProfileRule(rule) if (rule.inherited? || rule.overrides?)
-       if parent_active_rule || !rule.params.empty?
-    %>
-      <table width="100%" class="table spacer-bottom bordered background-gray">
-        <%
-           if parent_active_rule
-             parent_active_rule_link = link_to parent_profile.name, :controller => 'rules_configuration', :action => 'index',
-                                                 :id => parent_profile.id, :rule_id => rule.id, :anchor => 'rule' + rule.id.to_s
-        %>
-          <tr>
-            <td colspan="2">
-              <%= message(rule.inherited? ? 'rules_configuration.rule_inherited_from_profile_x' : 'rules_configuration.rule_overriding_from_profile_x',
-                          :params => parent_active_rule_link) -%>
-              <% if parent_active_rule.severity != rule.severity %>
-                <img src="<%= ApplicationController.root_context -%>/images/overrides.png" alt="Overrides parent definition" title="<%= message('rules_configuration.overrides_parent_definition') -%>" style="vertical-align: middle"/>
-                <span class="form-val-note" style="font-weight: bold"> <%= message('rules_configuration.original_severity') -%>
-                  : <%= parent_active_rule.severity -%></span>
-              <% end %>
-              <% if profiles_administrator? && rule.overrides? %>
-                <form action="<%= url_for :overwrite_params => {:action => 'revert_rule', :id => profile.id, :active_rule_id => rule.activeRuleId} -%>" method="post" style="display: inline">
-                  <input type="submit" value="<%= message('rules_configuration.revert_to_parent_definition') -%>">
-                </form>
-              <% end %>
-            </td>
-          </tr>
-        <% end %>
-        <% rule.params.each do |parameter| %>
-          <tr id="param_<%= parameter.key -%>">
-            <%= render :partial => 'rule_param', :object => nil,
-                       :locals => {:parameter => parameter, :profile => profile, :rule => rule, :parent_active_rule => parent_active_rule} %>
-          </tr>
-        <%
-           end
-        %>
-      </table>
-    <% end %>
-
-    <div id="active_rule_note_<%= rule.activeRuleId -%>">
-      <%= render :partial => 'active_rule_note', :locals => {:rule => rule} %>
-    </div>
-
-    <% if profiles_administrator? %>
-      <% if rule.template? %>
-        <%= link_to message('rules_configuration.copy_rule'), {:action => 'new', :id => profile.id, :rule_id => rule.id}, :id => "copy-#{u rule.key}", :class => 'link-action spacer-right' %>
-      <% end %>
-      <% if rule.editable? %>
-        <%= link_to message('rules_configuration.edit_rule'), {:action => 'edit', :id => profile.id, :rule_id => rule.id}, :class => 'link-action spacer-right' %>
-      <% end %>
-    <% end %>
-
-    <div class="note">
-      <span id="rule_repository_<%= rule.id -%>"><%= message('rules_configuration.repository') %>: <%= rule.repositoryKey %></span>
-      &nbsp;<%= image_tag 'sep12.png' -%>&nbsp;
-      <span id="rule_key_<%= rule.id -%>"><%= message('key') %>: <%= rule.key %></span>
-      <% unless rule.systemTags.isEmpty && rule.adminTags.isEmpty %>
-      &nbsp;<%= image_tag 'sep12.png' -%>&nbsp;
-        <% rule.systemTags.each do |tag| %>
-        <span id="rule_tag_<%= rule.id -%>_<%= tag -%>" style="background-color: #efe;padding: 1px 2px"><%= tag -%></span>
-        <% end %>
-        <% rule.adminTags.each do |tag| %>
-        <span id="rule_tag_<%= rule.id -%>_<%= tag -%>" style="background-color: #eef;padding: 1px 2px"><%= tag -%></span>
-        <% end %>
-      <% end %>
-      &nbsp;<%= image_tag 'sep12.png' -%>&nbsp;
-      <% if rule.status == "REMOVED" %>
-        <span id="rule_available_since_<%= rule.id -%>"><%= message('rules_configuration.removed_since') %>: <%= human_short_date(Api::Utils.java_to_ruby_datetime(rule.updatedAt)) %></span>
-      <% else %>
-        <span id="rule_available_since_<%= rule.id -%>"><%= message('rules_configuration.available_since') %> <%= human_short_date(Api::Utils.java_to_ruby_datetime(rule.createdAt)) %></span>
-      <% end %>
-    </div>
-  </div>
-</td>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/_rule_note.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/_rule_note.html.erb
deleted file mode 100644 (file)
index ee8392d..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-<% #locals = rule
-  note = rule.ruleNote
-  note_detail_div_id = "nd_" + rule.id.to_s
-  note_extend_link_id = "nel_" + rule.id.to_s
-  note_form_div_id = "nf_" + rule.id.to_s
-  note_textarea_id = "nt_" + rule.id.to_s
-  submit_note_update_button_id = "snub_" + rule.id.to_s
-%>
-
-<div id="<%= note_detail_div_id -%>">
-  <div class="marginbottom10">
-  <% unless rule.description.nil? %>
-    <% if rule.description.strip.start_with?('<p>') %>
-      <%= Internal.text.interpretMacros(rule.description) %>
-    <% else %>
-      <p><%= Internal.text.interpretMacros(rule.description) %></p>
-    <% end %>
-  <% end %>
-  </div>
-
-  <% unless rule.ruleNote.nil? %>
-    <p><%= rule.ruleNote.data -%></p>
-  <% end %>
-
-  <% if profiles_administrator? %>
-    <div>
-        <a href="#" id="<%= note_extend_link_id -%>" class="link-action spacer-right"
-           onclick="$j('#<%= note_detail_div_id -%>').hide();$j('#<%= note_form_div_id -%>').show();$j('#<%= note_textarea_id -%>').focus();return false;"><%= message('rules_configuration.extend_description') %></a>
-    </div>
-  <% end %>
-</div>
-
-<% if profiles_administrator? %>
-<div id="<%= note_form_div_id -%>" style="display: none" class="admin">
-
-  <form onsubmit="$j.ajax({
-                        url:'<%=ApplicationController.root_context-%>/new_rules_configuration/update_rule_note?rule_id=<%=rule.id-%>&active_rule_id=<%=rule.activeRuleId-%>',
-                        success:function(response){;$j('#rule_note_<%=rule.id-%>').html(response);},
-                        data: $j(this).serialize(),
-                        type:'post'});
-                  return false;"
-        method="post"
-        action="<%=ApplicationController.root_context-%>/new_rules_configuration/update_rule_note?rule_id=<%=rule.id-%>">
-  <table class="width100 table">
-    <tbody>
-      <tr>
-        <td colspan="2"><%= rule.description %></td>
-      </tr>
-      <tr>
-        <td class="width100" colspan="2">
-          <textarea name="text" id="<%= note_textarea_id -%>" rows="10" style="width:100%"><%= h(note.data) if note -%></textarea>
-        </td>
-      </tr>
-    <tr>
-      <td>
-        <input type="submit" value="<%= message('rules_configuration.extend_description') -%>" name="commit" id="<%= submit_note_update_button_id -%>"/>
-        <a href="#" onclick="$j('#<%= note_detail_div_id -%>').show();$j('#<%= note_form_div_id -%>').hide();return false;"><%= message('cancel') %></a>
-      </td>
-      <td align="right">
-        <%= render :partial => 'markdown/tips' -%>
-      </td>
-    </tr>
-    </tbody>
-  </table>
-  </form>
-</div>
-<% end %>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/_rule_param.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/_rule_param.html.erb
deleted file mode 100644 (file)
index 064c222..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-<% # locals = rule, profile, parameter, parent_active_rule
-   param_id = "#{rule.id}#{parameter.key}"
-   # Display default value only for inactive rules
-   param_value = parameter.default_value if !rule.activeRuleId
-   param_value = parameter.value if !param_value
-   active_rule_id = rule.activeRuleId
-   read_only = rule.activeRuleId.nil? || !profiles_administrator?
-%>
-
-<td class="form-key-cell"><%= parameter.key -%></td>
-
-<td class="form-val-cell">
-    <form onsubmit="$j.ajax({  url: '<%= ApplicationController.root_context -%>/new_rules_configuration/update_param/?active_rule_id=<%=active_rule_id-%>&param_id=<%=parameter.key-%>&profile_id=<%=profile.id-%>',
-                               type:'post',beforeSend: function(request){$j('#param_loading_<%=param_id-%>').show();$j('#error_<%=param_id-%>').hide();},
-                               data: $j(this).serialize(),
-                               success: function(response){$j('#rule_<%=rule.id-%>').html(response);},
-                               complete: function(request){$j('#desc_<%=rule.id-%>').show();$j('#param_loading_<%=param_id-%>').hide();},
-                               error: function(request){$j('#error_<%=param_id-%>').text(request.responseText);$j('#error_<%=param_id-%>').show();}
-                            }); return false;"
-           name="form-<%=u parameter.key-%>" method="post"
-           action="<%= ApplicationController.root_context -%>/new_rules_configuration/update_param/?active_rule_id=<%=active_rule_id-%>&param_id=<%=parameter.key-%>&profile_id=<%=profile.id-%>">
-
-  <div id="error_<%= param_id -%>" class="error" style="display: none"></div>
-
-  <span id="text_<%= param_id -%>"><%= param_value_input(rule, parameter, param_value, :disabled => read_only) -%></span>
-
-  <% unless read_only %>
-    <%= submit_tag(message('update_verb'), :id => 'submit_' + param_id.to_s) %>
-    <img src="<%= ApplicationController.root_context -%>/images/loading.gif" style="display:none;" id="param_loading_<%= param_id -%>" class="rule-param-loading">
-  <% end %>
-
-  <% if !rule.nil? && rule.overrides? && parent_active_rule
-       ancestor_param = parent_active_rule.params.to_a.find {|param| param.key() == parameter.key}
-       ancestor_value = ancestor_param && ancestor_param.value ? ancestor_param.value : ''
-  %>
-    <% if ancestor_value != param_value %>
-      <img src="<%= ApplicationController.root_context -%>/images/overrides.png" alt="Overrides parent definition" title="<%= message('rules_configuration.overrides_parent_definition') -%>" style="vertical-align: middle"/>
-      <span class="form-val-note" style="font-weight: bold; vertical-align: middle;">
-        <%= message('rules_configuration.original_value') -%>
-        : <%= ancestor_value.blank? ? '(' + message('rules_configuration.parent_parameter.empty') + ')' : ancestor_value -%>
-      </span>
-    <% end %>
-  <% end %>
-
-  <div class="form-val-note"><%= h(parameter.description || "") -%> <%= ('(' + readable_type(parameter.type) + ')') if !readable_type(parameter.type).empty? -%></div>
-
-  </form>
-</td>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/edit.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/edit.html.erb
deleted file mode 100644 (file)
index 5e98093..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-<h1 class="marginbottom10"><%= link_to message('quality_profiles.quality_profiles'), :controller => 'profiles', :action => 'index' -%> / <%= h @profile.language() -%> / <%= h @profile.name() %></h1>
-
-<%= render :partial => 'profiles/tabs', :locals => {:new_tab => 'Edit rule'} %>
-
-<div class="tabs-panel marginbottom10 background-gray">
-
-<form method="POST" id="delete-form" action="<%= url_for :action => 'delete', :id => @profile.id(), :rule_id => @rule.id() -%>" style="display: none"></form>
-<script>
-  function deleteRule() {
-    var count = <%= @active_rules -%>;
-    var message = 'Are you sure?';
-    if (count>0) {
-      message += ' This rule is activated in ' + count + ' profiles.';
-    }
-    if (confirm(message)) {
-      $j('#delete-form').submit();
-    }
-    return false;
-  }
-</script>
-<form method="POST" action="<%= url_for :action => 'update', :id => @profile.id(), :rule_id => @rule.id() -%>">
-<table width="100%" class="spaced">
-  <tr>
-    <td width="1%" nowrap><%= message('template') -%>:</td>
-    <td class="sep"> </td>
-    <td><%= h @parent_rule.name() -%></td>
-  </tr>
-  <tr>
-    <td width="1%" nowrap><%= message('name') -%>:</td>
-    <td class="sep"> </td>
-    <td><input type="text" name="rule[name]" size="80" value="<%= h @rule.name() -%>" /></td>
-  </tr>
-  <tr>
-    <td width="1%" nowrap><%= message('default_severity') -%>:</td>
-    <td class="sep"> </td>
-    <td>
-      <select name="rule[priority]">
-        <%= options_for_select(Sonar::RulePriority.as_options, Sonar::RulePriority.to_s(@rule.severity())) %>
-      </select>
-    </td>
-  </tr>
-  <% @rule.params.to_a.sort{|x,y| x.key() <=> y.key()}.each do |parameter| %>
-    <tr>
-      <td width="1%" nowrap><%= parameter.key() %>:</td>
-      <td class="sep"> </td>
-      <td>
-        <%= param_value_input(@rule, parameter, "#{h parameter.defaultValue()}", {:name => "rule_param[#{h parameter.key() }]", :size => '80x10'}) -%>
-        <span class="small"><%= h parameter.description() %></span>
-      </td>
-    </tr>
-  <% end %>
-  <tr>
-    <td width="1%" nowrap style="vertical-align: top">Description:</td>
-    <td class="sep"> </td>
-    <td valign="top">
-      <textarea name="rule[description]" cols="80" rows="10" style="vertical-align: baseline"><%= @rule.description() -%></textarea>
-      <span class="small"><%= message('rules_configuration.html_allowed') -%></span>
-    </td>
-  </tr>
-  <tr>
-    <td colspan="3">
-      <input type="submit" value="<%= message('update_verb') -%>" />
-      <input type="submit" value="<%= message('delete') -%>" onclick="return deleteRule()" class="red-button" />
-      <a href="<%= url_for :action => 'index', :id => @profile.id() -%>"><%= message('cancel') -%></a>
-    </td>
-  </tr>
-</table>
-</form>
-</div>
\ No newline at end of file
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/index.html.erb
deleted file mode 100644 (file)
index b2c5dbd..0000000
+++ /dev/null
@@ -1,153 +0,0 @@
-<div class="page">
-<script>
-  var localModifications=false;
-
-  function get_level_for_rule(rule_select_box,rule_check_box) {
-     return rule_check_box.prop('checked') ? rule_select_box.val() : '';
-  }
-
-  function submitBulkForm() {
-    if (localModifications) {
-      alert("Please refresh the search results before.");
-      $j('#bulk-form').reset();
-    } else {
-      $j('#bulk-form').submit();
-      $j('#select-bulk-change').select2('disable');
-    }
-    return !localModifications;
-  }
-
-  function expand_rules(){
-     $j('.rule-desc').show();
-  }
-
-  function collapse_rules(){
-    $j('.rule-desc').hide();
-  }
-
-  function submitSearch() {
-    $j("#rules-search-form").submit();
-  }
-
-  function submitSortBy(){
-    $j('#sort_by').val($j('#select-rules-sort-by').val());
-    $j("#rules-search-form").submit();
-  }
-</script>
-<%= render :partial => 'profiles/tabs', :locals => {:selected_tab=>'Coding rules reloaded'} %>
-
-<% enable_modification = profiles_administrator? %>
-<div class="tabs-panel marginbottom10 background-gray">
-
-<% form_tag({:action => 'index'}, {:id => 'rules-search-form', :method => 'get'}) do %>
-    <%= hidden_field_tag "sort_by", @sort_by, :id => 'sort_by' %>
-
-    <div class="table" id="search_table">
-      <div class="rule-search top">
-        <span class="note"><%= message('name') -%>/<%= message('key') -%></span><br/>
-        <%= text_field_tag "searchtext", @searchtext, :id => 'searchtext' %>
-      </div>
-      <div class="rule-search top">
-        <span class="note"><%= message('rules_configuration.repository') -%></span><br/>
-        <%= dropdown_tag "repositories", options_for_select(@select_repositories, @repositories), {
-            :show_search_box => true,
-            :width => '120px',
-            :placeholder => message('any')
-        }, {:id => 'search_repository', :multiple => true} -%>
-      </div>
-      <div class="rule-search top">
-        <span class="note"><%= message('severity') -%></span><br/>
-        <%= dropdown_tag "priorities", options_for_select(@select_priority, @priorities), {
-            :show_search_box => true,
-            :width => '90px',
-            :placeholder => message('any')
-        }, {:id => 'search_priority', :multiple => true} -%>
-      </div>
-      <div class="rule-search top">
-        <span class="note"><%= message('activation') -%></span><br/>
-        <%= dropdown_tag "rule_activation", options_for_select(@select_activation, @activation), {
-            :width => '100px'
-        }, {:id => 'search_activation'} -%>
-      </div>
-      <div class="rule-search top">
-        <span class="note"><%= message('rules_configuration.status_filters') -%></span><br/>
-        <%= dropdown_tag "status", options_for_select(@select_status, @status), {
-            :show_search_box => true,
-            :width => '120px',
-            :placeholder => message('any')
-        }, {:id => 'search_status', :multiple => true} -%>
-      </div>
-      <% if @profile.isInherited() %>
-        <div class="rule-search top">
-          <span class="note"><%= message('inheritance') -%></span><br/>
-          <%= dropdown_tag "inheritance", options_for_select(@select_inheritance, @inheritance), {
-              :width => '120px'
-          }, {:id => 'search_inheritance'} -%>
-        </div>
-      <% end %>
-      <div class="rule-search">
-        <br/>
-        <%= submit_tag message('search_verb'), :id => 'submit_search', :onclick => 'submitSearch();' %>
-      </div>
-    </div>
-
-<% end %>
-</div>
-<div class="line-block marginbottom10">
-  <% if enable_modification && @current_rules.size>0 %>
-    <ul style="float: right" class="horizontal">
-      <li class="marginleft10">
-        <div class="bulk-edit"><%= message('bulk_change') -%>:
-        <form action="<%= ApplicationController.root_context -%>/new_rules_configuration/bulk_edit?<%= @criteria_params.to_query -%>" method="POST" id="bulk-form"
-              style="display: inline; vertical-align: middle; padding-right:5px">
-          <input type="hidden" name="id" value="<%= @profile.id -%>"/>
-          <%= dropdown_tag "bulk_action", options_for_select([ ["", ""], [message('activate_all'), "activate"], [message('deactivate_all'), "deactivate"] ], ''), {
-              :width => '110px'
-          }, {:onChange => 'submitBulkForm()', :id => 'select-bulk-change'} -%>
-        </form>
-        </div>
-      </li>
-    </ul>
-  <% end %>
-  <h2>
-     <% if @hidden_actives && @hidden_actives>0 %>
-      <span class="small"><a href="<%= url_for params.merge({:rule_activation => 'ACTIVE'}) -%>"
-        id="active-rules-link">+<%= message('rules_configuration.x_found_in_active_rules', :params => @hidden_actives) -%></a></span><% end %>
-     <% if @hidden_inactives && @hidden_inactives>0 %>
-      <span class="small"><a href="<%= url_for params.merge({:rule_activation => 'INACTIVE'}) -%>"
-        id="inactive-rules-link">+<%= message('rules_configuration.x_found_in_inactive_rules', :params => @hidden_inactives) -%></a></span><% end %>
-  </h2>
-</div>
-<table class="table table-bordered width100 spacer-bottom" id="result_table">
-  <thead>
-    <tr>
-      <th class="left" nowrap><%= message('active') -%>/<%= message('severity') -%></th>
-      <th class="left"><%= message('name') -%> <span style="font-weight: normal">
-        [<%= link_to_function(message('rules_configuration.expand'), "expand_rules()") %> / <%= link_to_function(message('rules_configuration.collapse'), "collapse_rules()") %>]</span></th>
-      <th class="right" nowrap>
-        <span class="middle"><%= message('rules_configuration.sort_by') -%></span>
-        <% form_tag({:action => 'index'}, :class=> 'middle', :style => 'display:inline-block') do %>
-          <%= dropdown_tag "sort_by", options_for_select(@select_sort_by, @sort_by), {
-              :width => '120px'
-          }, {:id => 'select-rules-sort-by', :onChange => 'submitSortBy()'} -%>
-        <% end %>
-      </th>
-    </tr>
-</thead>
-
-<%= table_pagination(@pagination, :colspan => 2) { |label, page_id| link_to(label, params.merge({:page => page_id}))} -%>
-
-<tbody>
-<% if @current_rules.empty? %>
-<tr><td colspan="3" class="even"><%= message('no_results') -%>.</td></tr>
-<% end %>
-<%
-  @current_rules.each do |rule|
-%>
-  <tr id="rule_<%= rule.id -%>">
-    <%= render :partial => 'rule', :object => rule, :locals => {:rule => rule, :profile => @profile, :parent_profile => @parent_profile} %>
-  </tr>
-<% end %>
-</tbody>
-</table>
-</div>
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
deleted file mode 100644 (file)
index 46945e3..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-<div class="page">
-<%= render :partial => 'profiles/tabs', :locals => {:new_tab => message('rules_configuration.tab.new_rule')} %>
-
-<div class="tabs-panel marginbottom10 background-gray">
-
-<form method="POST" action="<%= url_for :action => 'create', :id => @profile.id, :rule_id => @rule.id -%>">
-<table width="100%" class="spaced">
-  <tr>
-    <td width="1%" nowrap><%= message('template') -%>:</td>
-    <td class="sep"> </td>
-    <td><%= h @rule.name -%></td>
-  </tr>
-  <tr>
-    <td width="1%" nowrap><%= message('name') -%>:</td>
-    <td class="sep"> </td>
-    <td><input type="text" name="rule[name]" size="80"/></td>
-  </tr>
-  <tr>
-    <td width="1%" nowrap><%= message('default_severity') -%>:</td>
-    <td class="sep"> </td>
-    <td>
-      <select name="rule[priority]">
-        <%= options_for_select(Sonar::RulePriority.as_options) %>
-      </select>
-    </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| %>
-      <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>
-    <td class="sep"> </td>
-    <td valign="top">
-      <textarea name="rule[description]" cols="80" rows="10" style="vertical-align: baseline"></textarea>
-      <span class="small"><%= message('rules_configuration.html_allowed') -%></span>
-    </td>
-  </tr>
-  <tr>
-    <td colspan="3">
-      <input type="submit" value="<%= message('create') -%>"/> <a href="<%= url_for :action => 'index', :id => @profile.id -%>"><%= message('cancel') -%></a>
-    </td>
-  </tr>
-</table>
-</form>
-</div>
-</div>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/_active_rule_note.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/_active_rule_note.html.erb
new file mode 100644 (file)
index 0000000..2928711
--- /dev/null
@@ -0,0 +1,70 @@
+<% #locals = active_rule, profile
+  note = active_rule.note
+  active_note_detail_div_id = "and_" + active_rule.id.to_s
+  add_active_note_button_id = "aanb_" + active_rule.id.to_s
+  edit_active_note_link_id = "eanl_" + active_rule.id.to_s
+  delete_active_note_link_id = "danl_" + active_rule.id.to_s
+  active_note_form_div_id = "anf_" + active_rule.id.to_s
+  active_note_textarea_id = "ant_" + active_rule.id.to_s
+  submit_active_note_update_button_id = "sanub_" + active_rule.id.to_s
+%>
+
+<div id="<%= active_note_detail_div_id -%>">
+  <% if note %>
+    <blockquote class="spacer-bottom">
+      <cite>
+        <b><%= note.user.name -%></b> (<%= distance_of_time_in_words_to_now(note.updated_at) -%>)&nbsp;
+        <% if profiles_administrator? %>
+          | &nbsp;
+          <a href="#" id="<%= edit_active_note_link_id -%>" class="link-action"
+             onclick="$j('#<%= active_note_detail_div_id -%>').hide();$j('#<%= active_note_form_div_id -%>').show();$j('#<%= active_note_textarea_id -%>').focus();return false;"><%= message('edit') %></a>
+          &nbsp;
+          <a class="link-action"
+             onclick="if(confirm('<%= escape_javascript(message('rules_configuration.confirm_delete_note')) -%>')){
+                             $j.ajax({
+                                       url: '<%=ApplicationController.root_context-%>/old_rules_configuration/delete_active_rule_note?active_rule_id=<%=active_rule.id-%>',
+                                       type: 'post',
+                                       success:function(response){$j('#active_rule_note_<%= active_rule.id -%>').html(response);}
+                                     });};return false;"
+             href="#!"><%=message('delete')-%></a>
+        <% end %>
+      </cite>
+      <p><%= note.html_text -%></p>
+    </blockquote>
+  <% elsif profiles_administrator? %>
+    <a href="#" onclick="$j('#<%= active_note_form_div_id -%>').show();$j('#<%= active_note_detail_div_id -%>').hide();$j('#<%= active_note_textarea_id -%>').focus(); return false;"
+       class="link-action spacer-right" id="<%= add_active_note_button_id -%>"><%= message('rules_configuration.add_note') -%></a>
+  <% end %>
+</div>
+
+<% if profiles_administrator? %>
+  <form onsubmit="$j.ajax({
+                            url:'<%= ApplicationController.root_context -%>/old_rules_configuration/update_active_rule_note?active_rule_id=<%=active_rule.id-%>',
+                            data: $j(this).serialize(),
+                            type:'post',
+                            success:function(response){$j('#active_rule_note_<%= active_rule.id -%>').html(response);}
+                          });
+                  return false;"
+          method="post"
+          action="<%= ApplicationController.root_context -%>/old_rules_configuration//update_active_rule_note?active_rule_id=<%=active_rule.id-%>">
+  <table id="<%= active_note_form_div_id -%>" style="display: none" class="admin table width100">
+    <tbody>
+      <tr>
+        <td class="width100" colspan="2">
+          <textarea name="note" id="<%= active_note_textarea_id -%>" rows="10" style="width:100%"
+                    onkeyup="if (this.value=='') $j('#<%= submit_active_note_update_button_id -%>').prop('disabled', true); else $j('#<%= submit_active_note_update_button_id -%>').prop('disabled', false);"><%= h(note.plain_text) if note -%></textarea>
+        </td>
+      </tr>
+    <tr>
+      <td>
+        <input type="submit" value="<%= note ? message('update_verb') : message('rules_configuration.add_note') -%>" name="submit-active-note" id="<%= submit_active_note_update_button_id -%>" disabled="disabled"/>
+        <a href="#" onclick="$j('#<%= active_note_detail_div_id -%>').show();$j('#<%= active_note_form_div_id -%>').hide();return false;"><%= message('cancel') %></a>
+      </td>
+      <td align="right">
+        <%= render :partial => 'markdown/tips' -%>
+      </td>
+    </tr>
+    </tbody>
+  </table>
+  </form>
+<% end %>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/_rule.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/_rule.html.erb
new file mode 100644 (file)
index 0000000..a04a2e4
--- /dev/null
@@ -0,0 +1,121 @@
+<td nowrap valign="top" class="left" x="<%= active_rule.failure_level if active_rule -%>" width="1%">
+  <form id="levels_<%= rule.id -%>" action="" class="rule-levels-form">
+    <% enable_modification = profiles_administrator?
+       select_box_id = "levels_select_#{rule.id}"
+       check_box_id = "levels_check_#{rule.id}"
+       activate_rule = "$j.ajax({url:'#{ApplicationController.root_context}/old_rules_configuration/activate_rule/#{profile.id}?rule_id=#{rule.id}',type: 'POST',
+                                 beforeSend: function(request){$j('#levels_#{rule.id}').replaceWith('<img src=\"#{ApplicationController.root_context}/images/loading.gif\"/>');},
+                                 data: 'level='+ get_level_for_rule($j('#levels_select_#{rule.id} :selected'),$j('#levels_check_#{rule.id}'))});"
+       changel_level = "if($j('#levels_check_#{rule.id}').prop('checked'))
+                        {$j.ajax({url:'#{ApplicationController.root_context}/old_rules_configuration/activate_rule/#{profile.id}?rule_id=#{rule.id}',type:'POST',
+                                  beforeSend:function(request){$j('#levels_#{rule.id}').replaceWith('<img src=\"#{ApplicationController.root_context}/images/loading.gif\"/>');},
+                                  data:'level='+$j('#levels_select_#{rule.id} :selected').val()})}"
+    %>
+
+    <%= check_box_tag(check_box_id, 'yes', (!active_rule.nil?), :onclick => activate_rule, :disabled => !enable_modification || (active_rule && (active_rule.inherited? || active_rule.overrides?))) %>
+    <%= select_tag(select_box_id, options_for_select(RulesConfigurationController::RULE_PRIORITIES, (active_rule.nil? ? rule.priority_text : active_rule.priority_text)),
+                   {:onchange => changel_level, :disabled => (!(enable_modification) || active_rule.nil?)}) %>
+
+    <% if active_rule %>
+      <% if active_rule.inherited? %>
+        <img src="<%= ApplicationController.root_context -%>/images/inherited.png" alt="Inherited from parent" title="<%= message('rules_configuration.inherited_from_parent') -%>"/>
+      <% elsif active_rule.overrides? %>
+        <img src="<%= ApplicationController.root_context -%>/images/overrides.png" alt="Overrides parent definition" title="<%= message('rules_configuration.overrides_parent_definition') -%>"/>
+      <% end %>
+    <% end %>
+  </form>
+</td>
+
+<td class="left" colspan="2">
+  <% unless rule.ready? %>
+    <div class="rule-status">
+      <% if rule.beta? %>
+        <span><%= message('rules.status.beta') %></span>
+      <% elsif rule.deprecated? %>
+        <span><%= message('rules.status.deprecated') %></span>
+      <% end %>
+    </div>
+  <% end %>
+
+  <div class="h3 rule-title"><%= link_to_function("#{h rule.name}", nil, :class => "") do |page|
+    page.toggle "desc_#{rule.id}"
+  end
+  %></div>
+
+  <div id="desc_<%= rule.id -%>" class="rule-desc" style="<%= 'display:none' -%>">
+    <a name="rule<%= rule.id -%>"></a>
+
+    <div id="rule_note_<%= rule.id -%>" class="marginbottom10">
+      <%= render :partial => 'rule_note', :locals => {:rule => rule} %>
+    </div>
+
+    <%
+       ancestor_profile = profile.parent
+       ancestor_active_rule = ancestor_profile.active_by_rule_id(rule.id) if ancestor_profile && active_rule && (active_rule.inherited? || active_rule.overrides?)
+       if ancestor_active_rule || !rule.parameters.empty?
+    %>
+      <table width="100%" class="table spacer-bottom bordered background-gray">
+        <%
+           if ancestor_active_rule
+             ancestor_active_rule_link = link_to ancestor_profile.name, :controller => 'rules_configuration', :action => 'index',
+                                                 :id => ancestor_profile.id, :rule_id => rule.id, :anchor => 'rule' + rule.id.to_s
+        %>
+          <tr>
+            <td colspan="2">
+              <%= message(active_rule.inherited? ? 'rules_configuration.rule_inherited_from_profile_x' : 'rules_configuration.rule_overriding_from_profile_x',
+                          :params => ancestor_active_rule_link) -%>
+              <% if ancestor_active_rule.priority != active_rule.priority %>
+                <img src="<%= ApplicationController.root_context -%>/images/overrides.png" alt="Overrides parent definition" title="<%= message('rules_configuration.overrides_parent_definition') -%>" style="vertical-align: middle"/>
+                <span class="form-val-note" style="font-weight: bold"> <%= message('rules_configuration.original_severity') -%>
+                  : <%= ancestor_active_rule.priority_text -%></span>
+              <% end %>
+              <% if profiles_administrator? && active_rule.overrides? %>
+                <form action="<%= url_for :overwrite_params => {:action => 'revert_rule', :id => profile.id, :active_rule_id => active_rule.id} -%>" method="post" style="display: inline">
+                  <input type="submit" value="<%= message('rules_configuration.revert_to_parent_definition') -%>">
+                </form>
+              <% end %>
+            </td>
+          </tr>
+        <% end %>
+        <% rule.parameters.sort.each do |parameter|
+          active_parameter = active_rule.active_param_by_param_id(parameter.id) if active_rule
+        %>
+          <tr id="param_<%= parameter.id -%>">
+            <%= render :partial => 'rule_param', :object => nil,
+                       :locals => {:parameter => parameter, :active_parameter => active_parameter, :profile => profile, :rule => rule,
+                                   :active_rule => active_rule, :ancestor_active_rule => ancestor_active_rule} %>
+          </tr>
+        <%
+           end
+        %>
+      </table>
+    <% end %>
+
+    <% if active_rule %>
+      <div id="active_rule_note_<%= active_rule.id -%>">
+        <%= render :partial => 'active_rule_note', :locals => {:active_rule => active_rule, :profile => profile} %>
+      </div>
+    <% end %>
+
+    <% if profiles_administrator? %>
+      <% if rule.template? %>
+        <%= link_to message('rules_configuration.copy_rule'), {:action => 'new', :id => profile.id, :rule_id => rule.id}, :id => "copy-#{u rule.key}", :class => 'link-action spacer-right' %>
+      <% end %>
+      <% if rule.editable? %>
+        <%= link_to message('rules_configuration.edit_rule'), {:action => 'edit', :id => profile.id, :rule_id => rule.id}, :class => 'link-action spacer-right' %>
+      <% end %>
+    <% end %>
+
+    <div class="note">
+      <span id="rule_repository_<%= rule.id -%>"><%= message('rules_configuration.repository') %>: <%= rule.repository_key %></span>
+      &nbsp;<%= image_tag 'sep12.png' -%>&nbsp;
+      <span id="rule_key_<%= rule.id -%>"><%= message('key') %>: <%= rule.plugin_rule_key %></span>
+      &nbsp;<%= image_tag 'sep12.png' -%>&nbsp;
+      <% if rule.removed? %>
+        <span id="rule_available_since_<%= rule.id -%>"><%= message('rules_configuration.removed_since') %>: <%= human_short_date(rule.updated_at) %></span>
+      <% else %>
+        <span id="rule_available_since_<%= rule.id -%>"><%= message('rules_configuration.available_since') %> <%= human_short_date(rule.created_at) %></span>
+      <% end %>
+    </div>
+  </div>
+</td>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/_rule_note.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/_rule_note.html.erb
new file mode 100644 (file)
index 0000000..f9f88e9
--- /dev/null
@@ -0,0 +1,65 @@
+<% #locals = rule
+  note = rule.note
+  note_detail_div_id = "nd_" + rule.id.to_s
+  note_extend_link_id = "nel_" + rule.id.to_s
+  note_form_div_id = "nf_" + rule.id.to_s
+  note_textarea_id = "nt_" + rule.id.to_s
+  submit_note_update_button_id = "snub_" + rule.id.to_s
+%>
+
+<div id="<%= note_detail_div_id -%>">
+  <div class="marginbottom10">
+  <% if rule.description.strip.start_with?('<p>') %>
+    <%= Internal.text.interpretMacros(rule.description) %>
+  <% else %>
+    <p><%= Internal.text.interpretMacros(rule.description) %></p>
+  <% end %>
+  </div>
+
+  <% if note && !note.text.strip.blank? %>
+    <p><%= note.html_text -%></p>
+  <% end %>
+
+  <% if profiles_administrator? %>
+    <div>
+        <a href="#" id="<%= note_extend_link_id -%>" class="link-action spacer-right"
+           onclick="$j('#<%= note_detail_div_id -%>').hide();$j('#<%= note_form_div_id -%>').show();$j('#<%= note_textarea_id -%>').focus();return false;"><%= message('rules_configuration.extend_description') %></a>
+    </div>
+  <% end %>
+</div>
+
+<% if profiles_administrator? %>
+<div id="<%= note_form_div_id -%>" style="display: none" class="admin">
+
+  <form onsubmit="$j.ajax({
+                        url:'<%=ApplicationController.root_context-%>/old_rules_configuration/update_rule_note?rule_id=<%=rule.id-%>',
+                        success:function(response){;$j('#rule_note_<%=rule.id-%>').html(response);},
+                        data: $j(this).serialize(),
+                        type:'post'});
+                  return false;"
+        method="post"
+        action="<%=ApplicationController.root_context-%>/old_rules_configuration/update_rule_note?rule_id=<%=rule.id-%>">
+  <table class="width100 table">
+    <tbody>
+      <tr>
+        <td colspan="2"><%= rule.description %></td>
+      </tr>
+      <tr>
+        <td class="width100" colspan="2">
+          <textarea name="text" id="<%= note_textarea_id -%>" rows="10" style="width:100%"><%= h(note.plain_text) if note -%></textarea>
+        </td>
+      </tr>
+    <tr>
+      <td>
+        <input type="submit" value="<%= message('rules_configuration.extend_description') -%>" name="commit" id="<%= submit_note_update_button_id -%>"/>
+        <a href="#" onclick="$j('#<%= note_detail_div_id -%>').show();$j('#<%= note_form_div_id -%>').hide();return false;"><%= message('cancel') %></a>
+      </td>
+      <td align="right">
+        <%= render :partial => 'markdown/tips' -%>
+      </td>
+    </tr>
+    </tbody>
+  </table>
+  </form>
+</div>
+<% end %>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/_rule_param.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/_rule_param.html.erb
new file mode 100644 (file)
index 0000000..6c51029
--- /dev/null
@@ -0,0 +1,51 @@
+<%
+   # Display default value only for inactive rules
+   param_value = parameter.default_value if !active_rule
+   param_value = active_parameter.value if !param_value && active_parameter
+   active_param_id = active_parameter.id if active_parameter
+   active_rule_id = active_rule.id if active_rule
+   read_only = !active_rule || !profiles_administrator?
+%>
+
+<td class="form-key-cell"><%= parameter.name -%></td>
+
+<td class="form-val-cell">
+    <form onsubmit="$j.ajax({  url: '<%= ApplicationController.root_context -%>/old_rules_configuration/update_param/<%=active_param_id-%>?active_rule_id=<%=active_rule_id-%>&param_id=<%=parameter.id-%>&profile_id=<%=profile.id-%>',
+                               type:'post',beforeSend: function(request){$j('#param_loading_<%=parameter.id-%>').show();$j('#error_<%=parameter.id-%>').hide();},
+                               data: $j(this).serialize(),
+                               success: function(response){$j('#rule_<%=rule.id-%>').html(response);},
+                               complete: function(request){$j('#desc_<%=rule.id-%>').show();$j('#param_loading_<%=parameter.id-%>').hide();},
+                               error: function(request){$j('#error_<%=parameter.id-%>').text(request.responseText);$j('#error_<%=parameter.id-%>').show();}
+                            }); return false;"
+           name="form-<%=u parameter.name-%>" method="post"
+           action="<%= ApplicationController.root_context -%>/old_rules_configuration/update_param/<%=active_param_id-%>?active_rule_id=<%=active_rule_id-%>&param_id=<%=parameter.id-%>&profile_id=<%=profile.id-%>">
+
+  <div id="error_<%= parameter.id -%>" class="error" style="display: none"></div>
+
+  <span id="text_<%= parameter.id -%>"><%= param_value_input(parameter, param_value, :disabled => read_only) -%></span>
+
+  <% unless read_only %>
+    <%= submit_tag(message('update_verb'), :id => 'submit_' + parameter.id.to_s) %>
+    <img src="<%= ApplicationController.root_context -%>/images/loading.gif" style="display:none;" id="param_loading_<%= parameter.id -%>" class="rule-param-loading">
+    <% if active_parameter and active_parameter.errors.size>0 %>
+      <span class="error"><%= active_parameter.errors.on 'value' %></span>
+    <% end %>
+  <% end %>
+
+  <% if active_rule && active_rule.overrides? && ancestor_active_rule
+       ancestor_param = ancestor_active_rule.active_param_by_param_id(parameter.id)
+       ancestor_value = ancestor_param && ancestor_param.value ? ancestor_param.value : ''
+  %>
+    <% if ancestor_value != param_value %>
+      <img src="<%= ApplicationController.root_context -%>/images/overrides.png" alt="Overrides parent definition" title="<%= message('rules_configuration.overrides_parent_definition') -%>" style="vertical-align: middle"/>
+      <span class="form-val-note" style="font-weight: bold; vertical-align: middle;">
+        <%= message('rules_configuration.original_value') -%>
+        : <%= ancestor_value.blank? ? '(' + message('rules_configuration.parent_parameter.empty') + ')' : ancestor_value -%>
+      </span>
+    <% end %>
+  <% end %>
+
+  <div class="form-val-note"><%= h(parameter.description || "") -%> <%= ('(' + readable_type(parameter.param_type) + ')') if !readable_type(parameter.param_type).empty? -%></div>
+
+  </form>
+</td>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/edit.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/edit.html.erb
new file mode 100644 (file)
index 0000000..fba5800
--- /dev/null
@@ -0,0 +1,69 @@
+<h1 class="marginbottom10"><%= link_to message('quality_profiles.quality_profiles'), :controller => 'profiles', :action => 'index' -%> / <%= h @profile.language -%> / <%= h @profile.name %></h1>
+
+<%= render :partial => 'profiles/tabs', :locals => {:new_tab => 'Edit rule'} %>
+
+<div class="tabs-panel marginbottom10 background-gray">
+
+<form method="POST" id="delete-form" action="<%= url_for :action => 'delete', :id => @profile.id, :rule_id => @rule.id -%>" style="display: none"></form>
+<script>
+  function deleteRule() {
+    var count = <%= ActiveRule.count(:conditions => {:rule_id => @rule.id}) -%>;
+    var message = 'Are you sure?';
+    if (count>0) {
+      message += ' This rule is activated in ' + count + ' profiles.';
+    }
+    if (confirm(message)) {
+      $j('#delete-form').submit();
+    }
+    return false;
+  }
+</script>
+<form method="POST" action="<%= url_for :action => 'update', :id => @profile.id, :rule_id => @rule.id -%>">
+<table width="100%" class="spaced">
+  <tr>
+    <td width="1%" nowrap><%= message('template') -%>:</td>
+    <td class="sep"> </td>
+    <td><%= h @rule.parent.name -%></td>
+  </tr>
+  <tr>
+    <td width="1%" nowrap><%= message('name') -%>:</td>
+    <td class="sep"> </td>
+    <td><input type="text" name="rule[name]" size="80" value="<%= h @rule.name -%>" /></td>
+  </tr>
+  <tr>
+    <td width="1%" nowrap><%= message('default_severity') -%>:</td>
+    <td class="sep"> </td>
+    <td>
+      <select name="rule[priority]">
+        <%= options_for_select(Sonar::RulePriority.as_options, Sonar::RulePriority.to_s(@rule.priority)) %>
+      </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, "#{h parameter.default_value}", {:name => "rule_param[#{h parameter.name }]", :size => '80x10'}) -%>
+        <span class="small"><%= h parameter.description %></span>
+      </td>
+    </tr>
+  <% end %>
+  <tr>
+    <td width="1%" nowrap style="vertical-align: top">Description:</td>
+    <td class="sep"> </td>
+    <td valign="top">
+      <textarea name="rule[description]" cols="80" rows="10" style="vertical-align: baseline"><%= @rule.description -%></textarea>
+      <span class="small"><%= message('rules_configuration.html_allowed') -%></span>
+    </td>
+  </tr>
+  <tr>
+    <td colspan="3">
+      <input type="submit" value="<%= message('update_verb') -%>" />
+      <input type="submit" value="<%= message('delete') -%>" onclick="return deleteRule()" class="red-button" />
+      <a href="<%= url_for :action => 'index', :id => @profile.id -%>"><%= message('cancel') -%></a>
+    </td>
+  </tr>
+</table>
+</form>
+</div>
\ No newline at end of file
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/index.html.erb
new file mode 100644 (file)
index 0000000..e25c991
--- /dev/null
@@ -0,0 +1,155 @@
+<div class="page">
+<script>
+  var localModifications=false;
+
+  function get_level_for_rule(rule_select_box,rule_check_box) {
+     return rule_check_box.prop('checked') ? rule_select_box.val() : '';
+  }
+
+  function submitBulkForm() {
+    if (localModifications) {
+      alert("Please refresh the search results before.");
+      $j('#bulk-form').reset();
+    } else {
+      $j('#bulk-form').submit();
+      $j('#select-bulk-change').select2('disable');
+    }
+    return !localModifications;
+  }
+
+  function expand_rules(){
+     $j('.rule-desc').show();
+  }
+
+  function collapse_rules(){
+    $j('.rule-desc').hide();
+  }
+
+  function submitSearch() {
+    $j("#rules-search-form").submit();
+  }
+
+  function submitSortBy(){
+    $j('#sort_by').val($j('#select-rules-sort-by').val());
+    $j("#rules-search-form").submit();
+  }
+</script>
+<%= render :partial => 'profiles/tabs', :locals => {:selected_tab=>'Old Coding rules'} %>
+
+<% enable_modification = profiles_administrator? %>
+<div class="tabs-panel marginbottom10 background-gray">
+
+<% form_tag({:action => 'index'}, {:id => 'rules-search-form', :method => 'get'}) do %>
+    <%= hidden_field_tag "sort_by", @sort_by, :id => 'sort_by' %>
+
+    <div class="table" id="search_table">
+      <div class="rule-search top">
+        <span class="note"><%= message('name') -%>/<%= message('key') -%></span><br/>
+        <%= text_field_tag "searchtext", @searchtext, :id => 'searchtext' %>
+      </div>
+      <div class="rule-search top">
+        <span class="note"><%= message('rules_configuration.repository') -%></span><br/>
+        <%= dropdown_tag "repositories", options_for_select(@select_repositories, @repositories), {
+            :show_search_box => true,
+            :width => '120px',
+            :placeholder => message('any')
+        }, {:id => 'search_repository', :multiple => true} -%>
+      </div>
+      <div class="rule-search top">
+        <span class="note"><%= message('severity') -%></span><br/>
+        <%= dropdown_tag "priorities", options_for_select(@select_priority, @priorities), {
+            :show_search_box => true,
+            :width => '90px',
+            :placeholder => message('any')
+        }, {:id => 'search_priority', :multiple => true} -%>
+      </div>
+      <div class="rule-search top">
+        <span class="note"><%= message('activation') -%></span><br/>
+        <%= dropdown_tag "rule_activation", options_for_select(@select_activation, @activation), {
+            :width => '100px'
+        }, {:id => 'search_activation'} -%>
+      </div>
+      <div class="rule-search top">
+        <span class="note"><%= message('rules_configuration.status_filters') -%></span><br/>
+        <%= dropdown_tag "status", options_for_select(@select_status, @status), {
+            :show_search_box => true,
+            :width => '120px',
+            :placeholder => message('any')
+        }, {:id => 'search_status', :multiple => true} -%>
+      </div>
+      <% if @profile.inherited? %>
+        <div class="rule-search top">
+          <span class="note"><%= message('inheritance') -%></span><br/>
+          <%= dropdown_tag "inheritance", options_for_select(@select_inheritance, @inheritance), {
+              :width => '120px'
+          }, {:id => 'search_inheritance'} -%>
+        </div>
+      <% end %>
+      <div class="rule-search">
+        <br/>
+        <%= submit_tag message('search_verb'), :id => 'submit_search', :onclick => 'submitSearch();' %>
+      </div>
+    </div>
+
+<% end %>
+</div>
+<div class="line-block marginbottom10">
+    <% if enable_modification && @rules.size>0 %>
+      <ul style="float: right" class="horizontal">
+      <li class="marginleft10">
+        <div class="bulk-edit"><%= message('bulk_change') -%>:
+        <form action="<%= ApplicationController.root_context -%>/old_rules_configuration/bulk_edit" method="POST" id="bulk-form"
+              style="display: inline; vertical-align: middle; padding-right:5px">
+          <input type="hidden" name="id" value="<%= @profile.id -%>"/>
+          <input type="hidden" name="bulk_rule_ids" value="<%= @rules.map{|r| r.id}.join(',') -%>"/>
+          <%= dropdown_tag "bulk_action", options_for_select([ ["", ""], [message('activate_all'), "activate"], [message('deactivate_all'), "deactivate"] ], ''), {
+              :width => '110px'
+          }, {:onChange => 'submitBulkForm()', :id => 'select-bulk-change'} -%>
+        </form>
+        </div>
+      </li>
+      </ul>
+    <% end %>
+  <h2>
+     <% if @hidden_actives && @hidden_actives>0 %>
+      <span class="small"><a href="<%= url_for params.merge({:rule_activation => ''}) -%>"
+        id="active-rules-link">+<%= message('rules_configuration.x_found_in_active_rules', :params => @hidden_actives) -%></a></span><% end %>
+     <% if @hidden_inactives && @hidden_inactives>0 %>
+      <span class="small"><a href="<%= url_for params.merge({:rule_activation => ''}) -%>"
+        id="inactive-rules-link">+<%= message('rules_configuration.x_found_in_inactive_rules', :params => @hidden_inactives) -%></a></span><% end %>
+  </h2>
+</div>
+<table class="table table-bordered width100 spacer-bottom" id="result_table">
+  <thead>
+    <tr>
+      <th class="left" nowrap><%= message('active') -%>/<%= message('severity') -%></th>
+      <th class="left"><%= message('name') -%> <span style="font-weight: normal">
+        [<%= link_to_function(message('rules_configuration.expand'), "expand_rules()") %> / <%= link_to_function(message('rules_configuration.collapse'), "collapse_rules()") %>]</span></th>
+      <th class="right" nowrap>
+        <span class="middle"><%= message('rules_configuration.sort_by') -%></span>
+        <% form_tag({:action => 'index'}, :class=> 'middle', :style => 'display:inline-block') do %>
+          <%= dropdown_tag "sort_by", options_for_select(@select_sort_by, @sort_by), {
+              :width => '120px'
+          }, {:id => 'select-rules-sort-by', :onChange => 'submitSortBy()'} -%>
+        <% end %>
+      </th>
+    </tr>
+</thead>
+
+<%= table_pagination(@pagination, :colspan => 2) { |label, page_id| link_to(label, params.merge({:page => page_id}))} -%>
+
+<tbody>
+<% if @current_rules.empty? %>
+<tr><td colspan="3" class="even"><%= message('no_results') -%>.</td></tr>
+<% end %>
+<%
+  @current_rules.each do |rule|
+    active_rule = @profile.active_by_rule_id(rule.id)
+%>
+  <tr id="rule_<%= rule.id -%>">
+    <%= render :partial => 'rule', :object => rule, :locals => {:profile => @profile, :rule => rule, :active_rule => active_rule} %>
+  </tr>
+<% end %>
+</tbody>
+</table>
+</div>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/new.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/new.html.erb
new file mode 100644 (file)
index 0000000..c767c20
--- /dev/null
@@ -0,0 +1,53 @@
+<div class="page">
+<%= render :partial => 'profiles/tabs', :locals => {:new_tab => message('rules_configuration.tab.new_rule')} %>
+
+<div class="tabs-panel marginbottom10 background-gray">
+
+<form method="POST" action="<%= url_for :action => 'create', :id => @profile.id, :rule_id => @rule.id -%>">
+<table width="100%" class="spaced">
+  <tr>
+    <td width="1%" nowrap><%= message('template') -%>:</td>
+    <td class="sep"> </td>
+    <td><%= h @rule.name -%></td>
+  </tr>
+  <tr>
+    <td width="1%" nowrap><%= message('name') -%>:</td>
+    <td class="sep"> </td>
+    <td><input type="text" name="rule[name]" size="80"/></td>
+  </tr>
+  <tr>
+    <td width="1%" nowrap><%= message('default_severity') -%>:</td>
+    <td class="sep"> </td>
+    <td>
+      <select name="rule[priority]">
+        <%= options_for_select(Sonar::RulePriority.as_options) %>
+      </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>
+  <% end %>
+  <tr>
+    <td width="1%" nowrap style="vertical-align: top"><%= message('description') -%>:</td>
+    <td class="sep"> </td>
+    <td valign="top">
+      <textarea name="rule[description]" cols="80" rows="10" style="vertical-align: baseline"></textarea>
+      <span class="small"><%= message('rules_configuration.html_allowed') -%></span>
+    </td>
+  </tr>
+  <tr>
+    <td colspan="3">
+      <input type="submit" value="<%= message('create') -%>"/> <a href="<%= url_for :action => 'index', :id => @profile.id -%>"><%= message('cancel') -%></a>
+    </td>
+  </tr>
+</table>
+</form>
+</div>
+</div>
index 4fc5f49a68f74a0759574e739eb6406503e5b54d..bf2244fe91bb80688003e60d642844d7a9b4531f 100644 (file)
@@ -22,7 +22,7 @@
     <a href="<%= url_for :controller => 'profiles', :action => 'changelog', :id => @profile.id -%>" <%= "class='selected'" if selected_tab=='changelog' -%> id="tab-changelog"><%= message('changelog') -%></a>
   </li>
   <li>
-    <a href="<%= url_for :controller => 'new_rules_configuration', :action => 'index', :id => @profile.id %>" <%= "class='selected'" if selected_tab=='Coding rules reloaded' -%> id="tab-rules"><%= message('Coding rules reloaded') -%></a>
+    <a href="<%= url_for :controller => 'old_rules_configuration', :action => 'index', :id => @profile.id %>" <%= "class='selected'" if selected_tab=='Old Coding rules' -%> id="tab-rules"><%= 'Old Coding rules' -%></a>
   </li>
   <% if new_tab %>
   <li>
index 246be175dfb99db2bdf354d67726c80fedd27161..23b66caa197ab64d508cc730a0b1866991fa5d1e 100644 (file)
@@ -1,19 +1,19 @@
-<% #locals = active_rule, profile
-  note = active_rule.note
-  active_note_detail_div_id = "and_" + active_rule.id.to_s
-  add_active_note_button_id = "aanb_" + active_rule.id.to_s
-  edit_active_note_link_id = "eanl_" + active_rule.id.to_s
-  delete_active_note_link_id = "danl_" + active_rule.id.to_s
-  active_note_form_div_id = "anf_" + active_rule.id.to_s
-  active_note_textarea_id = "ant_" + active_rule.id.to_s
-  submit_active_note_update_button_id = "sanub_" + active_rule.id.to_s
+<% #locals = rule, profile
+  note = rule.activeRuleNote
+  active_note_detail_div_id = "and_" + rule.activeRuleId.to_s
+  add_active_note_button_id = "aanb_" + rule.activeRuleId.to_s
+  edit_active_note_link_id = "eanl_" + rule.activeRuleId.to_s
+  delete_active_note_link_id = "danl_" + rule.activeRuleId.to_s
+  active_note_form_div_id = "anf_" + rule.activeRuleId.to_s
+  active_note_textarea_id = "ant_" + rule.activeRuleId.to_s
+  submit_active_note_update_button_id = "sanub_" + rule.activeRuleId.to_s
 %>
 
 <div id="<%= active_note_detail_div_id -%>">
-  <% if note %>
+  <% if !note.nil? %>
     <blockquote class="spacer-bottom">
       <cite>
-        <b><%= note.user.name -%></b> (<%= distance_of_time_in_words_to_now(note.updated_at) -%>)&nbsp;
+        <b><%= User.find_active_by_login(note.userLogin).name -%></b> (<%= distance_of_time_in_words_to_now(Time.at(note.updatedAt.time/1000)) -%>)&nbsp;
         <% if profiles_administrator? %>
           | &nbsp;
           <a href="#" id="<%= edit_active_note_link_id -%>" class="link-action"
           <a class="link-action"
              onclick="if(confirm('<%= escape_javascript(message('rules_configuration.confirm_delete_note')) -%>')){
                              $j.ajax({
-                                       url: '<%=ApplicationController.root_context-%>/rules_configuration/delete_active_rule_note?active_rule_id=<%=active_rule.id-%>',
+                                       url: '<%=ApplicationController.root_context-%>/rules_configuration/delete_active_rule_note?active_rule_id=<%=rule.activeRuleId-%>',
                                        type: 'post',
-                                       success:function(response){$j('#active_rule_note_<%= active_rule.id -%>').html(response);}
+                                       success:function(response){$j('#active_rule_note_<%= rule.activeRuleId -%>').html(response);}
                                      });};return false;"
              href="#!"><%=message('delete')-%></a>
         <% end %>
       </cite>
-      <p><%= note.html_text -%></p>
+      <p><%= note.data -%></p>
     </blockquote>
   <% elsif profiles_administrator? %>
     <a href="#" onclick="$j('#<%= active_note_form_div_id -%>').show();$j('#<%= active_note_detail_div_id -%>').hide();$j('#<%= active_note_textarea_id -%>').focus(); return false;"
 
 <% if profiles_administrator? %>
   <form onsubmit="$j.ajax({
-                            url:'<%= ApplicationController.root_context -%>/rules_configuration/update_active_rule_note?active_rule_id=<%=active_rule.id-%>',
+                            url:'<%= ApplicationController.root_context -%>/rules_configuration/update_active_rule_note?active_rule_id=<%=rule.activeRuleId-%>',
                             data: $j(this).serialize(),
                             type:'post',
-                            success:function(response){$j('#active_rule_note_<%= active_rule.id -%>').html(response);}
+                            success:function(response){$j('#active_rule_note_<%= rule.activeRuleId -%>').html(response);}
                           });
                   return false;"
           method="post"
-          action="<%= ApplicationController.root_context -%>/rules_configuration//update_active_rule_note?active_rule_id=<%=active_rule.id-%>">
+          action="<%= ApplicationController.root_context -%>/rules_configuration//update_active_rule_note?active_rule_id=<%=rule.activeRuleId-%>">
   <table id="<%= active_note_form_div_id -%>" style="display: none" class="admin table width100">
     <tbody>
       <tr>
         <td class="width100" colspan="2">
           <textarea name="note" id="<%= active_note_textarea_id -%>" rows="10" style="width:100%"
-                    onkeyup="if (this.value=='') $j('#<%= submit_active_note_update_button_id -%>').prop('disabled', true); else $j('#<%= submit_active_note_update_button_id -%>').prop('disabled', false);"><%= h(note.plain_text) if note -%></textarea>
+                    onkeyup="if (this.value=='') $j('#<%= submit_active_note_update_button_id -%>').prop('disabled', true); else $j('#<%= submit_active_note_update_button_id -%>').prop('disabled', false);"><%= h(note.data) unless note.nil? -%></textarea>
         </td>
       </tr>
     <tr>
index 7f005ead014c0ca8e32f149a74edccdc8196e86c..6927d455eccc031a14a53589f4e2a1be0a2fb345 100644 (file)
@@ -1,4 +1,6 @@
-<td nowrap valign="top" class="left" x="<%= active_rule.failure_level if active_rule -%>" width="1%">
+<% #locals = rule, profile, parent_profile -%>
+
+<td nowrap valign="top" class="left" x="<%= rule.severity -%>" width="1%">
   <form id="levels_<%= rule.id -%>" action="" class="rule-levels-form">
     <% enable_modification = profiles_administrator?
        select_box_id = "levels_select_#{rule.id}"
                                   data:'level='+$j('#levels_select_#{rule.id} :selected').val()})}"
     %>
 
-    <%= check_box_tag(check_box_id, 'yes', (!active_rule.nil?), :onclick => activate_rule, :disabled => !enable_modification || (active_rule && (active_rule.inherited? || active_rule.overrides?))) %>
-    <%= select_tag(select_box_id, options_for_select(RulesConfigurationController::RULE_PRIORITIES, (active_rule.nil? ? rule.priority_text : active_rule.priority_text)),
-                   {:onchange => changel_level, :disabled => (!(enable_modification) || active_rule.nil?)}) %>
+    <%= check_box_tag(check_box_id, 'yes', !rule.activeRuleId.nil?, :onclick => activate_rule, :disabled => !enable_modification || rule.inherited? || rule.overrides?) %>
+    <%= select_tag(select_box_id, options_for_select(RulesConfigurationController::RULE_PRIORITIES, rule.severity),
+                   {:onchange => changel_level, :disabled => (!(enable_modification))}) %>
 
-    <% if active_rule %>
-      <% if active_rule.inherited? %>
-        <img src="<%= ApplicationController.root_context -%>/images/inherited.png" alt="Inherited from parent" title="<%= message('rules_configuration.inherited_from_parent') -%>"/>
-      <% elsif active_rule.overrides? %>
-        <img src="<%= ApplicationController.root_context -%>/images/overrides.png" alt="Overrides parent definition" title="<%= message('rules_configuration.overrides_parent_definition') -%>"/>
-      <% end %>
+    <% if rule.inherited? %>
+      <img src="<%= ApplicationController.root_context -%>/images/inherited.png" alt="Inherited from parent" title="<%= message('rules_configuration.inherited_from_parent') -%>"/>
+    <% elsif rule.overrides? %>
+      <img src="<%= ApplicationController.root_context -%>/images/overrides.png" alt="Overrides parent definition" title="<%= message('rules_configuration.overrides_parent_definition') -%>"/>
     <% end %>
   </form>
 </td>
 
 <td class="left" colspan="2">
-  <% unless rule.ready? %>
+  <% unless rule.status == "READY" %>
     <div class="rule-status">
-      <% if rule.beta? %>
+      <% if rule.status == "BETA" %>
         <span><%= message('rules.status.beta') %></span>
-      <% elsif rule.deprecated? %>
+      <% elsif rule.status == "DEPRECATED" %>
         <span><%= message('rules.status.deprecated') %></span>
       <% end %>
     </div>
     </div>
 
     <%
-       ancestor_profile = profile.parent
-       ancestor_active_rule = ancestor_profile.active_by_rule_id(rule.id) if ancestor_profile && active_rule && (active_rule.inherited? || active_rule.overrides?)
-       if ancestor_active_rule || !rule.parameters.empty?
+       parent_active_rule = Internal.quality_profiles.parentProfileRule(rule) if (rule.inherited? || rule.overrides?)
+       if parent_active_rule || !rule.params.empty?
     %>
       <table width="100%" class="table spacer-bottom bordered background-gray">
         <%
-           if ancestor_active_rule
-             ancestor_active_rule_link = link_to ancestor_profile.name, :controller => 'rules_configuration', :action => 'index',
-                                                 :id => ancestor_profile.id, :rule_id => rule.id, :anchor => 'rule' + rule.id.to_s
+           if parent_active_rule
+             parent_active_rule_link = link_to parent_profile.name, :controller => 'rules_configuration', :action => 'index',
+                                                 :id => parent_profile.id, :rule_id => rule.id, :anchor => 'rule' + rule.id.to_s
         %>
           <tr>
             <td colspan="2">
-              <%= message(active_rule.inherited? ? 'rules_configuration.rule_inherited_from_profile_x' : 'rules_configuration.rule_overriding_from_profile_x',
-                          :params => ancestor_active_rule_link) -%>
-              <% if ancestor_active_rule.priority != active_rule.priority %>
+              <%= message(rule.inherited? ? 'rules_configuration.rule_inherited_from_profile_x' : 'rules_configuration.rule_overriding_from_profile_x',
+                          :params => parent_active_rule_link) -%>
+              <% if parent_active_rule.severity != rule.severity %>
                 <img src="<%= ApplicationController.root_context -%>/images/overrides.png" alt="Overrides parent definition" title="<%= message('rules_configuration.overrides_parent_definition') -%>" style="vertical-align: middle"/>
                 <span class="form-val-note" style="font-weight: bold"> <%= message('rules_configuration.original_severity') -%>
-                  : <%= ancestor_active_rule.priority_text -%></span>
+                  : <%= parent_active_rule.severity -%></span>
               <% end %>
-              <% if profiles_administrator? && active_rule.overrides? %>
-                <form action="<%= url_for :overwrite_params => {:action => 'revert_rule', :id => profile.id, :active_rule_id => active_rule.id} -%>" method="post" style="display: inline">
+              <% if profiles_administrator? && rule.overrides? %>
+                <form action="<%= url_for :overwrite_params => {:action => 'revert_rule', :id => profile.id, :active_rule_id => rule.activeRuleId} -%>" method="post" style="display: inline">
                   <input type="submit" value="<%= message('rules_configuration.revert_to_parent_definition') -%>">
                 </form>
               <% end %>
             </td>
           </tr>
         <% end %>
-        <% rule.parameters.sort.each do |parameter|
-          active_parameter = active_rule.active_param_by_param_id(parameter.id) if active_rule
-        %>
-          <tr id="param_<%= parameter.id -%>">
+        <% rule.params.each do |parameter| %>
+          <tr id="param_<%= parameter.key -%>">
             <%= render :partial => 'rule_param', :object => nil,
-                       :locals => {:parameter => parameter, :active_parameter => active_parameter, :profile => profile, :rule => rule,
-                                   :active_rule => active_rule, :ancestor_active_rule => ancestor_active_rule} %>
+                       :locals => {:parameter => parameter, :profile => profile, :rule => rule, :parent_active_rule => parent_active_rule} %>
           </tr>
         <%
            end
       </table>
     <% end %>
 
-    <% if active_rule %>
-      <div id="active_rule_note_<%= active_rule.id -%>">
-        <%= render :partial => 'active_rule_note', :locals => {:active_rule => active_rule, :profile => profile} %>
-      </div>
-    <% end %>
+    <div id="active_rule_note_<%= rule.activeRuleId -%>">
+      <%= render :partial => 'active_rule_note', :locals => {:rule => rule} %>
+    </div>
 
     <% if profiles_administrator? %>
       <% if rule.template? %>
-        <%= link_to message('rules_configuration.copy_rule'), {:action => 'new', :id => profile.id, :rule_id => rule.id}, :id => "copy-#{u rule.key}", :class => 'link-action spacer-right' %>
+        <%= link_to message('rules_configuration.copy_rule'), {:action => 'new', :id => profile.id, :rule_id => rule.id}, :id => "copy-#{u rule_key(rule)}", :class => 'link-action spacer-right' %>
       <% end %>
       <% if rule.editable? %>
         <%= link_to message('rules_configuration.edit_rule'), {:action => 'edit', :id => profile.id, :rule_id => rule.id}, :class => 'link-action spacer-right' %>
     <% end %>
 
     <div class="note">
-      <span id="rule_repository_<%= rule.id -%>"><%= message('rules_configuration.repository') %>: <%= rule.repository_key %></span>
+      <span id="rule_repository_<%= rule.id -%>"><%= message('rules_configuration.repository') %>: <%= rule.repositoryKey %></span>
       &nbsp;<%= image_tag 'sep12.png' -%>&nbsp;
-      <span id="rule_key_<%= rule.id -%>"><%= message('key') %>: <%= rule.plugin_rule_key %></span>
+      <span id="rule_key_<%= rule.id -%>"><%= message('key') %>: <%= rule.key %></span>
+      <% unless rule.systemTags.isEmpty && rule.adminTags.isEmpty %>
+      &nbsp;<%= image_tag 'sep12.png' -%>&nbsp;
+        <% rule.systemTags.each do |tag| %>
+        <span id="rule_tag_<%= rule.id -%>_<%= tag -%>" style="background-color: #efe;padding: 1px 2px"><%= tag -%></span>
+        <% end %>
+        <% rule.adminTags.each do |tag| %>
+        <span id="rule_tag_<%= rule.id -%>_<%= tag -%>" style="background-color: #eef;padding: 1px 2px"><%= tag -%></span>
+        <% end %>
+      <% end %>
       &nbsp;<%= image_tag 'sep12.png' -%>&nbsp;
-      <% if rule.removed? %>
-        <span id="rule_available_since_<%= rule.id -%>"><%= message('rules_configuration.removed_since') %>: <%= human_short_date(rule.updated_at) %></span>
+      <% if rule.status == "REMOVED" %>
+        <span id="rule_available_since_<%= rule.id -%>"><%= message('rules_configuration.removed_since') %>: <%= human_short_date(Api::Utils.java_to_ruby_datetime(rule.updatedAt)) %></span>
       <% else %>
-        <span id="rule_available_since_<%= rule.id -%>"><%= message('rules_configuration.available_since') %> <%= human_short_date(rule.created_at) %></span>
+        <span id="rule_available_since_<%= rule.id -%>"><%= message('rules_configuration.available_since') %> <%= human_short_date(Api::Utils.java_to_ruby_datetime(rule.createdAt)) %></span>
       <% end %>
     </div>
   </div>
index 2bf357b1f2436844f72f4bd3db631e062c2f813b..966c94d1c6a13d91f73f3e76fcfc0cfa48f89519 100644 (file)
@@ -1,5 +1,5 @@
 <% #locals = rule
-  note = rule.note
+  note = rule.ruleNote
   note_detail_div_id = "nd_" + rule.id.to_s
   note_extend_link_id = "nel_" + rule.id.to_s
   note_form_div_id = "nf_" + rule.id.to_s
@@ -9,15 +9,17 @@
 
 <div id="<%= note_detail_div_id -%>">
   <div class="marginbottom10">
-  <% if rule.description.strip.start_with?('<p>') %>
-    <%= Internal.text.interpretMacros(rule.description) %>
-  <% else %>
-    <p><%= Internal.text.interpretMacros(rule.description) %></p>
+  <% unless rule.description.nil? %>
+    <% if rule.description.strip.start_with?('<p>') %>
+      <%= Internal.text.interpretMacros(rule.description) %>
+    <% else %>
+      <p><%= Internal.text.interpretMacros(rule.description) %></p>
+    <% end %>
   <% end %>
   </div>
 
-  <% if note && !note.text.strip.blank? %>
-    <p><%= note.html_text -%></p>
+  <% unless rule.ruleNote.nil? %>
+    <p><%= rule.ruleNote.data -%></p>
   <% end %>
 
   <% if profiles_administrator? %>
@@ -32,7 +34,7 @@
 <div id="<%= note_form_div_id -%>" style="display: none" class="admin">
 
   <form onsubmit="$j.ajax({
-                        url:'<%=ApplicationController.root_context-%>/rules_configuration/update_rule_note?rule_id=<%=rule.id-%>',
+                        url:'<%=ApplicationController.root_context-%>/rules_configuration/update_rule_note?rule_id=<%=rule.id-%>&active_rule_id=<%=rule.activeRuleId-%>',
                         success:function(response){;$j('#rule_note_<%=rule.id-%>').html(response);},
                         data: $j(this).serialize(),
                         type:'post'});
@@ -46,7 +48,7 @@
       </tr>
       <tr>
         <td class="width100" colspan="2">
-          <textarea name="text" id="<%= note_textarea_id -%>" rows="10" style="width:100%"><%= h(note.plain_text) if note -%></textarea>
+          <textarea name="text" id="<%= note_textarea_id -%>" rows="10" style="width:100%"><%= h(note.data) if note -%></textarea>
         </td>
       </tr>
     <tr>
index bd034cc8a24203ce5045ae3478d88b307b76a2c1..7235ac2d3c931c22342dc3ec0217c485e4670acc 100644 (file)
@@ -1,39 +1,36 @@
-<%
+<% # locals = rule, profile, parameter, parent_active_rule
+   param_id = "#{rule.id}#{parameter.key}"
    # Display default value only for inactive rules
-   param_value = parameter.default_value if !active_rule
-   param_value = active_parameter.value if !param_value && active_parameter
-   active_param_id = active_parameter.id if active_parameter
-   active_rule_id = active_rule.id if active_rule
-   read_only = !active_rule || !profiles_administrator?
+   param_value = parameter.default_value if !rule.activeRuleId
+   param_value = parameter.value if !param_value
+   active_rule_id = rule.activeRuleId
+   read_only = rule.activeRuleId.nil? || !profiles_administrator?
 %>
 
-<td class="form-key-cell"><%= parameter.name -%></td>
+<td class="form-key-cell"><%= parameter.key -%></td>
 
 <td class="form-val-cell">
-    <form onsubmit="$j.ajax({  url: '<%= ApplicationController.root_context -%>/rules_configuration/update_param/<%=active_param_id-%>?active_rule_id=<%=active_rule_id-%>&param_id=<%=parameter.id-%>&profile_id=<%=profile.id-%>',
-                               type:'post',beforeSend: function(request){$j('#param_loading_<%=parameter.id-%>').show();$j('#error_<%=parameter.id-%>').hide();},
+    <form onsubmit="$j.ajax({  url: '<%= ApplicationController.root_context -%>/rules_configuration/update_param/?active_rule_id=<%=active_rule_id-%>&param_id=<%=parameter.key-%>&profile_id=<%=profile.id-%>',
+                               type:'post',beforeSend: function(request){$j('#param_loading_<%=param_id-%>').show();$j('#error_<%=param_id-%>').hide();},
                                data: $j(this).serialize(),
                                success: function(response){$j('#rule_<%=rule.id-%>').html(response);},
-                               complete: function(request){$j('#desc_<%=rule.id-%>').show();$j('#param_loading_<%=parameter.id-%>').hide();},
-                               error: function(request){$j('#error_<%=parameter.id-%>').text(request.responseText);$j('#error_<%=parameter.id-%>').show();}
+                               complete: function(request){$j('#desc_<%=rule.id-%>').show();$j('#param_loading_<%=param_id-%>').hide();},
+                               error: function(request){$j('#error_<%=param_id-%>').text(request.responseText);$j('#error_<%=param_id-%>').show();}
                             }); return false;"
-           name="form-<%=u parameter.name-%>" method="post"
-           action="<%= ApplicationController.root_context -%>/rules_configuration/update_param/<%=active_param_id-%>?active_rule_id=<%=active_rule_id-%>&param_id=<%=parameter.id-%>&profile_id=<%=profile.id-%>">
+           name="form-<%=u parameter.key-%>" method="post"
+           action="<%= ApplicationController.root_context -%>/rules_configuration/update_param/?active_rule_id=<%=active_rule_id-%>&param_id=<%=parameter.key-%>&profile_id=<%=profile.id-%>">
 
-  <div id="error_<%= parameter.id -%>" class="error" style="display: none"></div>
+  <div id="error_<%= param_id -%>" class="error" style="display: none"></div>
 
-  <span id="text_<%= parameter.id -%>"><%= param_value_input(parameter, param_value, :disabled => read_only) -%></span>
+  <span id="text_<%= param_id -%>"><%= param_value_input(rule, parameter, param_value, :disabled => read_only) -%></span>
 
   <% unless read_only %>
-    <%= submit_tag(message('update_verb'), :id => 'submit_' + parameter.id.to_s) %>
-    <img src="<%= ApplicationController.root_context -%>/images/loading.gif" style="display:none;" id="param_loading_<%= parameter.id -%>" class="rule-param-loading">
-    <% if active_parameter and active_parameter.errors.size>0 %>
-      <span class="error"><%= active_parameter.errors.on 'value' %></span>
-    <% end %>
+    <%= submit_tag(message('update_verb'), :id => 'submit_' + param_id.to_s) %>
+    <img src="<%= ApplicationController.root_context -%>/images/loading.gif" style="display:none;" id="param_loading_<%= param_id -%>" class="rule-param-loading">
   <% end %>
 
-  <% if active_rule && active_rule.overrides? && ancestor_active_rule
-       ancestor_param = ancestor_active_rule.active_param_by_param_id(parameter.id)
+  <% if !rule.nil? && rule.overrides? && parent_active_rule
+       ancestor_param = parent_active_rule.params.to_a.find {|param| param.key() == parameter.key}
        ancestor_value = ancestor_param && ancestor_param.value ? ancestor_param.value : ''
   %>
     <% if ancestor_value != param_value %>
@@ -45,7 +42,7 @@
     <% end %>
   <% end %>
 
-  <div class="form-val-note"><%= h(parameter.description || "") -%> <%= ('(' + readable_type(parameter.param_type) + ')') if !readable_type(parameter.param_type).empty? -%></div>
+  <div class="form-val-note"><%= h(parameter.description || "") -%> <%= ('(' + readable_type(parameter.type) + ')') if !readable_type(parameter.type).empty? -%></div>
 
   </form>
 </td>
index fba580006367f2a066379bff7fe5d5d11eaa4d17..5e980933a47ab715e02d5d3b1231ebfa5e3434a4 100644 (file)
@@ -1,13 +1,13 @@
-<h1 class="marginbottom10"><%= link_to message('quality_profiles.quality_profiles'), :controller => 'profiles', :action => 'index' -%> / <%= h @profile.language -%> / <%= h @profile.name %></h1>
+<h1 class="marginbottom10"><%= link_to message('quality_profiles.quality_profiles'), :controller => 'profiles', :action => 'index' -%> / <%= h @profile.language() -%> / <%= h @profile.name() %></h1>
 
 <%= render :partial => 'profiles/tabs', :locals => {:new_tab => 'Edit rule'} %>
 
 <div class="tabs-panel marginbottom10 background-gray">
 
-<form method="POST" id="delete-form" action="<%= url_for :action => 'delete', :id => @profile.id, :rule_id => @rule.id -%>" style="display: none"></form>
+<form method="POST" id="delete-form" action="<%= url_for :action => 'delete', :id => @profile.id(), :rule_id => @rule.id() -%>" style="display: none"></form>
 <script>
   function deleteRule() {
-    var count = <%= ActiveRule.count(:conditions => {:rule_id => @rule.id}) -%>;
+    var count = <%= @active_rules -%>;
     var message = 'Are you sure?';
     if (count>0) {
       message += ' This rule is activated in ' + count + ' profiles.';
     return false;
   }
 </script>
-<form method="POST" action="<%= url_for :action => 'update', :id => @profile.id, :rule_id => @rule.id -%>">
+<form method="POST" action="<%= url_for :action => 'update', :id => @profile.id(), :rule_id => @rule.id() -%>">
 <table width="100%" class="spaced">
   <tr>
     <td width="1%" nowrap><%= message('template') -%>:</td>
     <td class="sep"> </td>
-    <td><%= h @rule.parent.name -%></td>
+    <td><%= h @parent_rule.name() -%></td>
   </tr>
   <tr>
     <td width="1%" nowrap><%= message('name') -%>:</td>
     <td class="sep"> </td>
-    <td><input type="text" name="rule[name]" size="80" value="<%= h @rule.name -%>" /></td>
+    <td><input type="text" name="rule[name]" size="80" value="<%= h @rule.name() -%>" /></td>
   </tr>
   <tr>
     <td width="1%" nowrap><%= message('default_severity') -%>:</td>
     <td class="sep"> </td>
     <td>
       <select name="rule[priority]">
-        <%= options_for_select(Sonar::RulePriority.as_options, Sonar::RulePriority.to_s(@rule.priority)) %>
+        <%= options_for_select(Sonar::RulePriority.as_options, Sonar::RulePriority.to_s(@rule.severity())) %>
       </select>
     </td>
   </tr>
-  <% @rule.parameters.sort{|x,y| x.name <=> y.name}.each do |parameter| %>
+  <% @rule.params.to_a.sort{|x,y| x.key() <=> y.key()}.each do |parameter| %>
     <tr>
-      <td width="1%" nowrap><%= parameter.name %>:</td>
+      <td width="1%" nowrap><%= parameter.key() %>:</td>
       <td class="sep"> </td>
       <td>
-        <%= param_value_input(parameter, "#{h parameter.default_value}", {:name => "rule_param[#{h parameter.name }]", :size => '80x10'}) -%>
-        <span class="small"><%= h parameter.description %></span>
+        <%= param_value_input(@rule, parameter, "#{h parameter.defaultValue()}", {:name => "rule_param[#{h parameter.key() }]", :size => '80x10'}) -%>
+        <span class="small"><%= h parameter.description() %></span>
       </td>
     </tr>
   <% end %>
@@ -53,7 +53,7 @@
     <td width="1%" nowrap style="vertical-align: top">Description:</td>
     <td class="sep"> </td>
     <td valign="top">
-      <textarea name="rule[description]" cols="80" rows="10" style="vertical-align: baseline"><%= @rule.description -%></textarea>
+      <textarea name="rule[description]" cols="80" rows="10" style="vertical-align: baseline"><%= @rule.description() -%></textarea>
       <span class="small"><%= message('rules_configuration.html_allowed') -%></span>
     </td>
   </tr>
@@ -61,7 +61,7 @@
     <td colspan="3">
       <input type="submit" value="<%= message('update_verb') -%>" />
       <input type="submit" value="<%= message('delete') -%>" onclick="return deleteRule()" class="red-button" />
-      <a href="<%= url_for :action => 'index', :id => @profile.id -%>"><%= message('cancel') -%></a>
+      <a href="<%= url_for :action => 'index', :id => @profile.id() -%>"><%= message('cancel') -%></a>
     </td>
   </tr>
 </table>
index 99095ef180a7128298d2c086a85ac37e96411f6b..2488e4f9f90ad0b0c0c74d9fb3a817dc39d867b8 100644 (file)
@@ -77,7 +77,7 @@
             :placeholder => message('any')
         }, {:id => 'search_status', :multiple => true} -%>
       </div>
-      <% if @profile.inherited? %>
+      <% if @profile.isInherited() %>
         <div class="rule-search top">
           <span class="note"><%= message('inheritance') -%></span><br/>
           <%= dropdown_tag "inheritance", options_for_select(@select_inheritance, @inheritance), {
 <% end %>
 </div>
 <div class="line-block marginbottom10">
-    <% if enable_modification && @rules.size>0 %>
-      <ul style="float: right" class="horizontal">
+  <% if enable_modification && @current_rules.size>0 %>
+    <ul style="float: right" class="horizontal">
       <li class="marginleft10">
         <div class="bulk-edit"><%= message('bulk_change') -%>:
-        <form action="<%= ApplicationController.root_context -%>/rules_configuration/bulk_edit" method="POST" id="bulk-form"
+        <form action="<%= ApplicationController.root_context -%>/rules_configuration/bulk_edit?<%= @criteria_params.to_query -%>" method="POST" id="bulk-form"
               style="display: inline; vertical-align: middle; padding-right:5px">
           <input type="hidden" name="id" value="<%= @profile.id -%>"/>
-          <input type="hidden" name="bulk_rule_ids" value="<%= @rules.map{|r| r.id}.join(',') -%>"/>
           <%= dropdown_tag "bulk_action", options_for_select([ ["", ""], [message('activate_all'), "activate"], [message('deactivate_all'), "deactivate"] ], ''), {
               :width => '110px'
           }, {:onChange => 'submitBulkForm()', :id => 'select-bulk-change'} -%>
         </form>
         </div>
       </li>
-      </ul>
-    <% end %>
+    </ul>
+  <% end %>
   <h2>
      <% if @hidden_actives && @hidden_actives>0 %>
-      <span class="small"><a href="<%= url_for params.merge({:rule_activation => ''}) -%>"
+      <span class="small"><a href="<%= url_for params.merge({:rule_activation => 'ACTIVE'}) -%>"
         id="active-rules-link">+<%= message('rules_configuration.x_found_in_active_rules', :params => @hidden_actives) -%></a></span><% end %>
      <% if @hidden_inactives && @hidden_inactives>0 %>
-      <span class="small"><a href="<%= url_for params.merge({:rule_activation => ''}) -%>"
+      <span class="small"><a href="<%= url_for params.merge({:rule_activation => 'INACTIVE'}) -%>"
         id="inactive-rules-link">+<%= message('rules_configuration.x_found_in_inactive_rules', :params => @hidden_inactives) -%></a></span><% end %>
   </h2>
 </div>
 <% end %>
 <%
   @current_rules.each do |rule|
-    active_rule = @profile.active_by_rule_id(rule.id)
 %>
   <tr id="rule_<%= rule.id -%>">
-    <%= render :partial => 'rule', :object => rule, :locals => {:profile => @profile, :rule => rule, :active_rule => active_rule} %>
+    <%= render :partial => 'rule', :object => rule, :locals => {:rule => rule, :profile => @profile, :parent_profile => @parent_profile} %>
   </tr>
 <% end %>
 </tbody>
index c767c2059fd19a509e8fa339ace085d3c219f841..46945e3e3647db39a18979cce2c9cf5d4043376c 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| %>
+      <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>
diff --git a/sonar-server/src/test/java/org/sonar/server/util/StringTypeValidationTest.java b/sonar-server/src/test/java/org/sonar/server/util/StringTypeValidationTest.java
new file mode 100644 (file)
index 0000000..3b905c5
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+package org.sonar.server.util;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class StringTypeValidationTest {
+
+  StringTypeValidation validation;
+
+  @Before
+  public void setUp() throws Exception {
+    validation = new StringTypeValidation();
+  }
+
+  @Test
+  public void key() {
+    assertThat(validation.key()).isEqualTo("STRING");
+  }
+
+  @Test
+  public void not_fail_on_valid_string() {
+    validation.validate("10", null);
+    validation.validate("abc", null);
+  }
+
+}
diff --git a/sonar-server/src/test/java/org/sonar/server/util/TextTypeValidationTest.java b/sonar-server/src/test/java/org/sonar/server/util/TextTypeValidationTest.java
new file mode 100644 (file)
index 0000000..ee62352
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+package org.sonar.server.util;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class TextTypeValidationTest {
+
+  TextTypeValidation validation;
+
+  @Before
+  public void setUp() throws Exception {
+    validation = new TextTypeValidation();
+  }
+
+  @Test
+  public void key() {
+    assertThat(validation.key()).isEqualTo("TEXT");
+  }
+
+  @Test
+  public void not_fail_on_valid_text() {
+    validation.validate("10", null);
+    validation.validate("abc", null);
+  }
+
+}
index 9c0086cb787b4ffdf26a42e7e88abd9f0f0e79e9..00ae724b6fcb7452ee9eb2bb4bdfce95d18b9ed3 100644 (file)
@@ -21,8 +21,7 @@
 package org.sonar.server.util;
 
 import org.junit.Test;
-
-import java.util.NoSuchElementException;
+import org.sonar.server.exceptions.BadRequestException;
 
 import static com.google.common.collect.Lists.newArrayList;
 import static org.fest.assertions.Assertions.assertThat;
@@ -52,7 +51,9 @@ public class TypeValidationsTest {
       typeValidations.validate("10", "Unknown", null);
       fail();
     } catch (Exception e) {
-      assertThat(e).isInstanceOf(NoSuchElementException.class);
+      assertThat(e).isInstanceOf(BadRequestException.class);
+      BadRequestException badRequestException = (BadRequestException) e;
+      assertThat(badRequestException.getMessage()).isEqualTo("Type 'Unknown' is not valid.");
     }
   }