]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9083 Return type in /batch/issues
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 21 Apr 2017 13:02:55 +0000 (15:02 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 25 Apr 2017 08:51:31 +0000 (10:51 +0200)
server/sonar-server/src/main/java/org/sonar/server/batch/IssuesAction.java
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueDoc.java
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java
server/sonar-server/src/test/java/org/sonar/server/batch/IssuesActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java
sonar-scanner-protocol/src/main/protobuf/scanner_input.proto

index 7c0338f2c5c3cbc91758b86e2ded3e70941fcd2e..e73f74597c2f72508be6404d5da1d7e9cdce190c 100644 (file)
@@ -40,6 +40,7 @@ import org.sonarqube.ws.MediaTypes;
 
 import static com.google.common.collect.Maps.newHashMap;
 import static org.sonar.api.web.UserRole.USER;
+import static org.sonar.core.util.Protobuf.setNullable;
 import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001;
 
 public class IssuesAction implements BatchWsAction {
@@ -95,35 +96,18 @@ public class IssuesAction implements BatchWsAction {
   private static void handleIssue(IssueDoc issue, ScannerInput.ServerIssue.Builder issueBuilder, Map<String, String> keysByUUid, OutputStream out) {
     issueBuilder.setKey(issue.key());
     issueBuilder.setModuleKey(keysByUUid.get(issue.moduleUuid()));
-    String path = issue.filePath();
-    if (path != null) {
-      issueBuilder.setPath(path);
-    }
+    setNullable(issue.filePath(), issueBuilder::setPath);
     issueBuilder.setRuleRepository(issue.ruleKey().repository());
     issueBuilder.setRuleKey(issue.ruleKey().rule());
-    String checksum = issue.checksum();
-    if (checksum != null) {
-      issueBuilder.setChecksum(checksum);
-    }
-    String assigneeLogin = issue.assignee();
-    if (assigneeLogin != null) {
-      issueBuilder.setAssigneeLogin(assigneeLogin);
-    }
-    Integer line = issue.line();
-    if (line != null) {
-      issueBuilder.setLine(line);
-    }
-    String message = issue.message();
-    if (message != null) {
-      issueBuilder.setMsg(message);
-    }
+    setNullable(issue.checksum(), issueBuilder::setChecksum);
+    setNullable(issue.assignee(), issueBuilder::setAssigneeLogin);
+    setNullable(issue.line(), issueBuilder::setLine);
+    setNullable(issue.message(), issueBuilder::setMsg);
     issueBuilder.setSeverity(org.sonar.scanner.protocol.Constants.Severity.valueOf(issue.severity()));
     issueBuilder.setManualSeverity(issue.isManualSeverity());
     issueBuilder.setStatus(issue.status());
-    String resolution = issue.resolution();
-    if (resolution != null) {
-      issueBuilder.setResolution(resolution);
-    }
+    setNullable(issue.resolution(), issueBuilder::setResolution);
+    issueBuilder.setType(issue.type().name());
     issueBuilder.setCreationDate(issue.creationDate().getTime());
     try {
       issueBuilder.build().writeDelimitedTo(out);
index 914db627becc79b9e9dd8137cc9fd037a065a76b..4f649b9343e69e9694e9fe05166f64d0d99cad96 100644 (file)
@@ -226,13 +226,8 @@ public class IssueDoc extends BaseDoc implements Issue {
     return null;
   }
 
-  @CheckForNull
   public RuleType type() {
-    String type = getNullableField(IssueIndexDefinition.FIELD_ISSUE_TYPE);
-    if (type != null) {
-      return RuleType.valueOf(type);
-    }
-    return null;
+    return RuleType.valueOf(getField(IssueIndexDefinition.FIELD_ISSUE_TYPE));
   }
 
   @Override
index 28818f9e6c3c8253b593539ce7ad47739658d20c..0b87824c029ddd8338cdee599f03b353703a12cd 100644 (file)
@@ -685,7 +685,7 @@ public class IssueIndex {
           IssueIndexDefinition.FIELD_ISSUE_FILE_PATH, IssueIndexDefinition.FIELD_ISSUE_SEVERITY, IssueIndexDefinition.FIELD_ISSUE_MANUAL_SEVERITY,
           IssueIndexDefinition.FIELD_ISSUE_RESOLUTION, IssueIndexDefinition.FIELD_ISSUE_STATUS, IssueIndexDefinition.FIELD_ISSUE_ASSIGNEE,
           IssueIndexDefinition.FIELD_ISSUE_LINE, IssueIndexDefinition.FIELD_ISSUE_MESSAGE, IssueIndexDefinition.FIELD_ISSUE_CHECKSUM,
-          IssueIndexDefinition.FIELD_ISSUE_FUNC_CREATED_AT},
+          IssueIndexDefinition.FIELD_ISSUE_TYPE, IssueIndexDefinition.FIELD_ISSUE_FUNC_CREATED_AT},
         null)
       .setQuery(boolQuery().must(matchAllQuery()).filter(filter));
     SearchResponse response = requestBuilder.get();
index cf3660cb902b172dea3e471176845aaafaf9cdf8..da684380a7573b4f621d4bb61c5d0911a6172b8b 100644 (file)
@@ -48,6 +48,7 @@ import org.sonar.server.ws.TestResponse;
 import org.sonar.server.ws.WsActionTester;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.api.rules.RuleType.BUG;
 import static org.sonar.db.component.ComponentTesting.newFileDto;
 import static org.sonar.db.component.ComponentTesting.newModuleDto;
 import static org.sonar.db.component.ComponentTesting.newProjectDto;
@@ -94,6 +95,7 @@ public class IssuesActionTest {
       .setKee("EFGH")
       .setSeverity("BLOCKER")
       .setStatus("RESOLVED")
+      .setType(BUG)
       .setResolution(null)
       .setManualSeverity(false)
       .setMessage(null)
@@ -115,6 +117,7 @@ public class IssuesActionTest {
     assertThat(serverIssue.hasResolution()).isFalse();
     assertThat(serverIssue.getStatus()).isEqualTo("RESOLVED");
     assertThat(serverIssue.getSeverity()).isEqualTo(Severity.BLOCKER);
+    assertThat(serverIssue.getType()).isEqualTo(BUG.name());
     assertThat(serverIssue.getManualSeverity()).isFalse();
     assertThat(serverIssue.hasChecksum()).isFalse();
     assertThat(serverIssue.hasAssigneeLogin()).isFalse();
index 2e1525e956d8fc341367b22b9d188e16ff85c42c..82937b7944ad2246799fb60867b570f69d6eab46 100644 (file)
@@ -68,6 +68,7 @@ import static org.assertj.core.api.Assertions.entry;
 import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
+import static org.sonar.api.rules.RuleType.BUG;
 import static org.sonar.api.utils.DateUtils.parseDate;
 import static org.sonar.api.utils.DateUtils.parseDateTime;
 import static org.sonar.db.component.ComponentTesting.newFileDto;
@@ -98,8 +99,7 @@ public class IssueIndexTest {
   private RuleIndexer ruleIndexer = new RuleIndexer(tester.client(), db.getDbClient());
   private PermissionIndexerTester authorizationIndexerTester = new PermissionIndexerTester(tester, issueIndexer);
 
-  private IssueIndex underTest = new IssueIndex(tester.client(), system2, userSessionRule, new AuthorizationTypeSupport(userSessionRule)
-  );
+  private IssueIndex underTest = new IssueIndex(tester.client(), system2, userSessionRule, new AuthorizationTypeSupport(userSessionRule));
 
   @Before
   public void setUp() {
@@ -1250,6 +1250,7 @@ public class IssueIndexTest {
       .setManualSeverity(true)
       .setStatus(Issue.STATUS_RESOLVED)
       .setResolution(Issue.RESOLUTION_FIXED)
+      .setType(BUG)
       .setFuncCreationDate(new Date());
     indexIssues(issue);
 
@@ -1268,6 +1269,7 @@ public class IssueIndexTest {
     assertThat(result.isManualSeverity()).isTrue();
     assertThat(result.status()).isEqualTo(Issue.STATUS_RESOLVED);
     assertThat(result.resolution()).isEqualTo(Issue.RESOLUTION_FIXED);
+    assertThat(result.type()).isEqualTo(BUG);
     assertThat(result.creationDate()).isNotNull();
   }
 
index 654ef4fc9cd9ed7db4e5ea040a9d2d94576fc119..959eb5e97d8fe036b106d9e3f7a1f66811344dd5 100644 (file)
@@ -48,6 +48,7 @@ message ServerIssue {
     optional string checksum = 12;
     optional string assignee_login = 13;
     optional int64 creation_date = 14;
+    optional string type = 15;
 }
 
 message User {