3 * Copyright (C) 2009-2023 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.server.issue.ws.pull;
22 import org.sonar.api.server.ServerSide;
23 import org.sonar.db.issue.IssueDto;
24 import org.sonar.db.protobuf.DbIssues;
25 import org.sonarqube.ws.Common;
27 import static org.sonarqube.ws.Issues.IssueLite;
28 import static org.sonarqube.ws.Issues.IssuesPullQueryTimestamp;
29 import static org.sonarqube.ws.Issues.Location;
30 import static org.sonarqube.ws.Issues.TextRange;
33 public class PullActionProtobufObjectGenerator implements ProtobufObjectGenerator {
36 public IssuesPullQueryTimestamp generateTimestampMessage(long timestamp) {
37 IssuesPullQueryTimestamp.Builder responseBuilder = IssuesPullQueryTimestamp.newBuilder();
38 responseBuilder.setQueryTimestamp(timestamp);
39 return responseBuilder.build();
43 public IssueLite generateIssueMessage(IssueDto issueDto) {
44 IssueLite.Builder issueBuilder = IssueLite.newBuilder();
45 DbIssues.Locations mainLocation = issueDto.parseLocations();
47 Location.Builder locationBuilder = Location.newBuilder();
48 if (issueDto.getMessage() != null) {
49 locationBuilder.setMessage(issueDto.getMessage());
51 if (issueDto.getFilePath() != null) {
52 locationBuilder.setFilePath(issueDto.getFilePath());
54 if (mainLocation != null) {
55 TextRange textRange = buildTextRange(mainLocation);
56 locationBuilder.setTextRange(textRange);
58 Location location = locationBuilder.build();
60 issueBuilder.setKey(issueDto.getKey());
61 issueBuilder.setCreationDate(issueDto.getCreatedAt());
62 issueBuilder.setResolved(issueDto.getStatus().equals(org.sonar.api.issue.Issue.STATUS_RESOLVED));
63 issueBuilder.setRuleKey(issueDto.getRuleKey().toString());
64 if (issueDto.isManualSeverity() && issueDto.getSeverity() != null) {
65 issueBuilder.setUserSeverity(Common.Severity.valueOf(issueDto.getSeverity()));
67 issueBuilder.setType(Common.RuleType.forNumber(issueDto.getType()));
68 issueBuilder.setClosed(false);
69 issueBuilder.setMainLocation(location);
71 return issueBuilder.build();
75 public IssueLite generateClosedIssueMessage(String uuid) {
76 IssueLite.Builder issueBuilder = IssueLite.newBuilder();
77 issueBuilder.setKey(uuid);
78 issueBuilder.setClosed(true);
79 return issueBuilder.build();