aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server-common
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2020-12-03 09:37:58 +0100
committersonartech <sonartech@sonarsource.com>2020-12-03 20:06:38 +0000
commit6741d92467d65179e77e910612d91e55b84e660d (patch)
tree32c8cb53394f16f09609438435ea3062c5fc281e /server/sonar-server-common
parent19c1858b5e72a19332e6a77fd532712e07b47a77 (diff)
downloadsonarqube-6741d92467d65179e77e910612d91e55b84e660d.tar.gz
sonarqube-6741d92467d65179e77e910612d91e55b84e660d.zip
SONAR-8427 Add a timeZone param to api/issues/search
Diffstat (limited to 'server/sonar-server-common')
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/es/Facets.java12
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/es/SearchIdResult.java4
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/es/SearchResult.java4
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/issue/SearchRequest.java11
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndex.java2
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/user/index/UserIndex.java2
6 files changed, 23 insertions, 12 deletions
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/es/Facets.java b/server/sonar-server-common/src/main/java/org/sonar/server/es/Facets.java
index 27e7d089ae8..02b6b7e9344 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/es/Facets.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/es/Facets.java
@@ -19,13 +19,13 @@
*/
package org.sonar.server.es;
+import java.time.ZoneId;
import java.util.Collections;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.TimeZone;
import javax.annotation.CheckForNull;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
@@ -50,14 +50,14 @@ public class Facets {
private static final java.lang.String NO_DATA_PREFIX = "no_data_";
private final LinkedHashMap<String, LinkedHashMap<String, Long>> facetsByName;
- private final TimeZone timeZone;
+ private final ZoneId timeZone;
- public Facets(LinkedHashMap<String, LinkedHashMap<String, Long>> facetsByName, TimeZone timeZone) {
+ public Facets(LinkedHashMap<String, LinkedHashMap<String, Long>> facetsByName, ZoneId timeZone) {
this.facetsByName = facetsByName;
this.timeZone = timeZone;
}
- public Facets(SearchResponse response, TimeZone timeZone) {
+ public Facets(SearchResponse response, ZoneId timeZone) {
this.facetsByName = new LinkedHashMap<>();
this.timeZone = timeZone;
Aggregations aggregations = response.getAggregations();
@@ -144,9 +144,9 @@ public class Facets {
}
}
- private static String dateTimeToDate(String timestamp, TimeZone timeZone) {
+ private static String dateTimeToDate(String timestamp, ZoneId timeZone) {
Date date = parseDateTime(timestamp);
- return date.toInstant().atZone(timeZone.toZoneId()).toLocalDate().toString();
+ return date.toInstant().atZone(timeZone).toLocalDate().toString();
}
private void processSum(Sum aggregation) {
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/es/SearchIdResult.java b/server/sonar-server-common/src/main/java/org/sonar/server/es/SearchIdResult.java
index c369f0759a9..6783537663f 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/es/SearchIdResult.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/es/SearchIdResult.java
@@ -20,9 +20,9 @@
package org.sonar.server.es;
import com.google.common.base.Function;
+import java.time.ZoneId;
import java.util.ArrayList;
import java.util.List;
-import java.util.TimeZone;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.search.SearchHit;
@@ -34,7 +34,7 @@ public class SearchIdResult<ID> {
private final Facets facets;
private final long total;
- public SearchIdResult(SearchResponse response, Function<String, ID> converter, TimeZone timeZone) {
+ public SearchIdResult(SearchResponse response, Function<String, ID> converter, ZoneId timeZone) {
this.facets = new Facets(response, timeZone);
this.total = response.getHits().getTotalHits().value;
this.uuids = convertToIds(response.getHits(), converter);
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/es/SearchResult.java b/server/sonar-server-common/src/main/java/org/sonar/server/es/SearchResult.java
index 996ba9afd1d..7dfd2989359 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/es/SearchResult.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/es/SearchResult.java
@@ -19,9 +19,9 @@
*/
package org.sonar.server.es;
+import java.time.ZoneId;
import java.util.List;
import java.util.Map;
-import java.util.TimeZone;
import java.util.function.Function;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.elasticsearch.action.search.SearchResponse;
@@ -32,7 +32,7 @@ public class SearchResult<DOC extends BaseDoc> {
private final Facets facets;
private final long total;
- public SearchResult(SearchResponse response, Function<Map<String, Object>, DOC> converter, TimeZone timeZone) {
+ public SearchResult(SearchResponse response, Function<Map<String, Object>, DOC> converter, ZoneId timeZone) {
this.facets = new Facets(response, timeZone);
this.total = response.getHits().getTotalHits().value;
this.docs = EsUtils.convertToDocs(response.getHits(), converter);
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/SearchRequest.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/SearchRequest.java
index 3d3ddec151d..4ce3719c363 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/SearchRequest.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/SearchRequest.java
@@ -67,6 +67,7 @@ public class SearchRequest {
private List<String> sansTop25;
private List<String> sonarsourceSecurity;
private List<String> cwe;
+ private String timeZone;
public SearchRequest() {
// nothing to do here
@@ -469,4 +470,14 @@ public class SearchRequest {
this.pullRequest = pullRequest;
return this;
}
+
+ @CheckForNull
+ public String getTimeZone() {
+ return timeZone;
+ }
+
+ public SearchRequest setTimeZone(@Nullable String timeZone) {
+ this.timeZone = timeZone;
+ return this;
+ }
}
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndex.java b/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndex.java
index ead195c2e16..c21619b9464 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndex.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndex.java
@@ -172,7 +172,7 @@ public class RuleIndex {
SearchRequest esSearch = EsClient.prepareSearch(TYPE_RULE)
.source(sourceBuilder);
- return new SearchIdResult<>(client.search(esSearch), input -> input, system2.getDefaultTimeZone());
+ return new SearchIdResult<>(client.search(esSearch), input -> input, system2.getDefaultTimeZone().toZoneId());
}
/**
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/user/index/UserIndex.java b/server/sonar-server-common/src/main/java/org/sonar/server/user/index/UserIndex.java
index 75d142cd6ee..de6f7a0206e 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/user/index/UserIndex.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/user/index/UserIndex.java
@@ -115,7 +115,7 @@ public class UserIndex {
SearchRequest request = EsClient.prepareSearch(UserIndexDefinition.TYPE_USER)
.source(searchSourceBuilder.query(boolQuery().must(esQuery).filter(filter)));
- return new SearchResult<>(esClient.search(request), UserDoc::new, system2.getDefaultTimeZone());
+ return new SearchResult<>(esClient.search(request), UserDoc::new, system2.getDefaultTimeZone().toZoneId());
}
}