]> source.dussan.org Git - sonarqube.git/commitdiff
Display active rules, with initial pagination implementation
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Mon, 16 Dec 2013 15:18:38 +0000 (16:18 +0100)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Mon, 16 Dec 2013 16:14:47 +0000 (17:14 +0100)
12 files changed:
sonar-server/src/main/java/org/sonar/server/platform/Platform.java
sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileRule.java
sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfiles.java
sonar-server/src/main/java/org/sonar/server/rule/ProfileRuleQuery.java
sonar-server/src/main/java/org/sonar/server/rule/ProfileRules.java
sonar-server/src/main/java/org/sonar/server/search/SearchIndex.java
sonar-server/src/main/webapp/WEB-INF/app/controllers/new_rules_configuration_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/_active_rule_note.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/_rule.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/index.html.erb
sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfilesTest.java
sonar-server/src/test/java/org/sonar/server/rule/ProfileRulesTest.java

index 64d996599a6f87652eb642f0374147ddc2a8ed6c..3484c2de87325a51e80f86db4778f1039e0c44e8 100644 (file)
@@ -93,6 +93,7 @@ import org.sonar.server.plugins.*;
 import org.sonar.server.qualityprofile.QProfileOperations;
 import org.sonar.server.qualityprofile.QProfileSearch;
 import org.sonar.server.qualityprofile.QProfiles;
+import org.sonar.server.rule.ProfileRules;
 import org.sonar.server.rule.RubyRuleService;
 import org.sonar.server.rule.RuleRegistry;
 import org.sonar.server.rules.ProfilesConsole;
@@ -269,6 +270,7 @@ public final class Platform {
     servicesContainer.addSingleton(Periods.class);
 
     // quality profiles
+    servicesContainer.addSingleton(ProfileRules.class);
     servicesContainer.addSingleton(QProfiles.class);
     servicesContainer.addSingleton(QProfileSearch.class);
     servicesContainer.addSingleton(QProfileOperations.class);
index 72c430e0433643e9eb6852732543505de998f316..eca80d367d4149c47c69b63f9cb3473c72703395 100644 (file)
@@ -21,8 +21,11 @@ package org.sonar.server.qualityprofile;
 
 import org.elasticsearch.common.collect.Lists;
 import org.elasticsearch.common.collect.Maps;
-import org.sonar.api.rules.RulePriority;
+import org.joda.time.format.ISODateTimeFormat;
+import org.sonar.api.rules.ActiveRule;
+import org.sonar.check.Cardinality;
 
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
@@ -31,24 +34,40 @@ public class QProfileRule {
   private final Map<String, Object> ruleSource;
   private final Map<String, Object> activeRuleSource;
 
+  private final Integer id;
   private final String key;
+  private final String repositoryKey;
   private final String name;
   private final String description;
   private final String status;
-
-  private final RulePriority severity;
+  private final String cardinality;
+  private final String parentKey;
+  private final Date createdAt;
+  private final Date updatedAt;
+
+  private final int activeRuleId;
+  private final String severity;
+  private final String inheritance;
   private final List<Param> params;
 
   public QProfileRule(Map<String, Object> ruleSource, Map<String, Object> activeRuleSource) {
     this.ruleSource = ruleSource;
     this.activeRuleSource = activeRuleSource;
 
+    id = (Integer) ruleSource.get("id");
     key = (String) ruleSource.get("key");
+    repositoryKey = (String) ruleSource.get("repositoryKey");
     name = (String) ruleSource.get("name");
     description = (String) ruleSource.get("description");
     status = (String) ruleSource.get("status");
-
-    severity = RulePriority.valueOf((String) activeRuleSource.get("severity"));
+    cardinality = (String) ruleSource.get("cardinality");
+    parentKey = (String) ruleSource.get("parentKey");
+    createdAt = parseOptionalDate("createdAt", ruleSource);
+    updatedAt = parseOptionalDate("updatedAt", ruleSource);
+
+    activeRuleId = (Integer) activeRuleSource.get("id");
+    severity = (String) activeRuleSource.get("severity");
+    inheritance = (String) activeRuleSource.get("inheritance");
     params = Lists.newArrayList();
     if (ruleSource.containsKey("params")) {
       Map<String, Map<String, Object>> ruleParams = Maps.newHashMap();
@@ -56,8 +75,10 @@ public class QProfileRule {
         ruleParams.put((String) ruleParam.get("key"), ruleParam);
       }
       Map<String, Map<String, Object>> activeRuleParams = Maps.newHashMap();
-      for (Map<String, Object> activeRuleParam: (List<Map<String, Object>>) activeRuleSource.get("params")) {
-        activeRuleParams.put((String) activeRuleParam.get("key"), activeRuleParam);
+      if (activeRuleSource.containsKey("params")) {
+        for (Map<String, Object> activeRuleParam: (List<Map<String, Object>>) activeRuleSource.get("params")) {
+          activeRuleParams.put((String) activeRuleParam.get("key"), activeRuleParam);
+        }
       }
       for(Map.Entry<String, Map<String, Object>> ruleParam: ruleParams.entrySet()) {
         params.add(new Param(
@@ -72,6 +93,15 @@ public class QProfileRule {
     }
   }
 
+  protected Date parseOptionalDate(String field, Map<String, Object> ruleSource) {
+    String dateValue = (String) ruleSource.get(field);
+    if (dateValue == null) {
+      return null;
+    } else {
+      return ISODateTimeFormat.dateOptionalTimeParser().parseDateTime(dateValue).toDate();
+    }
+  }
+
   public Map<String, Object> ruleSource() {
     return ruleSource;
   }
@@ -80,10 +110,22 @@ public class QProfileRule {
     return activeRuleSource;
   }
 
+  public int id() {
+    return id;
+  }
+
+  public int activeRuleId() {
+    return activeRuleId;
+  }
+
   public String key() {
     return key;
   }
 
+  public String repositoryKey() {
+    return repositoryKey;
+  }
+
   public String name() {
     return name;
   }
@@ -96,14 +138,46 @@ public class QProfileRule {
     return status;
   }
 
-  public RulePriority severity() {
+  public Date createdAt() {
+    return createdAt;
+  }
+
+  public Date updatedAt() {
+    return updatedAt;
+  }
+
+  public String severity() {
     return severity;
   }
 
+  public String inheritance() {
+    return inheritance;
+  }
+
+  public boolean isInherited() {
+    return ActiveRule.INHERITED.equals(inheritance);
+  }
+
+  public boolean isOverrides() {
+    return ActiveRule.OVERRIDES.equals(inheritance);
+  }
+
+  public boolean isTemplate() {
+    return Cardinality.MULTIPLE.toString().equals(cardinality);
+  }
+
+  public boolean isEditable() {
+    return parentKey != null;
+  }
+
   public List<Param> params() {
     return params;
   }
 
+  public String note() {
+    return null;
+  }
+
   class Param {
     private final String key;
     private final String value;
index 1b4d063ed96cf55da2cbe9c70ecc3d9a286ea0fb..deb6ac7e345569fc7b0967b4b89cf9eca138ffa9 100644 (file)
@@ -129,10 +129,18 @@ public class QProfiles implements ServerComponent {
     return rules.searchActiveRules(query, paging);
   }
 
-  public void searchInactiveRules(Integer profileId) {
+  public long countActiveRules(ProfileRuleQuery query) {
+    return rules.countActiveRules(query);
+  }
+
+  public void searchInactiveRules(ProfileRuleQuery query, Paging paging) {
     throw new UnsupportedOperationException();
   }
 
+  public long countInactiveRules(ProfileRuleQuery query) {
+    return rules.countInactiveRules(query);
+  }
+
   public void activeRule(Integer profileId, RuleKey ruleKey) {
     throw new UnsupportedOperationException();
   }
index adaf03621b093eb0cec9ca4fc349f9aa43ce4934..1426fcdaa124ad67ad39b7a9e4c0060733e023ea 100644 (file)
@@ -24,6 +24,7 @@ import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
 import org.apache.commons.lang.StringUtils;
 import org.sonar.server.exceptions.BadRequestException;
+import org.sonar.server.util.RubyUtils;
 
 import javax.annotation.CheckForNull;
 
@@ -57,11 +58,37 @@ public class ProfileRuleQuery {
     ProfileRuleQuery result = new ProfileRuleQuery();
 
     try {
-      result.profileId = Integer.parseInt((String) params.get("profileId"));
+      result.profileId = RubyUtils.toInteger(params.get("profileId"));
     } catch (Exception badProfileId) {
       validationException.addError("profileId could not be parsed");
     }
 
+
+    if (params.containsKey("nameOrKey")) {
+      result.setNameOrKey((String) params.get("nameOrKey"));
+    }
+    if (params.get("repositoryKeys") != null) {
+      for (Object param: (Object[]) params.get("repositoryKeys")) {
+        if (! "".equals(param)) {
+          result.addRepositoryKeys((String) param);
+        }
+      }
+    }
+    if (params.get("severities") != null) {
+      for (Object param: (Object[]) params.get("severities")) {
+        if (! "".equals(param)) {
+          result.addSeverities((String) param);
+        }
+      }
+    }
+    if (params.get("statuses") != null) {
+      for (Object param: (Object[]) params.get("statuses")) {
+        if (! "".equals(param)) {
+          result.addStatuses((String) param);
+        }
+      }
+    }
+
     validationException.checkMessages();
 
     return result;
@@ -125,7 +152,6 @@ public class ProfileRuleQuery {
     return !(
       StringUtils.isEmpty(nameOrKey)
       && repositoryKeys.isEmpty()
-      && severities.isEmpty()
       && statuses.isEmpty()
     );
   }
index 255f4f6fd7ca608e2e6474fc51a8a5ca8c27a6b7..e9635c24d82464244f765f8730941ff86c52337c 100644 (file)
@@ -23,12 +23,11 @@ import org.apache.commons.lang.StringUtils;
 import org.elasticsearch.action.get.MultiGetItemResponse;
 import org.elasticsearch.action.search.SearchRequestBuilder;
 import org.elasticsearch.common.collect.Lists;
-import org.elasticsearch.index.query.BoolFilterBuilder;
-import org.elasticsearch.index.query.FilterBuilder;
-import org.elasticsearch.index.query.FilterBuilders;
+import org.elasticsearch.index.query.*;
 import org.elasticsearch.index.query.MatchQueryBuilder.Operator;
 import org.elasticsearch.search.SearchHit;
 import org.elasticsearch.search.SearchHits;
+import org.sonar.api.ServerExtension;
 import org.sonar.server.qualityprofile.Paging;
 import org.sonar.server.qualityprofile.PagingResult;
 import org.sonar.server.qualityprofile.QProfileRule;
@@ -45,7 +44,7 @@ import static org.sonar.server.rule.RuleRegistry.INDEX_RULES;
 import static org.sonar.server.rule.RuleRegistry.TYPE_ACTIVE_RULE;
 import static org.sonar.server.rule.RuleRegistry.TYPE_RULE;
 
-public class ProfileRules {
+public class ProfileRules implements ServerExtension {
 
   private static final String FIELD_PARENT = "_parent";
   private static final String FIELD_SOURCE = "_source";
@@ -57,11 +56,7 @@ public class ProfileRules {
   }
 
   public QProfileRuleResult searchActiveRules(ProfileRuleQuery query, Paging paging) {
-    BoolFilterBuilder filter = boolFilter().must(
-            termFilter("profileId", query.profileId()),
-            hasParentFilter(TYPE_RULE, parentRuleFilter(query))
-        );
-    addMustTermOrTerms(filter, "severity", query.severities());
+    BoolFilterBuilder filter = activeRuleFilter(query);
 
     SearchRequestBuilder builder = index.client().prepareSearch(INDEX_RULES).setTypes(TYPE_ACTIVE_RULE)
       .setFilter(filter)
@@ -93,6 +88,28 @@ public class ProfileRules {
     return new QProfileRuleResult(result, PagingResult.create(paging.pageSize(), paging.pageIndex(), hits.getTotalHits()));
   }
 
+  protected BoolFilterBuilder activeRuleFilter(ProfileRuleQuery query) {
+    BoolFilterBuilder filter = boolFilter().must(
+            termFilter("profileId", query.profileId()),
+            hasParentFilter(TYPE_RULE, parentRuleFilter(query))
+        );
+    addMustTermOrTerms(filter, "severity", query.severities());
+    return filter;
+  }
+
+  public long countActiveRules(ProfileRuleQuery query) {
+    return index.executeCount(index.client().prepareCount(INDEX_RULES).setTypes(TYPE_ACTIVE_RULE)
+      .setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), activeRuleFilter(query))));
+  }
+
+  public long countInactiveRules(ProfileRuleQuery query) {
+    return index.executeCount(index.client().prepareCount(INDEX_RULES).setTypes(TYPE_RULE)
+      .setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(),
+        boolFilter()
+          .must(parentRuleFilter(query))
+          .mustNot(hasChildFilter(TYPE_ACTIVE_RULE, termFilter("profileId", query.profileId()))))));
+  }
+
   private FilterBuilder parentRuleFilter(ProfileRuleQuery query) {
     if (! query.hasParentRuleCriteria()) {
       return FilterBuilders.matchAllFilter();
index eda2ad67cb07bd682fa85a75587c220ff17f76e0..f16281ab6d49e4fd16c38383171bbd77ec96e6cf 100644 (file)
@@ -26,6 +26,7 @@ import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsReques
 import org.elasticsearch.action.bulk.BulkItemResponse;
 import org.elasticsearch.action.bulk.BulkRequestBuilder;
 import org.elasticsearch.action.bulk.BulkResponse;
+import org.elasticsearch.action.count.CountRequestBuilder;
 import org.elasticsearch.action.index.IndexRequestBuilder;
 import org.elasticsearch.action.search.SearchRequestBuilder;
 import org.elasticsearch.action.search.SearchResponse;
@@ -216,6 +217,15 @@ public class SearchIndex {
     }
   }
 
+  public long executeCount(CountRequestBuilder builder) {
+    StopWatch watch = createWatch();
+    try {
+      return builder.execute().actionGet().getCount();
+    } finally {
+      watch.stop("Request executed: %s", builder.toString());
+    }
+  }
+
   private String builderToString(SearchRequestBuilder builder) {
     try {
       return builder.internalBuilder().toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS)
index 66caee178333eb6c9d84647aaa3be9403195fb03..abf180c21167b81b8f35e729dbf0baa4b3b95c16 100644 (file)
@@ -18,6 +18,7 @@
 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 require 'cgi'
+require 'java'
 
 class NewRulesConfigurationController < ApplicationController
 
@@ -40,7 +41,7 @@ class NewRulesConfigurationController < ApplicationController
 
     @select_repositories = ANY_SELECTION + java_facade.getRuleRepositoriesByLanguage(@profile.language).collect { |repo| [repo.getName(true), repo.getKey()] }.sort
     @select_priority = ANY_SELECTION + RULE_PRIORITIES
-    @select_activation = [[message('any'), 'any'], [message('active'), STATUS_ACTIVE], [message('inactive'), STATUS_INACTIVE]]
+    @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],
@@ -52,20 +53,31 @@ class NewRulesConfigurationController < ApplicationController
       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)
+      "profileId" => @profile.id.to_i, "activation" => @activation, "severities" => @priorities.to_java, "inheritance" => @inheritance, "statuses" => @status.to_java,
+      "repositoryKeys" => @repositories.to_java, "nameOrKey" => @searchtext, "include_parameters_and_notes" => true, "language" => @profile.language, "sort_by" => @sort_by}
+
+      @rules = []
+      @pagination = Api::Pagination.new(params)
+
+      call_java do
+        query = Java::OrgSonarServerRule::ProfileRuleQuery::parse(criteria.to_java)
+        paging = Java::OrgSonarServerQualityprofile::Paging.create(@pagination.per_page.to_i, @pagination.page.to_i)
 
-      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
+          result = Internal.qprofiles.searchActiveRules(query, paging)
+        else
+          result = Internal.qprofiles.searchInactiveRules(query, paging)
+        end
+
+        @rules = result.rules
+        @pagination.count = result.paging.total
+
+        unless @searchtext.blank?
+          if @activation==STATUS_ACTIVE
+            @hidden_inactives = Internal.qprofiles.countInactiveRules(query)
+          else
+            @hidden_actives = Internal.qprofiles.countInactiveRules(query)
+          end
         end
       end
 
@@ -73,9 +85,8 @@ class NewRulesConfigurationController < ApplicationController
     rescue
       @rules = []
     end
-      @pagination = Api::Pagination.new(params)
-      @pagination.count = @rules.size
-      @current_rules = @rules[@pagination.offset, @pagination.limit]
+
+    @current_rules = @rules
   end
 
 
index cc153964faf8d9bb356c83d9a42f559579598dc9..fb3dc3d928482c1096bd32dd9aafdb14716ac184 100644 (file)
@@ -1,12 +1,12 @@
 <% #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
+  note = rule.note
+  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 -%>">
@@ -22,9 +22,9 @@
           <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=<%=active_rule.id-%>',
+                                       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_<%= active_rule.id -%>').html(response);}
+                                       success:function(response){$j('#active_rule_note_<%= rule.activeRuleId -%>').html(response);}
                                      });};return false;"
              href="#!"><%=message('delete')-%></a>
         <% end %>
 
 <% if profiles_administrator? %>
   <form onsubmit="$j.ajax({
-                            url:'<%= ApplicationController.root_context -%>/new_rules_configuration/update_active_rule_note?active_rule_id=<%=active_rule.id-%>',
+                            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_<%= active_rule.id -%>').html(response);}
+                            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=<%=active_rule.id-%>">
+          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>
index 06d3415d04c475dc929df4c6d9eb741f5c865520..dbbf38439af4103f18c41c0354b424a7f9166b01 100644 (file)
@@ -1,4 +1,4 @@
-<td nowrap valign="top" class="left" x="<%= active_rule.failure_level if active_rule -%>" width="1%">
+<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', true, :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>
@@ -51,8 +49,8 @@
 
     <%
        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?
+       ancestor_active_rule = ancestor_profile.active_by_rule_id(rule.id) if ancestor_profile && (rule.inherited? || rule.overrides?)
+       if ancestor_active_rule || !rule.params.empty?
     %>
       <table width="100%" class="table spacer-bottom bordered background-gray">
         <%
         %>
           <tr>
             <td colspan="2">
-              <%= message(active_rule.inherited? ? 'rules_configuration.rule_inherited_from_profile_x' : 'rules_configuration.rule_overriding_from_profile_x',
+              <%= message(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 %>
+              <% if ancestor_active_rule.priority != 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>
               <% 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
-        %>
+        <% rule.params.each do |parameter| %>
+        <%
+=begin %>
           <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} %>
+                       :locals => {:parameter => parameter, :profile => profile, :rule => rule, :ancestor_active_rule => ancestor_active_rule} %>
           </tr>
+          <%
+=end %>
         <%
            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, :profile => profile} %>
+    </div>
 
     <% if profiles_administrator? %>
       <% if rule.template? %>
     <% 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>
       &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(Time.at(rule.updatedAt.getTime/1000)) %></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(Time.at(rule.createdAt.getTime/1000)) %></span>
       <% end %>
     </div>
   </div>
index 9c8d6425d70b2d97478bc1002155eb7cbf8613b4..0441adf73509fd9ce8d02667adbff245fb0f30e6 100644 (file)
 <% 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 => {:profile => @profile, :rule => rule} %>
   </tr>
 <% end %>
 </tbody>
index 15b8d0f7e340608954afc3827e65fe440a0fe6f3..31bfab9a74b2c975542b2c4904cfe68c90959226 100644 (file)
@@ -165,7 +165,10 @@ public class QProfilesTest {
 
   @Test(expected = UnsupportedOperationException.class)
   public void testSearchInactiveRules() throws Exception {
-    qProfiles.searchInactiveRules(null);
+    final int profileId = 42;
+    ProfileRuleQuery query = ProfileRuleQuery.create(profileId );
+    Paging paging = Paging.create(20, 1);
+    qProfiles.searchInactiveRules(query, paging);
   }
 
   @Test(expected = UnsupportedOperationException.class)
index 8a13f0169fbf05d2b58cb15cbea2b393f35752fb..b1524a59fd35588f58d6ee4425b3ac74a3b90b24 100644 (file)
@@ -85,7 +85,7 @@ public class ProfileRulesTest {
     List<QProfileRule> rules1 = profileRules.searchActiveRules(ProfileRuleQuery.create(1), paging).rules();
     assertThat(rules1).hasSize(3);
     assertThat(rules1.get(0).key()).isEqualTo("DM_CONVERT_CASE");
-    assertThat(rules1.get(0).severity()).isEqualTo(RulePriority.MINOR);
+    assertThat(rules1.get(0).severity()).isEqualTo(RulePriority.MINOR.toString());
 
     // All rules for profile 2
     List<QProfileRule> rules2 = profileRules.searchActiveRules(ProfileRuleQuery.create(2), paging).rules();