From 777d9010c1f88229730db03e1e8636a39a207645 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Tue, 22 May 2012 14:52:24 +0200 Subject: [PATCH] SONAR-3016 More work on extension point for filter template Introduce Criteria and FilterColums --- .../{CriteriaDto.java => CriterionDto.java} | 18 +-- ...iteriaMapper.java => CriterionMapper.java} | 4 +- .../java/org/sonar/core/filter/FilterDao.java | 4 +- .../java/org/sonar/core/filter/FilterDto.java | 18 +-- .../org/sonar/core/persistence/MyBatis.java | 8 +- ...-oracle.xml => CriterionMapper-oracle.xml} | 4 +- ...CriteriaMapper.xml => CriterionMapper.xml} | 4 +- .../org/sonar/core/filters/FilterDaoTest.java | 20 ++-- .../java/org/sonar/api/web/Criterion.java | 107 ++++++++++++++++++ .../main/java/org/sonar/api/web/Filter.java | 49 ++++++-- .../java/org/sonar/api/web/FilterColumn.java | 89 +++++++++++++++ .../java/org/sonar/api/web/CriterionTest.java | 46 ++++++++ .../server/startup/RegisterNewDashboards.java | 9 +- .../server/startup/RegisterNewFilters.java | 34 +++++- .../startup/RegisterNewDashboardsTest.java | 2 +- .../startup/RegisterNewFiltersTest.java | 34 ++++-- 16 files changed, 387 insertions(+), 63 deletions(-) rename sonar-core/src/main/java/org/sonar/core/filter/{CriteriaDto.java => CriterionDto.java} (81%) rename sonar-core/src/main/java/org/sonar/core/filter/{CriteriaMapper.java => CriterionMapper.java} (92%) rename sonar-core/src/main/resources/org/sonar/core/filter/{CriteriaMapper-oracle.xml => CriterionMapper-oracle.xml} (75%) rename sonar-core/src/main/resources/org/sonar/core/filter/{CriteriaMapper.xml => CriterionMapper.xml} (75%) create mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/web/Criterion.java create mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/web/FilterColumn.java create mode 100644 sonar-plugin-api/src/test/java/org/sonar/api/web/CriterionTest.java diff --git a/sonar-core/src/main/java/org/sonar/core/filter/CriteriaDto.java b/sonar-core/src/main/java/org/sonar/core/filter/CriterionDto.java similarity index 81% rename from sonar-core/src/main/java/org/sonar/core/filter/CriteriaDto.java rename to sonar-core/src/main/java/org/sonar/core/filter/CriterionDto.java index 4d9aaa034b5..02fc0d04a54 100644 --- a/sonar-core/src/main/java/org/sonar/core/filter/CriteriaDto.java +++ b/sonar-core/src/main/java/org/sonar/core/filter/CriterionDto.java @@ -22,7 +22,7 @@ package org.sonar.core.filter; /** * @since 3.1 */ -public final class CriteriaDto { +public final class CriterionDto { private Long id; private Long filterId; private String family; @@ -36,7 +36,7 @@ public final class CriteriaDto { return id; } - public CriteriaDto setId(Long id) { + public CriterionDto setId(Long id) { this.id = id; return this; } @@ -45,7 +45,7 @@ public final class CriteriaDto { return filterId; } - public CriteriaDto setFilterId(Long filterId) { + public CriterionDto setFilterId(Long filterId) { this.filterId = filterId; return this; } @@ -54,7 +54,7 @@ public final class CriteriaDto { return family; } - public CriteriaDto setFamily(String family) { + public CriterionDto setFamily(String family) { this.family = family; return this; } @@ -63,7 +63,7 @@ public final class CriteriaDto { return key; } - public CriteriaDto setKey(String key) { + public CriterionDto setKey(String key) { this.key = key; return this; } @@ -72,7 +72,7 @@ public final class CriteriaDto { return operator; } - public CriteriaDto setOperator(String operator) { + public CriterionDto setOperator(String operator) { this.operator = operator; return this; } @@ -81,7 +81,7 @@ public final class CriteriaDto { return value; } - public CriteriaDto setValue(Float value) { + public CriterionDto setValue(Float value) { this.value = value; return this; } @@ -90,7 +90,7 @@ public final class CriteriaDto { return textValue; } - public CriteriaDto setTextValue(String textValue) { + public CriterionDto setTextValue(String textValue) { this.textValue = textValue; return this; } @@ -99,7 +99,7 @@ public final class CriteriaDto { return variation; } - public CriteriaDto setVariation(Boolean variation) { + public CriterionDto setVariation(Boolean variation) { this.variation = variation; return this; } diff --git a/sonar-core/src/main/java/org/sonar/core/filter/CriteriaMapper.java b/sonar-core/src/main/java/org/sonar/core/filter/CriterionMapper.java similarity index 92% rename from sonar-core/src/main/java/org/sonar/core/filter/CriteriaMapper.java rename to sonar-core/src/main/java/org/sonar/core/filter/CriterionMapper.java index 9d21cd6ac44..f933c6ffda8 100644 --- a/sonar-core/src/main/java/org/sonar/core/filter/CriteriaMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/filter/CriterionMapper.java @@ -22,6 +22,6 @@ package org.sonar.core.filter; /** * @since 3.1 */ -public interface CriteriaMapper { - void insert(CriteriaDto criteriaDto); +public interface CriterionMapper { + void insert(CriterionDto criteriaDto); } diff --git a/sonar-core/src/main/java/org/sonar/core/filter/FilterDao.java b/sonar-core/src/main/java/org/sonar/core/filter/FilterDao.java index 809d91315b1..8521bf4e48f 100644 --- a/sonar-core/src/main/java/org/sonar/core/filter/FilterDao.java +++ b/sonar-core/src/main/java/org/sonar/core/filter/FilterDao.java @@ -47,11 +47,11 @@ public class FilterDao implements BatchComponent, ServerComponent { public void insert(FilterDto filterDto) { SqlSession session = mybatis.openSession(); FilterMapper filterMapper = session.getMapper(FilterMapper.class); - CriteriaMapper criteriaMapper = session.getMapper(CriteriaMapper.class); + CriterionMapper criteriaMapper = session.getMapper(CriterionMapper.class); FilterColumnMapper columnMapper = session.getMapper(FilterColumnMapper.class); try { filterMapper.insert(filterDto); - for (CriteriaDto criteriaDto : filterDto.getCriterias()) { + for (CriterionDto criteriaDto : filterDto.getCriteria()) { criteriaDto.setFilterId(filterDto.getId()); criteriaMapper.insert(criteriaDto); } diff --git a/sonar-core/src/main/java/org/sonar/core/filter/FilterDto.java b/sonar-core/src/main/java/org/sonar/core/filter/FilterDto.java index f37abd80254..91dccf33381 100644 --- a/sonar-core/src/main/java/org/sonar/core/filter/FilterDto.java +++ b/sonar-core/src/main/java/org/sonar/core/filter/FilterDto.java @@ -37,8 +37,8 @@ public final class FilterDto { private String defaultView; private Long pageSize; private Long periodIndex; - private List criteriaDtos = Lists.newArrayList(); - private List filterColumnDtos = Lists.newArrayList(); + private List criteria = Lists.newArrayList(); + private List filterColumns = Lists.newArrayList(); public Long getId() { return id; @@ -121,21 +121,21 @@ public final class FilterDto { return this; } - public Collection getCriterias() { - return criteriaDtos; + public Collection getCriteria() { + return criteria; } - public FilterDto addCriteria(CriteriaDto criteriaDto) { - criteriaDtos.add(criteriaDto); + public FilterDto add(CriterionDto criterion) { + criteria.add(criterion); return this; } public Collection getColumns() { - return filterColumnDtos; + return filterColumns; } - public FilterDto addColumn(FilterColumnDto filterColumnDto) { - filterColumnDtos.add(filterColumnDto); + public FilterDto add(FilterColumnDto filterColumn) { + filterColumns.add(filterColumn); return this; } } diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java index 7847470ddf3..5901695c53e 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java @@ -43,8 +43,8 @@ import org.sonar.core.dashboard.WidgetPropertyDto; import org.sonar.core.dashboard.WidgetPropertyMapper; import org.sonar.core.duplication.DuplicationMapper; import org.sonar.core.duplication.DuplicationUnitDto; -import org.sonar.core.filter.CriteriaDto; -import org.sonar.core.filter.CriteriaMapper; +import org.sonar.core.filter.CriterionDto; +import org.sonar.core.filter.CriterionMapper; import org.sonar.core.filter.FilterColumnDto; import org.sonar.core.filter.FilterColumnMapper; import org.sonar.core.filter.FilterDto; @@ -93,7 +93,7 @@ public class MyBatis implements BatchComponent, ServerComponent { loadAlias(conf, "ActiveDashboard", ActiveDashboardDto.class); loadAlias(conf, "Author", AuthorDto.class); loadAlias(conf, "Filter", FilterDto.class); - loadAlias(conf, "Criteria", CriteriaDto.class); + loadAlias(conf, "Criterion", CriterionDto.class); loadAlias(conf, "FilterColumn", FilterColumnDto.class); loadAlias(conf, "Dashboard", DashboardDto.class); loadAlias(conf, "DuplicationUnit", DuplicationUnitDto.class); @@ -113,7 +113,7 @@ public class MyBatis implements BatchComponent, ServerComponent { loadMapper(conf, ActiveDashboardMapper.class); loadMapper(conf, AuthorMapper.class); loadMapper(conf, FilterMapper.class); - loadMapper(conf, CriteriaMapper.class); + loadMapper(conf, CriterionMapper.class); loadMapper(conf, FilterColumnMapper.class); loadMapper(conf, DashboardMapper.class); loadMapper(conf, DuplicationMapper.class); diff --git a/sonar-core/src/main/resources/org/sonar/core/filter/CriteriaMapper-oracle.xml b/sonar-core/src/main/resources/org/sonar/core/filter/CriterionMapper-oracle.xml similarity index 75% rename from sonar-core/src/main/resources/org/sonar/core/filter/CriteriaMapper-oracle.xml rename to sonar-core/src/main/resources/org/sonar/core/filter/CriterionMapper-oracle.xml index 257e54e76d4..5c9d27ac100 100644 --- a/sonar-core/src/main/resources/org/sonar/core/filter/CriteriaMapper-oracle.xml +++ b/sonar-core/src/main/resources/org/sonar/core/filter/CriterionMapper-oracle.xml @@ -1,9 +1,9 @@ - + - + INSERT INTO criteria (id, filter_id, family, kee, operator, value, text_value, variation) VALUES (criteria_seq.NEXTVAL, #{filterId, jdbcType=INTEGER}, #{family, jdbcType=VARCHAR}, #{key, jdbcType=VARCHAR}, #{operator, jdbcType=VARCHAR}, #{value, jdbcType=FLOAT}, #{textValue, jdbcType=VARCHAR}, #{variation}) diff --git a/sonar-core/src/main/resources/org/sonar/core/filter/CriteriaMapper.xml b/sonar-core/src/main/resources/org/sonar/core/filter/CriterionMapper.xml similarity index 75% rename from sonar-core/src/main/resources/org/sonar/core/filter/CriteriaMapper.xml rename to sonar-core/src/main/resources/org/sonar/core/filter/CriterionMapper.xml index 1201f28d9b3..09c4769e9f8 100644 --- a/sonar-core/src/main/resources/org/sonar/core/filter/CriteriaMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/filter/CriterionMapper.xml @@ -1,9 +1,9 @@ - + - + INSERT INTO criteria (filter_id, family, kee, operator, value, text_value, variation) VALUES (#{filterId, jdbcType=INTEGER}, #{family, jdbcType=VARCHAR}, #{key, jdbcType=VARCHAR}, #{operator, jdbcType=VARCHAR}, #{value, jdbcType=FLOAT}, #{textValue, jdbcType=VARCHAR}, #{variation}) diff --git a/sonar-core/src/test/java/org/sonar/core/filters/FilterDaoTest.java b/sonar-core/src/test/java/org/sonar/core/filters/FilterDaoTest.java index 14460634ef5..01fc26a9c29 100644 --- a/sonar-core/src/test/java/org/sonar/core/filters/FilterDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/filters/FilterDaoTest.java @@ -21,7 +21,7 @@ package org.sonar.core.filters; import org.sonar.core.filter.FilterColumnDto; -import org.sonar.core.filter.CriteriaDto; +import org.sonar.core.filter.CriterionDto; import org.junit.Before; import org.junit.Test; @@ -64,14 +64,14 @@ public class FilterDaoTest extends DaoTestCase { filterDto.setPageSize(10L); filterDto.setPeriodIndex(1L); - CriteriaDto criteriaDto = new CriteriaDto(); - criteriaDto.setFamily("family"); - criteriaDto.setKey("key"); - criteriaDto.setOperator("="); - criteriaDto.setValue(1.5f); - criteriaDto.setTextValue("1.5"); - criteriaDto.setVariation(true); - filterDto.addCriteria(criteriaDto); + CriterionDto criterionDto = new CriterionDto(); + criterionDto.setFamily("family"); + criterionDto.setKey("key"); + criterionDto.setOperator("="); + criterionDto.setValue(1.5f); + criterionDto.setTextValue("1.5"); + criterionDto.setVariation(true); + filterDto.add(criterionDto); FilterColumnDto filterColumnDto = new FilterColumnDto(); filterColumnDto.setFamily("family"); @@ -79,7 +79,7 @@ public class FilterDaoTest extends DaoTestCase { filterColumnDto.setSortDirection("ASC"); filterColumnDto.setOrderIndex(2L); filterColumnDto.setVariation(true); - filterDto.addColumn(filterColumnDto); + filterDto.add(filterColumnDto); dao.insert(filterDto); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/Criterion.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/Criterion.java new file mode 100644 index 00000000000..7142c745dd5 --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/web/Criterion.java @@ -0,0 +1,107 @@ +/* + * 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 + */ +package org.sonar.api.web; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; + +import java.util.List; + +/** + * Definition of a criterion to be used to narrow down a {@see Filter}. + * + * @since 3.1 + */ +public class Criterion { + public static final List OPERATORS = ImmutableList.of("=", ">", "<", ">=", "<="); + + private String family; + private String key; + private String operator; + private Float value; + private String textValue; + private boolean variation; + + private Criterion() { + // The factory method should be used + } + + /** + * Creates a new {@link Criterion}. + */ + public static Criterion create() { + return new Criterion(); + } + + public String getFamily() { + return family; + } + + public Criterion setFamily(String family) { + this.family = family; + return this; + } + + public String getKey() { + return key; + } + + public Criterion setKey(String key) { + this.key = key; + return this; + } + + public String getOperator() { + return operator; + } + + public Criterion setOperator(String operator) { + Preconditions.checkArgument(OPERATORS.contains(operator), "Valid operators are %s, not %s", OPERATORS, operator); + this.operator = operator; + return this; + } + + public Float getValue() { + return value; + } + + public Criterion setValue(Float value) { + this.value = value; + return this; + } + + public String getTextValue() { + return textValue; + } + + public Criterion setTextValue(String textValue) { + this.textValue = textValue; + return this; + } + + public boolean isVariation() { + return variation; + } + + public Criterion setVariation(boolean variation) { + this.variation = variation; + return this; + } +} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/Filter.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/Filter.java index e906d07faf0..e1638ed985d 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/web/Filter.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/web/Filter.java @@ -19,19 +19,23 @@ */ package org.sonar.api.web; +import com.google.common.collect.Lists; + +import java.util.List; + import com.google.common.base.Preconditions; /** * Definition of a filter. - *

- * Its name can be retrieved using the i18n mechanism, using the keys "dashboard.<id>.name". + * + *

Its name can be retrieved using the i18n mechanism, using the keys "filter.<id>.name".

* * @since 3.1 */ public class Filter { - // Criteria - // Columns - // + public static final String LIST = "list"; + public static final String TREEMAP = "treemap"; + private boolean shared; private boolean favouritesOnly; private String defaultPeriod; @@ -39,9 +43,13 @@ public class Filter { private String resourceNameLike; private String language; private String searchFor; + private int pageSize; + private List criteria; + private List columns; private Filter() { - // The factory method should be used + criteria = Lists.newArrayList(); + columns = Lists.newArrayList(); } /** @@ -51,6 +59,24 @@ public class Filter { return new Filter(); } + public List getCriteria() { + return criteria; + } + + public Filter add(Criterion criterion) { + this.criteria.add(criterion); + return this; + } + + public List getColumns() { + return columns; + } + + public Filter add(FilterColumn column) { + this.columns.add(column); + return this; + } + public boolean isShared() { return shared; } @@ -74,7 +100,7 @@ public class Filter { } public Filter setDefaultPeriod(String defaultPeriod) { - Preconditions.checkArgument("list".equals(defaultPeriod) || "treemap".equals(defaultPeriod), "Default period should be either list or treemap, not %s", defaultPeriod); + Preconditions.checkArgument(LIST.equals(defaultPeriod) || TREEMAP.equals(defaultPeriod), "Default period should be either %s or %s, not %s", LIST, TREEMAP, defaultPeriod); this.defaultPeriod = defaultPeriod; return this; } @@ -114,4 +140,13 @@ public class Filter { this.searchFor = searchFor; return this; } + + public int getPageSize() { + return pageSize; + } + + public Filter setPageSize(int pageSize) { + this.pageSize = pageSize; + return this; + } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/FilterColumn.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/FilterColumn.java new file mode 100644 index 00000000000..09c266e749f --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/web/FilterColumn.java @@ -0,0 +1,89 @@ +/* + * 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 + */ +package org.sonar.api.web; + +/** + * Definition of a {@see Filter} column. + * + * @since 3.1 + */ +public class FilterColumn { + private String family; + private String key; + private String sortDirection; + private Long orderIndex; + private boolean variation; + + private FilterColumn() { + // The factory method should be used + } + + /** + * Creates a new {@link FilterColumn}. + */ + public static FilterColumn create() { + return new FilterColumn(); + } + + public String getFamily() { + return family; + } + + public FilterColumn setFamily(String family) { + this.family = family; + return this; + } + + public String getKey() { + return key; + } + + public FilterColumn setKey(String key) { + this.key = key; + return this; + } + + public String getSortDirection() { + return sortDirection; + } + + public FilterColumn setSortDirection(String sortDirection) { + this.sortDirection = sortDirection; + return this; + } + + public Long getOrderIndex() { + return orderIndex; + } + + public FilterColumn setOrderIndex(Long orderIndex) { + this.orderIndex = orderIndex; + return this; + } + + public boolean isVariation() { + return variation; + } + + public FilterColumn setVariation(boolean variation) { + this.variation = variation; + return this; + } +} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/web/CriterionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/web/CriterionTest.java new file mode 100644 index 00000000000..1526d4fb82e --- /dev/null +++ b/sonar-plugin-api/src/test/java/org/sonar/api/web/CriterionTest.java @@ -0,0 +1,46 @@ +/* + * 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 + */ +package org.sonar.api.web; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +public class CriterionTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + + @Test + public void should_accept_valid_operators() { + Criterion.create().setOperator("<="); + Criterion.create().setOperator("<"); + Criterion.create().setOperator("="); + Criterion.create().setOperator(">"); + Criterion.create().setOperator(">="); + } + + @Test + public void should_fail_on_invalid_operators() { + exception.expect(IllegalArgumentException.class); + exception.expectMessage("Valid operators are [=, >, <, >=, <=], not <>"); + + Criterion.create().setOperator("<>"); + } +} diff --git a/sonar-server/src/main/java/org/sonar/server/startup/RegisterNewDashboards.java b/sonar-server/src/main/java/org/sonar/server/startup/RegisterNewDashboards.java index db2fa9fc067..ff270e66719 100644 --- a/sonar-server/src/main/java/org/sonar/server/startup/RegisterNewDashboards.java +++ b/sonar-server/src/main/java/org/sonar/server/startup/RegisterNewDashboards.java @@ -47,17 +47,20 @@ public final class RegisterNewDashboards { private DashboardDao dashboardDao; private ActiveDashboardDao activeDashboardDao; private LoadedTemplateDao loadedTemplateDao; + private RegisterNewFilters registerNewFilters; // To force loading the filters before the dashboards - public RegisterNewDashboards(DashboardDao dashboardDao, ActiveDashboardDao activeDashboardDao, LoadedTemplateDao loadedTemplateDao) { - this(new DashboardTemplate[]{}, dashboardDao, activeDashboardDao, loadedTemplateDao); + public RegisterNewDashboards(DashboardDao dashboardDao, ActiveDashboardDao activeDashboardDao, LoadedTemplateDao loadedTemplateDao, RegisterNewFilters registerNewFilters) { + this(new DashboardTemplate[] {}, dashboardDao, activeDashboardDao, loadedTemplateDao, registerNewFilters); } public RegisterNewDashboards(DashboardTemplate[] dashboardTemplatesArray, DashboardDao dashboardDao, - ActiveDashboardDao activeDashboardDao, LoadedTemplateDao loadedTemplateDao) { + ActiveDashboardDao activeDashboardDao, LoadedTemplateDao loadedTemplateDao, + RegisterNewFilters registerNewFilters) { this.dashboardTemplates = Lists.newArrayList(dashboardTemplatesArray); this.dashboardDao = dashboardDao; this.activeDashboardDao = activeDashboardDao; this.loadedTemplateDao = loadedTemplateDao; + this.registerNewFilters = registerNewFilters; } public void start() { 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 cbc29fc4c52..32026da5528 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 @@ -19,7 +19,17 @@ */ package org.sonar.server.startup; -import org.sonar.core.filter.CriteriaDto; +import com.google.common.primitives.Longs; + +import com.google.common.primitives.Ints; + +import org.sonar.api.web.FilterColumn; + +import org.sonar.core.filter.FilterColumnDto; + +import org.sonar.api.web.Criterion; + +import org.sonar.core.filter.CriterionDto; import com.google.common.collect.ImmutableList; import org.slf4j.Logger; @@ -87,13 +97,14 @@ public final class RegisterNewFilters { private static void addCriteria(FilterDto filterDto, String family, String operator, String textValue) { if (textValue != null) { - filterDto.addCriteria(new CriteriaDto().setFamily(family).setOperator(operator).setTextValue(textValue)); + filterDto.add(new CriterionDto().setFamily(family).setOperator(operator).setTextValue(textValue)); } } protected FilterDto createDtoFromExtension(String name, Filter filter) { FilterDto filterDto = new FilterDto() .setName(name) + .setPageSize((long) filter.getPageSize()) .setShared(filter.isShared()) .setFavourites(filter.isFavouritesOnly()) .setDefaultView(filter.getDefaultPeriod()); @@ -102,6 +113,25 @@ public final class RegisterNewFilters { addCriteria(filterDto, "name", "=", filter.getResourceNameLike()); addCriteria(filterDto, "language", "=", filter.getLanguage()); addCriteria(filterDto, "qualifier", "=", filter.getSearchFor()); + + for (Criterion criterion : filter.getCriteria()) { + filterDto.add(new CriterionDto() + .setFamily(criterion.getFamily()) + .setKey(criterion.getKey()) + .setOperator(criterion.getOperator()) + .setTextValue(criterion.getTextValue()) + .setValue(criterion.getValue()) + .setVariation(criterion.isVariation())); + } + + for (FilterColumn column : filter.getColumns()) { + filterDto.add(new FilterColumnDto() + .setFamily(column.getFamily()) + .setKey(column.getKey()) + .setOrderIndex(column.getOrderIndex()) + .setSortDirection(column.getSortDirection()) + .setVariation(column.isVariation())); + } return filterDto; } diff --git a/sonar-server/src/test/java/org/sonar/server/startup/RegisterNewDashboardsTest.java b/sonar-server/src/test/java/org/sonar/server/startup/RegisterNewDashboardsTest.java index d64f29acba1..e74119c6817 100644 --- a/sonar-server/src/test/java/org/sonar/server/startup/RegisterNewDashboardsTest.java +++ b/sonar-server/src/test/java/org/sonar/server/startup/RegisterNewDashboardsTest.java @@ -59,7 +59,7 @@ public class RegisterNewDashboardsTest { fakeDashboardTemplate = new FakeDashboard(); task = new RegisterNewDashboards(new DashboardTemplate[]{fakeDashboardTemplate}, dashboardDao, - activeDashboardDao, loadedTemplateDao); + activeDashboardDao, loadedTemplateDao, null); } @Test 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 14af9023c51..1017a42f247 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 @@ -19,12 +19,18 @@ */ package org.sonar.server.startup; +import org.sonar.core.filter.FilterColumnDto; + +import org.sonar.api.web.FilterColumn; + +import org.sonar.api.web.Criterion; + import com.google.common.collect.Iterables; import org.junit.Before; import org.junit.Test; import org.sonar.api.web.Filter; import org.sonar.api.web.FilterTemplate; -import org.sonar.core.filter.CriteriaDto; +import org.sonar.core.filter.CriterionDto; import org.sonar.core.filter.FilterDao; import org.sonar.core.filter.FilterDto; import org.sonar.core.template.LoadedTemplateDao; @@ -117,24 +123,32 @@ public class RegisterNewFiltersTest { .setResourceNameLike("*NAME*") .setLanguage("java") .setSearchFor("TRK,BRC") + .setPageSize(200) + .add(Criterion.create().setFamily("metric").setKey("complexity").setOperator("<").setValue(12f)) + .add(FilterColumn.create().setFamily("metric").setKey("distance").setOrderIndex(1L).setSortDirection("ASC")) ); FilterDto dto = register.createDtoFromExtension("Fake", filterTemplate.createFilter()); - CriteriaDto criteriaResourceKeyDto = Iterables.get(dto.getCriterias(), 0); - CriteriaDto criteriaResourceNameDto = Iterables.get(dto.getCriterias(), 1); - CriteriaDto criteriaLangageDto = Iterables.get(dto.getCriterias(), 2); - CriteriaDto criteriaSearchForDto = Iterables.get(dto.getCriterias(), 3); + CriterionDto criteriaResourceKeyDto = Iterables.get(dto.getCriteria(), 0); + CriterionDto criteriaResourceNameDto = Iterables.get(dto.getCriteria(), 1); + CriterionDto criteriaLangageDto = Iterables.get(dto.getCriteria(), 2); + CriterionDto criteriaSearchForDto = Iterables.get(dto.getCriteria(), 3); assertThat(dto.getUserId()).isNull(); assertThat(dto.getName()).isEqualTo("Fake"); assertThat(dto.isShared()).isTrue(); assertThat(dto.isFavourites()).isFalse(); assertThat(dto.getDefaultView()).isEqualTo("list"); + assertThat(dto.getPageSize()).isEqualTo(200L); + + assertThat(dto.getCriteria()).hasSize(5); + assertThat(dto.getCriteria()).satisfies(contains(new CriterionDto().setFamily("key").setOperator("=").setTextValue("*KEY*"))); + assertThat(dto.getCriteria()).satisfies(contains(new CriterionDto().setFamily("name").setOperator("=").setTextValue("*NAME*"))); + assertThat(dto.getCriteria()).satisfies(contains(new CriterionDto().setFamily("language").setOperator("=").setTextValue("java"))); + assertThat(dto.getCriteria()).satisfies(contains(new CriterionDto().setFamily("qualifier").setOperator("=").setTextValue("TRK,BRC"))); + assertThat(dto.getCriteria()).satisfies(contains(new CriterionDto().setFamily("metric").setKey("complexity").setOperator("<").setValue(12f).setVariation(false))); - assertThat(dto.getCriterias()).hasSize(4); - assertThat(dto.getCriterias()).satisfies(contains(new CriteriaDto().setFamily("key").setOperator("=").setTextValue("*KEY*"))); - assertThat(dto.getCriterias()).satisfies(contains(new CriteriaDto().setFamily("name").setOperator("=").setTextValue("*NAME*"))); - assertThat(dto.getCriterias()).satisfies(contains(new CriteriaDto().setFamily("language").setOperator("=").setTextValue("java"))); - assertThat(dto.getCriterias()).satisfies(contains(new CriteriaDto().setFamily("qualifier").setOperator("=").setTextValue("TRK,BRC"))); + assertThat(dto.getColumns()).hasSize(1); + assertThat(dto.getColumns()).satisfies(contains(new FilterColumnDto().setFamily("metric").setKey("distance").setOrderIndex(1L).setSortDirection("ASC").setVariation(false))); } } -- 2.39.5