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 @Override 045 public String key() { 046 return JsonUtils.getString(json, "key"); 047 } 048 049 @Override 050 public Long componentId() { 051 return JsonUtils.getLong(json, "componentId"); 052 } 053 054 @Override 055 public String componentKey() { 056 return JsonUtils.getString(json, "component"); 057 } 058 059 @Override 060 public String projectKey() { 061 return JsonUtils.getString(json, "project"); 062 } 063 064 @Override 065 public String ruleKey() { 066 return JsonUtils.getString(json, "rule"); 067 } 068 069 @Override 070 public String severity() { 071 return JsonUtils.getString(json, "severity"); 072 } 073 074 @Override 075 @CheckForNull 076 public String message() { 077 return JsonUtils.getString(json, "message"); 078 } 079 080 @Override 081 @CheckForNull 082 public Integer line() { 083 return JsonUtils.getInteger(json, "line"); 084 } 085 086 @Override 087 @CheckForNull 088 public String debt() { 089 return JsonUtils.getString(json, "debt"); 090 } 091 092 @Override 093 public String status() { 094 return JsonUtils.getString(json, "status"); 095 } 096 097 /** 098 * The resolution type. Null if the issue is not resolved. 099 */ 100 @Override 101 @CheckForNull 102 public String resolution() { 103 return JsonUtils.getString(json, "resolution"); 104 } 105 106 @Override 107 @CheckForNull 108 public String reporter() { 109 return JsonUtils.getString(json, "reporter"); 110 } 111 112 /** 113 * Login of assignee. Null if issue is not assigned. 114 */ 115 @Override 116 @CheckForNull 117 public String assignee() { 118 return JsonUtils.getString(json, "assignee"); 119 } 120 121 /** 122 * SCM account 123 */ 124 @Override 125 @CheckForNull 126 public String author() { 127 return JsonUtils.getString(json, "author"); 128 } 129 130 @Override 131 @CheckForNull 132 public String actionPlan() { 133 return JsonUtils.getString(json, "actionPlan"); 134 } 135 136 @Override 137 public Date creationDate() { 138 return JsonUtils.getDateTime(json, "creationDate"); 139 } 140 141 @Override 142 public Date updateDate() { 143 return JsonUtils.getDateTime(json, "updateDate"); 144 } 145 146 @Override 147 @CheckForNull 148 public Date closeDate() { 149 return JsonUtils.getDateTime(json, "closeDate"); 150 } 151 152 @Override 153 @CheckForNull 154 public String attribute(String key) { 155 return attributes().get(key); 156 } 157 158 @Override 159 public Map<String, String> attributes() { 160 Map<String, String> attr = (Map<String, String>) json.get("attr"); 161 if (attr == null) { 162 return Collections.emptyMap(); 163 } 164 return attr; 165 } 166 167 /** 168 * Non-null list of comments 169 */ 170 @Override 171 public List<IssueComment> comments() { 172 List<IssueComment> comments = new ArrayList<IssueComment>(); 173 List<Map> jsonComments = (List<Map>) json.get("comments"); 174 if (jsonComments != null) { 175 for (Map jsonComment : jsonComments) { 176 comments.add(new DefaultIssueComment(jsonComment)); 177 } 178 } 179 return comments; 180 } 181}