]> source.dussan.org Git - sonarqube.git/blob
6a0bd2c77747ac09793da4f0bb93734f979a186c
[sonarqube.git] /
1 /*
2  * SonarQube
3  * Copyright (C) 2009-2024 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.sonar.db.rule.RuleDto;
26 import org.sonarqube.ws.Common;
27
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;
32
33 @ServerSide
34 public class PullActionProtobufObjectGenerator implements ProtobufObjectGenerator {
35
36   @Override
37   public IssuesPullQueryTimestamp generateTimestampMessage(long timestamp) {
38     IssuesPullQueryTimestamp.Builder responseBuilder = IssuesPullQueryTimestamp.newBuilder();
39     responseBuilder.setQueryTimestamp(timestamp);
40     return responseBuilder.build();
41   }
42
43   @Override
44   public IssueLite generateIssueMessage(IssueDto issueDto, RuleDto ruleDto) {
45     IssueLite.Builder issueBuilder = IssueLite.newBuilder();
46     DbIssues.Locations mainLocation = issueDto.parseLocations();
47
48     Location.Builder locationBuilder = Location.newBuilder();
49     if (issueDto.getMessage() != null) {
50       locationBuilder.setMessage(issueDto.getMessage());
51     }
52     if (issueDto.getFilePath() != null) {
53       locationBuilder.setFilePath(issueDto.getFilePath());
54     }
55     if (mainLocation != null) {
56       TextRange textRange = buildTextRange(mainLocation);
57       locationBuilder.setTextRange(textRange);
58     }
59     Location location = locationBuilder.build();
60
61     issueBuilder.setKey(issueDto.getKey());
62     if (issueDto.getIssueCreationTime() != null) {
63       issueBuilder.setCreationDate(issueDto.getIssueCreationTime());
64     }
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()));
69     }
70     issueBuilder.setType(Common.RuleType.forNumber(issueDto.getType()));
71     issueBuilder.setClosed(false);
72     issueBuilder.setMainLocation(location);
73
74     return issueBuilder.build();
75   }
76
77   @Override
78   public IssueLite generateClosedIssueMessage(String uuid) {
79     IssueLite.Builder issueBuilder = IssueLite.newBuilder();
80     issueBuilder.setKey(uuid);
81     issueBuilder.setClosed(true);
82     return issueBuilder.build();
83   }
84 }