From 014ba2d48296a2b98349ee4cd16a4767b737c239 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Thu, 11 Jul 2013 16:44:21 +0200 Subject: SONAR-4248 SONAR-4238 Add created column and add the possibility the add links and last analysis (formerly date) --- .../org/sonar/core/measure/MeasureFilterSort.java | 9 ++++++-- .../core/measure/MeasureFilterExecutorTest.java | 24 ++++++++++++++++++++++ .../measure/MeasureFilterExecutorTest/shared.xml | 15 +++++++++----- 3 files changed, 41 insertions(+), 7 deletions(-) (limited to 'sonar-core') 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"/>