diff options
author | Matteo Mara <matteo.mara@sonarsource.com> | 2022-03-22 17:39:03 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-03-23 20:02:45 +0000 |
commit | f6a29b92cafe474d5ea62619aef7d7ffa6453d96 (patch) | |
tree | ee8ff747855758cef3366f9cab1835eae2b00e63 /server/sonar-server-common | |
parent | 15bf48aa6f306d9185bfeda978e37811dbf771ff (diff) | |
download | sonarqube-f6a29b92cafe474d5ea62619aef7d7ffa6453d96.tar.gz sonarqube-f6a29b92cafe474d5ea62619aef7d7ffa6453d96.zip |
SONAR-16129 Handle Owasp Top 10 2021 facet ordering
Diffstat (limited to 'server/sonar-server-common')
-rw-r--r-- | server/sonar-server-common/src/main/java/org/sonar/server/es/Facets.java | 27 |
1 files changed, 24 insertions, 3 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 ec610bd5ea5..21c9ea6b8f8 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 @@ -20,6 +20,7 @@ package org.sonar.server.es; import java.time.ZoneId; +import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.LinkedHashMap; @@ -47,7 +48,9 @@ public class Facets { public static final String SELECTED_SUB_AGG_NAME_SUFFIX = "_selected"; public static final String TOTAL = "total"; - private static final java.lang.String NO_DATA_PREFIX = "no_data_"; + private static final String NO_DATA_PREFIX = "no_data_"; + private static final String FILTER_SUFFIX = "_filter"; + private static final String FILTER_BY_RULE_PREFIX = "filter_by_rule_types_"; private final LinkedHashMap<String, LinkedHashMap<String, Long>> facetsByName; private final ZoneId timeZone; @@ -122,16 +125,34 @@ public class Facets { if (Filter.class.isAssignableFrom(aggregation.getClass())) { Filter filter = (Filter) aggregation; if (filter.getName().startsWith(NO_DATA_PREFIX)) { - LinkedHashMap<String, Long> facet = getOrCreateFacet(filter.getName().replaceFirst(NO_DATA_PREFIX,"")); + LinkedHashMap<String, Long> facet = getOrCreateFacet(filter.getName().replaceFirst(NO_DATA_PREFIX, "")); facet.put("NO_DATA", ((Filter) aggregation).getDocCount()); } } - for (Aggregation sub : aggregation.getAggregations()) { + for (Aggregation sub : getOrderedAggregations(aggregation)) { processAggregation(sub); } } + private static List<Aggregation> getOrderedAggregations(HasAggregations topAggregation) { + String topAggregationName = ((Aggregation) topAggregation).getName(); + List<Aggregation> orderedAggregations = new ArrayList<>(); + for (Aggregation aggregation : topAggregation.getAggregations()) { + if (isNameMatchingTopAggregation(topAggregationName, aggregation.getName())) { + orderedAggregations.add(0, aggregation); + } else { + orderedAggregations.add(aggregation); + } + } + return orderedAggregations; + } + + private static boolean isNameMatchingTopAggregation(String topAggregationName, String aggregationName) { + return aggregationName.equals(topAggregationName) || + aggregationName.equals(FILTER_BY_RULE_PREFIX + topAggregationName.replace(FILTER_SUFFIX, "")); + } + private void processDateHistogram(Histogram aggregation) { LinkedHashMap<String, Long> facet = getOrCreateFacet(aggregation.getName()); for (Histogram.Bucket value : aggregation.getBuckets()) { |