001 /*
002 * SonarQube, open source software quality management tool.
003 * Copyright (C) 2008-2013 SonarSource
004 * mailto:contact AT sonarsource DOT com
005 *
006 * SonarQube is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 3 of the License, or (at your option) any later version.
010 *
011 * SonarQube is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014 * Lesser General Public License for more details.
015 *
016 * You should have received a copy of the GNU Lesser General Public License
017 * along with this program; if not, write to the Free Software Foundation,
018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
019 */
020 package org.sonar.wsclient.issue.internal;
021
022 import org.sonar.wsclient.issue.Issue;
023 import org.sonar.wsclient.issue.IssueComment;
024 import org.sonar.wsclient.unmarshallers.JsonUtils;
025
026 import javax.annotation.CheckForNull;
027 import java.util.*;
028
029 /**
030 * @since 3.6
031 */
032 public class DefaultIssue implements Issue {
033
034 private final Map json;
035
036 DefaultIssue(Map json) {
037 this.json = json;
038 }
039
040 /**
041 * Unique key
042 */
043 public String key() {
044 return JsonUtils.getString(json, "key");
045 }
046
047 public String componentKey() {
048 return JsonUtils.getString(json, "component");
049 }
050
051 public String projectKey() {
052 return JsonUtils.getString(json, "project");
053 }
054
055 public String ruleKey() {
056 return JsonUtils.getString(json, "rule");
057 }
058
059 public String severity() {
060 return JsonUtils.getString(json, "severity");
061 }
062
063 @CheckForNull
064 public String message() {
065 return JsonUtils.getString(json, "message");
066 }
067
068 @CheckForNull
069 public Integer line() {
070 return JsonUtils.getInteger(json, "line");
071 }
072
073 @CheckForNull
074 public Double effortToFix() {
075 return JsonUtils.getDouble(json, "effortToFix");
076 }
077
078 public String status() {
079 return JsonUtils.getString(json, "status");
080 }
081
082 /**
083 * The resolution type. Null if the issue is not resolved.
084 */
085 @CheckForNull
086 public String resolution() {
087 return JsonUtils.getString(json, "resolution");
088 }
089
090 @CheckForNull
091 public String reporter() {
092 return JsonUtils.getString(json, "reporter");
093 }
094
095 /**
096 * Login of assignee. Null if issue is not assigned.
097 */
098 @CheckForNull
099 public String assignee() {
100 return JsonUtils.getString(json, "assignee");
101 }
102
103 /**
104 * SCM account
105 */
106 @CheckForNull
107 public String author() {
108 return JsonUtils.getString(json, "author");
109 }
110
111 @CheckForNull
112 public String actionPlan() {
113 return JsonUtils.getString(json, "actionPlan");
114 }
115
116 public Date creationDate() {
117 return JsonUtils.getDateTime(json, "creationDate");
118 }
119
120 public Date updateDate() {
121 return JsonUtils.getDateTime(json, "updateDate");
122 }
123
124 @CheckForNull
125 public Date closeDate() {
126 return JsonUtils.getDateTime(json, "closeDate");
127 }
128
129 @CheckForNull
130 public String attribute(String key) {
131 return attributes().get(key);
132 }
133
134 public Map<String, String> attributes() {
135 Map<String, String> attr = (Map<String,String>) json.get("attr");
136 if (attr == null) {
137 return Collections.emptyMap();
138 }
139 return attr;
140 }
141
142 /**
143 * Non-null list of comments
144 */
145 public List<IssueComment> comments() {
146 List<IssueComment> comments = new ArrayList<IssueComment>();
147 List<Map> jsonComments = (List<Map>) json.get("comments");
148 if (jsonComments != null) {
149 for (Map jsonComment : jsonComments) {
150 comments.add(new DefaultIssueComment(jsonComment));
151 }
152 }
153 return comments;
154 }
155 }