From 0cd519b35d499f60fceec66f08dc7ca80301f127 Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Tue, 7 Dec 2010 16:17:50 +0000 Subject: [PATCH] SONAR-1937 add the field 'age' to violations web service + display the select box to filter violations by period --- .../client/ViolationsPanel.java | 7 ++- .../TimeMachineConfigurationPersister.java | 2 + .../unmarshallers/ViolationUnmarshaller.java | 3 +- .../WEB-INF/app/helpers/drilldown_helper.rb | 1 + .../webapp/WEB-INF/app/models/rule_failure.rb | 24 +++++++-- .../app/views/dashboard/_header.html.erb | 5 +- .../app/views/drilldown/violations.html.erb | 21 +++++++- .../views/project/_snapshot_title.html.erb | 2 +- .../WEB-INF/app/views/project/index.html.erb | 49 ------------------- .../sonar/wsclient/services/Violation.java | 13 +++++ .../unmarshallers/ViolationUnmarshaller.java | 1 + 11 files changed, 68 insertions(+), 60 deletions(-) diff --git a/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/violationsviewer/client/ViolationsPanel.java b/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/violationsviewer/client/ViolationsPanel.java index 772325dfa83..14cf189a9f0 100644 --- a/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/violationsviewer/client/ViolationsPanel.java +++ b/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/violationsviewer/client/ViolationsPanel.java @@ -139,13 +139,16 @@ public class ViolationsPanel extends SourcePanel { @Override public String getColumn4() { + String age = ""; + if (violation.getAge()!=null && violation.getAge()>0) { + age = " (" + violation.getAge() + " days)"; + } return "
" + Icons.forPriority(violation.getPriority()).getHTML() + " " - + Utils.formatDate(violation.getCreatedAt()) + " " + Utils.escapeHtml(violation.getRuleName()) + " : " - + Utils.escapeHtml(violation.getMessage()) + "
"; + + Utils.escapeHtml(violation.getMessage()) + age + ""; } } diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java index f119344ba32..d7f586d3993 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java @@ -40,9 +40,11 @@ public final class TimeMachineConfigurationPersister implements BatchExtension { public void start() { List variationSnapshots = configuration.getProjectPastSnapshots(); for (PastSnapshot variationSnapshot : variationSnapshots) { + projectSnapshot = session.reattach(Snapshot.class, projectSnapshot.getId()); projectSnapshot.setVariationMode(variationSnapshot.getIndex(), variationSnapshot.getMode()); projectSnapshot.setVariationModeParam(variationSnapshot.getIndex(), variationSnapshot.getModeParameter()); session.save(projectSnapshot); } + session.commit(); } } diff --git a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ViolationUnmarshaller.java b/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ViolationUnmarshaller.java index 7dc2efae3a5..d5fff51f259 100644 --- a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ViolationUnmarshaller.java +++ b/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ViolationUnmarshaller.java @@ -29,8 +29,9 @@ public class ViolationUnmarshaller extends AbstractUnmarshaller { Violation violation = new Violation(); violation.setMessage(JsonUtils.getString(json, "message")); violation.setLine(JsonUtils.getInteger(json, "line")); - violation.setPriority(JsonUtils.getString(json, "priority")); + violation.setSeverity(JsonUtils.getString(json, "priority")); violation.setCreatedAt(JsonUtils.getDate(json, "createdAt")); + violation.setAge(JsonUtils.getInteger(json, "age")); JSONObject rule = (JSONObject) json.get("rule"); if (rule != null) { diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/drilldown_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/drilldown_helper.rb index 43576d79496..7820bc17503 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/drilldown_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/drilldown_helper.rb @@ -18,6 +18,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 # module DrilldownHelper + include DashboardHelper def measure_or_variation_value(measure) if measure diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/rule_failure.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/rule_failure.rb index 181b4332bf3..3b4e73b4de7 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/rule_failure.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/rule_failure.rb @@ -23,21 +23,34 @@ class RuleFailure < ActiveRecord::Base belongs_to :rule belongs_to :snapshot + def age_in_days + if created_at + ((snapshot.created_at - created_at)/(60 * 60 * 24)).to_i + else + nil + end + end + def to_hash_json json = {} json['message'] = message json['line'] = line if line json['priority'] = Sonar::RulePriority.to_s(failure_level).upcase - json['createdAt'] = format_datetime(created_at) if created_at + if created_at + json['createdAt'] = format_datetime(created_at) + json['age'] = age_in_days + end json['rule'] = { :key => rule.key, - :name => rule.name} + :name => rule.name + } json['resource'] = { :key => snapshot.project.key, :name => snapshot.project.name, :scope => snapshot.project.scope, :qualifier => snapshot.project.qualifier, - :language => snapshot.project.language} + :language => snapshot.project.language + } json end @@ -46,7 +59,10 @@ class RuleFailure < ActiveRecord::Base xml.message(message) xml.line(line) if line xml.priority(Sonar::RulePriority.to_s(failure_level)) - xml.createdAt(format_datetime(created_at)) if created_at + if created_at + xml.createdAt(format_datetime(created_at)) + xml.age(age_in_days) + end xml.rule do xml.key(rule.key) xml.name(rule.name) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_header.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_header.html.erb index 6e60e64b5d6..331bea8eb7c 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_header.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_header.html.erb @@ -17,10 +17,9 @@

<% - version_event=@snapshot.event(EventCategory::KEY_VERSION) profile_measure=@snapshot.measure(Metric::PROFILE) %> - <%= link_to_favourite(@project) -%> <%= "#{version_event.fullname} - " if version_event %> <%= l @snapshot.created_at %> + <%= link_to_favourite(@project) -%> Version <%= @snapshot.version -%> - <%= l @snapshot.created_at %> <% if profile_measure %> - Profile <%= link_to profile_measure.data, :controller => '/rules_configuration', :action => 'index', :id => profile_measure.value.to_i %><% end %> - Compare to
@@ -29,6 +28,8 @@ <%= variation_select_option(@snapshot, 1) -%> <%= variation_select_option(@snapshot, 2) -%> <%= variation_select_option(@snapshot, 3) -%> + <%= variation_select_option(@snapshot, 4) -%> + <%= variation_select_option(@snapshot, 5) -%>

diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/violations.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/violations.html.erb index 2a5b503eeca..b59824efa91 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/violations.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/violations.html.erb @@ -1,4 +1,23 @@ -<%= render :partial => 'project/snapshot_title' -%> +
+

+<% + profile_measure=@snapshot.measure(Metric::PROFILE) + %> +<%= link_to_favourite(@project) -%> Version <%= @snapshot.version -%> - <%= l @snapshot.created_at %> +<% if profile_measure %> - Profile <%= link_to profile_measure.data, :controller => '/rules_configuration', :action => 'index', :id => profile_measure.value.to_i %><% end %> +-
+ +
+

+
+ <%= render :partial => 'gwt/base', :locals => {:resource => @highlighted_resource, :popup => false, :metric => 'violations'} %> <%= render :partial => 'gwt/resource_viewers', :locals => {:resource => @project} %> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/project/_snapshot_title.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/project/_snapshot_title.html.erb index c5a57fb1533..cecfecef2e3 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/project/_snapshot_title.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/project/_snapshot_title.html.erb @@ -5,7 +5,7 @@ version_event=@snapshot.event(EventCategory::KEY_VERSION) profile_measure=@snapshot.measure(Metric::PROFILE) %> -<%= link_to_favourite(@project) -%> <%= "#{version_event.fullname} - " if version_event %> <%= l @snapshot.created_at %> +<%= link_to_favourite(@project) -%> Version <%= "#{@snapshot.version} -%> - <%= l @snapshot.created_at %> <% if profile_measure %> - profile <%= link_to profile_measure.data, :controller => '/rules_configuration', :action => 'index', :id => profile_measure.value.to_i %><% end %>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/project/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/project/index.html.erb index 4789e49b0f8..e69de29bb2d 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/project/index.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/project/index.html.erb @@ -1,49 +0,0 @@ -
-<%= render :partial => 'project/snapshot_title' %> - - - -
- - - -<% @widgets.each do |widget| - begin - widget_body=render :inline => widget.getTarget().getTemplate() - rescue => error - logger.error("Can not render widget #{widget.getId()}: " + error) - logger.error(error.backtrace.join("\n")) - widget_body="

Can not render widget #{widget.getTitle()}. See logs.

" - end - if widget_body.include? '<' -%> -
-<%= widget_body %> -
-
-<% else %> -
-<% end -end %> -
- -
\ No newline at end of file diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Violation.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Violation.java index ff0c3f22ce9..c984d15a3bf 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Violation.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Violation.java @@ -33,6 +33,7 @@ public class Violation extends Model { private String resourceScope = null; private String resourceQualifier = null; private Date createdAt = null; + private Integer age = null; public String getMessage() { return message; @@ -133,6 +134,18 @@ public class Violation extends Model { return this; } + /** + * @since 2.5 + */ + public Integer getAge() { + return age; + } + + public Violation setAge(Integer age) { + this.age = age; + return this; + } + /** * @since 2.5 */ diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshaller.java index 258e5938570..c0c5aa538cc 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshaller.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshaller.java @@ -31,6 +31,7 @@ public class ViolationUnmarshaller extends AbstractUnmarshaller { violation.setLine(JsonUtils.getInteger(json, "line")); violation.setSeverity(JsonUtils.getString(json, "priority")); violation.setCreatedAt(JsonUtils.getDateTime(json, "createdAt")); + violation.setAge(JsonUtils.getInteger(json, "age")); JSONObject rule = (JSONObject) json.get("rule"); if (rule != null) { -- 2.39.5