3 * Copyright (C) 2009-2024 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.sonar.db.rule.RuleDto;
26 import org.sonarqube.ws.Common;
28 import static org.sonarqube.ws.Issues.IssueLite;
29 import static org.sonarqube.ws.Issues.IssuesPullQueryTimestamp;
30 import static org.sonarqube.ws.Issues.Location;
31 import static org.sonarqube.ws.Issues.TextRange;
34 public class PullActionProtobufObjectGenerator implements ProtobufObjectGenerator {
37 public IssuesPullQueryTimestamp generateTimestampMessage(long timestamp) {
38 IssuesPullQueryTimestamp.Builder responseBuilder = IssuesPullQueryTimestamp.newBuilder();
39 responseBuilder.setQueryTimestamp(timestamp);
40 return responseBuilder.build();
44 public IssueLite generateIssueMessage(IssueDto issueDto, RuleDto ruleDto) {
45 IssueLite.Builder issueBuilder = IssueLite.newBuilder();
46 DbIssues.Locations mainLocation = issueDto.parseLocations();
48 Location.Builder locationBuilder = Location.newBuilder();
49 if (issueDto.getMessage() != null) {
50 locationBuilder.setMessage(issueDto.getMessage());
52 if (issueDto.getFilePath() != null) {
53 locationBuilder.setFilePath(issueDto.getFilePath());
55 if (mainLocation != null) {
56 TextRange textRange = buildTextRange(mainLocation);
57 locationBuilder.setTextRange(textRange);
59 Location location = locationBuilder.build();
61 issueBuilder.setKey(issueDto.getKey());
62 if (issueDto.getIssueCreationTime() != null) {
63 issueBuilder.setCreationDate(issueDto.getIssueCreationTime());
65 issueBuilder.setResolved(issueDto.getStatus().equals(org.sonar.api.issue.Issue.STATUS_RESOLVED));
66 issueBuilder.setRuleKey(issueDto.getRuleKey().toString());
67 if (issueDto.isManualSeverity() && issueDto.getSeverity() != null) {
68 issueBuilder.setUserSeverity(Common.Severity.valueOf(issueDto.getSeverity()));
70 issueBuilder.setType(Common.RuleType.forNumber(issueDto.getType()));
71 issueBuilder.setClosed(false);
72 issueBuilder.setMainLocation(location);
74 return issueBuilder.build();
78 public IssueLite generateClosedIssueMessage(String uuid) {
79 IssueLite.Builder issueBuilder = IssueLite.newBuilder();
80 issueBuilder.setKey(uuid);
81 issueBuilder.setClosed(true);
82 return issueBuilder.build();