]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3016 More work on extension point for filter template
authorDavid Gageot <david@gageot.net>
Tue, 22 May 2012 12:52:24 +0000 (14:52 +0200)
committerDavid Gageot <david@gageot.net>
Tue, 22 May 2012 12:52:24 +0000 (14:52 +0200)
Introduce Criteria and FilterColums

20 files changed:
sonar-core/src/main/java/org/sonar/core/filter/CriteriaDto.java [deleted file]
sonar-core/src/main/java/org/sonar/core/filter/CriteriaMapper.java [deleted file]
sonar-core/src/main/java/org/sonar/core/filter/CriterionDto.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/filter/CriterionMapper.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/filter/FilterDao.java
sonar-core/src/main/java/org/sonar/core/filter/FilterDto.java
sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java
sonar-core/src/main/resources/org/sonar/core/filter/CriteriaMapper-oracle.xml [deleted file]
sonar-core/src/main/resources/org/sonar/core/filter/CriteriaMapper.xml [deleted file]
sonar-core/src/main/resources/org/sonar/core/filter/CriterionMapper-oracle.xml [new file with mode: 0644]
sonar-core/src/main/resources/org/sonar/core/filter/CriterionMapper.xml [new file with mode: 0644]
sonar-core/src/test/java/org/sonar/core/filters/FilterDaoTest.java
sonar-plugin-api/src/main/java/org/sonar/api/web/Criterion.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/web/Filter.java
sonar-plugin-api/src/main/java/org/sonar/api/web/FilterColumn.java [new file with mode: 0644]
sonar-plugin-api/src/test/java/org/sonar/api/web/CriterionTest.java [new file with mode: 0644]
sonar-server/src/main/java/org/sonar/server/startup/RegisterNewDashboards.java
sonar-server/src/main/java/org/sonar/server/startup/RegisterNewFilters.java
sonar-server/src/test/java/org/sonar/server/startup/RegisterNewDashboardsTest.java
sonar-server/src/test/java/org/sonar/server/startup/RegisterNewFiltersTest.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/CriteriaDto.java
deleted file mode 100644 (file)
index 4d9aaa0..0000000
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * 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;
-  }
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/filter/CriteriaMapper.java b/sonar-core/src/main/java/org/sonar/core/filter/CriteriaMapper.java
deleted file mode 100644 (file)
index 9d21cd6..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * 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);
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/filter/CriterionDto.java b/sonar-core/src/main/java/org/sonar/core/filter/CriterionDto.java
new file mode 100644 (file)
index 0000000..02fc0d0
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * 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;
+  }
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/filter/CriterionMapper.java b/sonar-core/src/main/java/org/sonar/core/filter/CriterionMapper.java
new file mode 100644 (file)
index 0000000..f933c6f
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * 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);
+}
index 809d91315b1d93931c230c284bdf184e7fa7cdfc..8521bf4e48f9f227dc4e29fb1e85d068de810768 100644 (file)
@@ -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);
       }
index f37abd80254f63869d2138da9ac2a84bf36b4bd3..91dccf33381de34316e3733419908fd5aea90a88 100644 (file)
@@ -37,8 +37,8 @@ public final class FilterDto {
   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;
@@ -121,21 +121,21 @@ public final class FilterDto {
     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;
   }
 }
index 7847470ddf3b7ef71b4de663b5248d49bdbcbf6e..5901695c53e00efecda9b4fd85b9f1088ce86bba 100644 (file)
@@ -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/CriteriaMapper-oracle.xml
deleted file mode 100644 (file)
index 257e54e..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-<?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>
diff --git a/sonar-core/src/main/resources/org/sonar/core/filter/CriteriaMapper.xml b/sonar-core/src/main/resources/org/sonar/core/filter/CriteriaMapper.xml
deleted file mode 100644 (file)
index 1201f28..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-<?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>
diff --git a/sonar-core/src/main/resources/org/sonar/core/filter/CriterionMapper-oracle.xml b/sonar-core/src/main/resources/org/sonar/core/filter/CriterionMapper-oracle.xml
new file mode 100644 (file)
index 0000000..5c9d27a
--- /dev/null
@@ -0,0 +1,12 @@
+<?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>
diff --git a/sonar-core/src/main/resources/org/sonar/core/filter/CriterionMapper.xml b/sonar-core/src/main/resources/org/sonar/core/filter/CriterionMapper.xml
new file mode 100644 (file)
index 0000000..09c4769
--- /dev/null
@@ -0,0 +1,12 @@
+<?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>
index 14460634ef593b79b126a4c82413ef316d1459b5..01fc26a9c29f42f2402576904dd3894873d158d7 100644 (file)
@@ -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 (file)
index 0000000..7142c74
--- /dev/null
@@ -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<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;
+  }
+}
index e906d07faf057645044833f8921395ab233673aa..e1638ed985d6ba4de39fab1f9f9788341e97aefd 100644 (file)
  */
 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.&lt;id&gt;.name".
+ *
+ * <p>Its name can be retrieved using the i18n mechanism, using the keys "filter.&lt;id&gt;.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;
@@ -39,9 +43,13 @@ public class Filter {
   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();
   }
 
   /**
@@ -51,6 +59,24 @@ public class Filter {
     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;
   }
@@ -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 (file)
index 0000000..09c266e
--- /dev/null
@@ -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 (file)
index 0000000..1526d4f
--- /dev/null
@@ -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("<>");
+  }
+}
index db2fa9fc067c4bf647f3461a8afc6883a219e564..ff270e667191e4524e7a5e5ec4cb04f66e38e5d4 100644 (file)
@@ -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() {
index cbc29fc4c52a660ea784689889bbfcca295b8328..32026da5528d4ff6fece88294880e297d38adbef 100644 (file)
  */
 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;
   }
index d64f29acba19bae50577d75c0ab50c9d83fe4143..e74119c681715f5d0f50e89ffe5c73b5dd82ed44 100644 (file)
@@ -59,7 +59,7 @@ public class RegisterNewDashboardsTest {
     fakeDashboardTemplate = new FakeDashboard();
 
     task = new RegisterNewDashboards(new DashboardTemplate[]{fakeDashboardTemplate}, dashboardDao,
-      activeDashboardDao, loadedTemplateDao);
+        activeDashboardDao, loadedTemplateDao, null);
   }
 
   @Test
index 14af9023c5147469f3ae9e803163ced465509e1b..1017a42f247210ee4be38d4073e62bc9eec75f76 100644 (file)
  */
 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)));
   }
 }