]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6013 Return overriddenSeverity instead of severity and do not return anymore...
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 22 Jan 2015 16:20:29 +0000 (17:20 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 22 Jan 2015 16:20:33 +0000 (17:20 +0100)
14 files changed:
server/sonar-server/src/main/java/org/sonar/server/batch/IssuesAction.java
server/sonar-server/src/test/java/org/sonar/server/batch/IssuesActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/db/IssueDaoTest.java
server/sonar-server/src/test/resources/org/sonar/server/batch/IssuesActionTest/issues_on_module-expected.json
server/sonar-server/src/test/resources/org/sonar/server/batch/IssuesActionTest/issues_on_project-expected.json
server/sonar-server/src/test/resources/org/sonar/server/batch/IssuesActionTest/return_only_manual_severity-expected.json [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/batch/IssuesActionTest/return_only_manual_severity.xml [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/batch/IssuesActionTest/shared.xml
server/sonar-server/src/test/resources/org/sonar/server/issue/db/IssueDaoTest/select_non_closed_issues_by_module_uuid.xml
server/sonar-server/src/test/resources/org/sonar/server/issue/db/IssueDaoTest/select_non_closed_issues_by_project_uuid.xml
sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/issues/PreviousIssue.java
sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/issues/PreviousIssueHelperTest.java
sonar-core/src/main/java/org/sonar/core/issue/db/BatchIssueDto.java
sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml

index 95b3a3fcca59ee95181dddec5a55932d270b1e25..b8dc23cee32e1d69b991a88f3eccdc33f756a1b2 100644 (file)
@@ -114,11 +114,11 @@ public class IssuesAction implements RequestHandler {
           .setComponentKey(batchIssueDto.getComponentKey())
           .setChecksum(batchIssueDto.getChecksum())
           .setAssigneeLogin(batchIssueDto.getAssigneeLogin())
-          .setAssigneeFullname(batchIssueDto.getAssigneeName())
           .setLine(batchIssueDto.getLine())
           .setRuleKey(batchIssueDto.getRuleRepo(), batchIssueDto.getRuleKey())
           .setMessage(batchIssueDto.getMessage())
           .setResolution(batchIssueDto.getResolution())
+          .setOverriddenSeverity(batchIssueDto.isManualSeverity() ? batchIssueDto.getSeverity() : null)
           .setStatus(batchIssueDto.getStatus());
       }
       return null;
index ca142cd48272312bccadc07476d40698cdbecf8f..bd70521030860472fc4181286a6d869481aac9e2 100644 (file)
@@ -83,6 +83,16 @@ public class IssuesActionTest {
     request.execute().assertJson(getClass(), "issues_on_project-expected.json");
   }
 
+  @Test
+  public void return_only_manual_severity() throws Exception {
+    db.prepareDbUnit(getClass(), "return_only_manual_severity.xml");
+
+    MockUserSession.set().setLogin("henry").setGlobalPermissions(GlobalPermissions.PREVIEW_EXECUTION).addComponentPermission(UserRole.USER, PROJECT_KEY, PROJECT_KEY);
+
+    WsTester.TestRequest request = tester.newGetRequest("batch", "issues").setParam("key", PROJECT_KEY);
+    request.execute().assertJson(getClass(), "return_only_manual_severity-expected.json");
+  }
+
   @Test
   public void return_issues_on_module() throws Exception {
     db.prepareDbUnit(getClass(), "shared.xml");
index 54a4d403171632c1531d48c383d5099cd8e50b34..ed157d4de9570e9e522d1df6593d03ffeaf0e26f 100644 (file)
@@ -25,6 +25,7 @@ import org.junit.Before;
 import org.junit.Test;
 import org.sonar.api.issue.Issue;
 import org.sonar.api.rule.RuleKey;
+import org.sonar.api.rule.Severity;
 import org.sonar.api.utils.DateUtils;
 import org.sonar.core.component.ComponentDto;
 import org.sonar.core.issue.db.BatchIssueDto;
@@ -155,10 +156,11 @@ public class IssueDaoTest extends AbstractDaoTestCase {
     assertThat(batchIssueDto.getLine()).isEqualTo(200);
     assertThat(batchIssueDto.getResolution()).isEqualTo(Issue.RESOLUTION_FALSE_POSITIVE);
     assertThat(batchIssueDto.getStatus()).isEqualTo(Issue.STATUS_RESOLVED);
+    assertThat(batchIssueDto.getSeverity()).isEqualTo(Severity.BLOCKER);
+    assertThat(batchIssueDto.isManualSeverity()).isTrue();
     assertThat(batchIssueDto.getComponentKey()).isEqualTo("Sample.java");
     assertThat(batchIssueDto.getChecksum()).isEqualTo("123456");
     assertThat(batchIssueDto.getAssigneeLogin()).isEqualTo("john");
-    assertThat(batchIssueDto.getAssigneeName()).isEqualTo("John Doo");
   }
 
   @Test
@@ -183,10 +185,11 @@ public class IssueDaoTest extends AbstractDaoTestCase {
     assertThat(batchIssueDto.getLine()).isEqualTo(200);
     assertThat(batchIssueDto.getResolution()).isEqualTo(Issue.RESOLUTION_FALSE_POSITIVE);
     assertThat(batchIssueDto.getStatus()).isEqualTo(Issue.STATUS_RESOLVED);
+    assertThat(batchIssueDto.getSeverity()).isEqualTo(Severity.BLOCKER);
+    assertThat(batchIssueDto.isManualSeverity()).isTrue();
     assertThat(batchIssueDto.getComponentKey()).isEqualTo("Sample.java");
     assertThat(batchIssueDto.getChecksum()).isEqualTo("123456");
     assertThat(batchIssueDto.getAssigneeLogin()).isEqualTo("john");
-    assertThat(batchIssueDto.getAssigneeName()).isEqualTo("John Doo");
   }
 
   @Test
index 491791042f980c98e56ac9c6ec7e100b2e8698ca..a19dad630434953a28665713b130904bf3961880 100644 (file)
@@ -9,8 +9,7 @@
     "resolution": "FALSE-POSITIVE",
     "status": "RESOLVED",
     "checksum": "123456",
-    "assigneeLogin": "john",
-    "assigneeFullname": "John Doo"
+    "assigneeLogin": "john"
   }
 ]
 
index 491791042f980c98e56ac9c6ec7e100b2e8698ca..a19dad630434953a28665713b130904bf3961880 100644 (file)
@@ -9,8 +9,7 @@
     "resolution": "FALSE-POSITIVE",
     "status": "RESOLVED",
     "checksum": "123456",
-    "assigneeLogin": "john",
-    "assigneeFullname": "John Doo"
+    "assigneeLogin": "john"
   }
 ]
 
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/IssuesActionTest/return_only_manual_severity-expected.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/IssuesActionTest/return_only_manual_severity-expected.json
new file mode 100644 (file)
index 0000000..3716f04
--- /dev/null
@@ -0,0 +1,15 @@
+[
+  {
+    "key": "FGHI",
+    "componentKey": "Action.java",
+    "ruleKey": "API",
+    "ruleRepo": "manual",
+    "line": 201,
+    "message": "Do not use this method",
+    "status": "OPEN",
+    "overriddenSeverity": "CRITICAL",
+    "checksum": "234567",
+    "assigneeLogin": "john"
+  }
+]
+
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/IssuesActionTest/return_only_manual_severity.xml b/server/sonar-server/src/test/resources/org/sonar/server/batch/IssuesActionTest/return_only_manual_severity.xml
new file mode 100644 (file)
index 0000000..798a1eb
--- /dev/null
@@ -0,0 +1,38 @@
+<dataset>
+
+  <!-- Multi module project -->
+  <projects id="399" kee="struts" root_id="[null]" qualifier="TRK" scope="PRJ" uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="." path="[null]"/>
+  <projects id="400" kee="struts-core" root_id="399" qualifier="BRC" scope="PRJ" uuid="BCDE" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD.BCDE."
+            path="struts-core"/>
+  <projects id="401" kee="Action.java" root_id="400" qualifier="CLA" scope="PRJ" uuid="CDEF" project_uuid="ABCD" module_uuid="BCDE" module_uuid_path=".ABCD.BCDE."
+            path="src/main/java/Action.java"/>
+
+  <rules id="501" tags="[null]" system_tags="[null]" plugin_rule_key="API" plugin_name="manual" language="[null]"/>
+
+  <!-- Open Issue with manual severity on a file -->
+  <issues
+      id="101"
+      kee="FGHI"
+      component_id="401"
+      root_component_id="399"
+      rule_id="501"
+      severity="CRITICAL"
+      manual_severity="[true]"
+      message="Do not use this method"
+      line="201"
+      effort_to_fix="[null]"
+      status="OPEN"
+      resolution="[null]"
+      checksum="234567"
+      reporter="user"
+      assignee="john"
+      author_login="[null]"
+      issue_attributes="[null]"
+      issue_creation_date="2013-04-16"
+      issue_update_date="2013-04-16"
+      issue_close_date="2013-04-16"
+      created_at="1400000000000"
+      updated_at="[null]"
+      />
+
+</dataset>
index 2d199b069a8e33958d8dd36be435b39ee1143a9d..36efd6773128d7c9209e526388b928d718305000 100644 (file)
@@ -9,8 +9,6 @@
 
   <rules id="500" tags="[null]" system_tags="[null]" plugin_rule_key="AvoidCycle" plugin_name="squid" language="java"/>
 
-  <users id="10" login="john" name="John Doo" active="[true]"/>
-
   <!-- Open Issue on a file -->
   <issues
       id="100"
index 197ddde6a39ab5e6ba91b8e1f835f6e272b26b87..cf95656f2a1a9669e9d40d8b75e792553fa09232 100644 (file)
       root_component_id="1000"
       rule_id="500"
       severity="BLOCKER"
-      manual_severity="[false]"
+      manual_severity="[true]"
       message="Avoid this"
       line="200"
       effort_to_fix="[null]"
index 197ddde6a39ab5e6ba91b8e1f835f6e272b26b87..cf95656f2a1a9669e9d40d8b75e792553fa09232 100644 (file)
       root_component_id="1000"
       rule_id="500"
       severity="BLOCKER"
-      manual_severity="[false]"
+      manual_severity="[true]"
       message="Avoid this"
       line="200"
       effort_to_fix="[null]"
index 32432f731e70925dc347df2dd4e7c3dc711d080d..27afc945c299016d1c95b417815af5eb7c4c63c9 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.batch.protocol.input.issues;
 
+import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 
 public class PreviousIssue {
@@ -29,12 +30,11 @@ public class PreviousIssue {
   private String ruleRepo;
   private Integer line;
   private String message;
-  private String severity;
+  private String overriddenSeverity;
   private String resolution;
   private String status;
   private String checksum;
   private String assigneeLogin;
-  private String assigneeFullname;
 
   public PreviousIssue setKey(String key) {
     this.key = key;
@@ -90,13 +90,14 @@ public class PreviousIssue {
     return status;
   }
 
-  public PreviousIssue setSeverity(String severity) {
-    this.severity = severity;
+  public PreviousIssue setOverriddenSeverity(@Nullable String overriddenSeverity) {
+    this.overriddenSeverity = overriddenSeverity;
     return this;
   }
 
-  public String severity() {
-    return severity;
+  @CheckForNull
+  public String overriddenSeverity() {
+    return overriddenSeverity;
   }
 
   public PreviousIssue setChecksum(String checksum) {
@@ -117,15 +118,6 @@ public class PreviousIssue {
     return assigneeLogin;
   }
 
-  public PreviousIssue setAssigneeFullname(String assigneeFullname) {
-    this.assigneeFullname = assigneeFullname;
-    return this;
-  }
-
-  public String assigneeFullname() {
-    return assigneeFullname;
-  }
-
   public PreviousIssue setRuleKey(String ruleRepo, String ruleKey) {
     this.ruleRepo = ruleRepo;
     this.ruleKey = ruleKey;
index 1462bb32e23a74ba694985e3b263b3b8a6772e8b..c36431c7e14cec70da78dcd654672ba2f27cfb6f 100644 (file)
@@ -42,12 +42,11 @@ public class PreviousIssueHelperTest {
     issue1.setRuleKey("repokey", "rulekey");
     issue1.setLine(2);
     issue1.setMessage("message");
-    issue1.setSeverity("severity");
+    issue1.setOverriddenSeverity("severity");
     issue1.setResolution("resolution");
     issue1.setStatus("status");
     issue1.setChecksum("checksum");
     issue1.setAssigneeLogin("login");
-    issue1.setAssigneeFullname("fullname");
     PreviousIssue issue2 = new PreviousIssue();
     issue2.setKey("key2");
 
@@ -58,7 +57,7 @@ public class PreviousIssueHelperTest {
 
     JSONAssert
       .assertEquals(
-        "[{\"key\": \"key1\", \"componentKey\": \"key\", \"ruleKey\": \"rulekey\", \"ruleRepo\": \"repokey\", \"line\": 2,\"message\": \"message\", \"severity\": \"severity\", \"resolution\": \"resolution\", \"status\": \"status\", \"checksum\": \"checksum\",\"assigneeLogin\": \"login\", \"assigneeFullname\": \"fullname\"},"
+        "[{\"key\": \"key1\", \"componentKey\": \"key\", \"ruleKey\": \"rulekey\", \"ruleRepo\": \"repokey\", \"line\": 2,\"message\": \"message\", \"overriddenSeverity\": \"severity\", \"resolution\": \"resolution\", \"status\": \"status\", \"checksum\": \"checksum\",\"assigneeLogin\": \"login\"},"
           +
           "{\"key\": \"key2\"}]",
         out.getBuffer().toString(), true);
@@ -77,7 +76,7 @@ public class PreviousIssueHelperTest {
     StringWriter out = new StringWriter();
     PreviousIssueHelper helper = PreviousIssueHelper.create(out);
     StringReader reader = new StringReader(
-      "[{\"key\": \"key1\", \"componentKey\": \"key\", \"ruleKey\": \"rulekey\", \"ruleRepo\": \"repokey\", \"line\": 2,\"message\": \"message\", \"severity\": \"severity\", \"resolution\": \"resolution\", \"status\": \"status\", \"checksum\": \"checksum\",\"assigneeLogin\": \"login\", \"assigneeFullname\": \"fullname\"},"
+      "[{\"key\": \"key1\", \"componentKey\": \"key\", \"ruleKey\": \"rulekey\", \"ruleRepo\": \"repokey\", \"line\": 2,\"message\": \"message\", \"overriddenSeverity\": \"severity\", \"resolution\": \"resolution\", \"status\": \"status\", \"checksum\": \"checksum\",\"assigneeLogin\": \"login\"},"
         +
         "{\"key\": \"key2\"}]");
 
@@ -93,12 +92,11 @@ public class PreviousIssueHelperTest {
     assertThat(issue1.ruleKey()).isEqualTo("rulekey");
     assertThat(issue1.line()).isEqualTo(2);
     assertThat(issue1.message()).isEqualTo("message");
-    assertThat(issue1.severity()).isEqualTo("severity");
+    assertThat(issue1.overriddenSeverity()).isEqualTo("severity");
     assertThat(issue1.resolution()).isEqualTo("resolution");
     assertThat(issue1.status()).isEqualTo("status");
     assertThat(issue1.checksum()).isEqualTo("checksum");
     assertThat(issue1.assigneeLogin()).isEqualTo("login");
-    assertThat(issue1.assigneeFullname()).isEqualTo("fullname");
 
     assertThat(issue2.key()).isEqualTo("key2");
     helper.close();
index bc576daf4176a8e34c58ea191ed4fe3e6623fed1..e9c4ed7f516e5b69e470ff5aa27154f65f8a2d90 100644 (file)
@@ -26,10 +26,11 @@ public class BatchIssueDto {
   private String message;
   private Integer line;
   private String status;
+  private String severity;
+  private boolean manualSeverity;
   private String resolution;
   private String checksum;
   private String assigneeLogin;
-  private String assigneeName;
   private String componentKey;
   private String ruleKey;
   private String ruleRepo;
@@ -43,15 +44,6 @@ public class BatchIssueDto {
     return this;
   }
 
-  public String getAssigneeName() {
-    return assigneeName;
-  }
-
-  public BatchIssueDto setAssigneeName(String assigneeName) {
-    this.assigneeName = assigneeName;
-    return this;
-  }
-
   public String getChecksum() {
     return checksum;
   }
@@ -132,4 +124,22 @@ public class BatchIssueDto {
     this.status = status;
     return this;
   }
+
+  public boolean isManualSeverity() {
+    return manualSeverity;
+  }
+
+  public BatchIssueDto setManualSeverity(boolean manualSeverity) {
+    this.manualSeverity = manualSeverity;
+    return this;
+  }
+
+  public String getSeverity() {
+    return severity;
+  }
+
+  public BatchIssueDto setSeverity(String severity) {
+    this.severity = severity;
+    return this;
+  }
 }
index 2e0228f95817a2a244ba6097ae2e702776d8833a..bd1a61b84d7493cf8ef752d33f3235ee2537d195 100644 (file)
     i.message as message,
     i.line as line,
     i.status as status,
+    i.severity as severity,
+    i.manual_severity as manualSeverity,
     i.resolution as resolution,
     i.checksum as checksum,
+    i.assignee as assigneeLogin,
     r.plugin_rule_key as ruleKey,
     r.plugin_name as ruleRepo,
-    component.kee as componentKey,
-    i.assignee as assigneeLogin,
-    u.name as assigneeName
+    component.kee as componentKey
     FROM issues i
     INNER JOIN (SELECT p.id,p.kee FROM projects p WHERE p.module_uuid=#{uuid} OR p.uuid=#{uuid}) component ON component.id=i.component_id
     INNER JOIN rules r ON r.id=i.rule_id
-    LEFT OUTER JOIN users u ON u.login=i.assignee
     WHERE i.status &lt;&gt; 'CLOSED'
   </select>
 
     i.message as message,
     i.line as line,
     i.status as status,
+    i.severity as severity,
+    i.manual_severity as manualSeverity,
     i.resolution as resolution,
     i.checksum as checksum,
+    i.assignee as assigneeLogin,
     r.plugin_rule_key as ruleKey,
     r.plugin_name as ruleRepo,
-    component.kee as componentKey,
-    i.assignee as assigneeLogin,
-    u.name as assigneeName
+    component.kee as componentKey
     FROM issues i
     INNER JOIN projects component on component.id=i.component_id
     INNER JOIN projects project on project.uuid=component.project_uuid AND project.uuid=#{uuid}
     INNER JOIN rules r ON r.id=i.rule_id
-    LEFT OUTER JOIN users u ON u.login=i.assignee
     WHERE i.status &lt;&gt; 'CLOSED'
   </select>