]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3073 column sorting for 'key' does not work in filter
authorFabrice Bellingard <bellingard@gmail.com>
Tue, 13 Mar 2012 14:49:56 +0000 (15:49 +0100)
committerFabrice Bellingard <bellingard@gmail.com>
Tue, 13 Mar 2012 14:49:56 +0000 (15:49 +0100)
sonar-server/src/main/java/org/sonar/server/filters/Filter.java
sonar-server/src/main/java/org/sonar/server/filters/FilterExecutor.java
sonar-server/src/main/webapp/WEB-INF/app/models/filters.rb
sonar-server/src/test/java/org/sonar/server/filters/FilterExecutorTest.java
sonar-server/src/test/resources/org/sonar/server/filters/FilterExecutorTest/shared.xml

index e7e997bbf3e77e26ee5dc923d8208f085a76fae9..0e30211528203017c383623795ce2bad618b5ca0 100644 (file)
@@ -56,6 +56,7 @@ public class Filter {
   private Boolean sortedByMeasureVariation = Boolean.FALSE;
   private boolean sortedByLanguage;
   private boolean sortedByName;
+  private boolean sortedByKey;
   private boolean sortedByDate;
   private boolean sortedByVersion;
   private boolean isNumericMetric = true;
@@ -178,7 +179,7 @@ public class Filter {
   }
 
   public boolean isTextSort() {
-    return !isNumericMetric || sortedByLanguage || sortedByName || sortedByVersion;
+    return !isNumericMetric || sortedByLanguage || sortedByName || sortedByVersion || sortedByKey;
   }
 
   public Filter setSortedMetricId(Integer id, boolean isNumericValue, Boolean isVariation) {
@@ -203,6 +204,10 @@ public class Filter {
     return sortedByName;
   }
 
+  public boolean isSortedByKey() {
+    return sortedByKey;
+  }
+
   public boolean isSortedByVersion() {
     return sortedByVersion;
   }
@@ -214,7 +219,7 @@ public class Filter {
   }
 
   public boolean isSorted() {
-    return isSortedByLanguage() || isSortedByName() || isSortedByDate() || isSortedByVersion() || getSortedMetricId() != null;
+    return isSortedByLanguage() || isSortedByName() || isSortedByKey() || isSortedByDate() || isSortedByVersion() || getSortedMetricId() != null;
   }
 
   public boolean isSortedByDate() {
@@ -233,10 +238,17 @@ public class Filter {
     return this;
   }
 
+  public Filter setSortedByKey() {
+    unsetSorts();
+    this.sortedByKey = true;
+    return this;
+  }
+
   private void unsetSorts() {
     this.sortedByDate = false;
     this.sortedByLanguage = false;
     this.sortedByName = false;
+    this.sortedByKey = false;
     this.sortedMetricId = null;
     this.sortedByVersion = false;
     this.isNumericMetric = true;
index 11c44f424e6d1ab5353150d15f88cd5748abaca8..2a656f30051ebe0731de154673c682f28f5dce2a 100644 (file)
@@ -85,6 +85,9 @@ public class FilterExecutor implements ServerComponent {
     } else if (filter.isSortedByName()) {
       sql.append(", MAX(p.long_name) as name ");
 
+    } else if (filter.isSortedByKey()) {
+      sql.append(", MAX(p.kee) as kee ");
+
     } else if (filter.isSortedByDate()) {
       sql.append(", MAX(s.created_at) as createdat ");
 
index 75312ecb27cd4eaf81bcf94b17a99e8180a467d4..af1c7257f42ffced0c11c13276122f3674310e81 100644 (file)
@@ -86,6 +86,9 @@ class Filters
 
     elsif filter.sorted_column.on_language?
       java_filter.setSortedByLanguage()
+  
+    elsif filter.sorted_column.on_key?
+      java_filter.setSortedByKey()
 
     elsif filter.sorted_column.on_metric? && filter.sorted_column.metric
       metric=filter.sorted_column.metric
index 4feb4c7abeacc504015fbb54e2c7473bab5bcce7..6022e0191d53b2c5d389160477e5446aba347df3 100644 (file)
@@ -101,6 +101,14 @@ public class FilterExecutorTest extends AbstractDbUnitTestCase {
     assertSortedSnapshotIds(result, 2, 4, 3);
   }
 
+  @Test
+  public void sortByKey() {
+    setupData("shared");
+    FilterExecutor executor = new FilterExecutor(getSession());
+    FilterResult result = executor.execute(Filter.createForAllQualifiers().setSortedByKey());
+    assertSortedSnapshotIds(result, 3, 2, 4);
+  }
+
   @Test
   public void sortByDate() {
     setupData("shared");
index 26eed6f6800dd0ac914cfb4a97e90c5581582696..03e194f11aa739c952fcaff89f0240f200dc1a30 100644 (file)
@@ -3,7 +3,7 @@
             root_id="[null]"
             description="[null]" enabled="true" profile_id="[null]" language="java" copy_resource_id="[null]" person_id="[null]"/>
 
-  <projects long_name="php project" id="2" scope="PRJ" kee="project:php" qualifier="TRK" name="php project"
+  <projects long_name="php project" id="2" scope="PRJ" kee="project:a-php-project" qualifier="TRK" name="php project"
             root_id="[null]"
             description="[null]" enabled="true" profile_id="[null]" language="php" copy_resource_id="[null]" person_id="[null]"/>