3 * Copyright (C) 2009-2022 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.qualitygate.changeevent;
22 import java.util.Objects;
23 import org.sonar.api.issue.Issue;
24 import org.sonar.api.rules.RuleType;
25 import org.sonar.core.issue.DefaultIssue;
27 class ChangedIssueImpl implements QGChangeEventListener.ChangedIssue {
28 private final String key;
29 private final QGChangeEventListener.Status status;
30 private final RuleType type;
31 private final String severity;
32 private final boolean fromAlm;
34 ChangedIssueImpl(DefaultIssue issue) {
38 ChangedIssueImpl(DefaultIssue issue, boolean fromAlm) {
39 this.key = issue.key();
40 this.status = statusOf(issue);
41 this.type = issue.type();
42 this.severity = issue.severity();
43 this.fromAlm = fromAlm;
46 static QGChangeEventListener.Status statusOf(DefaultIssue issue) {
47 switch (issue.status()) {
48 case Issue.STATUS_OPEN:
49 return QGChangeEventListener.Status.OPEN;
50 case Issue.STATUS_CONFIRMED:
51 return QGChangeEventListener.Status.CONFIRMED;
52 case Issue.STATUS_REOPENED:
53 return QGChangeEventListener.Status.REOPENED;
54 case Issue.STATUS_TO_REVIEW:
55 return QGChangeEventListener.Status.TO_REVIEW;
56 case Issue.STATUS_IN_REVIEW:
57 return QGChangeEventListener.Status.IN_REVIEW;
58 case Issue.STATUS_REVIEWED:
59 return QGChangeEventListener.Status.REVIEWED;
60 case Issue.STATUS_RESOLVED:
61 return statusOfResolved(issue);
63 throw new IllegalStateException("Unexpected status: " + issue.status());
67 private static QGChangeEventListener.Status statusOfResolved(DefaultIssue issue) {
68 String resolution = issue.resolution();
69 Objects.requireNonNull(resolution, "A resolved issue should have a resolution");
71 case Issue.RESOLUTION_FALSE_POSITIVE:
72 return QGChangeEventListener.Status.RESOLVED_FP;
73 case Issue.RESOLUTION_WONT_FIX:
74 return QGChangeEventListener.Status.RESOLVED_WF;
75 case Issue.RESOLUTION_FIXED:
76 return QGChangeEventListener.Status.RESOLVED_FIXED;
78 throw new IllegalStateException("Unexpected resolution for a resolved issue: " + resolution);
83 public String getKey() {
88 public QGChangeEventListener.Status getStatus() {
93 public RuleType getType() {
98 public String getSeverity() {
103 public boolean fromAlm() {
108 public String toString() {
109 return "ChangedIssueImpl{" +
110 "key='" + key + '\'' +
111 ", status=" + status +
113 ", severity=" + severity +
114 ", fromAlm=" + fromAlm +