]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10008 Issue search: return days as keys of creation date buckets
authorDaniel Schwarz <daniel.schwarz@sonarsource.com>
Fri, 20 Oct 2017 13:02:46 +0000 (15:02 +0200)
committerDaniel Schwarz <bartfastiel@users.noreply.github.com>
Tue, 24 Oct 2017 15:40:56 +0000 (17:40 +0200)
In the createdAt facet of api/issues/search

server/sonar-server/src/main/java/org/sonar/server/es/Facets.java
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexDebtTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java

index c45c4fd9fcf389998877a5cac7a09f7c89ad5ff5..574ceb158e7766a056144de0607f355c8c2651a0 100644 (file)
@@ -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());
       }
     }
   }
index 71f737ce3c32c16b76eaf01b7a04a69eebb342b1..2e13410c33b489219095a136a227f020f15c8edc 100644 (file)
@@ -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
index 18acde0f685074c91cd45b0498892b48e42df291..acc20812f26f58d98004da490e607af75fc13df7 100644 (file)
@@ -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