+++ /dev/null
-/*
- * 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.core.filter;
-
-/**
- * @since 3.1
- */
-public final class CriteriaDto {
- private Long id;
- private Long filterId;
- private String family;
- private String key;
- private String operator;
- private Float value;
- private String textValue;
- private Boolean variation;
-
- public Long getId() {
- return id;
- }
-
- public CriteriaDto setId(Long id) {
- this.id = id;
- return this;
- }
-
- public Long getFilterId() {
- return filterId;
- }
-
- public CriteriaDto setFilterId(Long filterId) {
- this.filterId = filterId;
- return this;
- }
-
- public String getFamily() {
- return family;
- }
-
- public CriteriaDto setFamily(String family) {
- this.family = family;
- return this;
- }
-
- public String getKey() {
- return key;
- }
-
- public CriteriaDto setKey(String key) {
- this.key = key;
- return this;
- }
-
- public String getOperator() {
- return operator;
- }
-
- public CriteriaDto setOperator(String operator) {
- this.operator = operator;
- return this;
- }
-
- public Float getValue() {
- return value;
- }
-
- public CriteriaDto setValue(Float value) {
- this.value = value;
- return this;
- }
-
- public String getTextValue() {
- return textValue;
- }
-
- public CriteriaDto setTextValue(String textValue) {
- this.textValue = textValue;
- return this;
- }
-
- public Boolean getVariation() {
- return variation;
- }
-
- public CriteriaDto setVariation(Boolean variation) {
- this.variation = variation;
- return this;
- }
-}
+++ /dev/null
-/*
- * 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.core.filter;
-
-/**
- * @since 3.1
- */
-public interface CriteriaMapper {
- void insert(CriteriaDto criteriaDto);
-}
--- /dev/null
+/*
+ * 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.core.filter;
+
+/**
+ * @since 3.1
+ */
+public final class CriterionDto {
+ private Long id;
+ private Long filterId;
+ private String family;
+ private String key;
+ private String operator;
+ private Float value;
+ private String textValue;
+ private Boolean variation;
+
+ public Long getId() {
+ return id;
+ }
+
+ public CriterionDto setId(Long id) {
+ this.id = id;
+ return this;
+ }
+
+ public Long getFilterId() {
+ return filterId;
+ }
+
+ public CriterionDto setFilterId(Long filterId) {
+ this.filterId = filterId;
+ return this;
+ }
+
+ public String getFamily() {
+ return family;
+ }
+
+ public CriterionDto setFamily(String family) {
+ this.family = family;
+ return this;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public CriterionDto setKey(String key) {
+ this.key = key;
+ return this;
+ }
+
+ public String getOperator() {
+ return operator;
+ }
+
+ public CriterionDto setOperator(String operator) {
+ this.operator = operator;
+ return this;
+ }
+
+ public Float getValue() {
+ return value;
+ }
+
+ public CriterionDto setValue(Float value) {
+ this.value = value;
+ return this;
+ }
+
+ public String getTextValue() {
+ return textValue;
+ }
+
+ public CriterionDto setTextValue(String textValue) {
+ this.textValue = textValue;
+ return this;
+ }
+
+ public Boolean getVariation() {
+ return variation;
+ }
+
+ public CriterionDto setVariation(Boolean variation) {
+ this.variation = variation;
+ return this;
+ }
+}
--- /dev/null
+/*
+ * 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.core.filter;
+
+/**
+ * @since 3.1
+ */
+public interface CriterionMapper {
+ void insert(CriterionDto criteriaDto);
+}
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);
}
private String defaultView;
private Long pageSize;
private Long periodIndex;
- private List<CriteriaDto> criteriaDtos = Lists.newArrayList();
- private List<FilterColumnDto> filterColumnDtos = Lists.newArrayList();
+ private List<CriterionDto> criteria = Lists.newArrayList();
+ private List<FilterColumnDto> filterColumns = Lists.newArrayList();
public Long getId() {
return id;
return this;
}
- public Collection<CriteriaDto> getCriterias() {
- return criteriaDtos;
+ public Collection<CriterionDto> getCriteria() {
+ return criteria;
}
- public FilterDto addCriteria(CriteriaDto criteriaDto) {
- criteriaDtos.add(criteriaDto);
+ public FilterDto add(CriterionDto criterion) {
+ criteria.add(criterion);
return this;
}
public Collection<FilterColumnDto> getColumns() {
- return filterColumnDtos;
+ return filterColumns;
}
- public FilterDto addColumn(FilterColumnDto filterColumnDto) {
- filterColumnDtos.add(filterColumnDto);
+ public FilterDto add(FilterColumnDto filterColumn) {
+ filterColumns.add(filterColumn);
return this;
}
}
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;
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);
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);
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-
-<mapper namespace="org.sonar.core.filter.CriteriaMapper">
-
- <insert id="insert" parameterType="Criteria" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
- 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})
- </insert>
-
-</mapper>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-
-<mapper namespace="org.sonar.core.filter.CriteriaMapper">
-
- <insert id="insert" parameterType="Criteria" useGeneratedKeys="true" keyProperty="id">
- 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})
- </insert>
-
-</mapper>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="org.sonar.core.filter.CriterionMapper">
+
+ <insert id="insert" parameterType="Criterion" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
+ 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})
+ </insert>
+
+</mapper>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="org.sonar.core.filter.CriterionMapper">
+
+ <insert id="insert" parameterType="Criterion" useGeneratedKeys="true" keyProperty="id">
+ 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})
+ </insert>
+
+</mapper>
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;
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");
filterColumnDto.setSortDirection("ASC");
filterColumnDto.setOrderIndex(2L);
filterColumnDto.setVariation(true);
- filterDto.addColumn(filterColumnDto);
+ filterDto.add(filterColumnDto);
dao.insert(filterDto);
--- /dev/null
+/*
+ * 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<String> 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;
+ }
+}
*/
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.
- * <p/>
- * Its name can be retrieved using the i18n mechanism, using the keys "dashboard.<id>.name".
+ *
+ * <p>Its name can be retrieved using the i18n mechanism, using the keys "filter.<id>.name".</p>
*
* @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;
private String resourceNameLike;
private String language;
private String searchFor;
+ private int pageSize;
+ private List<Criterion> criteria;
+ private List<FilterColumn> columns;
private Filter() {
- // The factory method should be used
+ criteria = Lists.newArrayList();
+ columns = Lists.newArrayList();
}
/**
return new Filter();
}
+ public List<Criterion> getCriteria() {
+ return criteria;
+ }
+
+ public Filter add(Criterion criterion) {
+ this.criteria.add(criterion);
+ return this;
+ }
+
+ public List<FilterColumn> getColumns() {
+ return columns;
+ }
+
+ public Filter add(FilterColumn column) {
+ this.columns.add(column);
+ return this;
+ }
+
public boolean isShared() {
return shared;
}
}
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;
}
this.searchFor = searchFor;
return this;
}
+
+ public int getPageSize() {
+ return pageSize;
+ }
+
+ public Filter setPageSize(int pageSize) {
+ this.pageSize = pageSize;
+ return this;
+ }
}
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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("<>");
+ }
+}
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() {
*/
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;
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());
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;
}
fakeDashboardTemplate = new FakeDashboard();
task = new RegisterNewDashboards(new DashboardTemplate[]{fakeDashboardTemplate}, dashboardDao,
- activeDashboardDao, loadedTemplateDao);
+ activeDashboardDao, loadedTemplateDao, null);
}
@Test
*/
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;
.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)));
}
}