]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6137 Publish createdAt facet in WS API
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Tue, 3 Feb 2015 15:12:47 +0000 (16:12 +0100)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Wed, 4 Feb 2015 14:14:29 +0000 (15:14 +0100)
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java
server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchAction.java
server/sonar-server/src/main/java/org/sonar/server/search/Result.java

index 0710cf444f3a17ac1378132278ee72c5a77c1101..6e1e7cbc0fdb0e14be8d65e90cdf2ca06681ec20 100644 (file)
@@ -556,8 +556,10 @@ public class IssueIndex extends BaseIndex<Issue, FakeIssueDto, String> {
     String timeZoneString = tzFormat.format(now);
 
     Interval bucketSize = Interval.YEAR;
-    long startTime = query.createdAfter() == null ? getMinCreatedAt(filters, esQuery) : query.createdAfter().getTime();
-    long endTime = query.createdBefore() == null ? now.getTime() : query.createdBefore().getTime();
+    Date createdAfter = query.createdAfter();
+    long startTime = createdAfter == null ? getMinCreatedAt(filters, esQuery) : createdAfter.getTime();
+    Date createdBefore = query.createdBefore();
+    long endTime = createdBefore == null ? now.getTime() : createdBefore.getTime();
     Duration timeSpan = new Duration(startTime, endTime);
     if (timeSpan.isShorterThan(TWENTY_DAYS)) {
       bucketSize = Interval.DAY;
@@ -586,7 +588,7 @@ public class IssueIndex extends BaseIndex<Issue, FakeIssueDto, String> {
     setQueryFilter(minCount, esQuery, filters);
     minCount.addAggregation(AggregationBuilders.min(facetNameAndField).field(facetNameAndField));
     Min minValue = minCount.get().getAggregations().get(facetNameAndField);
-    return Double.valueOf(minValue.getValue()).longValue();
+    return (long) minValue.getValue();
   }
 
   private void setSorting(IssueQuery query, SearchRequestBuilder esRequest) {
index 287313e846f4504d7cef247ea5ca23b4a412a4ae..6960a88c93e0591cb568a4a1fe30515728731a7a 100644 (file)
@@ -297,6 +297,7 @@ public class SearchAction extends SearchRequestHandler<IssueQuery, Issue> {
       IssueFilterParameters.DIRECTORIES,
       IssueFilterParameters.LANGUAGES,
       IssueFilterParameters.TAGS,
+      IssueFilterParameters.CREATED_AT,
     });
   }
 
index f57a1c21221607a96c2feb20c5fbac1bd82fe8dd..a35fab832a1314be45848a2b17fdc40774865a59 100644 (file)
@@ -72,36 +72,52 @@ public class Result<K> {
 
   private void processAggregation(Aggregation aggregation) {
     if (Missing.class.isAssignableFrom(aggregation.getClass())) {
-      Missing missing = (Missing) aggregation;
-      long docCount = missing.getDocCount();
-      if (docCount > 0L) {
-        this.facets.put(aggregation.getName().replace("_missing",""), new FacetValue("", docCount));
-      }
+      processMissingAggregation(aggregation);
     } else if (Terms.class.isAssignableFrom(aggregation.getClass())) {
-      Terms termAggregation = (Terms) aggregation;
-      for (Terms.Bucket value : termAggregation.getBuckets()) {
-        String facetName = aggregation.getName();
-        if (facetName.contains("__") && !facetName.startsWith("__")) {
-          facetName = facetName.substring(0, facetName.indexOf("__"));
-        }
-        facetName = facetName.replace("_selected", "");
-        this.facets.put(facetName, new FacetValue(value.getKey(), value.getDocCount()));
-      }
+      processTermsAggregation(aggregation);
     } else if (HasAggregations.class.isAssignableFrom(aggregation.getClass())) {
-      HasAggregations hasAggregations = (HasAggregations) aggregation;
-      for (Aggregation internalAggregation : hasAggregations.getAggregations()) {
-        this.processAggregation(internalAggregation);
-      }
+      processSubAggregations(aggregation);
     } else if (DateHistogram.class.isAssignableFrom(aggregation.getClass())) {
-      DateHistogram dateHistogram = (DateHistogram) aggregation;
-      for (DateHistogram.Bucket value : dateHistogram.getBuckets()) {
-        this.facets.put(dateHistogram.getName(), new FacetValue(value.getKeyAsText().toString(), value.getDocCount()));
-      }
+      processDateHistogram(aggregation);
     } else {
       LOGGER.warn("Cannot process {} type of aggregation", aggregation.getClass());
     }
   }
 
+  private void processMissingAggregation(Aggregation aggregation) {
+    Missing missing = (Missing) aggregation;
+    long docCount = missing.getDocCount();
+    if (docCount > 0L) {
+      this.facets.put(aggregation.getName().replace("_missing",""), new FacetValue("", docCount));
+    }
+  }
+
+  private void processTermsAggregation(Aggregation aggregation) {
+    Terms termAggregation = (Terms) aggregation;
+    for (Terms.Bucket value : termAggregation.getBuckets()) {
+      String facetName = aggregation.getName();
+      if (facetName.contains("__") && !facetName.startsWith("__")) {
+        facetName = facetName.substring(0, facetName.indexOf("__"));
+      }
+      facetName = facetName.replace("_selected", "");
+      this.facets.put(facetName, new FacetValue(value.getKey(), value.getDocCount()));
+    }
+  }
+
+  private void processSubAggregations(Aggregation aggregation) {
+    HasAggregations hasAggregations = (HasAggregations) aggregation;
+    for (Aggregation internalAggregation : hasAggregations.getAggregations()) {
+      this.processAggregation(internalAggregation);
+    }
+  }
+
+  private void processDateHistogram(Aggregation aggregation) {
+    DateHistogram dateHistogram = (DateHistogram) aggregation;
+    for (DateHistogram.Bucket value : dateHistogram.getBuckets()) {
+      this.facets.put(dateHistogram.getName(), new FacetValue(value.getKeyAsText().toString(), value.getDocCount()));
+    }
+  }
+
   public Iterator<K> scroll() {
     Preconditions.checkState(scrollId != null, "Result is not scrollable. Please use QueryOptions.setScroll()");
     return index.scroll(scrollId);