]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-22224 Add prioritizedRule flag to Issues index
authorOrlovAlexander <35396155+OrlovAlexander85@users.noreply.github.com>
Mon, 27 May 2024 12:50:45 +0000 (14:50 +0200)
committersonartech <sonartech@sonarsource.com>
Mon, 3 Jun 2024 20:02:58 +0000 (20:02 +0000)
server/sonar-db-dao/src/main/java/org/sonar/db/issue/IndexedIssueDto.java
server/sonar-db-dao/src/test/java/org/sonar/db/issue/IndexedIssueDtoTest.java
server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueDoc.java
server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIndexDefinition.java
server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIteratorForSingleChunk.java

index ac20921ca864c27bb90cc98025c1bcb333c1f69b..530e17181132f03198a021925ff004ccaba533b4 100644 (file)
@@ -58,6 +58,7 @@ public final class IndexedIssueDto {
   private String qualifier = null;
   private boolean isNewCodeReferenceIssue = false;
   private String codeVariants = null;
+  private boolean prioritizedRule = false;
 
   private Set<ImpactDto> impacts = new HashSet<>();
   private Set<ImpactDto> ruleDefaultImpacts = new HashSet<>();
@@ -339,4 +340,13 @@ public final class IndexedIssueDto {
     this.ruleCleanCodeAttribute = ruleCleanCodeAttribute;
     return this;
   }
+
+  public boolean isPrioritizedRule(){
+    return prioritizedRule;
+  }
+
+  public IndexedIssueDto setPrioritizedRule(boolean prioritizedRule){
+    this.prioritizedRule = prioritizedRule;
+    return this;
+  }
 }
index 2ce99d8031b1f508baedc0696f3b64c8e1cad178..a50271bc1cbeca9cc44533ec3065f3bd96f3aae0 100644 (file)
@@ -60,7 +60,8 @@ class IndexedIssueDtoTest {
       .setSeverity("severity")
       .setTags("tags")
       .setIssueType(6)
-      .setBranchUuid("branchUuid");
+      .setBranchUuid("branchUuid")
+      .setPrioritizedRule(true);
 
     indexedIssueDto.getImpacts().add(new ImpactDto().setSoftwareQuality(SoftwareQuality.SECURITY).setSeverity(Severity.HIGH));
     indexedIssueDto.getRuleDefaultImpacts().add(new ImpactDto().setSoftwareQuality(SoftwareQuality.MAINTAINABILITY).setSeverity(Severity.MEDIUM));
@@ -76,11 +77,11 @@ class IndexedIssueDtoTest {
         IndexedIssueDto::getPath, IndexedIssueDto::getProjectUuid, IndexedIssueDto::getQualifier, IndexedIssueDto::getResolution,
         IndexedIssueDto::getRuleUuid, IndexedIssueDto::getScope, IndexedIssueDto::getSeverity, IndexedIssueDto::getTags,
         IndexedIssueDto::getIssueType,
-        IndexedIssueDto::getBranchUuid)
+        IndexedIssueDto::getBranchUuid, IndexedIssueDto::isPrioritizedRule)
       .containsExactly("issueKey", "assignee", "authorLogin", "status", true, "cleanCodeAttribute", "ruleCleanCodeAttribute",
         "codeVariants", "securityStandards",
         "componentUuid", 1L, 2L, 3L, 4L, true, "language", 5, "path", "projectUuid", "qualifier", "resolution", "ruleUuid",
-        "scope", "severity", "tags", 6, "branchUuid");
+        "scope", "severity", "tags", 6, "branchUuid", true);
 
     assertThat(indexedIssueDto.getImpacts())
       .extracting(ImpactDto::getSoftwareQuality, ImpactDto::getSeverity)
index 83d37c8cc66c034ed3416cdbe9783279cddc685b..90c1bc3f0166fb745b16ed637a09552a1adee336 100644 (file)
@@ -424,4 +424,13 @@ public class IssueDoc extends BaseDoc {
     setField(IssueIndexDefinition.FIELD_ISSUE_CODE_VARIANTS, codeVariants);
     return this;
   }
+
+  public boolean isPrioritizedRule(){
+    return getField(IssueIndexDefinition.FIELD_PRIORITIZED_RULE);
+  }
+
+  public IssueDoc setPrioritizedRule(boolean prioritizedRule){
+    setField(IssueIndexDefinition.FIELD_PRIORITIZED_RULE, prioritizedRule);
+    return this;
+  }
 }
index ad23ab677b20d637fdf41db484f8a63f6d03038f..088f435eb59668e9c3ad4157fa25c1b8e619b43c 100644 (file)
@@ -111,6 +111,7 @@ public class IssueIndexDefinition implements IndexDefinition {
   public static final String SUB_FIELD_SEVERITY = "severity";
   public static final String FIELD_ISSUE_IMPACT_SOFTWARE_QUALITY = FIELD_ISSUE_IMPACTS + "." + SUB_FIELD_SOFTWARE_QUALITY;
   public static final String FIELD_ISSUE_IMPACT_SEVERITY = FIELD_ISSUE_IMPACTS + "." + SUB_FIELD_SEVERITY;
+  public static final String FIELD_PRIORITIZED_RULE = "prioritizedRule";
 
   private final Configuration config;
   private final boolean enableSource;
@@ -136,11 +137,11 @@ public class IssueIndexDefinition implements IndexDefinition {
   @Override
   public void define(IndexDefinitionContext context) {
     NewAuthorizedIndex index = context.createWithAuthorization(
-      DESCRIPTOR,
-      newBuilder(config)
-        .setRefreshInterval(MANUAL_REFRESH_INTERVAL)
-        .setDefaultNbOfShards(5)
-        .build())
+        DESCRIPTOR,
+        newBuilder(config)
+          .setRefreshInterval(MANUAL_REFRESH_INTERVAL)
+          .setDefaultNbOfShards(5)
+          .build())
       .setEnableSource(enableSource);
 
     TypeMapping mapping = index.createTypeMapping(TYPE_ISSUE);
@@ -185,5 +186,6 @@ public class IssueIndexDefinition implements IndexDefinition {
     mapping.keywordFieldBuilder(FIELD_ISSUE_VULNERABILITY_PROBABILITY).disableNorms().build();
     mapping.createBooleanField(FIELD_ISSUE_NEW_CODE_REFERENCE);
     mapping.keywordFieldBuilder(FIELD_ISSUE_CODE_VARIANTS).disableNorms().build();
+    mapping.createBooleanField(FIELD_PRIORITIZED_RULE);
   }
 }
index fad352719d533039f9a5d10ca60866f923f1c4a5..d17baac56792783f43325a0d62ed4e2cb8c1411e 100644 (file)
@@ -143,6 +143,7 @@ class IssueIteratorForSingleChunk implements IssueIterator {
     doc.setIsNewCodeReference(indexedIssueDto.isNewCodeReferenceIssue());
     String codeVariants = indexedIssueDto.getCodeVariants();
     doc.setCodeVariants(STRING_LIST_SPLITTER.splitToList(codeVariants == null ? "" : codeVariants));
+    doc.setPrioritizedRule(indexedIssueDto.isPrioritizedRule());
     return doc;
 
   }