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 */ 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 028 import java.util.*; 029 030 /** 031 * @since 3.6 032 */ 033 public 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 String componentKey() { 049 return JsonUtils.getString(json, "component"); 050 } 051 052 public Long componentId() { 053 return JsonUtils.getLong(json, "componentId"); 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 Double effortToFix() { 080 return JsonUtils.getDouble(json, "effortToFix"); 081 } 082 083 @CheckForNull 084 public String debt() { 085 return JsonUtils.getString(json, "debt"); 086 } 087 088 public String status() { 089 return JsonUtils.getString(json, "status"); 090 } 091 092 /** 093 * The resolution type. Null if the issue is not resolved. 094 */ 095 @CheckForNull 096 public String resolution() { 097 return JsonUtils.getString(json, "resolution"); 098 } 099 100 @CheckForNull 101 public String reporter() { 102 return JsonUtils.getString(json, "reporter"); 103 } 104 105 /** 106 * Login of assignee. Null if issue is not assigned. 107 */ 108 @CheckForNull 109 public String assignee() { 110 return JsonUtils.getString(json, "assignee"); 111 } 112 113 /** 114 * SCM account 115 */ 116 @CheckForNull 117 public String author() { 118 return JsonUtils.getString(json, "author"); 119 } 120 121 @CheckForNull 122 public String actionPlan() { 123 return JsonUtils.getString(json, "actionPlan"); 124 } 125 126 public Date creationDate() { 127 return JsonUtils.getDateTime(json, "creationDate"); 128 } 129 130 public Date updateDate() { 131 return JsonUtils.getDateTime(json, "updateDate"); 132 } 133 134 @CheckForNull 135 public Date closeDate() { 136 return JsonUtils.getDateTime(json, "closeDate"); 137 } 138 139 @CheckForNull 140 public String attribute(String key) { 141 return attributes().get(key); 142 } 143 144 public Map<String, String> attributes() { 145 Map<String, String> attr = (Map<String, String>) json.get("attr"); 146 if (attr == null) { 147 return Collections.emptyMap(); 148 } 149 return attr; 150 } 151 152 /** 153 * Non-null list of comments 154 */ 155 public List<IssueComment> comments() { 156 List<IssueComment> comments = new ArrayList<IssueComment>(); 157 List<Map> jsonComments = (List<Map>) json.get("comments"); 158 if (jsonComments != null) { 159 for (Map jsonComment : jsonComments) { 160 comments.add(new DefaultIssueComment(jsonComment)); 161 } 162 } 163 return comments; 164 } 165 }