]> source.dussan.org Git - sonarqube.git/blob
47e0085f92457cb0b61290ee63741ee7534a173f
[sonarqube.git] /
1 /*
2  * SonarQube
3  * Copyright (C) 2009-2023 SonarSource SA
4  * mailto:info AT sonarsource DOT com
5  *
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.
10  *
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.
15  *
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.
19  */
20 package org.sonar.server.issue.ws.pull;
21
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;
26
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;
31
32 @ServerSide
33 public class PullActionProtobufObjectGenerator implements ProtobufObjectGenerator {
34
35   @Override
36   public IssuesPullQueryTimestamp generateTimestampMessage(long timestamp) {
37     IssuesPullQueryTimestamp.Builder responseBuilder = IssuesPullQueryTimestamp.newBuilder();
38     responseBuilder.setQueryTimestamp(timestamp);
39     return responseBuilder.build();
40   }
41
42   @Override
43   public IssueLite generateIssueMessage(IssueDto issueDto) {
44     IssueLite.Builder issueBuilder = IssueLite.newBuilder();
45     DbIssues.Locations mainLocation = issueDto.parseLocations();
46
47     Location.Builder locationBuilder = Location.newBuilder();
48     if (issueDto.getMessage() != null) {
49       locationBuilder.setMessage(issueDto.getMessage());
50     }
51     if (issueDto.getFilePath() != null) {
52       locationBuilder.setFilePath(issueDto.getFilePath());
53     }
54     if (mainLocation != null) {
55       TextRange textRange = buildTextRange(mainLocation);
56       locationBuilder.setTextRange(textRange);
57     }
58     Location location = locationBuilder.build();
59
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()));
66     }
67     issueBuilder.setType(Common.RuleType.forNumber(issueDto.getType()));
68     issueBuilder.setClosed(false);
69     issueBuilder.setMainLocation(location);
70
71     return issueBuilder.build();
72   }
73
74   @Override
75   public IssueLite generateClosedIssueMessage(String uuid) {
76     IssueLite.Builder issueBuilder = IssueLite.newBuilder();
77     issueBuilder.setKey(uuid);
78     issueBuilder.setClosed(true);
79     return issueBuilder.build();
80   }
81 }