aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Schwarz <daniel.schwarz@sonarsource.com>2017-10-20 15:02:46 +0200
committerDaniel Schwarz <bartfastiel@users.noreply.github.com>2017-10-24 17:40:56 +0200
commit0670c244e9e2d38a63263beaf11316708af6c6d3 (patch)
treed0025791e4b206ab3ae363a6b478549cd22926a8
parent60b4ef64ff2668e808081457d4a80bac06679ba8 (diff)
downloadsonarqube-0670c244e9e2d38a63263beaf11316708af6c6d3.tar.gz
sonarqube-0670c244e9e2d38a63263beaf11316708af6c6d3.zip
SONAR-10008 Issue search: return days as keys of creation date buckets
In the createdAt facet of api/issues/search
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/es/Facets.java7
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexDebtTest.java10
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java76
3 files changed, 48 insertions, 45 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/es/Facets.java b/server/sonar-server/src/main/java/org/sonar/server/es/Facets.java
index c45c4fd9fcf..574ceb158e7 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/es/Facets.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/es/Facets.java
@@ -38,6 +38,8 @@ import org.elasticsearch.search.aggregations.bucket.missing.Missing;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.metrics.sum.Sum;
+import static org.sonar.api.utils.DateUtils.formatDate;
+import static org.sonar.api.utils.DateUtils.parseDateTime;
import static org.sonarqube.ws.client.issue.IssuesWsParameters.FACET_MODE_EFFORT;
public class Facets {
@@ -128,10 +130,11 @@ public class Facets {
private void processDateHistogram(Histogram aggregation) {
LinkedHashMap<String, Long> facet = getOrCreateFacet(aggregation.getName());
for (Histogram.Bucket value : aggregation.getBuckets()) {
+ String day = formatDate(parseDateTime(value.getKeyAsString()));
if (value.getAggregations().getAsMap().containsKey(FACET_MODE_EFFORT)) {
- facet.put(value.getKeyAsString(), Math.round(((Sum) value.getAggregations().get(FACET_MODE_EFFORT)).getValue()));
+ facet.put(day, Math.round(((Sum) value.getAggregations().get(FACET_MODE_EFFORT)).getValue()));
} else {
- facet.put(value.getKeyAsString(), value.getDocCount());
+ facet.put(day, value.getDocCount());
}
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexDebtTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexDebtTest.java
index 71f737ce3c3..2e13410c33b 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexDebtTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexDebtTest.java
@@ -240,11 +240,11 @@ public class IssueIndexDebtTest {
Builder query = newQueryBuilder().createdBefore(DateUtils.parseDateTime("2016-01-01T00:00:00+0100"));
Map<String, Long> createdAt = new Facets(underTest.search(query.build(), searchOptions)).get("createdAt");
assertThat(createdAt).containsOnly(
- entry("2011-01-01T00:00:00+0000", 10L),
- entry("2012-01-01T00:00:00+0000", 0L),
- entry("2013-01-01T00:00:00+0000", 0L),
- entry("2014-01-01T00:00:00+0000", 50L),
- entry("2015-01-01T00:00:00+0000", 10L));
+ entry("2011-01-01", 10L),
+ entry("2012-01-01", 0L),
+ entry("2013-01-01", 0L),
+ entry("2014-01-01", 50L),
+ entry("2015-01-01", 10L));
}
@Test
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java
index 18acde0f685..acc20812f26 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java
@@ -787,14 +787,14 @@ public class IssueIndexTest {
SearchResponse result = underTest.search(query, options);
Map<String, Long> buckets = new Facets(result).get("createdAt");
assertThat(buckets).containsOnly(
- entry("2014-08-31T00:00:00-0100", 0L),
- entry("2014-09-01T00:00:00-0100", 2L),
- entry("2014-09-02T00:00:00-0100", 1L),
- entry("2014-09-03T00:00:00-0100", 0L),
- entry("2014-09-04T00:00:00-0100", 0L),
- entry("2014-09-05T00:00:00-0100", 1L),
- entry("2014-09-06T00:00:00-0100", 0L),
- entry("2014-09-07T00:00:00-0100", 0L));
+ entry("2014-08-31", 0L),
+ entry("2014-09-01", 2L),
+ entry("2014-09-02", 1L),
+ entry("2014-09-03", 0L),
+ entry("2014-09-04", 0L),
+ entry("2014-09-05", 1L),
+ entry("2014-09-06", 0L),
+ entry("2014-09-07", 0L));
}
@Test
@@ -807,10 +807,10 @@ public class IssueIndexTest {
options);
Map<String, Long> createdAt = new Facets(result).get("createdAt");
assertThat(createdAt).containsOnly(
- entry("2014-08-25T00:00:00-0100", 0L),
- entry("2014-09-01T00:00:00-0100", 4L),
- entry("2014-09-08T00:00:00-0100", 0L),
- entry("2014-09-15T00:00:00-0100", 1L));
+ entry("2014-08-25", 0L),
+ entry("2014-09-01", 4L),
+ entry("2014-09-08", 0L),
+ entry("2014-09-15", 1L));
}
@Test
@@ -823,12 +823,12 @@ public class IssueIndexTest {
options);
Map<String, Long> createdAt = new Facets(result).get("createdAt");
assertThat(createdAt).containsOnly(
- entry("2014-08-01T00:00:00-0100", 0L),
- entry("2014-09-01T00:00:00-0100", 5L),
- entry("2014-10-01T00:00:00-0100", 0L),
- entry("2014-11-01T00:00:00-0100", 0L),
- entry("2014-12-01T00:00:00-0100", 0L),
- entry("2015-01-01T00:00:00-0100", 1L));
+ entry("2014-08-01", 0L),
+ entry("2014-09-01", 5L),
+ entry("2014-10-01", 0L),
+ entry("2014-11-01", 0L),
+ entry("2014-12-01", 0L),
+ entry("2015-01-01", 1L));
}
@Test
@@ -841,12 +841,12 @@ public class IssueIndexTest {
options);
Map<String, Long> createdAt = new Facets(result).get("createdAt");
assertThat(createdAt).containsOnly(
- entry("2010-01-01T00:00:00-0100", 0L),
- entry("2011-01-01T00:00:00-0100", 1L),
- entry("2012-01-01T00:00:00-0100", 0L),
- entry("2013-01-01T00:00:00-0100", 0L),
- entry("2014-01-01T00:00:00-0100", 5L),
- entry("2015-01-01T00:00:00-0100", 1L));
+ entry("2010-01-01", 0L),
+ entry("2011-01-01", 1L),
+ entry("2012-01-01", 0L),
+ entry("2013-01-01", 0L),
+ entry("2014-01-01", 5L),
+ entry("2015-01-01", 1L));
}
@Test
@@ -859,7 +859,7 @@ public class IssueIndexTest {
options);
Map<String, Long> createdAt = new Facets(result).get("createdAt");
assertThat(createdAt).containsOnly(
- entry("2014-09-01T00:00:00-0100", 2L));
+ entry("2014-09-01", 2L));
}
@Test
@@ -872,14 +872,14 @@ public class IssueIndexTest {
.build(), options);
Map<String, Long> createdAt = new Facets(result).get("createdAt");
assertThat(createdAt).containsOnly(
- entry("2008-01-01T00:00:00-0100", 0L),
- entry("2009-01-01T00:00:00-0100", 0L),
- entry("2010-01-01T00:00:00-0100", 0L),
- entry("2011-01-01T00:00:00-0100", 1L),
- entry("2012-01-01T00:00:00-0100", 0L),
- entry("2013-01-01T00:00:00-0100", 0L),
- entry("2014-01-01T00:00:00-0100", 5L),
- entry("2015-01-01T00:00:00-0100", 1L));
+ entry("2008-01-01", 0L),
+ entry("2009-01-01", 0L),
+ entry("2010-01-01", 0L),
+ entry("2011-01-01", 1L),
+ entry("2012-01-01", 0L),
+ entry("2013-01-01", 0L),
+ entry("2014-01-01", 5L),
+ entry("2015-01-01", 1L));
}
@Test
@@ -891,11 +891,11 @@ public class IssueIndexTest {
searchOptions);
Map<String, Long> createdAt = new Facets(result).get("createdAt");
assertThat(createdAt).containsOnly(
- entry("2011-01-01T00:00:00-0100", 1L),
- entry("2012-01-01T00:00:00-0100", 0L),
- entry("2013-01-01T00:00:00-0100", 0L),
- entry("2014-01-01T00:00:00-0100", 5L),
- entry("2015-01-01T00:00:00-0100", 1L));
+ entry("2011-01-01", 1L),
+ entry("2012-01-01", 0L),
+ entry("2013-01-01", 0L),
+ entry("2014-01-01", 5L),
+ entry("2015-01-01", 1L));
}
@Test