From 014ba2d48296a2b98349ee4cd16a4767b737c239 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Thu, 11 Jul 2013 16:44:21 +0200 Subject: [PATCH] SONAR-4248 SONAR-4238 Add created column and add the possibility the add links and last analysis (formerly date) --- .../resources/org/sonar/l10n/core.properties | 7 ++++-- .../sonar/core/measure/MeasureFilterSort.java | 9 +++++-- .../measure/MeasureFilterExecutorTest.java | 24 +++++++++++++++++++ .../MeasureFilterExecutorTest/shared.xml | 15 ++++++++---- .../WEB-INF/app/helpers/measures_helper.rb | 2 ++ .../WEB-INF/app/models/measure_filter.rb | 10 ++++---- .../app/views/measures/_display_list.html.erb | 12 +++++++++- 7 files changed, 64 insertions(+), 15 deletions(-) diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties index e125aa371c5..cf14f39fac1 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties @@ -427,7 +427,7 @@ measure_filter.favourite_filters=Favourite Filters measure_filter.more_criteria=+ More Criteria measure_filter.languages=Languages measure_filter.alert_levels=Alert levels -measure_filter.col.date=Date +measure_filter.col.date=Last Analysis measure_filter.col.description=Description measure_filter.col.key=Key measure_filter.col.language=Language @@ -435,7 +435,8 @@ measure_filter.col.links=Links measure_filter.col.name=Name measure_filter.col.short_name=Short Name measure_filter.col.version=Version -measure_filter.abbr.date=Date +measure_filter.col.project_creation_date=Created +measure_filter.abbr.date=Last Analysis measure_filter.abbr.description=Description measure_filter.abbr.key=Key measure_filter.abbr.language=Lang. @@ -443,6 +444,7 @@ measure_filter.abbr.links=Links measure_filter.abbr.name=Name measure_filter.abbr.short_name=Name measure_filter.abbr.version=Version +measure_filter.abbr.project_creation_date=Created measure_filter.missing_name=Name is missing measure_filter.name_too_long=Name is too long measure_filter.sharing=Sharing @@ -461,6 +463,7 @@ measure_filter.widget.unknown_filter_warning=This widget is configured to displa measure_filter.error.UNKNOWN=Unexpected error. Please contact the administrator. measure_filter.error.TOO_MANY_RESULTS=Too many results. Please refine your search. + #------------------------------------------------------------------------------ # # ISSUES diff --git a/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterSort.java b/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterSort.java index 92bce6c6407..14af5ee8206 100644 --- a/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterSort.java +++ b/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterSort.java @@ -23,7 +23,9 @@ import org.sonar.api.measures.Metric; class MeasureFilterSort { public static enum Field { - KEY, NAME, VERSION, LANGUAGE, DATE, METRIC, SHORT_NAME, DESCRIPTION + KEY, NAME, VERSION, LANGUAGE, METRIC, SHORT_NAME, DESCRIPTION, + DATE, // Sort by last analysis date + PROJECT_CREATION_DATE // Sort by project creation date } private Field field = Field.NAME; @@ -76,7 +78,7 @@ class MeasureFilterSort { } boolean isOnDate() { - return Field.DATE.equals(field); + return Field.DATE.equals(field) || Field.PROJECT_CREATION_DATE.equals(field); } boolean isAsc() { @@ -108,6 +110,9 @@ class MeasureFilterSort { case DATE: column = "s.created_at"; break; + case PROJECT_CREATION_DATE: + column = "p.created_at"; + break; case METRIC: if (metric.isNumericType()) { column = (period != null ? "pmsort.variation_value_" + period : "pmsort.value"); diff --git a/sonar-core/src/test/java/org/sonar/core/measure/MeasureFilterExecutorTest.java b/sonar-core/src/test/java/org/sonar/core/measure/MeasureFilterExecutorTest.java index 214ceba319c..392ead327cd 100644 --- a/sonar-core/src/test/java/org/sonar/core/measure/MeasureFilterExecutorTest.java +++ b/sonar-core/src/test/java/org/sonar/core/measure/MeasureFilterExecutorTest.java @@ -335,6 +335,30 @@ public class MeasureFilterExecutorTest { verifyJavaProject(rows.get(1));// 2008 } + @Test + public void sort_by_ascending_created_at() throws SQLException { + db.prepareDbUnit(getClass(), "shared.xml"); + MeasureFilter filter = new MeasureFilter().setResourceQualifiers(Arrays.asList("TRK")).setSortOn(MeasureFilterSort.Field.PROJECT_CREATION_DATE); + List rows = executor.execute(filter, new MeasureFilterContext()); + + verifyJavaProject(rows.get(0));// 2008 + assertThat(DateUtils.formatDate(rows.get(0).getSortDate())).isEqualTo("2008-12-19"); + verifyPhpProject(rows.get(1));// 2012 + assertThat(DateUtils.formatDate(rows.get(1).getSortDate())).isEqualTo("2012-12-12"); + } + + @Test + public void sort_by_descending_created_at() throws SQLException { + db.prepareDbUnit(getClass(), "shared.xml"); + MeasureFilter filter = new MeasureFilter().setResourceQualifiers(Arrays.asList("TRK")).setSortOn(MeasureFilterSort.Field.PROJECT_CREATION_DATE).setSortAsc(false); + List rows = executor.execute(filter, new MeasureFilterContext()); + + verifyPhpProject(rows.get(0));// 2012 + assertThat(DateUtils.formatDate(rows.get(0).getSortDate())).isEqualTo("2012-12-12"); + verifyJavaProject(rows.get(1));// 2008 + assertThat(DateUtils.formatDate(rows.get(1).getSortDate())).isEqualTo("2008-12-19"); + } + @Test public void condition_on_numeric_measure() throws SQLException { db.prepareDbUnit(getClass(), "shared.xml"); diff --git a/sonar-core/src/test/resources/org/sonar/core/measure/MeasureFilterExecutorTest/shared.xml b/sonar-core/src/test/resources/org/sonar/core/measure/MeasureFilterExecutorTest/shared.xml index 8b4a6bbc26e..bcfe738a901 100644 --- a/sonar-core/src/test/resources/org/sonar/core/measure/MeasureFilterExecutorTest/shared.xml +++ b/sonar-core/src/test/resources/org/sonar/core/measure/MeasureFilterExecutorTest/shared.xml @@ -25,20 +25,24 @@ + description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" + created_at="2008-12-19 00:00:00.00"/> + description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" + created_at="2008-12-19 00:00:00.00"/> + description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" + created_at="2008-12-19 00:00:00.00"/> + description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" + created_at="2008-12-19 00:00:00.00"/> + description="[null]" enabled="[true]" language="php" copy_resource_id="[null]" person_id="[null]" + created_at="2012-12-12 04:06:00.00"/> 'dashboard', :id => row.snapshot.resource_id}, :title => h(row.snapshot.resource.key))}" elsif column.key=='date' human_short_date(row.snapshot.created_at) + elsif column.key=='project_creation_date' + human_short_date(row.snapshot.resource.created_at) elsif column.key=='key' "#{row.snapshot.resource.kee}" elsif column.key=='description' diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter.rb index 1f4bb44e29e..e0e8e519dad 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter.rb @@ -185,7 +185,7 @@ class MeasureFilter < ActiveRecord::Base def base_resource if criteria('base') - Project.find(:first, :conditions => ['kee=? and copy_resource_id is null and person_id is null', criteria('base')]) + Project.first(:conditions => ['kee=? and copy_resource_id is null and person_id is null', criteria('base')]) elsif criteria('baseId') Project.find(criteria('baseId')) end @@ -249,7 +249,7 @@ class MeasureFilter < ActiveRecord::Base if !snapshot_ids.empty? rows_by_snapshot_id = {} - snapshots = Snapshot.find(:all, :include => ['project'], :conditions => ['id in (?)', snapshot_ids]) + snapshots = Snapshot.all(:include => ['project'], :conditions => ['id in (?)', snapshot_ids]) snapshots.each do |snapshot| row = Row.new(snapshot) rows_by_snapshot_id[snapshot.id] = row @@ -261,7 +261,7 @@ class MeasureFilter < ActiveRecord::Base end unless metric_ids.empty? - measures = ProjectMeasure.find(:all, :conditions => + measures = ProjectMeasure.all(:conditions => ['rule_priority is null and rule_id is null and characteristic_id is null and person_id is null and snapshot_id in (?) and metric_id in (?)', snapshot_ids, metric_ids] ) measures.each do |measure| @@ -277,7 +277,7 @@ class MeasureFilter < ActiveRecord::Base project_ids << snapshot.project_id rows_by_project_id[snapshot.project_id] = rows_by_snapshot_id[snapshot.id] end - links = ProjectLink.find(:all, :conditions => {:project_id => project_ids}, :order => 'link_type') + links = ProjectLink.all(:conditions => {:project_id => project_ids}, :order => 'link_type') links.each do |link| rows_by_project_id[link.project_id].add_link(link) end @@ -288,7 +288,7 @@ class MeasureFilter < ActiveRecord::Base if base_snapshot @base_row = Row.new(base_snapshot) unless metric_ids.empty? - base_measures = ProjectMeasure.find(:all, :conditions => + base_measures = ProjectMeasure.all(:conditions => ['rule_priority is null and rule_id is null and characteristic_id is null and person_id is null and snapshot_id=? and metric_id in (?)', base_snapshot.id, metric_ids] ) base_measures.each do |base_measure| diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_list.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_list.html.erb index 597df3699a8..7d5c6e76bde 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_list.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_list.html.erb @@ -126,7 +126,17 @@ :html_id => 'select-metric', :allow_empty => true, :key_prefix => 'metric:', - :extra_values => [[message('measure_filter.col.name'), 'name'], [message('measure_filter.col.short_name'), 'short_name'], [message('measure_filter.col.description'), 'description'], [message('measure_filter.col.language'), 'language'], [message('measure_filter.col.version'), 'version']] -%> + :extra_values => [ + [message('measure_filter.col.name'), 'name'], + [message('measure_filter.col.short_name'), 'short_name'], + [message('measure_filter.col.description'), 'description'], + [message('measure_filter.col.language'), 'language'], + [message('measure_filter.col.version'), 'version'], + [message('measure_filter.col.date'), 'date'], + [message('measure_filter.col.project_creation_date'), 'project_creation_date'], + [message('measure_filter.col.links'), 'links'] + ] + -%>