From dd9829b274c2300ac5441931239c3aa76446c023 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Lievremont Date: Wed, 18 Dec 2013 12:40:13 +0100 Subject: [PATCH] Display active rules (with rule notes) in new profile rule search page --- .../java/org/sonar/core/rule/RuleDto.java | 36 ++++++++++ .../org/sonar/core/rule/RuleMapper.xml | 3 +- .../java/org/sonar/core/rule/RuleDaoTest.java | 1 + .../sonar/core/rule/RuleDaoTest/selectAll.xml | 6 +- .../java/org/sonar/api/rules/ActiveRule.java | 52 ++++++++++++-- .../server/qualityprofile/QProfileRule.java | 68 +++++++++---------- .../qualityprofile/QProfileRuleNote.java | 48 +++++++++++++ .../qualityprofile/QProfileRuleParam.java | 51 ++++++++++++++ .../sonar/server/rule/ActiveRuleDocument.java | 6 ++ .../org/sonar/server/rule/RuleDocument.java | 7 ++ .../org/sonar/server/rule/RuleRegistry.java | 26 ++++++- .../org/sonar/server/search/SearchIndex.java | 2 +- .../com/sonar/search/active_rule_mapping.json | 20 ++++++ .../com/sonar/search/rule_mapping.json | 24 +++++++ .../helpers/new_rules_configuration_helper.rb | 2 +- .../_active_rule_note.html.erb | 12 ++-- .../new_rules_configuration/_rule.html.erb | 6 +- .../_rule_note.html.erb | 8 +-- .../_rule_param.html.erb | 29 ++++---- .../sonar/server/rule/RuleRegistryTest.java | 6 +- .../rule/RuleRegistryTest/rules/rule3.json | 8 ++- 21 files changed, 345 insertions(+), 76 deletions(-) create mode 100644 sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileRuleNote.java create mode 100644 sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileRuleParam.java diff --git a/sonar-core/src/main/java/org/sonar/core/rule/RuleDto.java b/sonar-core/src/main/java/org/sonar/core/rule/RuleDto.java index bff6c368b75..de0b9ce63a7 100644 --- a/sonar-core/src/main/java/org/sonar/core/rule/RuleDto.java +++ b/sonar-core/src/main/java/org/sonar/core/rule/RuleDto.java @@ -38,6 +38,10 @@ public final class RuleDto { private Long parentId; private Date createdAt; private Date updatedAt; + private String noteData; + private String noteUserLogin; + private Date noteCreatedAt; + private Date noteUpdatedAt; public Long getId() { return id; @@ -150,4 +154,36 @@ public final class RuleDto { public void setUpdatedAt(Date updatedAt) { this.updatedAt = updatedAt; } + + public String getNoteData() { + return noteData; + } + + public void setNoteData(String noteData) { + this.noteData = noteData; + } + + public String getNoteUserLogin() { + return noteUserLogin; + } + + public void setNoteUserLogin(String noteUserLogin) { + this.noteUserLogin = noteUserLogin; + } + + public Date getNoteCreatedAt() { + return noteCreatedAt; + } + + public void setNoteCreatedAt(Date noteCreatedAt) { + this.noteCreatedAt = noteCreatedAt; + } + + public Date getNoteUpdatedAt() { + return noteUpdatedAt; + } + + public void setNoteUpdatedAt(Date noteUpdatedAt) { + this.noteUpdatedAt = noteUpdatedAt; + } } diff --git a/sonar-core/src/main/resources/org/sonar/core/rule/RuleMapper.xml b/sonar-core/src/main/resources/org/sonar/core/rule/RuleMapper.xml index 263431ba75a..1bf537be962 100644 --- a/sonar-core/src/main/resources/org/sonar/core/rule/RuleMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/rule/RuleMapper.xml @@ -6,7 +6,8 @@ id, plugin_rule_key as "ruleKey", plugin_name as "repositoryKey", description, status, name, plugin_config_key as "configKey", priority as "priorityOrdinal", cardinality, language as "language", parent_id as "parentId", - created_at as "createdAt", updated_at as "updatedAt" + created_at as "createdAt", updated_at as "updatedAt", + note_data as "noteData", note_user_login as "noteUserLogin", note_created_at as "noteCreatedAt", note_updated_at as "noteUpdatedAt" + 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? -%> 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 index dbbf38439af..49a714ea9c1 100644 --- 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 @@ -76,14 +76,10 @@ <% end %> <% rule.params.each do |parameter| %> - <% -=begin %> - + <%= render :partial => 'rule_param', :object => nil, :locals => {:parameter => parameter, :profile => profile, :rule => rule, :ancestor_active_rule => ancestor_active_rule} %> - <% -=end %> <% end %> 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 index 047267665cc..ed46d04a7e0 100644 --- 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 @@ -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 @@ -18,8 +18,8 @@ <% end %> - <% if note && !note.text.strip.blank? %> -

<%= note.html_text -%>

+ <% unless rule.ruleNote.nil? %> +

<%= rule.ruleNote.data -%>

<% end %> <% if profiles_administrator? %> @@ -48,7 +48,7 @@ - + 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 index dcd477ee187..36f9da2c544 100644 --- 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 @@ -1,36 +1,39 @@ -<% param_value = parameter.default_value || '' - param_value = active_parameter.value if 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? +<% # locals = rule, profile, parameter + param_value = parameter.defaultValue || parameter.value || '' + active_rule_id = rule.activeRuleId + read_only = rule.activeRuleId.nil? || !profiles_administrator? %> -<%= parameter.name -%> +<%= parameter.key -%> -
/new_rules_configuration/update_param/?active_rule_id=<%=active_rule_id-%>¶m_id=<%=parameter.key-%>&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 -%>/new_rules_configuration/update_param/<%=active_param_id-%>?active_rule_id=<%=active_rule_id-%>¶m_id=<%=parameter.id-%>&profile_id=<%=profile.id-%>"> + name="form-<%=u parameter.key-%>" method="post" + action="<%= ApplicationController.root_context -%>/new_rules_configuration/update_param/?active_rule_id=<%=active_rule_id-%>¶m_id=<%=parameter.key-%>&profile_id=<%=profile.id-%>"> - + - <%= param_value_input(parameter, param_value, :disabled => read_only) -%> + <%= param_value_input(parameter, param_value, :disabled => read_only) -%> <% unless read_only %> <%= submit_tag(message('update_verb'), :id => 'submit_' + parameter.id.to_s) %> +<% +=begin %> <% if active_parameter and active_parameter.errors.size>0 %> <%= active_parameter.errors.on 'value' %> <% end %> +<% +=end %> <% end %> - <% if active_rule && active_rule.overrides? && ancestor_active_rule + <% if !rule.nil? && 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 : '' %> @@ -43,7 +46,7 @@ <% end %> <% end %> -
<%= h(parameter.description || "") -%> <%= ('(' + readable_type(parameter.param_type) + ')') if !readable_type(parameter.param_type).empty? -%>
+
<%= h(parameter.description || "") -%> <%= ('(' + readable_type(parameter.type) + ')') if !readable_type(parameter.type).empty? -%>
diff --git a/sonar-server/src/test/java/org/sonar/server/rule/RuleRegistryTest.java b/sonar-server/src/test/java/org/sonar/server/rule/RuleRegistryTest.java index d2f1972e0c2..5d38bbd74b6 100644 --- a/sonar-server/src/test/java/org/sonar/server/rule/RuleRegistryTest.java +++ b/sonar-server/src/test/java/org/sonar/server/rule/RuleRegistryTest.java @@ -52,7 +52,9 @@ import java.util.HashMap; import java.util.List; import static com.google.common.collect.Lists.newArrayList; -import static org.elasticsearch.index.query.FilterBuilders.*; +import static org.elasticsearch.index.query.FilterBuilders.hasChildFilter; +import static org.elasticsearch.index.query.FilterBuilders.hasParentFilter; +import static org.elasticsearch.index.query.FilterBuilders.termFilter; import static org.fest.assertions.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -169,6 +171,8 @@ public class RuleRegistryTest { rule1.setRepositoryKey("repo"); rule1.setRuleKey("key1"); rule1.setId(ruleId1); + rule1.setNoteData("noteData"); + rule1.setNoteUserLogin("userLogin"); long ruleId2 = 4L; RuleDto rule2 = new RuleDto(); rule2.setRepositoryKey("repo"); diff --git a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistryTest/rules/rule3.json b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistryTest/rules/rule3.json index 83ec573d96e..534591d038b 100644 --- a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistryTest/rules/rule3.json +++ b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistryTest/rules/rule3.json @@ -9,5 +9,11 @@ "severity": "CRITICAL", "status": "REMOVED", "createdAt": "2013-10-28T13:07:26.329Z", - "updatedAt": "2013-11-08T10:52:53.473Z" + "updatedAt": "2013-11-08T10:52:53.473Z", + "note": { + "userLogin": "freddy.mallet", + "data": "", + "createdAt": "2013-12-10T13:07:26.329Z", + "updatedAt": "2013-12-12T10:52:53.473Z" + } } -- 2.39.5