aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-11-24 17:17:54 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2012-11-26 13:54:16 +0100
commitea13e4fddb1a70c36d0c6b641825cb8289aba50b (patch)
tree7b1afc3148c33181d7e92c2cd76414b39e3c1f39 /sonar-core
parent5c920f1d8e47f3c61f951fecf3e1fa6e31a1892a (diff)
downloadsonarqube-ea13e4fddb1a70c36d0c6b641825cb8289aba50b.tar.gz
sonarqube-ea13e4fddb1a70c36d0c6b641825cb8289aba50b.zip
SONAR-3825 manage my filters
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/measure/MeasureFilter.java2
-rw-r--r--sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterEngine.java2
-rw-r--r--sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterFactory.java45
-rw-r--r--sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterSort.java8
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl2
5 files changed, 39 insertions, 20 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilter.java b/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilter.java
index be5b8966ad5..5c4d247a6d6 100644
--- a/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilter.java
+++ b/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilter.java
@@ -190,6 +190,6 @@ public class MeasureFilter {
@Override
public String toString() {
- return ReflectionToStringBuilder.toString(this, ToStringStyle.SIMPLE_STYLE);
+ return ReflectionToStringBuilder.toString(this);
}
}
diff --git a/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterEngine.java b/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterEngine.java
index 80c3627e881..a161e7e9d45 100644
--- a/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterEngine.java
+++ b/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterEngine.java
@@ -54,11 +54,11 @@ public class MeasureFilterEngine implements ServerComponent {
public List<MeasureFilterRow> execute2(Map<String, Object> filterMap, @Nullable Long userId) throws ParseException {
Logger logger = FILTER_LOG;
MeasureFilterContext context = new MeasureFilterContext();
- context.setJson(Joiner.on("|").withKeyValueSeparator("=").join(filterMap));
context.setUserId(userId);
try {
long start = System.currentTimeMillis();
MeasureFilter filter = factory.create(filterMap);
+ context.setJson(filter.toString());
List<MeasureFilterRow> rows = executor.execute(filter, context);
log(context, rows, (System.currentTimeMillis() - start), logger);
return rows;
diff --git a/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterFactory.java b/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterFactory.java
index 8908226fc30..761f8d5c121 100644
--- a/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterFactory.java
+++ b/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterFactory.java
@@ -26,6 +26,7 @@ import org.sonar.api.utils.DateUtils;
import javax.annotation.Nullable;
+import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
@@ -41,33 +42,33 @@ public class MeasureFilterFactory implements ServerComponent {
public MeasureFilter create(Map<String, Object> properties) {
MeasureFilter filter = new MeasureFilter();
- filter.setBaseResourceKey((String)properties.get("base"));
- filter.setResourceScopes((List<String>)properties.get("scopes"));
- filter.setResourceQualifiers((List<String>)(properties.get("qualifiers")));
- filter.setResourceLanguages((List<String>)(properties.get("languages")));
- if (properties.containsKey("onBaseChildren")) {
- filter.setOnBaseResourceChildren(Boolean.valueOf((String)properties.get("onBaseChildren")));
+ filter.setBaseResourceKey((String) properties.get("base"));
+ filter.setResourceScopes(toList(properties.get("scopes")));
+ filter.setResourceQualifiers(toList(properties.get("qualifiers")));
+ filter.setResourceLanguages(toList(properties.get("languages")));
+ if (properties.containsKey("onBaseComponents")) {
+ filter.setOnBaseResourceChildren(Boolean.valueOf((String) properties.get("onBaseComponents")));
}
- filter.setResourceName((String)properties.get("nameRegexp"));
- filter.setResourceKeyRegexp((String)properties.get("keyRegexp"));
+ filter.setResourceName((String) properties.get("nameRegexp"));
+ filter.setResourceKeyRegexp((String) properties.get("keyRegexp"));
if (properties.containsKey("fromDate")) {
- filter.setFromDate(toDate((String)properties.get("fromDate")));
+ filter.setFromDate(toDate((String) properties.get("fromDate")));
} else if (properties.containsKey("afterDays")) {
- filter.setFromDate(toDays((String)properties.get("afterDays")));
+ filter.setFromDate(toDays((String) properties.get("afterDays")));
}
if (properties.containsKey("toDate")) {
- filter.setToDate(toDate((String)properties.get("toDate")));
+ filter.setToDate(toDate((String) properties.get("toDate")));
} else if (properties.containsKey("beforeDays")) {
- filter.setToDate(toDays((String)properties.get("beforeDays")));
+ filter.setToDate(toDays((String) properties.get("beforeDays")));
}
- if (properties.containsKey("favourites")) {
- filter.setUserFavourites(Boolean.valueOf((String)properties.get("favourites")));
+ if (properties.containsKey("onFavourites")) {
+ filter.setUserFavourites(Boolean.valueOf((String) properties.get("onFavourites")));
}
if (properties.containsKey("asc")) {
- filter.setSortAsc(Boolean.valueOf((String)properties.get("asc")));
+ filter.setSortAsc(Boolean.valueOf((String) properties.get("asc")));
}
- String s = (String)properties.get("sort");
+ String s = (String) properties.get("sort");
if (s != null) {
if (StringUtils.startsWith(s, "metric:")) {
filter.setSortOnMetric(metricFinder.findByKey(StringUtils.substringAfter(s, "metric:")));
@@ -81,6 +82,18 @@ public class MeasureFilterFactory implements ServerComponent {
return filter;
}
+ private List<String> toList(@Nullable Object obj) {
+ List<String> result = null;
+ if (obj != null) {
+ if (obj instanceof String) {
+ result = Arrays.asList((String)obj);
+ } else {
+ result = (List<String>)obj;
+ }
+ }
+ return result;
+ }
+
private static Date toDate(@Nullable String date) {
if (date != null) {
return DateUtils.parseDate(date);
diff --git a/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterSort.java b/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterSort.java
index 3eae1162992..b29e11b549f 100644
--- a/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterSort.java
+++ b/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterSort.java
@@ -23,7 +23,7 @@ import org.sonar.api.measures.Metric;
class MeasureFilterSort {
public static enum Field {
- KEY, NAME, VERSION, LANGUAGE, DATE, METRIC
+ KEY, NAME, VERSION, LANGUAGE, DATE, METRIC, SHORT_NAME, DESCRIPTION
}
private Field field = Field.NAME;
@@ -85,6 +85,12 @@ class MeasureFilterSort {
case NAME:
column = "p.long_name";
break;
+ case SHORT_NAME:
+ column = "p.name";
+ break;
+ case DESCRIPTION:
+ column = "p.description";
+ break;
case VERSION:
column = "s.version";
break;
diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl
index e67a2a9ef63..98e7e586b04 100644
--- a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl
+++ b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl
@@ -517,7 +517,7 @@ CREATE TABLE "SEMAPHORES" (
CREATE TABLE "MEASURE_FILTERS" (
"ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
"NAME" VARCHAR(100) NOT NULL,
- "SHARED" BOOLEAN NOT NULL,
+ "SHARED" BOOLEAN NOT NULL DEFAULT FALSE,
"USER_ID" INTEGER,
"DESCRIPTION" VARCHAR(4000),
"DATA" CLOB(2147483647),