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 {
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);
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
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();
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;
.setKee("EFGH")
.setSeverity("BLOCKER")
.setStatus("RESOLVED")
+ .setType(BUG)
.setResolution(null)
.setManualSeverity(false)
.setMessage(null)
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();
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;
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() {
.setManualSeverity(true)
.setStatus(Issue.STATUS_RESOLVED)
.setResolution(Issue.RESOLUTION_FIXED)
+ .setType(BUG)
.setFuncCreationDate(new Date());
indexIssues(issue);
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();
}
optional string checksum = 12;
optional string assignee_login = 13;
optional int64 creation_date = 14;
+ optional string type = 15;
}
message User {