diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-04-21 15:02:55 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-04-25 10:51:31 +0200 |
commit | e564fecaa4473dae48517778ab947bdaec7efbb3 (patch) | |
tree | c2bb6aec3dee7e68457b5f710faa0f1954919b53 | |
parent | 18484ac7409f25ce403641fba715340486a78d8b (diff) | |
download | sonarqube-e564fecaa4473dae48517778ab947bdaec7efbb3.tar.gz sonarqube-e564fecaa4473dae48517778ab947bdaec7efbb3.zip |
SONAR-9083 Return type in /batch/issues
6 files changed, 18 insertions, 33 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/batch/IssuesAction.java b/server/sonar-server/src/main/java/org/sonar/server/batch/IssuesAction.java index 7c0338f2c5c..e73f74597c2 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/batch/IssuesAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/batch/IssuesAction.java @@ -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); diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueDoc.java b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueDoc.java index 914db627bec..4f649b9343e 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueDoc.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueDoc.java @@ -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 diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java index 28818f9e6c3..0b87824c029 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java @@ -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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/batch/IssuesActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/batch/IssuesActionTest.java index cf3660cb902..da684380a75 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/batch/IssuesActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/batch/IssuesActionTest.java @@ -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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java index 2e1525e956d..82937b7944a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java @@ -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(); } diff --git a/sonar-scanner-protocol/src/main/protobuf/scanner_input.proto b/sonar-scanner-protocol/src/main/protobuf/scanner_input.proto index 654ef4fc9cd..959eb5e97d8 100644 --- a/sonar-scanner-protocol/src/main/protobuf/scanner_input.proto +++ b/sonar-scanner-protocol/src/main/protobuf/scanner_input.proto @@ -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 { |