001/*
002 * SonarQube, open source software quality management tool.
003 * Copyright (C) 2008-2014 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 */
020package org.sonar.wsclient.issue.internal;
021
022import org.sonar.wsclient.issue.Issue;
023import org.sonar.wsclient.issue.IssueComment;
024import org.sonar.wsclient.unmarshallers.JsonUtils;
025
026import javax.annotation.CheckForNull;
027
028import java.util.*;
029
030/**
031 * @since 3.6
032 */
033public class DefaultIssue implements Issue {
034
035  private final Map json;
036
037  DefaultIssue(Map json) {
038    this.json = json;
039  }
040
041  /**
042   * Unique key
043   */
044  public String key() {
045    return JsonUtils.getString(json, "key");
046  }
047
048  public Long componentId() {
049    return JsonUtils.getLong(json, "componentId");
050  }
051
052  public String componentKey() {
053    return JsonUtils.getString(json, "component");
054  }
055
056  public String projectKey() {
057    return JsonUtils.getString(json, "project");
058  }
059
060  public String ruleKey() {
061    return JsonUtils.getString(json, "rule");
062  }
063
064  public String severity() {
065    return JsonUtils.getString(json, "severity");
066  }
067
068  @CheckForNull
069  public String message() {
070    return JsonUtils.getString(json, "message");
071  }
072
073  @CheckForNull
074  public Integer line() {
075    return JsonUtils.getInteger(json, "line");
076  }
077
078  @CheckForNull
079  public String debt() {
080    return JsonUtils.getString(json, "debt");
081  }
082
083  public String status() {
084    return JsonUtils.getString(json, "status");
085  }
086
087  /**
088   * The resolution type. Null if the issue is not resolved.
089   */
090  @CheckForNull
091  public String resolution() {
092    return JsonUtils.getString(json, "resolution");
093  }
094
095  @CheckForNull
096  public String reporter() {
097    return JsonUtils.getString(json, "reporter");
098  }
099
100  /**
101   * Login of assignee. Null if issue is not assigned.
102   */
103  @CheckForNull
104  public String assignee() {
105    return JsonUtils.getString(json, "assignee");
106  }
107
108  /**
109   * SCM account
110   */
111  @CheckForNull
112  public String author() {
113    return JsonUtils.getString(json, "author");
114  }
115
116  @CheckForNull
117  public String actionPlan() {
118    return JsonUtils.getString(json, "actionPlan");
119  }
120
121  public Date creationDate() {
122    return JsonUtils.getDateTime(json, "creationDate");
123  }
124
125  public Date updateDate() {
126    return JsonUtils.getDateTime(json, "updateDate");
127  }
128
129  @CheckForNull
130  public Date closeDate() {
131    return JsonUtils.getDateTime(json, "closeDate");
132  }
133
134  @CheckForNull
135  public String attribute(String key) {
136    return attributes().get(key);
137  }
138
139  public Map<String, String> attributes() {
140    Map<String, String> attr = (Map<String, String>) json.get("attr");
141    if (attr == null) {
142      return Collections.emptyMap();
143    }
144    return attr;
145  }
146
147  /**
148   * Non-null list of comments
149   */
150  public List<IssueComment> comments() {
151    List<IssueComment> comments = new ArrayList<IssueComment>();
152    List<Map> jsonComments = (List<Map>) json.get("comments");
153    if (jsonComments != null) {
154      for (Map jsonComment : jsonComments) {
155        comments.add(new DefaultIssueComment(jsonComment));
156      }
157    }
158    return comments;
159  }
160}