]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3016 Don't load default filters if they already exist
authorDavid Gageot <david@gageot.net>
Wed, 23 May 2012 06:53:45 +0000 (08:53 +0200)
committerDavid Gageot <david@gageot.net>
Wed, 23 May 2012 08:11:04 +0000 (10:11 +0200)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/filters/MyFavouritesFilter.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/filters/ProjectFilter.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/filters/TreeMapFilter.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/filters/MyFavouritesFilterTest.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/filters/ProjectFilterTest.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/filters/TreeMapFilterTest.java
sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java
sonar-core/src/main/resources/org/sonar/core/persistence/rows-derby.sql
sonar-server/src/main/java/org/sonar/server/startup/RegisterNewFilters.java
sonar-server/src/main/webapp/WEB-INF/db/migrate/304_mark_default_filters_as_loaded.rb [new file with mode: 0644]
sonar-server/src/test/java/org/sonar/server/startup/RegisterNewFiltersTest.java

index 43e47fa0a36fdc1120f608e8bbc40d9f026bb3f1..ceb8b8ec1db2e60809e762dbd116610c4af5b192 100644 (file)
@@ -33,7 +33,7 @@ import org.sonar.api.web.FilterTemplate;
 public class MyFavouritesFilter extends FilterTemplate {
   @Override
   public String getName() {
-    return "My favouritesBis";
+    return "My favourites";
   }
 
   @Override
index c5d3086cff44fa5a2d839c17b1a21223e1ff024d..368805b21bba90455661c53342dcf4c82d1dc684 100644 (file)
@@ -32,7 +32,7 @@ import org.sonar.api.web.FilterTemplate;
 public class ProjectFilter extends FilterTemplate {
   @Override
   public String getName() {
-    return "ProjectsBis";
+    return "Projects";
   }
 
   @Override
index f921a3c8267dc0d51f1dfc201dc595708cffcf01..0227fb7146841cc5de9e718b28ef3e34fd1360c3 100644 (file)
@@ -33,7 +33,7 @@ import org.sonar.api.web.FilterTemplate;
 public class TreeMapFilter extends FilterTemplate {
   @Override
   public String getName() {
-    return "TreemapBis";
+    return "Treemap";
   }
 
   @Override
index 8b3cd981e967c2fd7c1a6296fd3edcf8c9dc7279..089f06e8dcc2836346602e8443bf125609aafe50 100644 (file)
@@ -31,7 +31,7 @@ public class MyFavouritesFilterTest {
 
     Filter filter = template.createFilter();
 
-    assertThat(template.getName()).isEqualTo("My favouritesBis");
+    assertThat(template.getName()).isEqualTo("My favourites");
     assertThat(filter).isNotNull();
     assertThat(filter.isFavouritesOnly()).isTrue();
     assertThat(filter.getCriteria()).hasSize(1);
index 39196d82a5c4e67e0dfe0b05ddc9c5fae24cc5aa..e918d19f36af216117ea781f2592e95f1e939fcf 100644 (file)
@@ -31,7 +31,7 @@ public class ProjectFilterTest {
     
     Filter filter = template.createFilter();
 
-    assertThat(template.getName()).isEqualTo("ProjectsBis");
+    assertThat(template.getName()).isEqualTo("Projects");
     assertThat(filter).isNotNull();
     assertThat(filter.getCriteria()).hasSize(1);
     assertThat(filter.getColumns()).hasSize(7);
index c6c13695830c67bf42dd1bda202bdd23ac4dc8cf..20d1e0b98414e1b5a8f53c3dcac9bf44f44ea49c 100644 (file)
@@ -31,7 +31,7 @@ public class TreeMapFilterTest {
 
     Filter filter = template.createFilter();
 
-    assertThat(template.getName()).isEqualTo("TreemapBis");
+    assertThat(template.getName()).isEqualTo("Treemap");
     assertThat(filter).isNotNull();
     assertThat(filter.getCriteria()).hasSize(1);
     assertThat(filter.getColumns()).hasSize(3);
index fc6290e80a417ad7ef1424728b35580ce5073204..fd07de5a93ad2c8964003c5ac7b71573cc9424dc 100644 (file)
@@ -35,7 +35,7 @@ import java.util.List;
  */
 public class DatabaseVersion implements BatchComponent, ServerComponent {
 
-  public static final int LAST_VERSION = 303;
+  public static final int LAST_VERSION = 304;
 
   public static enum Status {
     UP_TO_DATE, REQUIRES_UPGRADE, REQUIRES_DOWNGRADE, FRESH_INSTALL
index 445efefd4765c05ecdf7e7357d478d966395773c..26c6fbc884403b7d82f2c21f21f0c4e7da35c9c7 100644 (file)
@@ -1,32 +1,5 @@
 -- All the rows inserted during Rails migrations. Rows inserted during server startup tasks (Java) are excluded : rules, profiles, metrics, ...
 
-INSERT INTO CRITERIA(ID, FILTER_ID, FAMILY, KEE, OPERATOR, VALUE, TEXT_VALUE, VARIATION) VALUES (1, 1, 'qualifier', null, '=', null, 'TRK', null);
-INSERT INTO CRITERIA(ID, FILTER_ID, FAMILY, KEE, OPERATOR, VALUE, TEXT_VALUE, VARIATION) VALUES (2, 2, 'qualifier', null, '=', null, 'TRK', null);
-INSERT INTO CRITERIA(ID, FILTER_ID, FAMILY, KEE, OPERATOR, VALUE, TEXT_VALUE, VARIATION) VALUES (3, 3, 'qualifier', null, '=', null, 'VW,SVW,TRK,BRC,DIR,PAC,FIL,CLA,UTS,LIB', null);
-ALTER TABLE CRITERIA ALTER COLUMN ID RESTART WITH 4;
-
-INSERT INTO FILTER_COLUMNS(ID, FILTER_ID, FAMILY, KEE, SORT_DIRECTION, ORDER_INDEX, VARIATION) VALUES (1, 1, 'metric', 'alert_status', null, 1, null);
-INSERT INTO FILTER_COLUMNS(ID, FILTER_ID, FAMILY, KEE, SORT_DIRECTION, ORDER_INDEX, VARIATION) VALUES (2, 1, 'name', null, 'ASC', 2, null);
-INSERT INTO FILTER_COLUMNS(ID, FILTER_ID, FAMILY, KEE, SORT_DIRECTION, ORDER_INDEX, VARIATION) VALUES (3, 1, 'version', null, null, 3, null);
-INSERT INTO FILTER_COLUMNS(ID, FILTER_ID, FAMILY, KEE, SORT_DIRECTION, ORDER_INDEX, VARIATION) VALUES (4, 1, 'metric', 'ncloc', null, 4, null);
-INSERT INTO FILTER_COLUMNS(ID, FILTER_ID, FAMILY, KEE, SORT_DIRECTION, ORDER_INDEX, VARIATION) VALUES (5, 1, 'metric', 'violations_density', null, 5, null);
-INSERT INTO FILTER_COLUMNS(ID, FILTER_ID, FAMILY, KEE, SORT_DIRECTION, ORDER_INDEX, VARIATION) VALUES (6, 1, 'date', null, null, 6, null);
-INSERT INTO FILTER_COLUMNS(ID, FILTER_ID, FAMILY, KEE, SORT_DIRECTION, ORDER_INDEX, VARIATION) VALUES (7, 1, 'links', null, null, 7, null);
-INSERT INTO FILTER_COLUMNS(ID, FILTER_ID, FAMILY, KEE, SORT_DIRECTION, ORDER_INDEX, VARIATION) VALUES (8, 2, 'name', null, 'ASC', 1, null);
-INSERT INTO FILTER_COLUMNS(ID, FILTER_ID, FAMILY, KEE, SORT_DIRECTION, ORDER_INDEX, VARIATION) VALUES (9, 2, 'metric', 'ncloc', null, 2, null);
-INSERT INTO FILTER_COLUMNS(ID, FILTER_ID, FAMILY, KEE, SORT_DIRECTION, ORDER_INDEX, VARIATION) VALUES (10, 2, 'metric', 'violations_density', null, 3, null);
-INSERT INTO FILTER_COLUMNS(ID, FILTER_ID, FAMILY, KEE, SORT_DIRECTION, ORDER_INDEX, VARIATION) VALUES (11, 3, 'metric', 'alert_status', null, 1, null);
-INSERT INTO FILTER_COLUMNS(ID, FILTER_ID, FAMILY, KEE, SORT_DIRECTION, ORDER_INDEX, VARIATION) VALUES (12, 3, 'name', null, 'ASC', 2, null);
-INSERT INTO FILTER_COLUMNS(ID, FILTER_ID, FAMILY, KEE, SORT_DIRECTION, ORDER_INDEX, VARIATION) VALUES (13, 3, 'metric', 'ncloc', null, 3, null);
-INSERT INTO FILTER_COLUMNS(ID, FILTER_ID, FAMILY, KEE, SORT_DIRECTION, ORDER_INDEX, VARIATION) VALUES (14, 3, 'metric', 'violations_density', null, 4, null);
-INSERT INTO FILTER_COLUMNS(ID, FILTER_ID, FAMILY, KEE, SORT_DIRECTION, ORDER_INDEX, VARIATION) VALUES (15, 3, 'date', null, null, 5, null);
-ALTER TABLE FILTER_COLUMNS ALTER COLUMN ID RESTART WITH 16;
-
-INSERT INTO FILTERS(ID, NAME, USER_ID, SHARED, FAVOURITES, RESOURCE_ID, DEFAULT_VIEW, PAGE_SIZE, PERIOD_INDEX) VALUES (1, 'Projects', null, true, false, null, 'list', null, null);
-INSERT INTO FILTERS(ID, NAME, USER_ID, SHARED, FAVOURITES, RESOURCE_ID, DEFAULT_VIEW, PAGE_SIZE, PERIOD_INDEX) VALUES (2, 'Treemap', null, true, false, null, 'treemap', null, null);
-INSERT INTO FILTERS(ID, NAME, USER_ID, SHARED, FAVOURITES, RESOURCE_ID, DEFAULT_VIEW, PAGE_SIZE, PERIOD_INDEX) VALUES (3, 'My favourites', null, true, true, null, 'list', null, null);
-ALTER TABLE FILTERS ALTER COLUMN ID RESTART WITH 4;
-
 INSERT INTO DASHBOARDS(ID, USER_ID, NAME, DESCRIPTION, COLUMN_LAYOUT, SHARED, IS_GLOBAL) VALUES (1, null, 'Projects', null, '100%', true, true);
 INSERT INTO DASHBOARDS(ID, USER_ID, NAME, DESCRIPTION, COLUMN_LAYOUT, SHARED, IS_GLOBAL) VALUES (2, null, 'Treemap', null, '100%', true, true);
 INSERT INTO DASHBOARDS(ID, USER_ID, NAME, DESCRIPTION, COLUMN_LAYOUT, SHARED, IS_GLOBAL) VALUES (3, null, 'My favourites', null, '100%', true, true);
@@ -205,6 +178,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('300');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('301');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('302');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('303');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('304');
 
 INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '2011-09-26 22:27:48.0', '2011-09-26 22:27:48.0', null, null);
 ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
index 774ca9f6176a5f77716fb50c2da6625776479658..58f540fd07831b399d6775f42e8d5115df106716 100644 (file)
@@ -97,7 +97,7 @@ public final class RegisterNewFilters {
   protected FilterDto createDtoFromExtension(String name, Filter filter) {
     FilterDto filterDto = new FilterDto()
         .setName(name)
-        .setPageSize((long) filter.getPageSize())
+        .setPageSize(0 == filter.getPageSize() ? null : (long) filter.getPageSize())
         .setShared(true)
         .setFavourites(filter.isFavouritesOnly())
         .setDefaultView(filter.getDisplayAs());
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/304_mark_default_filters_as_loaded.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/304_mark_default_filters_as_loaded.rb
new file mode 100644 (file)
index 0000000..0f6ee4a
--- /dev/null
@@ -0,0 +1,41 @@
+#
+# Sonar, open source software quality management tool.
+# Copyright (C) 2008-2012 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# Sonar is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 3 of the License, or (at your option) any later version.
+#
+# Sonar is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with Sonar; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+#
+
+#
+# Sonar 3.1
+#
+class MarkDefaultFiltersAsLoaded < ActiveRecord::Migration
+  class LoadedTemplate < ActiveRecord::Base
+  end
+
+  def self.up
+    mark_filter_as_loaded('Projects')
+    mark_filter_as_loaded('Treemap')
+    mark_filter_as_loaded('My favourites')
+  end
+
+  def self.mark_filter_as_loaded(name)
+    if Filter.find(:first, :conditions => {:name => name, :user_id => nil})
+      unless LoadedTemplate.find(:first, :conditions => {:kee => name, :template_type => 'FILTER'})
+        LoadedTemplate.create(:kee => name, :template_type => 'FILTER').save
+      end
+    end
+  end
+end
index 0a3876fcda9b8a81e40bcaaa3d9143524f3280e6..25b2bdd67146a945b6e7fc77572e94ffd1691178 100644 (file)
@@ -114,7 +114,6 @@ public class RegisterNewFiltersTest {
     when(filterTemplate.createFilter()).thenReturn(Filter.create()
         .setFavouritesOnly(false)
         .setDisplayAs("list")
-        .setPageSize(200)
         .add(Criterion.create("metric", "complexity", Criterion.LT, 12f, false))
         .add(Criterion.create("metric", "LCOM4", Criterion.GTE, "5", true))
         .add(FilterColumn.create("metric", "distance", "ASC", false))
@@ -128,7 +127,7 @@ public class RegisterNewFiltersTest {
     assertThat(dto.isShared()).isTrue();
     assertThat(dto.isFavourites()).isFalse();
     assertThat(dto.getDefaultView()).isEqualTo("list");
-    assertThat(dto.getPageSize()).isEqualTo(200L);
+    assertThat(dto.getPageSize()).isNull();
 
     assertThat(dto.getCriteria()).hasSize(2);
     assertThat(dto.getCriteria()).satisfies(contains(new CriterionDto().setFamily("metric").setKey("complexity").setOperator("<").setValue(12f).setVariation(false)));