aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao
diff options
context:
space:
mode:
authorLukasz Jarocki <lukasz.jarocki@sonarsource.com>2022-11-23 15:16:10 +0100
committersonartech <sonartech@sonarsource.com>2022-12-01 20:03:11 +0000
commit24d4519ea1b8a4426dd90e0bb80b2b09bd7a1c12 (patch)
tree43407e4c9983c83fe250ad65e0ea50b5e677c39d /server/sonar-db-dao
parent8f833f4b90d60e1a560e5d3ff3711482a3af67a5 (diff)
downloadsonarqube-24d4519ea1b8a4426dd90e0bb80b2b09bd7a1c12.tar.gz
sonarqube-24d4519ea1b8a4426dd90e0bb80b2b09bd7a1c12.zip
SONAR-17592 adding column messageFormattings to issues table
Diffstat (limited to 'server/sonar-db-dao')
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java22
-rw-r--r--server/sonar-db-dao/src/main/protobuf/db-issues.proto14
-rw-r--r--server/sonar-db-dao/src/schema/schema-sq.ddl3
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDtoTest.java27
4 files changed, 55 insertions, 11 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java
index 2e9fa59db67..1cbc7ee2660 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java
@@ -60,6 +60,7 @@ public final class IssueDto implements Serializable {
private String severity;
private boolean manualSeverity;
private String message;
+ private byte[] messageFormattings;
private Integer line;
private Double gap;
private Long effort;
@@ -114,6 +115,7 @@ public final class IssueDto implements Serializable {
.setLine(issue.line())
.setLocations((DbIssues.Locations) issue.getLocations())
.setMessage(issue.message())
+ .setMessageFormattings((byte[]) null)
.setGap(issue.gap())
.setEffort(issue.effortInMinutes())
.setResolution(issue.resolution())
@@ -163,6 +165,7 @@ public final class IssueDto implements Serializable {
.setLine(issue.line())
.setLocations((DbIssues.Locations) issue.getLocations())
.setMessage(issue.message())
+ .setMessageFormattings((byte[]) null)
.setGap(issue.gap())
.setEffort(issue.effortInMinutes())
.setResolution(issue.resolution())
@@ -262,6 +265,25 @@ public final class IssueDto implements Serializable {
return this;
}
+ public IssueDto setMessageFormattings(@Nullable byte[] messageFormattings) {
+ this.messageFormattings = messageFormattings;
+ return this;
+ }
+
+ public IssueDto setMessageFormattings(@Nullable DbIssues.MessageFormattings messageFormattings) {
+ if (messageFormattings == null) {
+ this.messageFormattings = null;
+ } else {
+ this.messageFormattings = messageFormattings.toByteArray();
+ }
+ return this;
+ }
+
+ @CheckForNull
+ public byte[] getMessageFormattings() {
+ return messageFormattings;
+ }
+
@CheckForNull
public Integer getLine() {
return line;
diff --git a/server/sonar-db-dao/src/main/protobuf/db-issues.proto b/server/sonar-db-dao/src/main/protobuf/db-issues.proto
index a094ea162ca..8672388eecc 100644
--- a/server/sonar-db-dao/src/main/protobuf/db-issues.proto
+++ b/server/sonar-db-dao/src/main/protobuf/db-issues.proto
@@ -54,4 +54,18 @@ message Location {
optional sonarqube.db.commons.TextRange text_range = 2;
optional string msg = 3;
optional string checksum = 4;
+ repeated MessageFormatting msgFormattings = 5;
+}
+message MessageFormattings {
+ repeated MessageFormatting messageFormatting = 1;
+}
+
+message MessageFormatting {
+ required int32 start = 1;
+ required int32 end = 2;
+ required MessageFormattingType type = 3;
+}
+
+enum MessageFormattingType {
+ CODE = 0;
}
diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl
index 3e0f5bcdde0..023646e06ff 100644
--- a/server/sonar-db-dao/src/schema/schema-sq.ddl
+++ b/server/sonar-db-dao/src/schema/schema-sq.ddl
@@ -428,7 +428,8 @@ CREATE TABLE "ISSUES"(
"ISSUE_TYPE" TINYINT,
"FROM_HOTSPOT" BOOLEAN,
"QUICK_FIX_AVAILABLE" BOOLEAN,
- "RULE_DESCRIPTION_CONTEXT_KEY" CHARACTER VARYING(50)
+ "RULE_DESCRIPTION_CONTEXT_KEY" CHARACTER VARYING(50),
+ "MESSAGE_FORMATTINGS" BINARY LARGE OBJECT
);
ALTER TABLE "ISSUES" ADD CONSTRAINT "PK_ISSUES" PRIMARY KEY("KEE");
CREATE INDEX "ISSUES_ASSIGNEE" ON "ISSUES"("ASSIGNEE" NULLS FIRST);
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDtoTest.java
index 53c2eb6e3e8..d90e7fc671f 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDtoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDtoTest.java
@@ -32,6 +32,7 @@ import org.sonar.api.rule.RuleKey;
import org.sonar.api.rules.RuleType;
import org.sonar.api.utils.Duration;
import org.sonar.core.issue.DefaultIssue;
+import org.sonar.db.protobuf.DbIssues;
import org.sonar.db.rule.RuleDto;
import static org.assertj.core.api.Assertions.assertThat;
@@ -40,8 +41,12 @@ public class IssueDtoTest {
private static final String TEST_CONTEXT_KEY = "test_context_key";
+ private static final DbIssues.MessageFormattings EXAMPLE_MESSAGE_FORMATTINGS = DbIssues.MessageFormattings.newBuilder()
+ .addMessageFormatting(DbIssues.MessageFormatting.newBuilder().setStart(0).setEnd(1).setType(DbIssues.MessageFormattingType.CODE)
+ .build()).build();
+
@Test
- public void set_issue_fields() {
+ public void toDefaultIssue_set_issue_fields() {
Date createdAt = DateUtils.addDays(new Date(), -5);
Date updatedAt = DateUtils.addDays(new Date(), -3);
Date closedAt = DateUtils.addDays(new Date(), -1);
@@ -64,6 +69,7 @@ public class IssueDtoTest {
.setLine(6)
.setSeverity("BLOCKER")
.setMessage("message")
+ .setMessageFormattings(EXAMPLE_MESSAGE_FORMATTINGS)
.setManualSeverity(true)
.setAssigneeUuid("perceval")
.setAuthorLogin("pierre")
@@ -89,6 +95,7 @@ public class IssueDtoTest {
assertThat(issue.line()).isEqualTo(6);
assertThat(issue.severity()).isEqualTo("BLOCKER");
assertThat(issue.message()).isEqualTo("message");
+ //assertThat(issue.getMessageFormatting()).isEqualTo(EXAMPLE_MESSAGE_FORMATTING); //TODO fix later SONAR-17592
assertThat(issue.manualSeverity()).isTrue();
assertThat(issue.assignee()).isEqualTo("perceval");
assertThat(issue.authorLogin()).isEqualTo("pierre");
@@ -150,20 +157,20 @@ public class IssueDtoTest {
containsExactly("key", RuleType.BUG.getDbConstant(), RuleKey.of("repo", "rule"));
assertThat(issueDto).extracting(IssueDto::getIssueCreationDate, IssueDto::getIssueCloseDate,
- IssueDto::getIssueUpdateDate, IssueDto::getSelectedAt, IssueDto::getUpdatedAt, IssueDto::getCreatedAt)
+ IssueDto::getIssueUpdateDate, IssueDto::getSelectedAt, IssueDto::getUpdatedAt, IssueDto::getCreatedAt)
.containsExactly(dateNow, dateNow, dateNow, dateNow.getTime(), now, now);
assertThat(issueDto).extracting(IssueDto::getLine, IssueDto::getMessage,
- IssueDto::getGap, IssueDto::getEffort, IssueDto::getResolution, IssueDto::getStatus, IssueDto::getSeverity)
+ IssueDto::getGap, IssueDto::getEffort, IssueDto::getResolution, IssueDto::getStatus, IssueDto::getSeverity)
.containsExactly(1, "message", 1.0, 1L, Issue.RESOLUTION_FALSE_POSITIVE, Issue.STATUS_CLOSED, "BLOCKER");
assertThat(issueDto).extracting(IssueDto::getTags, IssueDto::getAuthorLogin)
.containsExactly(Set.of("todo"), "admin");
assertThat(issueDto).extracting(IssueDto::isManualSeverity, IssueDto::getChecksum, IssueDto::getAssigneeUuid,
- IssueDto::isExternal, IssueDto::getComponentUuid, IssueDto::getComponentKey,
- IssueDto::getModuleUuidPath, IssueDto::getProjectUuid, IssueDto::getProjectKey,
- IssueDto::getRuleUuid)
+ IssueDto::isExternal, IssueDto::getComponentUuid, IssueDto::getComponentKey,
+ IssueDto::getModuleUuidPath, IssueDto::getProjectUuid, IssueDto::getProjectKey,
+ IssueDto::getRuleUuid)
.containsExactly(true, "123", "123", true, "123", "componentKey",
"path/to/module/uuid", "123", "projectKey", "ruleUuid");
@@ -184,19 +191,19 @@ public class IssueDtoTest {
containsExactly("key", RuleType.BUG.getDbConstant(), RuleKey.of("repo", "rule"));
assertThat(issueDto).extracting(IssueDto::getIssueCreationDate, IssueDto::getIssueCloseDate,
- IssueDto::getIssueUpdateDate, IssueDto::getSelectedAt, IssueDto::getUpdatedAt)
+ IssueDto::getIssueUpdateDate, IssueDto::getSelectedAt, IssueDto::getUpdatedAt)
.containsExactly(dateNow, dateNow, dateNow, dateNow.getTime(), now);
assertThat(issueDto).extracting(IssueDto::getLine, IssueDto::getMessage,
- IssueDto::getGap, IssueDto::getEffort, IssueDto::getResolution, IssueDto::getStatus, IssueDto::getSeverity)
+ IssueDto::getGap, IssueDto::getEffort, IssueDto::getResolution, IssueDto::getStatus, IssueDto::getSeverity)
.containsExactly(1, "message", 1.0, 1L, Issue.RESOLUTION_FALSE_POSITIVE, Issue.STATUS_CLOSED, "BLOCKER");
assertThat(issueDto).extracting(IssueDto::getTags, IssueDto::getAuthorLogin)
.containsExactly(Set.of("todo"), "admin");
assertThat(issueDto).extracting(IssueDto::isManualSeverity, IssueDto::getChecksum, IssueDto::getAssigneeUuid,
- IssueDto::isExternal, IssueDto::getComponentUuid, IssueDto::getComponentKey,
- IssueDto::getModuleUuidPath, IssueDto::getProjectUuid, IssueDto::getProjectKey)
+ IssueDto::isExternal, IssueDto::getComponentUuid, IssueDto::getComponentKey,
+ IssueDto::getModuleUuidPath, IssueDto::getProjectUuid, IssueDto::getProjectKey)
.containsExactly(true, "123", "123", true, "123", "componentKey",
"path/to/module/uuid", "123", "projectKey");