From f1525ab2b1fb18209f2cce91161a57c527f4c751 Mon Sep 17 00:00:00 2001 From: OrlovAlexander <35396155+OrlovAlexander85@users.noreply.github.com> Date: Mon, 27 May 2024 14:50:45 +0200 Subject: [PATCH] SONAR-22224 Add prioritizedRule flag to Issues index --- .../java/org/sonar/db/issue/IndexedIssueDto.java | 10 ++++++++++ .../java/org/sonar/db/issue/IndexedIssueDtoTest.java | 7 ++++--- .../java/org/sonar/server/issue/index/IssueDoc.java | 9 +++++++++ .../server/issue/index/IssueIndexDefinition.java | 12 +++++++----- .../issue/index/IssueIteratorForSingleChunk.java | 1 + 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IndexedIssueDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IndexedIssueDto.java index ac20921ca86..530e1718113 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IndexedIssueDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IndexedIssueDto.java @@ -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 impacts = new HashSet<>(); private Set 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; + } } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IndexedIssueDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IndexedIssueDtoTest.java index 2ce99d8031b..a50271bc1cb 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IndexedIssueDtoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IndexedIssueDtoTest.java @@ -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) diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueDoc.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueDoc.java index 83d37c8cc66..90c1bc3f016 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueDoc.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueDoc.java @@ -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; + } } diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIndexDefinition.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIndexDefinition.java index ad23ab677b2..088f435eb59 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIndexDefinition.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIndexDefinition.java @@ -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); } } diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIteratorForSingleChunk.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIteratorForSingleChunk.java index fad352719d5..d17baac5679 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIteratorForSingleChunk.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIteratorForSingleChunk.java @@ -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; } -- 2.39.5