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.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_REVIEWED:
57 return QGChangeEventListener.Status.REVIEWED;
58 case Issue.STATUS_RESOLVED:
59 return statusOfResolved(issue);
61 throw new IllegalStateException("Unexpected status: " + issue.status());
65 private static QGChangeEventListener.Status statusOfResolved(DefaultIssue issue) {
66 String resolution = issue.resolution();
67 Objects.requireNonNull(resolution, "A resolved issue should have a resolution");
69 case Issue.RESOLUTION_FALSE_POSITIVE:
70 return QGChangeEventListener.Status.RESOLVED_FP;
71 case Issue.RESOLUTION_WONT_FIX:
72 return QGChangeEventListener.Status.RESOLVED_WF;
73 case Issue.RESOLUTION_FIXED:
74 return QGChangeEventListener.Status.RESOLVED_FIXED;
76 throw new IllegalStateException("Unexpected resolution for a resolved issue: " + resolution);
81 public String getKey() {
86 public QGChangeEventListener.Status getStatus() {
91 public RuleType getType() {
96 public String getSeverity() {
101 public boolean fromAlm() {
106 public String toString() {
107 return "ChangedIssueImpl{" +
108 "key='" + key + '\'' +
109 ", status=" + status +
111 ", severity=" + severity +
112 ", fromAlm=" + fromAlm +