aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server-common
diff options
context:
space:
mode:
authorDDMili <130993898+dejan-milisavljevic-sonarsource@users.noreply.github.com>2024-05-31 16:19:26 +0200
committersonartech <sonartech@sonarsource.com>2024-06-03 20:02:59 +0000
commit8ec69dbae88e4b5d38315d0f4d1b8544ddceac3f (patch)
treebf653dfae836ba2feabb1a63c7f9ece35ce38c55 /server/sonar-server-common
parent82474726c053724fea320ee773e26f53961e5dc7 (diff)
downloadsonarqube-8ec69dbae88e4b5d38315d0f4d1b8544ddceac3f.tar.gz
sonarqube-8ec69dbae88e4b5d38315d0f4d1b8544ddceac3f.zip
SONAR-22224 Add prioritizedRule to rules/search api
Diffstat (limited to 'server/sonar-server-common')
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java9
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexer.java3
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndex.java9
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndexDefinition.java4
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleQuery.java10
5 files changed, 33 insertions, 2 deletions
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java b/server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java
index eedbf89adc6..f602bb21a5e 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java
@@ -21,6 +21,8 @@ package org.sonar.server.qualityprofile.index;
import com.google.common.collect.Maps;
import java.util.Map;
+import java.util.Optional;
+import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.server.es.BaseDoc;
import org.sonar.server.qualityprofile.ActiveRuleInheritance;
@@ -30,6 +32,7 @@ import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_PROFILE_UUID;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_SEVERITY;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_UUID;
+import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_PRIORITIZED_RULE;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_RULE_UUID;
import static org.sonar.server.rule.index.RuleIndexDefinition.TYPE_ACTIVE_RULE;
@@ -87,6 +90,12 @@ public class ActiveRuleDoc extends BaseDoc {
return this;
}
+ ActiveRuleDoc setPrioritizedRule(@Nullable Boolean b) {
+ Boolean notNull = Optional.ofNullable(b).orElse(Boolean.FALSE);
+ setField(FIELD_PRIORITIZED_RULE, notNull);
+ return this;
+ }
+
ActiveRuleInheritance getInheritance() {
String inheritance = getNullableField(FIELD_ACTIVE_RULE_INHERITANCE);
if (inheritance == null || inheritance.isEmpty() ||
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexer.java b/server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexer.java
index 7b91c40c152..d21651b379e 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexer.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexer.java
@@ -225,7 +225,8 @@ public class ActiveRuleIndexer implements ResilientIndexer {
ActiveRuleDoc doc = new ActiveRuleDoc(dto.getUuid())
.setRuleUuid(dto.getRuleUuid())
.setRuleProfileUuid(dto.getRuleProfileUuid())
- .setSeverity(SeverityUtil.getSeverityFromOrdinal(dto.getSeverity()));
+ .setSeverity(SeverityUtil.getSeverityFromOrdinal(dto.getSeverity()))
+ .setPrioritizedRule(dto.getPrioritizedRule());
// all the fields must be present, even if value is null
String inheritance = dto.getInheritance();
doc.setInheritance(inheritance == null ? ActiveRuleInheritance.NONE.name() : inheritance);
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 4416dc50cd9..c3b6f438e97 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
@@ -96,6 +96,7 @@ import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_IMPA
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_INHERITANCE;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_PROFILE_UUID;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_SEVERITY;
+import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_PRIORITIZED_RULE;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_RULE_CLEAN_CODE_ATTRIBUTE_CATEGORY;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_RULE_CREATED_AT;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_RULE_CWE;
@@ -443,6 +444,7 @@ public class RuleIndex {
addTermFilter(activeRuleFilter, FIELD_ACTIVE_RULE_PROFILE_UUID, profile.getRulesProfileUuid());
addTermFilter(activeRuleFilter, FIELD_ACTIVE_RULE_INHERITANCE, query.getInheritance());
addTermFilter(activeRuleFilter, FIELD_ACTIVE_RULE_SEVERITY, query.getActiveSeverities());
+ addTermFilter(activeRuleFilter, FIELD_PRIORITIZED_RULE, query.getPrioritizedRule());
// ChildQuery
QueryBuilder childQuery;
@@ -473,6 +475,13 @@ public class RuleIndex {
return filter;
}
+ private static BoolQueryBuilder addTermFilter(BoolQueryBuilder filter, String field, @Nullable Boolean value) {
+ if (value != null) {
+ filter.must(QueryBuilders.termQuery(field, value));
+ }
+ return filter;
+ }
+
private static Map<String, AggregationBuilder> getFacets(RuleQuery query, SearchOptions options, QueryBuilder queryBuilder,
Map<String, QueryBuilder> filters) {
Map<String, AggregationBuilder> aggregations = new HashMap<>();
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndexDefinition.java b/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndexDefinition.java
index 6a27bb34c32..6da248e2eac 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndexDefinition.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndexDefinition.java
@@ -86,6 +86,7 @@ public class RuleIndexDefinition implements IndexDefinition {
public static final String SUB_FIELD_SEVERITY = "severity";
public static final String FIELD_RULE_IMPACT_SOFTWARE_QUALITY = FIELD_RULE_IMPACTS + "." + SUB_FIELD_SOFTWARE_QUALITY;
public static final String FIELD_RULE_IMPACT_SEVERITY = FIELD_RULE_IMPACTS + "." + SUB_FIELD_SEVERITY;
+ public static final String FIELD_PRIORITIZED_RULE = "activeRule_prioritizedRule";
private final Configuration config;
private final boolean enableSource;
@@ -166,6 +167,7 @@ public class RuleIndexDefinition implements IndexDefinition {
.keywordFieldBuilder(FIELD_ACTIVE_RULE_UUID).disableNorms().build()
.keywordFieldBuilder(FIELD_ACTIVE_RULE_PROFILE_UUID).disableNorms().build()
.keywordFieldBuilder(FIELD_ACTIVE_RULE_INHERITANCE).disableNorms().build()
- .keywordFieldBuilder(FIELD_ACTIVE_RULE_SEVERITY).disableNorms().build();
+ .keywordFieldBuilder(FIELD_ACTIVE_RULE_SEVERITY).disableNorms().build()
+ .createBooleanField(FIELD_PRIORITIZED_RULE);
}
}
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleQuery.java b/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleQuery.java
index b3f4abb0aa4..7c46f846f6b 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleQuery.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleQuery.java
@@ -61,6 +61,7 @@ public class RuleQuery {
private Collection<String> impactSeverities;
private Collection<String> impactSoftwareQualities;
private Collection<String> cleanCodeAttributesCategories;
+ private Boolean prioritizedRule;
@CheckForNull
@@ -369,4 +370,13 @@ public class RuleQuery {
return this;
}
+ @Nullable
+ public Boolean getPrioritizedRule() {
+ return prioritizedRule;
+ }
+
+ public RuleQuery setPrioritizedRule(@Nullable Boolean prioritizedRule) {
+ this.prioritizedRule = prioritizedRule;
+ return this;
+ }
}