From 02a640ea12a7e3a0285d0c68ab0733689b6ea0ff Mon Sep 17 00:00:00 2001 From: David Gageot Date: Wed, 23 May 2012 08:53:45 +0200 Subject: [PATCH] SONAR-3016 Don't load default filters if they already exist --- .../core/filters/MyFavouritesFilter.java | 2 +- .../plugins/core/filters/ProjectFilter.java | 2 +- .../plugins/core/filters/TreeMapFilter.java | 2 +- .../core/filters/MyFavouritesFilterTest.java | 2 +- .../core/filters/ProjectFilterTest.java | 2 +- .../core/filters/TreeMapFilterTest.java | 2 +- .../core/persistence/DatabaseVersion.java | 2 +- .../org/sonar/core/persistence/rows-derby.sql | 28 +------------ .../server/startup/RegisterNewFilters.java | 2 +- .../304_mark_default_filters_as_loaded.rb | 41 +++++++++++++++++++ .../startup/RegisterNewFiltersTest.java | 3 +- 11 files changed, 51 insertions(+), 37 deletions(-) create mode 100644 sonar-server/src/main/webapp/WEB-INF/db/migrate/304_mark_default_filters_as_loaded.rb diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/filters/MyFavouritesFilter.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/filters/MyFavouritesFilter.java index 43e47fa0a36..ceb8b8ec1db 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/filters/MyFavouritesFilter.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/filters/MyFavouritesFilter.java @@ -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 diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/filters/ProjectFilter.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/filters/ProjectFilter.java index c5d3086cff4..368805b21bb 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/filters/ProjectFilter.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/filters/ProjectFilter.java @@ -32,7 +32,7 @@ import org.sonar.api.web.FilterTemplate; public class ProjectFilter extends FilterTemplate { @Override public String getName() { - return "ProjectsBis"; + return "Projects"; } @Override diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/filters/TreeMapFilter.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/filters/TreeMapFilter.java index f921a3c8267..0227fb71468 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/filters/TreeMapFilter.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/filters/TreeMapFilter.java @@ -33,7 +33,7 @@ import org.sonar.api.web.FilterTemplate; public class TreeMapFilter extends FilterTemplate { @Override public String getName() { - return "TreemapBis"; + return "Treemap"; } @Override diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/filters/MyFavouritesFilterTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/filters/MyFavouritesFilterTest.java index 8b3cd981e96..089f06e8dcc 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/filters/MyFavouritesFilterTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/filters/MyFavouritesFilterTest.java @@ -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); diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/filters/ProjectFilterTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/filters/ProjectFilterTest.java index 39196d82a5c..e918d19f36a 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/filters/ProjectFilterTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/filters/ProjectFilterTest.java @@ -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); diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/filters/TreeMapFilterTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/filters/TreeMapFilterTest.java index c6c13695830..20d1e0b9841 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/filters/TreeMapFilterTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/filters/TreeMapFilterTest.java @@ -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); diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java index fc6290e80a4..fd07de5a93a 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java @@ -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 diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-derby.sql b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-derby.sql index 445efefd476..26c6fbc8844 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-derby.sql +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-derby.sql @@ -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; diff --git a/sonar-server/src/main/java/org/sonar/server/startup/RegisterNewFilters.java b/sonar-server/src/main/java/org/sonar/server/startup/RegisterNewFilters.java index 774ca9f6176..58f540fd078 100644 --- a/sonar-server/src/main/java/org/sonar/server/startup/RegisterNewFilters.java +++ b/sonar-server/src/main/java/org/sonar/server/startup/RegisterNewFilters.java @@ -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 index 00000000000..0f6ee4a39ad --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/304_mark_default_filters_as_loaded.rb @@ -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 diff --git a/sonar-server/src/test/java/org/sonar/server/startup/RegisterNewFiltersTest.java b/sonar-server/src/test/java/org/sonar/server/startup/RegisterNewFiltersTest.java index 0a3876fcda9..25b2bdd6714 100644 --- a/sonar-server/src/test/java/org/sonar/server/startup/RegisterNewFiltersTest.java +++ b/sonar-server/src/test/java/org/sonar/server/startup/RegisterNewFiltersTest.java @@ -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))); -- 2.39.5